### Example RGA Driver Version Output (debugfs) Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md This example shows the output format when querying the driver version via debugfs, indicating the driver name and its version number. ```shell cat /sys/kernel/debug/rkrga/driver_version RGA multicore Device Driver: v1.2.23 ``` -------------------------------- ### Example RGA2 Driver Version Output (debugfs) Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md This example shows the output format when querying the RGA2 driver version via debugfs, specifying the driver name and its version. ```shell cat /sys/kernel/debug/rkrga/driver_version RGA2 Device Driver: v2.1.0 ``` -------------------------------- ### Linux RGA Detailed Log Output Example Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md An example of detailed RGA log output on a Linux system, showing rendering mode, source/destination buffer details, and MMU configuration. ```log render_mode=0 rotate_mode=0 src:[0,a681a008,a68fb008],x-y[0,0],w-h[1280,720],vw-vh[1280,720],f=0 dst:[0,a6495008,a6576008],x-y[0,0],w-h[1280,720],vw-vh[1280,720],f=0 pat:[0,0,0],x-y[0,0],w-h[0,0],vw-vh[0,0],f=0 ROP:[0,0,0], LUT[0] color:[0,0,0,0,0] MMU:[1,0,80000521] mode[0,0,0,0,0] gr_color_x [0, 0, 0] gr_color_x [0, 0, 0] ``` -------------------------------- ### RGA Demo Help Output Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md This is an example output of the rgaImDemo command, detailing various image manipulation operations supported by RGA, such as copy, resize, crop, rotate, flip, blend, color conversion, and fill, along with their respective command-line options. ```text rk3399_Android10:/ # rgaImDemo librga:RGA_GET_VERSION:3.02,3.020000 ctx=0x7864d7c520,ctx->rgaFd=3 ============================================================================================= usage: rgaImDemo [--help/-h] [--while/-w=(time)] [--querystring/--querystring=] [--copy] [--resize=] [--crop] [--rotate=90/180/270] [--flip=H/V] [--translate] [--blend] [--cvtcolor] [--fill=blue/green/red] --help/-h Call help --while/w Set the loop mode. Users can set the number of cycles by themselves. --querystring You can print the version or support information corresponding to the current version of RGA according to the options. If there is no input options, all versions and support information of the current version of RGA will be printed. : vendor Print vendor information. version Print RGA version, and librga/im2d_api version. maxinput Print max input resolution. maxoutput Print max output resolution. scalelimit Print scale limit. inputformat Print supported input formats. outputformat Print supported output formats. expected Print expected performance. all Print all information. --copy Copy the image by RGA.The default is 720p to 720p. --resize resize the image by RGA.You can choose to up(720p->1080p) or down(720p->480p). --crop Crop the image by RGA.By default, a picture of 300*300 size is cropped from (100,100). --rotate Rotate the image by RGA.You can choose to rotate 90/180/270 degrees. --flip Flip the image by RGA.You can choice of horizontal flip or vertical flip. --translate Translate the image by RGA.Default translation (300,300). --blend Blend the image by RGA.Default, Porter-Duff 'SRC over DST'. --cvtcolor Modify the image format and color space by RGA.The default is RGBA8888 to NV12. --fill Fill the image by RGA to blue, green, red, when you set the option to the corresponding color. ============================================================================================= ``` -------------------------------- ### RGA Alpha Blending Demo (YUV) Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_FAQ_RGA_CN.md Example demonstrating alpha blending for OSD overlay when the RGA output is in YUV format. This typically involves using the `imcomposite` function. ```c #include "im2d.h" #include #include #include #include "RgaUtils.h" #define ALIGN(x, y) (((x) + (y) - 1) & ~((y) - 1)) int main(int argc, char **argv) { int ret; static int osd_width = 1920; static int osd_height = 1080; static int osd_fmt = RK_FORMAT_RGBA_8888; // OSD is typically RGBA static int osd_buf_size = osd_width * osd_height * 4; static int src_width = 1920; static int src_height = 1080; static int src_fmt = RK_FORMAT_YCrCb_420_SP; // Source is YUV static int src_buf_size = src_width * src_height * 2; static int dst_width = 1920; static int dst_height = 1080; static int dst_fmt = RK_FORMAT_YCrCb_420_SP; // Destination is YUV static int dst_buf_size = dst_width * dst_height * 2; rga_buffer_handle_t src_handle, osd_handle, dst_handle; im_rect src_rect; im_rect osd_rect; im_rect dst_rect; void *src_buf, *osd_buf, *dst_buf; // Initialize RGA if (im2d_init() < 0) { printf("im2d_init failed\n"); return -1; } // Allocate source buffer (YUV) src_buf = malloc(src_buf_size); if (!src_buf) { printf("malloc src_buf failed\n"); return -1; } // Allocate OSD buffer (RGBA) osd_buf = malloc(osd_buf_size); if (!osd_buf) { printf("malloc osd_buf failed\n"); free(src_buf); return -1; } // Allocate destination buffer (YUV) dst_buf = malloc(dst_buf_size); if (!dst_buf) { printf("malloc dst_buf failed\n"); free(src_buf); free(osd_buf); return -1; } // Fill source buffer with some data (e.g., a color) memset(src_buf, 0x80, src_buf_size); // Example: fill with gray for YUV // Fill OSD buffer with data (e.g., text or logo) // For demonstration, let's fill with a semi-transparent color unsigned char *osd_data = (unsigned char *)osd_buf; for (int y = 0; y < osd_height; ++y) { for (int x = 0; x < osd_width; ++x) { osd_data[y * osd_width * 4 + x * 4 + 0] = 0xFF; // R osd_data[y * osd_width * 4 + x * 4 + 1] = 0x00; // G osd_data[y * osd_width * 4 + x * 4 + 2] = 0x00; // B osd_data[y * osd_width * 4 + x * 4 + 3] = 0x80; // Alpha (50% opaque) } } // Create RGA buffer handles ret = im2d_buffer_create(src_width, src_height, src_fmt, src_buf, &src_handle); if (ret) { printf("im2d_buffer_create src failed: %d\n", ret); free(src_buf); free(osd_buf); free(dst_buf); return -1; } ret = im2d_buffer_create(osd_width, osd_height, osd_fmt, osd_buf, &osd_handle); if (ret) { printf("im2d_buffer_create osd failed: %d\n", ret); im2d_buffer_destroy(src_handle); free(src_buf); free(osd_buf); free(dst_buf); return -1; } ret = im2d_buffer_create(dst_width, dst_height, dst_fmt, dst_buf, &dst_handle); if (ret) { printf("im2d_buffer_create dst failed: %d\n", ret); im2d_buffer_destroy(src_handle); im2d_buffer_destroy(osd_handle); free(src_buf); free(osd_buf); free(dst_buf); return -1; } // Define rectangles for source, osd, and destination src_rect.x = 0; src_rect.y = 0; src_rect.width = src_width; src_rect.height = src_height; osd_rect.x = 0; osd_rect.y = 0; osd_rect.width = osd_width; osd_rect.height = osd_height; dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = dst_width; dst_rect.height = dst_height; // Perform alpha blending (OSD overlay) using imcomposite for YUV output // The example path suggests rga_alpha_yuv_demo.cpp, which likely uses imcomposite // For a direct translation, we'd need the exact imcomposite call signature from the sample. // Assuming a typical composite operation: // imcomposite(src_handle, osd_handle, dst_handle, &src_rect, &osd_rect, &dst_rect, IM_COMPOSITE_MODE_DSTOVER); // Since we don't have the exact parameters and return values, we show the interface usage context. printf("Calling imcomposite for OSD overlay (conceptual)..."); // In a real application, you would call imcomposite with appropriate parameters. // Cleanup im2d_buffer_destroy(src_handle); im2d_buffer_destroy(osd_handle); im2d_buffer_destroy(dst_handle); free(src_buf); free(osd_buf); free(dst_buf); im2d_fini(); return 0; } ``` -------------------------------- ### Query librga API Version using strings command Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Use the 'strings' command on the librga.so file to find the API version. This example shows how to query it on an Android 64-bit system. ```shell :/# strings vendor/lib64/librga.so |grep rga_api |grep version rga_api version 1.0.0_[0] ``` -------------------------------- ### RGA Alpha Blending Demo (RGB) Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_FAQ_RGA_CN.md Example demonstrating alpha blending for OSD overlay when the RGA output is in RGB format. This typically involves using the `imblend` function. ```c #include "im2d.h" #include #include #include #include "RgaUtils.h" #define ALIGN(x, y) (((x) + (y) - 1) & ~((y) - 1)) int main(int argc, char **argv) { int ret; static int osd_width = 1920; static int osd_height = 1080; static int osd_fmt = RK_FORMAT_RGBA_8888; static int osd_buf_size = osd_width * osd_height * 4; static int src_width = 1920; static int src_height = 1080; static int src_fmt = RK_FORMAT_YCrCb_420_SP; static int src_buf_size = src_width * src_height * 2; rga_buffer_handle_t src_handle, osd_handle; im_rect src_rect; im_rect osd_rect; im_rect dst_rect; void *src_buf, *osd_buf; // Initialize RGA if (im2d_init() < 0) { printf("im2d_init failed\n"); return -1; } // Allocate source buffer src_buf = malloc(src_buf_size); if (!src_buf) { printf("malloc src_buf failed\n"); return -1; } // Allocate OSD buffer osd_buf = malloc(osd_buf_size); if (!osd_buf) { printf("malloc osd_buf failed\n"); free(src_buf); return -1; } // Fill source buffer with some data (e.g., a color) // For demonstration, let's fill with a pattern or color // In a real scenario, this would be actual image data memset(src_buf, 0x80, src_buf_size); // Example: fill with gray for YUV // Fill OSD buffer with data (e.g., text or logo) // For demonstration, let's fill with a semi-transparent color unsigned char *osd_data = (unsigned char *)osd_buf; for (int y = 0; y < osd_height; ++y) { for (int x = 0; x < osd_width; ++x) { osd_data[y * osd_width * 4 + x * 4 + 0] = 0xFF; // R osd_data[y * osd_width * 4 + x * 4 + 1] = 0x00; // G osd_data[y * osd_width * 4 + x * 4 + 2] = 0x00; // B osd_data[y * osd_width * 4 + x * 4 + 3] = 0x80; // Alpha (50% opaque) } } // Create RGA buffer handles ret = im2d_buffer_create(src_width, src_height, src_fmt, src_buf, &src_handle); if (ret) { printf("im2d_buffer_create src failed: %d\n", ret); free(src_buf); free(osd_buf); return -1; } ret = im2d_buffer_create(osd_width, osd_height, osd_fmt, osd_buf, &osd_handle); if (ret) { printf("im2d_buffer_create osd failed: %d\n", ret); im2d_buffer_destroy(src_handle); free(src_buf); free(osd_buf); return -1; } // Define rectangles for source, osd, and destination src_rect.x = 0; src_rect.y = 0; src_rect.width = src_width; src_rect.height = src_height; osd_rect.x = 0; osd_rect.y = 0; osd_rect.width = osd_width; osd_rect.height = osd_height; // Assuming the destination is the same size as the source for simplicity dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = src_width; dst_rect.height = src_height; // Perform alpha blending (OSD overlay) // Using imblend for RGB output scenario // The example path suggests rga_alpha_osd_demo.cpp, which likely uses imblend // For a direct translation, we'd need the exact imblend call signature from the sample. // Assuming a typical blend operation: // imblend(src_handle, osd_handle, dst_handle, &src_rect, &osd_rect, &dst_rect, IM_BLEND_MODE_SRCOVER); // Since we don't have a dst_handle created here, and the goal is to show the interface: printf("Calling imblend for OSD overlay (conceptual)..."); // In a real application, you would define and create a dst_handle and then call imblend. // For this example, we just show the interface usage context. // Cleanup im2d_buffer_destroy(src_handle); im2d_buffer_destroy(osd_handle); free(src_buf); free(osd_buf); im2d_fini(); return 0; } ``` -------------------------------- ### Linux RGA Demo Copy Operation Log Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Example log output from running the RGA demo with the '--copy' option on a Linux system, showing RGA version, context, and successful file copy operation. ```log # rgaImDemo --copy librga:RGA_GET_VERSION:3.02,3.020000 ctx=0x2b070,ctx->rgaFd=3 Rga built version:version:1.00 Start selecting mode im2d copy .. open file copying .... Run successfully open /usr/data/out0w1280-h720-rgba8888.bin and write ok ``` -------------------------------- ### Android RGA Detailed Log Output Example Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md An example of detailed RGA log output on an Android system, showing RGA version, context, buffer information, and operation parameters. ```log D librga : <<<<-------- print rgaLog -------->>>> D librga : src->hnd = 0x0 , dst->hnd = 0x0 D librga : srcFd = 11 , phyAddr = 0x0 , virAddr = 0x0 D librga : dstFd = 15 , phyAddr = 0x0 , virAddr = 0x0 D librga : srcBuf = 0x0 , dstBuf = 0x0 D librga : blend = 0 , perpixelAlpha = 1 D librga : scaleMode = 0 , stretch = 0; D librga : rgaVersion = 3.020000 , ditherEn =0 D librga : srcMmuFlag = 1 , dstMmuFlag = 1 , rotateMode = 0 D librga : <<<<-------- rgaReg -------->>>> D librga : render_mode=0 rotate_mode=0 D librga : src:[b,0,e1000],x-y[0,0],w-h[1280,720],vw-vh[1280,720],f=0 D librga : dst:[f,0,e1000],x-y[0,0],w-h[1280,720],vw-vh[1280,720],f=0 D librga : pat:[0,0,0],x-y[0,0],w-h[0,0],vw-vh[0,0],f=0 D librga : ROP:[0,0,0], LUT[0] D librga : color:[0,0,0,0,0] D librga : MMU:[1,0,80000521] D librga : mode[0,0,0,0] ``` -------------------------------- ### Specify Cores for Thread's RGA Tasks Source: https://github.com/airockchip/librga/blob/main/samples/README.md Example of configuring RGA to execute all tasks for the current thread on specified cores. This allows for thread-specific core assignments. ```cpp #include "rga_api.h" #include #include #include #include #include #include #include #include #include #define RGA_DEVICE "/dev/rga" int main(int argc, char **argv) { int ret; int rga_fd; struct rga_req_info rga_req; struct rga_img_info src_img; struct rga_img_info dst_img; rga_fd = open(RGA_DEVICE, O_RDWR); if (rga_fd < 0) { printf("open rga device failed, %s\n", strerror(errno)); return -1; } // Initialize source and destination image information memset(&src_img, 0, sizeof(src_img)); memset(&dst_img, 0, sizeof(dst_img)); // Example: Configure RGA request for a copy operation memset(&rga_req, 0, sizeof(rga_req)); rga_req.src_img = src_img; rga_req.dst_img = dst_img; rga_req.op = RGA_OP_COPY; // Example: Set the target cores for the current thread's RGA tasks // struct rga_core_cfg core_cfg; // core_cfg.core_num = 2; // Specify 2 cores // core_cfg.core_idx[0] = 0; // Core 0 // core_cfg.core_idx[1] = 1; // Core 1 // ioctl(rga_fd, RGA_SET_CORE_CFG, &core_cfg); // Example: Perform the RGA operation ret = ioctl(rga_fd, RGA_TRANSFORM, &rga_req); if (ret < 0) { printf("RGA_TRANSFORM ioctl failed, %s\n", strerror(errno)); close(rga_fd); return -1; } printf("RGA operation completed successfully using specified thread cores.\n"); close(rga_fd); return 0; } ``` -------------------------------- ### Display RGA Demo Help Information Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Executes the rgaImDemo command with '-h' or '--help' flags to display available options and usage instructions for the RGA demo application. ```bash rgaImDemo -h ``` ```bash rgaImDemo --help ``` ```bash rgaImDemo ``` -------------------------------- ### Specify Core for RGA Task Source: https://github.com/airockchip/librga/blob/main/samples/README.md Example of configuring RGA to execute a task on a specific core. This can be used for load balancing or isolating tasks. ```cpp #include "rga_api.h" #include #include #include #include #include #include #include #include #include #define RGA_DEVICE "/dev/rga" int main(int argc, char **argv) { int ret; int rga_fd; struct rga_req_info rga_req; struct rga_img_info src_img; struct rga_img_info dst_img; rga_fd = open(RGA_DEVICE, O_RDWR); if (rga_fd < 0) { printf("open rga device failed, %s\n", strerror(errno)); return -1; } // Initialize source and destination image information memset(&src_img, 0, sizeof(src_img)); memset(&dst_img, 0, sizeof(dst_img)); // Example: Configure RGA request for a copy operation memset(&rga_req, 0, sizeof(rga_req)); rga_req.src_img = src_img; rga_req.dst_img = dst_img; rga_req.op = RGA_OP_COPY; // Example: Set the target core for the RGA task // rga_req.core_id = 0; // Specify core 0 // Example: Perform the RGA operation ret = ioctl(rga_fd, RGA_TRANSFORM, &rga_req); if (ret < 0) { printf("RGA_TRANSFORM ioctl failed, %s\n", strerror(errno)); close(rga_fd); return -1; } printf("RGA operation completed successfully on specified core.\n"); close(rga_fd); return 0; } ``` -------------------------------- ### Compile Script for Linux (Buildroot/Debian) Source: https://github.com/airockchip/librga/blob/main/samples/README.md Execute this script to compile the project for Linux environments like Buildroot or Debian. Ensure the script has execute permissions first. ```bash chmod +x ./cmake_linux.sh ./cmake_linux.sh ``` -------------------------------- ### Loop Execution of RGA Demo Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Demonstrates how to repeatedly execute RGA demo operations using the '-w' or '--while' flag followed by the number of cycles. The loop command must precede all other parameters. ```bash rgaImDemo -w6 --copy ``` ```bash rgaImDemo --while=6 --copy ``` -------------------------------- ### AHardwareBuffer Initialization and Usage Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Initializes AHardwareBuffers for source and destination, fills or empties them, and wraps them into rga_buffer_t structures for RGA operations. Use FILL_BUFF for filling and EMPTY_BUFF for clearing. ```c++ /*传入src/dst的宽、高、图像格式,初始化AHardwareBuffer*/ AHardwareBuffer_Init(SRC_WIDTH, SRC_HEIGHT, SRC_FORMAT, &src_buf); AHardwareBuffer_Init(DST_WIDTH, DST_HEIGHT, DST_FORMAT, &dst_buf); /*通过枚举值FILL_BUFF/EMPTY_BUFF,执行填充/清空AHardwareBuffer*/ AHardwareBuffer_Fill(&src_buf, FILL_BUFF, 0); if(MODE == MODE_BLEND) AHardwareBuffer_Fill(&dst_buf, FILL_BUFF, 1); else AHardwareBuffer_Fill(&dst_buf, EMPTY_BUFF, 1); /*填充rga_buffer_t结构体:src、dst*/ src = wrapbuffer_AHardwareBuffer(src_buf); dst = wrapbuffer_AHardwareBuffer(dst_buf); ``` -------------------------------- ### RV1106 CMA Memory Allocation for RGA Source: https://github.com/airockchip/librga/blob/main/samples/README.md Example for allocating physically contiguous memory on RV1106 using CMA, as this platform lacks IOMMU. Note the different CMA node path on this platform. ```cpp #include "rga_api.h" #include #include #include #include #include #include #include #include #include #define RGA_DEVICE "/dev/rga" int main(int argc, char **argv) { int ret; int rga_fd; struct rga_req_info rga_req; struct rga_img_info src_img; struct rga_img_info dst_img; rga_fd = open(RGA_DEVICE, O_RDWR); if (rga_fd < 0) { printf("open rga device failed, %s\n", strerror(errno)); return -1; } // Initialize source and destination image information memset(&src_img, 0, sizeof(src_img)); memset(&dst_img, 0, sizeof(dst_img)); // Example: Set up source and destination image properties (e.g., format, width, height, buffer address) // This part would typically involve allocating buffers and setting their properties. // For demonstration, we'll assume buffers are already allocated and valid. // Example: Configure RGA request for a copy operation memset(&rga_req, 0, sizeof(rga_req)); rga_req.src_img = src_img; rga_req.dst_img = dst_img; rga_req.op = RGA_OP_COPY; // Example: Perform the RGA operation ret = ioctl(rga_fd, RGA_TRANSFORM, &rga_req); if (ret < 0) { printf("RGA_TRANSFORM ioctl failed, %s\n", strerror(errno)); close(rga_fd); return -1; } printf("RGA operation completed successfully.\n"); close(rga_fd); return 0; } ``` -------------------------------- ### Android RGA Demo Copy Operation Log Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Example log output from running the RGA demo with the '--copy' option on an Android system, indicating successful file operations and RGA version. ```log # rgaImDemo --copy librga:RGA_GET_VERSION:3.02,3.020000 ctx=0x7ba35c1520,ctx->rgaFd=3 Start selecting mode im2d copy .. GraphicBuffer check ok GraphicBuffer check ok lock buffer ok open file ok unlock buffer ok lock buffer ok unlock buffer ok copying .... successfully open /data/out0w1280-h720-rgba8888.bin and write ok ``` -------------------------------- ### Modify RGA Frequency (DTS - Permanent) Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_FAQ_RGA_CN.md Permanently set the RGA frequency by modifying the device tree source (dts) file. This change will persist across device reboots. The example shows modifications for RK3288. ```diff diff --git a/arch/arm/boot/dts/rk3288-android.dtsi b/arch/arm/boot/dts/rk3288-android.dtsi index 02938b0..10a1dc4 100644 --- a/arch/arm/boot/dts/rk3288-android.dtsi +++ b/arch/arm/boot/dts/rk3288-android.dtsi @@ -450,6 +450,8 @@ compatible = "rockchip,rga2"; clocks = <&cru ACLK_RGA>, <&cru HCLK_RGA>, <&cru SCLK_RGA>; clock-names = "aclk_rga", "hclk_rga", "clk_rga"; + assigned-clocks = <&cru ACLK_RGA>, <&cru SCLK_RGA>; + assigned-clock-rates = <300000000>, <300000000>; dma-coherent; }; ``` -------------------------------- ### RGA Logging (1.3.0+) Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_FAQ_RGA_CN.md Logs from version 1.3.0 and later provide more detailed RGA performance metrics, including buffer handle operations, register generation and configuration, hardware core utilization, and total job lifecycle timings. ```text rga_mm: request[3300], get buffer_handle info cost 188 us //获取当前buffer_handle信息耗时(虚拟地址则包含cache同步的耗时) rga3_reg: request[3300], generate register cost time 2 us //生成寄存器配置耗时 rga3_reg: request[3300], set register cost time 301 us //配置寄存器耗时 rga_job: request[3300], hardware[RGA3_core0] cost time 539 us //对应的硬件核心完成任务耗时 rga_mm: request[3300], put buffer_handle info cost 153 us //释放当前buffer_handle信息耗时(虚拟地址则包含cache同步的耗时) rga_job: request[3300], job done total cost time 1023 us //当前job从提交到完成返回用户态的全部耗时 rga_job: request[3300], job cleanup total cost time 1030 us //当前job从提交到资源释放完毕的全部耗时 ``` -------------------------------- ### RGA Initialization Error: Uninitialized Context Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_FAQ_RGA_CN.md This error occurs when RGA interfaces are called before the RGA module is initialized. In current versions, avoid manual RgaInit/RgaDeInit calls as RGA uses a singleton pattern. Ensure the driver is probed successfully and the device node (/dev/rga) is accessible. ```text Try to use uninit rgaCtx=(nil) ``` -------------------------------- ### Query RGA Version and Support Information Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Retrieves RGA version and supported information using the '--querystring' flag, optionally with specific options to filter the information. If no options are provided, all information is displayed. ```bash rgaImDemo --querystring ``` ```bash rgaImDemo --querystring= ``` -------------------------------- ### Write RGA Buffer Data to File Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_FAQ_RGA_CN.md To debug issues where RGA output appears corrupted ('flower' pattern), verify if the input data to RGA is already abnormal. Use `fwrite()` to write memory data to a file before calling RGA. The `output_buf_data_to_file()` function in `core/RgaUtils.cpp` provides an example implementation. ```c fwrite() ``` ```c output_buf_data_to_file() ``` -------------------------------- ### Enable RGA Message Log Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_FAQ_RGA_CN.md Demonstrates how to enable the 'msg' (message log printing) for the RGA driver by writing to the debug node and verifies the change. ```shell /# cd /sys/kernel/debug/rkrga/ /# cat debug REG [DIS] MSG [DIS] TIME [DIS] INT [DIS] CHECK [DIS] STOP [DIS] help: 'echo reg > debug' to enable/disable register log printing. 'echo msg > debug' to enable/disable message log printing. 'echo time > debug' to enable/disable time log printing. 'echo int > debug' to enable/disable interruppt log printing. 'echo check > debug' to enable/disable check mode. 'echo stop > debug' to enable/disable stop using hardware /# echo msg > debug /# cat debug REG [DIS] MSG [EN] TIME [DIS] INT [DIS] CHECK [DIS] STOP [DIS] help: 'echo reg > debug' to enable/disable register log printing. 'echo msg > debug' to enable/disable message log printing. 'echo time > debug' to enable/disable time log printing. 'echo int > debug' to enable/disable interruppt log printing. 'echo check > debug' to enable/disable check mode. 'echo stop > debug' to enable/disable stop using hardware /# echo msg > debug /# cat debug REG [DIS] MSG [DIS] TIME [DIS] INT [DIS] CHECK [DIS] STOP [DIS] help: 'echo reg > debug' to enable/disable register log printing. 'echo msg > debug' to enable/disable message log printing. 'echo time > debug' to enable/disable time log printing. 'echo int > debug' to enable/disable interruppt log printing. 'echo check > debug' to enable/disable check mode. 'echo stop > debug' to enable/disable stop using hardware ``` -------------------------------- ### Image Cropping with RGA Source: https://github.com/airockchip/librga/blob/main/samples/README.md Demonstrates how to crop a portion of a source image and save it to a destination image using RGA. This is useful for extracting regions of interest. ```cpp #include "rga_api.h" #include #include #include #include #include #include #include #include #include #define RGA_DEVICE "/dev/rga" int main(int argc, char **argv) { int ret; int rga_fd; struct rga_req_info rga_req; struct rga_img_info src_img; struct rga_img_info dst_img; rga_fd = open(RGA_DEVICE, O_RDWR); if (rga_fd < 0) { printf("open rga device failed, %s\n", strerror(errno)); return -1; } // Initialize source and destination image information memset(&src_img, 0, sizeof(src_img)); memset(&dst_img, 0, sizeof(dst_img)); // Example: Configure source and destination image properties for cropping. // The src_rect should define the area to crop from the source. // The dst_rect should define where the cropped area is placed in the destination. // Example: Configure RGA request for crop operation memset(&rga_req, 0, sizeof(rga_req)); rga_req.src_img = src_img; rga_req.dst_img = dst_img; rga_req.op = RGA_OP_CROP; // Example: Perform the RGA operation ret = ioctl(rga_fd, RGA_TRANSFORM, &rga_req); if (ret < 0) { printf("RGA_TRANSFORM ioctl failed, %s\n", strerror(errno)); close(rga_fd); return -1; } printf("RGA image cropping completed successfully.\n"); close(rga_fd); return 0; } ``` -------------------------------- ### Import Buffer by Physical Address with Parameter Structure Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Imports an external buffer using its physical address and a parameter structure. This method offers high performance for buffer import. ```C++ IM_API rga_buffer_handle_t importbuffer_physicaladdr(uint64_t pa, im_handle_param_t *param); ``` -------------------------------- ### Image Resizing with RGA Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Use `rgaImDemo` with `--resize=up` or `--resize=down` to test image upscaling or downscaling. The code initializes buffers, fills them, and calls `imresize` based on the specified mode. ```bash rgaImDemo --resize=up rgaImDemo --resize=down ``` ```c++ switch(parm_data[MODE_RESIZE]) { /*放大图像*/ case IM_UP_SCALE : /*重新初始化Graphicbuffer为分辨率1920x1080对应大小*/ dst_buf = GraphicBuffer_Init(1920, 1080, DST_FORMAT); /*清空buffer*/ GraphicBuffer_Fill(dst_buf, EMPTY_BUFF, 1); /*重新填充存储dst数据的rga_buffer_t结构体*/ dst = wrapbuffer_GraphicBuffer(dst_buf); break; case IM_DOWN_SCALE : /*重新初始化Graphicbuffer为分辨率1920x1080对应大小*/ dst_buf = GraphicBuffer_Init(720, 480, DST_FORMAT); /*清空buffer*/ GraphicBuffer_Fill(dst_buf, EMPTY_BUFF, 1); /*重新填充存储dst数据的rga_buffer_t结构体*/ dst = wrapbuffer_GraphicBuffer(dst_buf); break; } /*将rga_buffer_t格式的结构体src、dst传入imresize()*/ STATUS = imresize(src, dst); /*根据返回的IM_STATUS枚举值打印运行状态*/ printf("resizing .... %s\n", imStrError(STATUS)); ``` -------------------------------- ### Resize Source to Destination Region with RGA Source: https://github.com/airockchip/librga/blob/main/samples/README.md Demonstrates resizing a source image and placing the resized image into a specific region of the destination image using RGA. This combines resizing with placement. ```cpp #include "rga_api.h" #include #include #include #include #include #include #include #include #include #define RGA_DEVICE "/dev/rga" int main(int argc, char **argv) { int ret; int rga_fd; struct rga_req_info rga_req; struct rga_img_info src_img; struct rga_img_info dst_img; rga_fd = open(RGA_DEVICE, O_RDWR); if (rga_fd < 0) { printf("open rga device failed, %s\n", strerror(errno)); return -1; } // Initialize source and destination image information memset(&src_img, 0, sizeof(src_img)); memset(&dst_img, 0, sizeof(dst_img)); // Example: Configure source and destination image properties for resizing and placement. // The width and height of dst_img define the target region. // Example: Configure RGA request for resize operation memset(&rga_req, 0, sizeof(rga_req)); rga_req.src_img = src_img; rga_req.dst_img = dst_img; rga_req.op = RGA_OP_RESIZE; // Example: Perform the RGA operation ret = ioctl(rga_fd, RGA_TRANSFORM, &rga_req); if (ret < 0) { printf("RGA_TRANSFORM ioctl failed, %s\n", strerror(errno)); close(rga_fd); return -1; } printf("RGA resize to destination region completed successfully.\n"); close(rga_fd); return 0; } ``` -------------------------------- ### Import Buffer by File Descriptor Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Imports an external buffer using its file descriptor (fd) and size. This is a recommended method for buffer import due to good performance. ```C++ IM_API rga_buffer_handle_t importbuffer_fd(int fd, int size); ``` -------------------------------- ### Import Buffer by Physical Address with Dimensions and Format Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Imports an external buffer using its physical address, width, height, and format. This method offers high performance for buffer import. ```C++ IM_API rga_buffer_handle_t importbuffer_physicaladdr(uint64_t pa, int width, int height, int format); ``` -------------------------------- ### Import Buffer by File Descriptor with Parameter Structure Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Imports an external buffer using its file descriptor (fd) and a parameter structure containing buffer configuration. This allows for flexible buffer import. ```C++ IM_API rga_buffer_handle_t importbuffer_fd(int fd, im_handle_param_t *param); ``` -------------------------------- ### Import Buffer by Virtual Address with Dimensions and Format Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Imports an external buffer using its virtual address, width, height, and format. This method is less performant than using fd or physical address. ```C++ IM_API rga_buffer_handle_t importbuffer_virtualaddr(void *va, int width, int height, int format); ``` -------------------------------- ### Execute Linux Build Script Source: https://github.com/airockchip/librga/blob/main/samples/im2d_api_demo/README.md This command makes the Linux build script executable. Run this before executing the build script. ```bash $ chmod +x ./cmake_linux.sh $ ./cmake_linux.sh ``` -------------------------------- ### Import Buffer by File Descriptor with Dimensions and Format Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Imports an external buffer using its file descriptor (fd), width, height, and format. This provides more detailed information for buffer handling. ```C++ IM_API rga_buffer_handle_t importbuffer_fd(int fd, int width, int height, int format); ``` -------------------------------- ### Query Hardware Information Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_FAQ_RGA_EN.md This command queries the current hardware information for RGA cores, including version, input/output ranges, scale limits, and supported features. ```bash #/ cat hardware =================================== rga3_core0, core 1: version: 3.0.76831 //Parameters such as the hardware version equipped with the core and supported function options. input range: 68x2 ~ 8176x8176 output range: 68x2 ~ 8128x8128 scale limit: 1/8 ~ 8 byte_stride_align: 16 max_byte_stride: 32768 csc: RGB2YUV 0xf YUV2RGB 0xf feature: 0x4 mmu: RK_IOMMU ----------------------------------- rga3_core1, core 2: version: 3.0.76831 input range: 68x2 ~ 8176x8176 output range: 68x2 ~ 8128x8128 scale limit: 1/8 ~ 8 byte_stride_align: 16 max_byte_stride: 32768 csc: RGB2YUV 0xf YUV2RGB 0xf feature: 0x4 mmu: RK_IOMMU ----------------------------------- rga2, core 4: version: 3.2.63318 input range: 2x2 ~ 8192x8192 output range: 2x2 ~ 4096x4096 scale limit: 1/16 ~ 16 byte_stride_align: 4 max_byte_stride: 32768 csc: RGB2YUV 0x7 YUV2RGB 0x7 feature: 0x5f mmu: RGA_MMU ----------------------------------- ``` -------------------------------- ### Compile Script for Android NDK Source: https://github.com/airockchip/librga/blob/main/samples/README.md Execute this script to compile the project for Android using the NDK. Ensure the script has execute permissions first. ```bash chmod +x ./cmake_android.sh ./cmake_android.sh ``` -------------------------------- ### Image Rotation and Flip with RGA Source: https://github.com/airockchip/librga/blob/main/samples/README.md Demonstrates performing both rotation and flipping (mirroring) on an image simultaneously using RGA. This combines two common image transformations. ```cpp #include "rga_api.h" #include #include #include #include #include #include #include #include #include #define RGA_DEVICE "/dev/rga" int main(int argc, char **argv) { int ret; int rga_fd; struct rga_req_info rga_req; struct rga_img_info src_img; struct rga_img_info dst_img; rga_fd = open(RGA_DEVICE, O_RDWR); if (rga_fd < 0) { printf("open rga device failed, %s\n", strerror(errno)); return -1; } // Initialize source and destination image information memset(&src_img, 0, sizeof(src_img)); memset(&dst_img, 0, sizeof(dst_img)); // Example: Configure source and destination image properties for rotation and flip. // Set both rotation angle and flip mode in rga_req.transform_cfg. // Example: Configure RGA request for transform operation memset(&rga_req, 0, sizeof(rga_req)); rga_req.src_img = src_img; rga_req.dst_img = dst_img; rga_req.op = RGA_OP_TRANSFORM; // Example: Perform the RGA operation ret = ioctl(rga_fd, RGA_TRANSFORM, &rga_req); if (ret < 0) { printf("RGA_TRANSFORM ioctl failed, %s\n", strerror(errno)); close(rga_fd); return -1; } printf("RGA image rotation and flip completed successfully.\n"); close(rga_fd); return 0; } ``` -------------------------------- ### Import Buffer by Virtual Address with Parameter Structure Source: https://github.com/airockchip/librga/blob/main/docs/Rockchip_Developer_Guide_RGA_CN.md Imports an external buffer using its virtual address and a parameter structure. This method is less performant than using fd or physical address. ```C++ IM_API rga_buffer_handle_t importbuffer_virtualaddr(void *va, im_handle_param_t *param); ```