arch(draw): add parallel rendering architecture

BREAKING CHANGE

This is a huge update which introduces parallel rendering. lv_conf.h needs to be updated too.
This commit is contained in:
Gabor Kiss-Vamosi
2023-07-05 13:05:19 +02:00
parent 08870996d1
commit f753265a79
637 changed files with 34425 additions and 35325 deletions

View File

@@ -4,62 +4,68 @@
static void event_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if(code == LV_EVENT_DRAW_PART_BEGIN) {
lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
lv_draw_task_t * draw_task = lv_event_get_draw_task(e);
lv_draw_dsc_base_t * base_dsc = draw_task->draw_dsc;
/*When the button matrix draws the buttons...*/
if(base_dsc->part == LV_PART_ITEMS) {
bool pressed = false;
if(lv_btnmatrix_get_selected_btn(obj) == base_dsc->id1 && lv_obj_has_state(obj, LV_STATE_PRESSED)) {
pressed = true;
}
/*When the button matrix draws the buttons...*/
if(dsc->class_p == &lv_btnmatrix_class && dsc->type == LV_BTNMATRIX_DRAW_PART_BTN) {
/*Change the draw descriptor of the 2nd button*/
if(dsc->id == 1) {
dsc->rect_dsc->radius = 0;
if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_palette_darken(LV_PALETTE_BLUE, 3);
else dsc->rect_dsc->bg_color = lv_palette_main(LV_PALETTE_BLUE);
dsc->rect_dsc->shadow_width = 6;
dsc->rect_dsc->shadow_ofs_x = 3;
dsc->rect_dsc->shadow_ofs_y = 3;
dsc->label_dsc->color = lv_color_white();
/*Change the draw descriptor of the 2nd button*/
if(base_dsc->id1 == 1) {
if(draw_task->type == LV_DRAW_TASK_TYPE_FILL) {
lv_draw_rect_dsc_t * rect_draw_dsc = draw_task->draw_dsc;
rect_draw_dsc->radius = 0;
if(pressed) rect_draw_dsc->bg_color = lv_palette_darken(LV_PALETTE_BLUE, 3);
else rect_draw_dsc->bg_color = lv_palette_main(LV_PALETTE_BLUE);
rect_draw_dsc->shadow_width = 6;
rect_draw_dsc->shadow_ofs_x = 3;
rect_draw_dsc->shadow_ofs_y = 3;
}
/*Change the draw descriptor of the 3rd button*/
else if(dsc->id == 2) {
dsc->rect_dsc->radius = LV_RADIUS_CIRCLE;
if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_palette_darken(LV_PALETTE_RED, 3);
else dsc->rect_dsc->bg_color = lv_palette_main(LV_PALETTE_RED);
dsc->label_dsc->color = lv_color_white();
if(draw_task->type == LV_DRAW_TASK_TYPE_LABEL) {
lv_draw_label_dsc_t * label_draw_dsc = draw_task->draw_dsc;
label_draw_dsc->color = lv_color_white();
}
else if(dsc->id == 3) {
dsc->label_dsc->opa = LV_OPA_TRANSP; /*Hide the text if any*/
}
/*Change the draw descriptor of the 3rd button*/
else if(base_dsc->id1 == 2) {
if(draw_task->type == LV_DRAW_TASK_TYPE_FILL) {
lv_draw_rect_dsc_t * rect_draw_dsc = draw_task->draw_dsc;
rect_draw_dsc->radius = LV_RADIUS_CIRCLE;
if(pressed) rect_draw_dsc->bg_color = lv_palette_darken(LV_PALETTE_RED, 3);
else rect_draw_dsc->bg_color = lv_palette_main(LV_PALETTE_RED);
}
}
}
if(code == LV_EVENT_DRAW_PART_END) {
lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
/*When the button matrix draws the buttons...*/
if(dsc->class_p == &lv_btnmatrix_class && dsc->type == LV_BTNMATRIX_DRAW_PART_BTN) {
/*Add custom content to the 4th button when the button itself was drawn*/
if(dsc->id == 3) {
else if(base_dsc->id1 == 3) {
if(draw_task->type == LV_DRAW_TASK_TYPE_LABEL) {
lv_draw_label_dsc_t * label_draw_dsc = draw_task->draw_dsc;
label_draw_dsc->opa = 0;
}
if(draw_task->type == LV_DRAW_TASK_TYPE_FILL) {
LV_IMG_DECLARE(img_star);
lv_img_header_t header;
lv_res_t res = lv_img_decoder_get_info(&img_star, &header);
if(res != LV_RES_OK) return;
lv_area_t a;
a.x1 = dsc->draw_area->x1 + (lv_area_get_width(dsc->draw_area) - header.w) / 2;
a.x2 = a.x1 + header.w - 1;
a.y1 = dsc->draw_area->y1 + (lv_area_get_height(dsc->draw_area) - header.h) / 2;
a.y2 = a.y1 + header.h - 1;
a.x1 = 0;
a.x2 = header.w - 1;
a.y1 = 0;
a.y2 = header.h - 1;
lv_area_align(&draw_task->area, &a, LV_ALIGN_CENTER, 0, 0);
lv_draw_img_dsc_t img_draw_dsc;
lv_draw_img_dsc_init(&img_draw_dsc);
img_draw_dsc.src = &img_star;
img_draw_dsc.recolor = lv_color_black();
if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) img_draw_dsc.recolor_opa = LV_OPA_30;
if(pressed) img_draw_dsc.recolor_opa = LV_OPA_30;
lv_draw_img(base_dsc->layer, &img_draw_dsc, &a);
lv_draw_img(dsc->draw_ctx, &img_draw_dsc, &a, &img_star);
}
}
}
@@ -71,7 +77,8 @@ static void event_cb(lv_event_t * e)
void lv_example_btnmatrix_2(void)
{
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act());
lv_obj_add_event(btnm, event_cb, LV_EVENT_ALL, NULL);
lv_obj_add_event(btnm, event_cb, LV_EVENT_DRAW_TASK_ADDED, NULL);
lv_obj_add_flag(btnm, LV_OBJ_FLAG_SEND_DRAW_TASK_EVENTS);
lv_obj_center(btnm);
}

View File

@@ -1,74 +0,0 @@
# Create an image from the png file
try:
with open('../../assets/img_star.png','rb') as f:
png_data = f.read()
except:
print("Could not find star.png")
sys.exit()
img_star_argb = lv.img_dsc_t({
'data_size': len(png_data),
'data': png_data
})
def event_cb(e):
code = e.get_code()
obj = e.get_target_obj()
dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param())
if code == lv.EVENT.DRAW_PART_BEGIN:
# Change the draw descriptor the 2nd button
if dsc.id == 1:
dsc.rect_dsc.radius = 0
if obj.get_selected_btn() == dsc.id:
dsc.rect_dsc.bg_color = lv.palette_darken(lv.PALETTE.GREY, 3)
else:
dsc.rect_dsc.bg_color = lv.palette_main(lv.PALETTE.BLUE)
dsc.rect_dsc.shadow_width = 6
dsc.rect_dsc.shadow_ofs_x = 3
dsc.rect_dsc.shadow_ofs_y = 3
dsc.label_dsc.color = lv.color_white()
# Change the draw descriptor the 3rd button
elif dsc.id == 2:
dsc.rect_dsc.radius = lv.RADIUS_CIRCLE
if obj.get_selected_btn() == dsc.id:
dsc.rect_dsc.bg_color = lv.palette_darken(lv.PALETTE.RED, 3)
else:
dsc.rect_dsc.bg_color = lv.palette_main(lv.PALETTE.RED)
dsc.label_dsc.color = lv.color_white()
elif dsc.id == 3:
dsc.label_dsc.opa = lv.OPA.TRANSP # Hide the text if any
if code == lv.EVENT.DRAW_PART_END:
# Add custom content to the 4th button when the button itself was drawn
if dsc.id == 3:
# LV_IMG_DECLARE(img_star)
header = lv.img_header_t()
res = lv.img.decoder_get_info(img_star_argb, header)
if res != lv.RES.OK:
print("error when getting image header")
return
else:
a = lv.area_t()
a.x1 = dsc.draw_area.x1 + (dsc.draw_area.get_width() - header.w) // 2
a.x2 = a.x1 + header.w - 1
a.y1 = dsc.draw_area.y1 + (dsc.draw_area.get_height() - header.h) // 2
a.y2 = a.y1 + header.h - 1
img_draw_dsc = lv.draw_img_dsc_t()
img_draw_dsc.init()
img_draw_dsc.recolor = lv.color_black()
if obj.get_selected_btn() == dsc.id:
img_draw_dsc.recolor_opa = lv.OPA._30
dsc.draw_ctx.img(img_draw_dsc, a, img_star_argb)
#
# Add custom drawer to the button matrix to c
#
btnm = lv.btnmatrix(lv.scr_act())
btnm.add_event(event_cb, lv.EVENT.ALL, None)
btnm.center()