1 /**
2 * @file lv_draw_pxp_layer.c
3 *
4 */
5
6 /**
7 * Copyright 2023-2024 NXP
8 *
9 * SPDX-License-Identifier: MIT
10 */
11
12 /*********************
13 * INCLUDES
14 *********************/
15
16 #include "lv_draw_pxp.h"
17
18 #if LV_USE_PXP
19 #if LV_USE_DRAW_PXP
20
21 #include "../../../stdlib/lv_string.h"
22 #if LV_USE_PARALLEL_DRAW_DEBUG
23 #include "../../../core/lv_global.h"
24 #endif
25
26 /*********************
27 * DEFINES
28 *********************/
29
30 /**********************
31 * TYPEDEFS
32 **********************/
33
34 /**********************
35 * STATIC PROTOTYPES
36 **********************/
37
38 /**********************
39 * STATIC VARIABLES
40 **********************/
41
42 #if LV_USE_PARALLEL_DRAW_DEBUG
43 #define _draw_info LV_GLOBAL_DEFAULT()->draw_info
44 #endif
45
46 /**********************
47 * MACROS
48 **********************/
49
50 /**********************
51 * GLOBAL FUNCTIONS
52 **********************/
53
lv_draw_pxp_layer(lv_draw_unit_t * draw_unit,const lv_draw_image_dsc_t * draw_dsc,const lv_area_t * coords)54 void lv_draw_pxp_layer(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t * draw_dsc,
55 const lv_area_t * coords)
56 {
57 lv_layer_t * layer_to_draw = (lv_layer_t *)draw_dsc->src;
58 const lv_draw_buf_t * draw_buf = layer_to_draw->draw_buf;
59
60 /* It can happen that nothing was draw on a layer and therefore its buffer is not allocated.
61 * In this case just return.
62 */
63 if(draw_buf == NULL)
64 return;
65
66 const lv_area_t area_to_draw = {
67 .x1 = 0,
68 .y1 = 0,
69 .x2 = draw_buf->header.w - 1,
70 .y2 = draw_buf->header.h - 1
71 };
72 lv_draw_buf_invalidate_cache(draw_buf, &area_to_draw);
73
74 lv_draw_image_dsc_t new_draw_dsc = *draw_dsc;
75 new_draw_dsc.src = draw_buf;
76 lv_draw_pxp_img(draw_unit, &new_draw_dsc, coords);
77
78 #if LV_USE_LAYER_DEBUG || LV_USE_PARALLEL_DRAW_DEBUG
79 lv_area_t area_rot;
80 lv_area_copy(&area_rot, coords);
81 if(draw_dsc->rotation || draw_dsc->scale_x != LV_SCALE_NONE || draw_dsc->scale_y != LV_SCALE_NONE) {
82 int32_t w = lv_area_get_width(coords);
83 int32_t h = lv_area_get_height(coords);
84
85 lv_image_buf_get_transformed_area(&area_rot, w, h, draw_dsc->rotation, draw_dsc->scale_x, draw_dsc->scale_y,
86 &draw_dsc->pivot);
87
88 area_rot.x1 += coords->x1;
89 area_rot.y1 += coords->y1;
90 area_rot.x2 += coords->x1;
91 area_rot.y2 += coords->y1;
92 }
93 lv_area_t draw_area;
94 if(!lv_area_intersect(&draw_area, &area_rot, draw_unit->clip_area)) return;
95 #endif
96
97 #if LV_USE_LAYER_DEBUG
98 lv_draw_fill_dsc_t fill_dsc;
99 lv_draw_fill_dsc_init(&fill_dsc);
100 fill_dsc.color = lv_color_hex(layer_to_draw->color_format == LV_COLOR_FORMAT_ARGB8888 ? 0xff0000 : 0x00ff00);
101 fill_dsc.opa = LV_OPA_20;
102 lv_draw_sw_fill(draw_unit, &fill_dsc, &area_rot);
103
104 lv_draw_border_dsc_t border_dsc;
105 lv_draw_border_dsc_init(&border_dsc);
106 border_dsc.color = fill_dsc.color;
107 border_dsc.opa = LV_OPA_60;
108 border_dsc.width = 2;
109 lv_draw_sw_border(draw_unit, &border_dsc, &area_rot);
110
111 #endif
112
113 #if LV_USE_PARALLEL_DRAW_DEBUG
114 uint32_t idx = 0;
115 lv_draw_unit_t * draw_unit_tmp = _draw_info.unit_head;
116 while(draw_unit_tmp != draw_unit) {
117 draw_unit_tmp = draw_unit_tmp->next;
118 idx++;
119 }
120
121 lv_draw_fill_dsc_t fill_dsc;
122 lv_draw_rect_dsc_init(&fill_dsc);
123 fill_dsc.color = lv_palette_main(idx % LV_PALETTE_LAST);
124 fill_dsc.opa = LV_OPA_10;
125 lv_draw_sw_fill(draw_unit, &fill_dsc, &area_rot);
126
127 lv_draw_border_dsc_t border_dsc;
128 lv_draw_border_dsc_init(&border_dsc);
129 border_dsc.color = lv_palette_main(idx % LV_PALETTE_LAST);
130 border_dsc.opa = LV_OPA_100;
131 border_dsc.width = 2;
132 lv_draw_sw_border(draw_unit, &border_dsc, &area_rot);
133
134 lv_point_t txt_size;
135 lv_text_get_size(&txt_size, "W", LV_FONT_DEFAULT, 0, 0, 100, LV_TEXT_FLAG_NONE);
136
137 lv_area_t txt_area;
138 txt_area.x1 = draw_area.x1;
139 txt_area.x2 = draw_area.x1 + txt_size.x - 1;
140 txt_area.y2 = draw_area.y2;
141 txt_area.y1 = draw_area.y2 - txt_size.y + 1;
142
143 lv_draw_fill_dsc_init(&fill_dsc);
144 fill_dsc.color = lv_color_black();
145 lv_draw_sw_fill(draw_unit, &fill_dsc, &txt_area);
146
147 char buf[8];
148 lv_snprintf(buf, sizeof(buf), "%d", idx);
149 lv_draw_label_dsc_t label_dsc;
150 lv_draw_label_dsc_init(&label_dsc);
151 label_dsc.color = lv_color_white();
152 label_dsc.text = buf;
153 lv_draw_sw_label(draw_unit, &label_dsc, &txt_area);
154 #endif
155 }
156
157 #endif /*LV_USE_DRAW_PXP*/
158 #endif /*LV_USE_PXP*/
159