From da3ff11bd5e56a46e67aa15cae004b9877a8f377 Mon Sep 17 00:00:00 2001 From: Neo Xu Date: Mon, 29 Jan 2024 17:18:24 +0800 Subject: [PATCH] feat(draw_buf): misc update (#5498) Signed-off-by: Xu Xingliang --- src/draw/lv_draw_buf.c | 4 ++++ src/draw/lv_draw_buf.h | 10 ++++++++++ src/draw/vg_lite/lv_draw_vg_lite.c | 3 +++ src/draw/vg_lite/lv_draw_vg_lite_layer.c | 4 +++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/draw/lv_draw_buf.c b/src/draw/lv_draw_buf.c index fba6a4d1d..13cf59b66 100644 --- a/src/draw/lv_draw_buf.c +++ b/src/draw/lv_draw_buf.c @@ -296,8 +296,12 @@ lv_draw_buf_t * lv_draw_buf_adjust_stride(const lv_draw_buf_t * src, uint32_t st lv_draw_buf_t * dst = lv_draw_buf_create(header->w, header->h, header->cf, stride); if(dst == NULL) return NULL; + uint32_t offset = LV_COLOR_INDEXED_PALETTE_SIZE(header->cf) * 4; + if(offset) lv_memcpy(dst->data, src->data, offset); uint8_t * dst_data = dst->data; + dst_data += offset; const uint8_t * src_data = src->data; + src_data += offset; for(int32_t y = 0; y < src->header.h; y++) { lv_memcpy(dst_data, src_data, min_stride); src_data += src->header.stride; diff --git a/src/draw/lv_draw_buf.h b/src/draw/lv_draw_buf.h index 4b14262cf..560a21dc5 100644 --- a/src/draw/lv_draw_buf.h +++ b/src/draw/lv_draw_buf.h @@ -224,6 +224,16 @@ static inline bool lv_draw_buf_has_flag(lv_draw_buf_t * draw_buf, lv_image_flags return draw_buf->header.flags & flag; } +static inline void lv_draw_buf_set_flag(lv_draw_buf_t * draw_buf, lv_image_flags_t flag) +{ + draw_buf->header.flags |= flag; +} + +static inline void lv_draw_buf_clear_flag(lv_draw_buf_t * draw_buf, lv_image_flags_t flag) +{ + draw_buf->header.flags &= ~flag; +} + /** * As of now, draw buf share same definition as `lv_image_dsc_t`. * And is interchangeable with `lv_image_dsc_t`. diff --git a/src/draw/vg_lite/lv_draw_vg_lite.c b/src/draw/vg_lite/lv_draw_vg_lite.c index 07f1504db..08fea7e85 100644 --- a/src/draw/vg_lite/lv_draw_vg_lite.c +++ b/src/draw/vg_lite/lv_draw_vg_lite.c @@ -104,6 +104,9 @@ static void draw_execute(lv_draw_vg_lite_unit_t * u) lv_vg_lite_buffer_from_draw_buf(&u->target_buffer, layer->draw_buf); + /* VG-Lite will output premultiplied image, set the flag correspondingly. */ + lv_draw_buf_set_flag(layer->draw_buf, LV_IMAGE_FLAGS_PREMULTIPLIED); + vg_lite_identity(&u->global_matrix); vg_lite_translate(-layer->buf_area.x1, -layer->buf_area.y1, &u->global_matrix); diff --git a/src/draw/vg_lite/lv_draw_vg_lite_layer.c b/src/draw/vg_lite/lv_draw_vg_lite_layer.c index 825265627..c70ba8946 100644 --- a/src/draw/vg_lite/lv_draw_vg_lite_layer.c +++ b/src/draw/vg_lite/lv_draw_vg_lite_layer.c @@ -51,7 +51,9 @@ void lv_draw_vg_lite_layer(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t LV_PROFILER_BEGIN; /* The GPU output should already be premultiplied RGB */ - layer->draw_buf->header.flags |= LV_IMAGE_FLAGS_PREMULTIPLIED; + if(!lv_draw_buf_has_flag(layer->draw_buf, LV_IMAGE_FLAGS_PREMULTIPLIED)) { + LV_LOG_WARN("Non-premultiplied layer buffer for GPU to draw."); + } lv_draw_image_dsc_t new_draw_dsc = *draw_dsc; new_draw_dsc.src = layer->draw_buf;