Debian Codegraph @

lvgl/src/draw/nxp/g2d/lv_g2d_utils.c

raw symbols SCIP
1 /**
2 * @file lv_g2d_utils.c
3 *
4 */
5
6 /**
7 * Copyright 2024 NXP
8 *
9 * SPDX-License-Identifier: MIT
10 */
11
12 /*********************
13 * INCLUDES
14 *********************/
15
16 #include "lv_g2d_utils.h"
17
18 #if LV_USE_G2D
19 #if LV_USE_DRAW_G2D || LV_USE_ROTATE_G2D
20 #include "lv_g2d_buf_map.h"
21 #include "lv_draw_g2d.h"
22
23 /*********************
24 * DEFINES
25 *********************/
26
27 /**********************
28 * TYPEDEFS
29 **********************/
30
31 /**********************
32 * STATIC PROTOTYPES
33 **********************/
34 static void * g2d_handle;
35 /**********************
36 * MACROS
37 **********************/
38
39 /**********************
40 * GLOBAL FUNCTIONS
41 **********************/
42
43 g2d_format_t g2d_get_buf_format(lv_color_format_t cf)
44 {
45 g2d_format_t color_f = G2D_RGB565;
46
47 switch(cf) {
48 case LV_COLOR_FORMAT_RGB565:
49 color_f = G2D_RGB565;
50 break;
51 case LV_COLOR_FORMAT_ARGB8888:
52 color_f = G2D_BGRA8888;
53 break;
54 case LV_COLOR_FORMAT_XRGB8888:
55 color_f = G2D_BGRX8888;
56 break;
57 case LV_COLOR_FORMAT_RGB888:
58 color_f = G2D_BGR888;
59 break;
60 case LV_COLOR_FORMAT_NV12:
61 color_f = G2D_NV12;
62 break;
63 case LV_COLOR_FORMAT_I420:
64 color_f = G2D_I420;
65 break;
66 case LV_COLOR_FORMAT_NV21:
67 color_f = G2D_NV21;
68 break;
69 case LV_COLOR_FORMAT_YUY2:
70 color_f = G2D_YUYV;
71 break;
72 case LV_COLOR_FORMAT_UYVY:
73 color_f = G2D_UYVY;
74 break;
75 default:
76 G2D_ASSERT_MSG(false, "Unsupported color format.");
77 break;
78 }
79 return color_f;
80 }
81
82 uint32_t g2d_rgba_to_u32(lv_color_t color)
83 {
84 return (uint32_t)((color.red) + (color.green << 8) + (color.blue << 16) + ((uint32_t)0xff << 24));
85 }
86
87 int32_t g2d_get_buf_fd(const lv_draw_buf_t * draw_buf)
88 {
89 struct g2d_buf * buf = g2d_search_buf_map(draw_buf->data);
90 G2D_ASSERT_MSG(buf, "Failed to find buffer in map.");
91 return g2d_buf_export_fd(buf);
92 }
93
94 void g2d_set_handle(void * handle)
95 {
96 g2d_handle = handle;
97 }
98 void * g2d_get_handle(void)
99 {
100 return g2d_handle;
101 }
102
103 #if LV_USE_ROTATE_G2D
104 void g2d_rotate(lv_draw_buf_t * buf1, lv_draw_buf_t * buf2, int32_t width, int32_t height, uint32_t rotation,
105 lv_color_format_t cf)
106 {
107 struct g2d_surface src_surf, dst_surf;
108 struct g2d_buf * src_buf = g2d_search_buf_map(buf1->data);
109 struct g2d_buf * dst_buf = g2d_search_buf_map(buf2->data);
110 bool has_rotation = (rotation != 0);
111
112 int32_t src_width = width;
113 int32_t src_height = height;
114 if(has_rotation) {
115 if(rotation == LV_DISPLAY_ROTATION_90 || rotation == LV_DISPLAY_ROTATION_270) {
116 src_width = height;
117 src_height = width;
118 }
119 }
120
121 src_surf.format = g2d_get_buf_format(cf);
122
123 src_surf.left = 0;
124 src_surf.top = 0;
125 src_surf.right = src_width;
126 src_surf.bottom = src_height;
127 src_surf.stride = src_width;
128 src_surf.width = src_width;
129 src_surf.height = src_height;
130
131 src_surf.planes[0] = src_buf->buf_paddr;
132 src_surf.rot = G2D_ROTATION_0;
133
134 enum g2d_rotation g2d_angle = G2D_ROTATION_0;
135 if(has_rotation) {
136 switch(rotation) {
137 case LV_DISPLAY_ROTATION_0:
138 g2d_angle = G2D_ROTATION_0;
139 break;
140 case LV_DISPLAY_ROTATION_90:
141 g2d_angle = G2D_ROTATION_90;
142 break;
143 case LV_DISPLAY_ROTATION_180:
144 g2d_angle = G2D_ROTATION_180;
145 break;
146 case LV_DISPLAY_ROTATION_270:
147 g2d_angle = G2D_ROTATION_270;
148 break;
149 default:
150 g2d_angle = G2D_ROTATION_0;
151 }
152 }
153
154 dst_surf.format = g2d_get_buf_format(cf);
155
156 dst_surf.left = 0;
157 dst_surf.top = 0;
158 dst_surf.right = width;
159 dst_surf.bottom = height;
160 dst_surf.stride = width;
161 dst_surf.width = width;
162 dst_surf.height = height;
163
164 dst_surf.planes[0] = dst_buf->buf_paddr;
165 dst_surf.rot = g2d_angle;
166
167 void * handle = g2d_get_handle();
168 g2d_blit(handle, &src_surf, &dst_surf);
169 g2d_finish(handle);
170 }
171 #endif
172
173 /**********************
174 * STATIC FUNCTIONS
175 **********************/
176
177 #endif /*LV_USE_DRAW_G2D || LV_USE_ROTATE_G2D*/
178 #endif /*LV_USE_G2D*/