Debian Codegraph @

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

raw symbols SCIP
1 /**
2 * @file lv_draw_g2d_fill.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_draw_g2d.h"
17
18 #if LV_USE_G2D
19 #if LV_USE_DRAW_G2D
20 #include <stdlib.h>
21 #include "g2d.h"
22 #include "../../../misc/lv_area_private.h"
23 #include "lv_g2d_buf_map.h"
24 #include "lv_g2d_utils.h"
25
26 /*********************
27 * DEFINES
28 *********************/
29
30 /**********************
31 * TYPEDEFS
32 **********************/
33
34 /**********************
35 * STATIC PROTOTYPES
36 **********************/
37
38 /* Blit simple w/ opa and alpha channel */
39 static void _g2d_fill(void * handle, struct g2d_surface * dst_surf);
40 static void _g2d_fill_with_opa(void * handle, struct g2d_surface * dst_surf, struct g2d_surface * src_surf);
41
42 static void _g2d_set_src_surf(struct g2d_surface * src_surf, struct g2d_buf * buf, const lv_area_t * area,
43 lv_color_t color, lv_opa_t opa, lv_color_format_t cf);
44
45 static void _g2d_set_dst_surf(struct g2d_surface * dst_surf, struct g2d_buf * buf, const lv_area_t * area,
46 int32_t stride, lv_color_t color, lv_color_format_t cf);
47
48 /**********************
49 * STATIC VARIABLES
50 **********************/
51
52 /**********************
53 * MACROS
54 **********************/
55
56 /**********************
57 * GLOBAL FUNCTIONS
58 **********************/
59
60 void lv_draw_g2d_fill(lv_draw_task_t * t)
61 {
62 lv_draw_fill_dsc_t * dsc = t->draw_dsc;
63
64 if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
65 return;
66
67 lv_layer_t * layer = t->target_layer;
68 lv_draw_buf_t * draw_buf = layer->draw_buf;
69 lv_area_t * coords = &t->area;
70
71 lv_area_t rel_coords;
72 lv_area_copy(&rel_coords, coords);
73 lv_area_move(&rel_coords, -layer->buf_area.x1, -layer->buf_area.y1);
74
75 lv_area_t rel_clip_area;
76 lv_area_copy(&rel_clip_area, &t->clip_area);
77 lv_area_move(&rel_clip_area, -layer->buf_area.x1, -layer->buf_area.y1);
78
79 lv_area_t blend_area;
80 if(!lv_area_intersect(&blend_area, &rel_coords, &rel_clip_area))
81 return; /*Fully clipped, nothing to do*/
82
83 /* G2D takes stride in pixels. */
84 int32_t stride = draw_buf->header.stride / (lv_color_format_get_bpp(draw_buf->header.cf) / 8);
85
86 /* Destination buffer */
87 struct g2d_buf * dst_buf = g2d_search_buf_map(draw_buf->data);
88
89 bool has_opa = (dsc->opa < (lv_opa_t)LV_OPA_MAX);
90 struct g2d_surface dst_surf;
91 _g2d_set_dst_surf(&dst_surf, dst_buf, &blend_area, stride, dsc->color, draw_buf->header.cf);
92
93 void * handle = g2d_get_handle();
94
95 if(has_opa) {
96 struct g2d_buf * tmp_buf = g2d_alloc(lv_area_get_width(&blend_area) * lv_area_get_height(
97 &blend_area) * lv_color_format_get_size(draw_buf->header.cf), 1);
98 G2D_ASSERT_MSG(tmp_buf, "Failed to alloc temporary buffer.");
99 struct g2d_surface src_surf;
100 _g2d_set_src_surf(&src_surf, tmp_buf, &blend_area, dsc->color, dsc->opa, draw_buf->header.cf);
101 _g2d_fill_with_opa(handle, &dst_surf, &src_surf);
102 g2d_free(tmp_buf);
103 }
104 else {
105 _g2d_fill(handle, &dst_surf);
106 }
107 }
108
109 /**********************
110 * STATIC FUNCTIONS
111 **********************/
112
113 static void _g2d_set_src_surf(struct g2d_surface * src_surf, struct g2d_buf * buf, const lv_area_t * area,
114 lv_color_t color, lv_opa_t opa, lv_color_format_t cf)
115 {
116 int32_t width = lv_area_get_width(area);
117 int32_t height = lv_area_get_height(area);
118
119 src_surf->format = g2d_get_buf_format(cf);
120
121 src_surf->left = 0;
122 src_surf->top = 0;
123 src_surf->right = width;
124 src_surf->bottom = height;
125 src_surf->stride = width;
126 src_surf->width = width;
127 src_surf->height = height;
128
129 src_surf->planes[0] = buf->buf_paddr;
130 src_surf->rot = G2D_ROTATION_0;
131
132 src_surf->clrcolor = g2d_rgba_to_u32(color);
133 src_surf->global_alpha = opa;
134 src_surf->blendfunc = G2D_ONE | G2D_PRE_MULTIPLIED_ALPHA;
135 }
136
137 static void _g2d_set_dst_surf(struct g2d_surface * dst_surf, struct g2d_buf * buf, const lv_area_t * area,
138 int32_t stride, lv_color_t color, lv_color_format_t cf)
139 {
140 int32_t width = lv_area_get_width(area);
141 int32_t height = lv_area_get_height(area);
142
143 dst_surf->format = g2d_get_buf_format(cf);
144
145 dst_surf->left = area->x1;
146 dst_surf->top = area->y1;
147 dst_surf->right = area->x1 + width;
148 dst_surf->bottom = area->y1 + height;
149 dst_surf->stride = stride;
150 dst_surf->width = width;
151 dst_surf->height = height;
152
153 dst_surf->planes[0] = buf->buf_paddr;
154 dst_surf->rot = G2D_ROTATION_0;
155
156 dst_surf->clrcolor = g2d_rgba_to_u32(color);
157 dst_surf->global_alpha = 0xff;
158 dst_surf->blendfunc = G2D_ONE_MINUS_SRC_ALPHA | G2D_PRE_MULTIPLIED_ALPHA;
159 }
160
161 static void _g2d_fill_with_opa(void * handle, struct g2d_surface * dst_surf, struct g2d_surface * src_surf)
162 {
163 g2d_clear(handle, src_surf);
164
165 g2d_enable(handle, G2D_BLEND);
166 g2d_enable(handle, G2D_GLOBAL_ALPHA);
167 g2d_blit(handle, src_surf, dst_surf);
168 g2d_finish(handle);
169 g2d_disable(handle, G2D_GLOBAL_ALPHA);
170 g2d_disable(handle, G2D_BLEND);
171 }
172
173 static void _g2d_fill(void * handle, struct g2d_surface * dst_surf)
174 {
175 g2d_clear(handle, dst_surf);
176
177 g2d_finish(handle);
178 }
179
180 #endif /*LV_USE_DRAW_G2D*/
181 #endif /*LV_USE_G2D*/