1From acae83e9502dd420b25b73fb7e580dca73918d2e Mon Sep 17 00:00:00 2001
2From: ZiHan Huang <zack.huang@rock-chips.com>
3Date: Thu, 5 Jan 2023 14:25:03 +0800
4Subject: [PATCH 7/8] Added rga Acceleration: rga copy instead of memcpy
5
6Signed-off-by: ZiHan Huang <zack.huang@rock-chips.com>
7---
8 CMakeLists.txt |  9 +++++++++
9 display/drm.c  | 45 +++++++++++++++++++++++++++++++++++++++++++--
10 display/drm.h  |  5 +++++
11 3 files changed, 57 insertions(+), 2 deletions(-)
12
13diff --git a/CMakeLists.txt b/CMakeLists.txt
14index 278e964..48500e9 100644
15--- a/CMakeLists.txt
16+++ b/CMakeLists.txt
17@@ -23,6 +23,11 @@ endif()
18 if (LV_DRV_USE_DRM)
19     add_definitions(-DUSE_DRM=1)
20 endif()
21+if (LV_DRV_USE_RGA)
22+    add_definitions(-DUSE_RGA=1)
23+    include_directories(${CMAKE_SYSROOT}/usr/include/rga/)
24+endif()
25+
26 add_definitions(-g -DLV_CONF_INCLUDE_SIMPLE)
27 include_directories(${CMAKE_SYSROOT}/usr/include/libdrm/)
28
29@@ -32,6 +37,10 @@ find_package(PkgConfig)
30 pkg_check_modules(PKG_WAYLAND wayland-client wayland-cursor wayland-protocols xkbcommon)
31 target_link_libraries(lv_drivers PUBLIC lvgl ${PKG_WAYLAND_LIBRARIES})
32
33+if (LV_DRV_USE_RGA)
34+    target_link_libraries(lv_drivers PUBLIC rga)
35+endif()
36+
37 if("${LIB_INSTALL_DIR}" STREQUAL "")
38   set(LIB_INSTALL_DIR "lib")
39 endif()
40diff --git a/display/drm.c b/display/drm.c
41index 17af072..26e0d7b 100644
42--- a/display/drm.c
43+++ b/display/drm.c
44@@ -866,7 +866,7 @@ static void *drm_thread(void *arg)
45             draw_update = 0;
46         }
47         pthread_mutex_unlock(&draw_mutex);
48-        usleep(10000);
49+        usleep(1000);
50     }
51     return NULL;
52 }
53@@ -876,14 +876,55 @@ void drm_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color
54    /*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
55     int32_t x;
56     int32_t y;
57-
58+    lv_coord_t w = (area->x2 - area->x1 + 1);
59+    lv_coord_t h = (area->y2 - area->y1 + 1);
60+#if USE_RGA
61+    int wstride = w;
62+    int hstride = h;
63+    int lcd_ws = lcd_w;
64+    int lcd_hs = lcd_h;
65+    int format = 0;
66+    if(lcd_ws % 32 != 0) {
67+        lcd_ws = (lcd_ws + 32) & (~31);
68+    }
69+    if(lcd_hs % 32 != 0) {
70+        lcd_hs = (lcd_hs + 32) & (~31);
71+    }
72+    if (LV_COLOR_DEPTH == 16) {
73+        format = RK_FORMAT_RGB_565;
74+    }else if (LV_COLOR_DEPTH == 32) {
75+        format = RK_FORMAT_ARGB_8888;
76+    }else {
77+        format = -1;
78+        printf("drm_flush rga not supported format\n");
79+        return;
80+    }
81+#endif
82     pthread_mutex_lock(&draw_mutex);
83+#if USE_RGA
84+    rga_info_t src;
85+    rga_info_t dst;
86+    int area_w = area->x2 - area->x1 + 1;
87+    int area_h = area->y2 - area->y1 + 1;
88+    memset(&src, 0, sizeof(rga_info_t));
89+    memset(&dst, 0, sizeof(rga_info_t));
90+    src.virAddr = color_p;
91+    src.mmuFlag = 1;
92+    dst.fd = gbo->buf_fd;
93+    dst.mmuFlag = 1;
94+    rga_set_rect(&src.rect, 0, 0, area_w, area_h, wstride, hstride, format);
95+    rga_set_rect(&dst.rect, area->x1, area->y1, area_w, area_h, lcd_ws, lcd_hs, format);
96+    int ret = c_RkRgaBlit(&src, &dst, NULL);
97+    if (ret)
98+        printf("c_RkRgaBlit2 error : %s\n", strerror(errno));
99+#else
100     for(y = area->y1; y <= area->y2; y++) {
101         int area_w = area->x2 - area->x1 + 1;
102         lv_color_t *disp = (lv_color_t*)(drm_buff + (y * lcd_sw + area->x1) * 4);
103         memcpy(disp, color_p, area_w * 4);
104         color_p += area_w;
105     }
106+#endif
107     draw_update = 1;
108     pthread_mutex_unlock(&draw_mutex);
109     /*IMPORTANT!!!
110diff --git a/display/drm.h b/display/drm.h
111index 74695a9..1b98217 100644
112--- a/display/drm.h
113+++ b/display/drm.h
114@@ -29,6 +29,11 @@ extern "C" {
115 #include "lvgl/lvgl.h"
116 #endif
117
118+#if USE_RGA
119+#include <rga/im2d.h>
120+#include <rga/rga.h>
121+#include <rga/RgaApi.h>
122+#endif
123 /*********************
124  *      DEFINES
125  *********************/
126--
1272.25.1
128
129