Debian Codegraph @

lvgl/src/draw/renesas/dave2d/lv_draw_dave2d_fill.c

raw symbols SCIP
1 #include "lv_draw_dave2d.h"
2 #if LV_USE_DRAW_DAVE2D
3
4 #include "../../../misc/lv_area_private.h"
5
6 void lv_draw_dave2d_fill(lv_draw_task_t * t, const lv_draw_fill_dsc_t * dsc, const lv_area_t * coords)
7 {
8 lv_area_t draw_area;
9 lv_area_t coordinates;
10 bool is_common;
11 int32_t x;
12 int32_t y;
13 d2_u8 current_alpha_mode = 0;
14 d2_s32 result;
15 d2_u32 flags = 0;
16
17 lv_point_t arc_centre;
18 lv_draw_dave2d_unit_t * u = (lv_draw_dave2d_unit_t *)t->draw_unit;
19
20 is_common = lv_area_intersect(&draw_area, coords, &t->clip_area);
21 if(!is_common) return;
22
23 #if LV_USE_OS
24 lv_result_t status;
25 status = lv_mutex_lock(u->pd2Mutex);
26 LV_ASSERT(LV_RESULT_OK == status);
27 #endif
28
29 lv_area_copy(&coordinates, coords);
30
31 x = 0 - t->target_layer->buf_area.x1;
32 y = 0 - t->target_layer->buf_area.y1;
33
34 lv_area_move(&draw_area, x, y);
35 lv_area_move(&coordinates, x, y);
36
37 d2_u8 current_alpha = d2_getalpha(u->d2_handle);
38 d2_framebuffer_from_layer(u->d2_handle, t->target_layer);
39
40 if(LV_GRAD_DIR_NONE != dsc->grad.dir) {
41 float a1;
42 float a2;
43
44 float y1;
45 float y2;
46
47 float y3;
48 float y0;
49 int16_t y0_i ;
50 int16_t y3_i ;
51
52 if(LV_GRAD_DIR_VER == dsc->grad.dir) {
53 a1 = dsc->grad.stops[0].opa;
54 a2 = dsc->grad.stops[dsc->grad.stops_count - 1].opa;
55
56 y1 = (float)LV_MIN(coordinates.y1, coordinates.y2);
57 y2 = (float)LV_MAX(coordinates.y1, coordinates.y2);
58
59 if(a1 < a2) {
60 y0 = 0.0f;//silence the compiler warning
61 y3 = 0.0f;
62
63 }
64 else {
65 y0 = y2 - ((y2 - y1) / (a2 - a1) * (a2)); //point where alpha is 0
66 y3 = y1 + ((y2 - y1) / (a2 - a1) * (255 - a1)); //point where alpha is 255
67 }
68
69 y0_i = (int16_t)y0;
70 y3_i = (int16_t)y3;
71
72 d2_setalphagradient(u->d2_handle, 0, (d2_point)D2_FIX4(0), (d2_point)D2_FIX4(y0_i), (d2_point)D2_FIX4(0),
73 (d2_point)D2_FIX4((y3_i - y0_i)));
74 }
75 else if(LV_GRAD_DIR_HOR == dsc->grad.dir) {
76
77 float x1;
78 float x2;
79
80 float x3;
81 float x0;
82 int16_t x0_i ;
83 int16_t x3_i ;
84
85 a1 = dsc->grad.stops[0].opa;
86 a2 = dsc->grad.stops[dsc->grad.stops_count - 1].opa;
87
88 x1 = (float)LV_MIN(coordinates.x1, coordinates.x2);
89 x2 = (float)LV_MAX(coordinates.x1, coordinates.x2);
90
91 if(a1 < a2) {
92 x0 = 0.0f;//silence the compiler warning
93 x3 = 0.0f;
94
95 }
96 else {
97 x0 = x2 - ((x2 - x1) / (a2 - a1) * (a2)); //point where alpha is 0
98 x3 = x1 + ((x2 - x1) / (a2 - a1) * (255 - a1)); //point where alpha is 255
99 }
100
101 x0_i = (int16_t)x0;
102 x3_i = (int16_t)x3;
103
104 d2_setalphagradient(u->d2_handle, 0, (d2_point)D2_FIX4(x0_i), (d2_point)D2_FIX4(0), (d2_point)D2_FIX4(x3_i - x0_i),
105 (d2_point)D2_FIX4((0)));
106 }
107
108 current_alpha_mode = d2_getalphamode(u->d2_handle);
109 d2_setfillmode(u->d2_handle, d2_fm_color);
110 d2_setcolor(u->d2_handle, 0, lv_draw_dave2d_lv_colour_to_d2_colour(dsc->grad.stops[0].color));
111 d2_setalphamode(u->d2_handle, d2_am_gradient1);
112 }
113 else {
114 d2_setfillmode(u->d2_handle, d2_fm_color); //default
115 d2_setcolor(u->d2_handle, 0, lv_draw_dave2d_lv_colour_to_d2_colour(dsc->color));
116 d2_setalpha(u->d2_handle, dsc->opa);
117 }
118
119 d2_cliprect(u->d2_handle, (d2_border)draw_area.x1, (d2_border)draw_area.y1, (d2_border)draw_area.x2,
120 (d2_border)draw_area.y2);
121
122 if(dsc->radius == 0) {
123
124 d2_renderbox(u->d2_handle, (d2_point)D2_FIX4(coordinates.x1),
125 (d2_point)D2_FIX4(coordinates.y1),
126 (d2_point)D2_FIX4(lv_area_get_width(&coordinates)),
127 (d2_point)D2_FIX4(lv_area_get_height(&coordinates)));
128 }
129 else {
130 /*Get the real radius. Can't be larger than the half of the shortest side */
131 int32_t coords_bg_w = lv_area_get_width(&coordinates);
132 int32_t coords_bg_h = lv_area_get_height(&coordinates);
133 int32_t short_side = LV_MIN(coords_bg_w, coords_bg_h);
134 int32_t radius = LV_MIN(dsc->radius, short_side >> 1);
135
136 arc_centre.x = coordinates.x1 + radius;
137 arc_centre.y = coordinates.y1 + radius;
138
139 if(((2 * radius) == coords_bg_w) && ((2 * radius) == coords_bg_h)) {
140 result = d2_rendercircle(u->d2_handle,
141 (d2_point)D2_FIX4(arc_centre.x),
142 (d2_point) D2_FIX4(arc_centre.y),
143 (d2_width) D2_FIX4(radius),
144 (d2_width) D2_FIX4(0));
145 LV_ASSERT(D2_OK == result);
146 }
147 else {
148
149 lv_area_t arc_area;
150 lv_area_t clip_arc;
151 arc_centre.x = coordinates.x1 + radius;
152 arc_centre.y = coordinates.y1 + radius;
153
154 arc_area.x1 = coordinates.x1;
155 arc_area.y1 = coordinates.y1;
156 arc_area.x2 = coordinates.x1 + radius;
157 arc_area.y2 = coordinates.y1 + radius;
158
159 if(lv_area_intersect(&clip_arc, &arc_area, &draw_area)) {
160
161 d2_cliprect(u->d2_handle, (d2_border)clip_arc.x1, (d2_border)clip_arc.y1, (d2_border)clip_arc.x2,
162 (d2_border)clip_arc.y2);
163
164 // d2_renderwedge internally changes the clip rectangle, only draw it if it is in side the current clip rectangle
165 result = d2_renderwedge(u->d2_handle,
166 (d2_point)D2_FIX4(arc_centre.x),
167 (d2_point) D2_FIX4(arc_centre.y),
168 (d2_width) D2_FIX4(radius),
169 (d2_width) D2_FIX4(0),
170 (d2_s32) D2_FIX16(0), // 180 Degrees
171 (d2_s32) D2_FIX16((int16_t) -1),
172 (d2_s32) D2_FIX16((int16_t) -1),//( 270 Degrees
173 (d2_s32) D2_FIX16(0),
174 flags);
175 LV_ASSERT(D2_OK == result);
176 }
177
178 arc_centre.x = coordinates.x2 - radius;
179 arc_centre.y = coordinates.y1 + radius;
180
181 arc_area.x1 = coordinates.x2 - radius;
182 arc_area.y1 = coordinates.y1;
183 arc_area.x2 = coordinates.x2;
184 arc_area.y2 = coordinates.y1 + radius;
185
186 if(lv_area_intersect(&clip_arc, &arc_area, &draw_area)) {
187 d2_cliprect(u->d2_handle, (d2_border)clip_arc.x1, (d2_border)clip_arc.y1, (d2_border)clip_arc.x2,
188 (d2_border)clip_arc.y2);
189
190 result = d2_renderwedge(u->d2_handle,
191 (d2_point)D2_FIX4(arc_centre.x),
192 (d2_point) D2_FIX4(arc_centre.y),
193 (d2_width) D2_FIX4(radius),
194 (d2_width) D2_FIX4(0),
195 (d2_s32) D2_FIX16((int16_t)1), // 270 Degrees
196 (d2_s32) D2_FIX16(0),
197 (d2_s32) D2_FIX16(0),// 0 degrees
198 (d2_s32) D2_FIX16(-1),
199 flags);
200 LV_ASSERT(D2_OK == result);
201 }
202
203 arc_centre.x = coordinates.x2 - radius;
204 arc_centre.y = coordinates.y2 - radius;
205
206 arc_area.x1 = coordinates.x2 - radius;
207 arc_area.y1 = coordinates.y2 - radius;
208 arc_area.x2 = coordinates.x2;
209 arc_area.y2 = coordinates.y2;
210
211 if(lv_area_intersect(&clip_arc, &arc_area, &draw_area)) {
212 d2_cliprect(u->d2_handle, (d2_border)clip_arc.x1, (d2_border)clip_arc.y1, (d2_border)clip_arc.x2,
213 (d2_border)clip_arc.y2);
214
215 result = d2_renderwedge(u->d2_handle,
216 (d2_point)D2_FIX4(arc_centre.x),
217 (d2_point) D2_FIX4(arc_centre.y),
218 (d2_width) D2_FIX4(radius),
219 (d2_width) D2_FIX4(0),
220 (d2_s32) D2_FIX16(0),// 0 degrees
221 (d2_s32) D2_FIX16(1),
222 (d2_s32) D2_FIX16(1),// 90 degrees
223 (d2_s32) D2_FIX16(0),
224 flags);
225 LV_ASSERT(D2_OK == result);
226 }
227
228 arc_centre.x = coordinates.x1 + radius;
229 arc_centre.y = coordinates.y2 - radius;
230
231 arc_area.x1 = coordinates.x1;
232 arc_area.y1 = coordinates.y2 - radius;
233 arc_area.x2 = coordinates.x1 + radius;
234 arc_area.y2 = coordinates.y2;
235
236 if(lv_area_intersect(&clip_arc, &arc_area, &draw_area)) {
237 d2_cliprect(u->d2_handle, (d2_border)clip_arc.x1, (d2_border)clip_arc.y1, (d2_border)clip_arc.x2,
238 (d2_border)clip_arc.y2);
239
240 result = d2_renderwedge(u->d2_handle,
241 (d2_point)D2_FIX4(arc_centre.x),
242 (d2_point) D2_FIX4(arc_centre.y),
243 (d2_width) D2_FIX4(radius),
244 (d2_width) D2_FIX4(0),
245 (d2_s32) D2_FIX16((int16_t) -1), //90 degrees
246 (d2_s32) D2_FIX16(0),
247 (d2_s32) D2_FIX16(0), //180 degrees
248 (d2_s32) D2_FIX16(1),
249 flags);
250 LV_ASSERT(D2_OK == result);
251 }
252
253 /* reset the clip rectangle */
254 d2_cliprect(u->d2_handle, (d2_border)draw_area.x1, (d2_border)draw_area.y1, (d2_border)draw_area.x2,
255 (d2_border)draw_area.y2);
256
257 result = d2_renderbox(u->d2_handle,
258 (d2_width)D2_FIX4(coordinates.x1 + radius),
259 (d2_width)D2_FIX4(coordinates.y1),
260 (d2_width)D2_FIX4(lv_area_get_width(&coordinates) - (2 * radius)),
261 (d2_width)D2_FIX4(lv_area_get_height(&coordinates)));
262 LV_ASSERT(D2_OK == result);
263
264 result = d2_renderbox(u->d2_handle,
265 (d2_width)D2_FIX4(coordinates.x1),
266 (d2_width)D2_FIX4(coordinates.y1 + radius),
267 (d2_width)D2_FIX4(radius),
268 (d2_width)D2_FIX4(lv_area_get_height(&coordinates) - (2 * radius)));
269 LV_ASSERT(D2_OK == result);
270
271 result = d2_renderbox(u->d2_handle,
272 (d2_width)D2_FIX4(coordinates.x2 - radius + 1),
273 (d2_width)D2_FIX4(coordinates.y1 + radius),
274 (d2_width)D2_FIX4(radius),
275 (d2_width)D2_FIX4(lv_area_get_height(&coordinates) - (2 * radius)));
276 LV_ASSERT(D2_OK == result);
277 }
278 }
279
280 if(LV_GRAD_DIR_NONE != dsc->grad.dir) {
281 d2_setalphamode(u->d2_handle, current_alpha_mode);
282 d2_setfillmode(u->d2_handle, d2_fm_color); //default
283 }
284 else {
285 d2_setalpha(u->d2_handle, current_alpha);
286 }
287
288 #if LV_USE_OS
289 status = lv_mutex_unlock(u->pd2Mutex);
290 LV_ASSERT(LV_RESULT_OK == status);
291 #endif
292 }
293
294 #endif /*LV_USE_DRAW_DAVE2D*/