fix(nxp/vglite): fix stride calculation (#6613)

Signed-off-by: Cristian Stoica <cristianmarian.stoica@nxp.com>
Signed-off-by: Nicușor Cîțu <nicusor.citu@nxp.com>
Signed-off-by: Neo Xu
Signed-off-by: Cristian Stoica
Signed-off-by: Cosmin-Daniel Radu <cosmin.radu_1@nxp.com>
Co-authored-by: Nicușor Cîțu <nicusor.citu@nxp.com>
Co-authored-by: Cosmin-Daniel Radu <cosmin.radu_1@nxp.com>
This commit is contained in:
cristian-stoica
2024-08-02 07:17:42 +03:00
committed by GitHub
parent d7b93dd3f1
commit 89f2ff6701
8 changed files with 20 additions and 70 deletions
+2 -1
View File
@@ -577,7 +577,8 @@ static uint32_t width_to_stride(uint32_t w, lv_color_format_t color_format)
uint32_t width_byte;
width_byte = w * lv_color_format_get_bpp(color_format);
width_byte = (width_byte + 7) >> 3; /*Round up*/
return (width_byte + LV_DRAW_BUF_STRIDE_ALIGN - 1) & ~(LV_DRAW_BUF_STRIDE_ALIGN - 1);
return LV_ROUND_UP(width_byte, LV_DRAW_BUF_STRIDE_ALIGN);
}
static void * draw_buf_malloc(const lv_draw_buf_handlers_t * handlers, size_t size_bytes,
-42
View File
@@ -33,14 +33,8 @@
* STATIC PROTOTYPES
**********************/
static void * _buf_malloc(size_t size_bytes, lv_color_format_t cf);
static void * _buf_align(void * buf, lv_color_format_t cf);
static void _invalidate_cache(const lv_draw_buf_t * draw_buf, const lv_area_t * area);
static uint32_t _width_to_stride(uint32_t w, lv_color_format_t cf);
/**********************
* STATIC VARIABLES
**********************/
@@ -57,39 +51,13 @@ void lv_draw_buf_vglite_init_handlers(void)
{
lv_draw_buf_handlers_t * handlers = lv_draw_buf_get_handlers();
handlers->buf_malloc_cb = _buf_malloc;
handlers->align_pointer_cb = _buf_align;
handlers->invalidate_cache_cb = _invalidate_cache;
handlers->width_to_stride_cb = _width_to_stride;
}
/**********************
* STATIC FUNCTIONS
**********************/
static void * _buf_malloc(size_t size_bytes, lv_color_format_t cf)
{
uint8_t align_bytes = vglite_get_alignment(cf);
/*Allocate larger memory to be sure it can be aligned as needed*/
size_bytes += align_bytes - 1;
return lv_malloc(size_bytes);
}
static void * _buf_align(void * buf, lv_color_format_t cf)
{
uint8_t align_bytes = vglite_get_alignment(cf);
uint8_t * buf_u8 = buf;
if(buf_u8) {
buf_u8 += align_bytes - 1;
buf_u8 = (uint8_t *)((lv_uintptr_t)buf_u8 & ~(align_bytes - 1));
}
return buf_u8;
}
static void _invalidate_cache(const lv_draw_buf_t * draw_buf, const lv_area_t * area)
{
const lv_image_header_t * header = &draw_buf->header;
@@ -139,14 +107,4 @@ static void _invalidate_cache(const lv_draw_buf_t * draw_buf, const lv_area_t *
}
}
static uint32_t _width_to_stride(uint32_t w, lv_color_format_t cf)
{
uint8_t bits_per_pixel = lv_color_format_get_bpp(cf);
uint32_t width_bits = (w * bits_per_pixel + 7) & ~7;
uint32_t width_bytes = width_bits / 8;
uint8_t align_bytes = vglite_get_alignment(cf);
return (width_bytes + align_bytes - 1) & ~(align_bytes - 1);
}
#endif /*LV_USE_DRAW_VGLITE*/
+2 -4
View File
@@ -163,7 +163,7 @@ static inline bool _vglite_dest_cf_supported(lv_color_format_t cf)
case LV_COLOR_FORMAT_L8:
#endif
case LV_COLOR_FORMAT_RGB565:
#if CHIPTID == 0x555
#if CHIPID == 0x555
case LV_COLOR_FORMAT_RGB565A8:
case LV_COLOR_FORMAT_RGB888:
#endif
@@ -212,8 +212,6 @@ static int32_t _vglite_evaluate(lv_draw_unit_t * u, lv_draw_task_t * t)
return 1;
case LV_DRAW_TASK_TYPE_BORDER: {
const lv_draw_border_dsc_t * draw_dsc = (lv_draw_border_dsc_t *) t->draw_dsc;
if(t->preference_score > 90) {
t->preference_score = 90;
t->preferred_draw_unit_id = DRAW_UNIT_ID_VGLITE;
@@ -256,7 +254,7 @@ static int32_t _vglite_evaluate(lv_draw_unit_t * u, lv_draw_task_t * t)
#if LV_USE_VGLITE_BLIT_SPLIT
|| has_transform
#endif
|| (!vglite_buf_aligned(img_dsc->data, img_dsc->header.stride, img_dsc->header.cf))
|| (!vglite_src_buf_aligned(img_dsc->data, img_dsc->header.stride, img_dsc->header.cf))
)
return 0;
+1 -1
View File
@@ -213,7 +213,7 @@ static void _vglite_blit(const lv_area_t * src_area, const lv_draw_image_dsc_t *
static void _move_buf_close_to_area(void ** buf, lv_area_t * area, uint32_t stride, lv_color_format_t cf)
{
uint8_t ** buf_u8 = (uint8_t **)buf;
uint8_t align_bytes = vglite_get_alignment(cf);
uint8_t align_bytes = vglite_get_stride_alignment(cf);
uint8_t bits_per_pixel = lv_color_format_get_bpp(cf);
uint16_t align_pixels = align_bytes * 8 / bits_per_pixel;
+1 -1
View File
@@ -118,7 +118,7 @@ static void _draw_vglite_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t
mask_area.x2 = mask_width - 1;
mask_area.y2 = mask_height - 1;
if(!vglite_buf_aligned(mask_buf, mask_stride, LV_COLOR_FORMAT_A8)) {
if(!vglite_src_buf_aligned(mask_buf, mask_stride, LV_COLOR_FORMAT_A8)) {
/* Draw a placeholder rectangle*/
lv_draw_border_dsc_t border_draw_dsc;
lv_draw_border_dsc_init(&border_draw_dsc);
@@ -134,10 +134,13 @@ static void _vglite_draw_triangle(const lv_area_t * coords, const lv_area_t * cl
/* Gradient Setup */
vg_lite_uint32_t cnt = LV_MAX(dsc->bg_grad.stops_count, LV_GRADIENT_MAX_STOPS);
lv_opa_t bg_opa;
for(uint8_t i = 0; i < cnt; i++) {
stops[i] = dsc->bg_grad.stops[i].frac;
bg_opa = LV_OPA_MIX2(dsc->bg_grad.stops[i].opa, dsc->bg_opa);
col32[i] = lv_color_to_32(dsc->bg_grad.stops[i].color, dsc->bg_grad.stops[i].opa);
col32[i] = lv_color_to_32(dsc->bg_grad.stops[i].color, bg_opa);
colors[i] = vglite_get_color(col32[i], true);
}
+6 -16
View File
@@ -218,7 +218,7 @@ vg_lite_buffer_format_t vglite_get_buf_format(lv_color_format_t cf)
return vg_buffer_format;
}
uint8_t vglite_get_alignment(lv_color_format_t cf)
uint8_t vglite_get_stride_alignment(lv_color_format_t cf)
{
uint8_t align_bytes = LV_COLOR_DEPTH / 8 * 16; /*16 pixels*/
@@ -226,20 +226,12 @@ uint8_t vglite_get_alignment(lv_color_format_t cf)
case LV_COLOR_FORMAT_I1:
case LV_COLOR_FORMAT_I2:
case LV_COLOR_FORMAT_I4:
/*
* VGLite alignment require 8 bytes.
* But ARM clean and invalidate cache needs 32 bytes address alignment.
*/
align_bytes = 32;
align_bytes = 8;
break;
case LV_COLOR_FORMAT_I8:
case LV_COLOR_FORMAT_A8:
case LV_COLOR_FORMAT_L8:
/*
* VGLite alignment require 16 bytes.
* But ARM clean and invalidate cache needs 32 bytes address alignment.
*/
align_bytes = 32;
align_bytes = 16;
break;
case LV_COLOR_FORMAT_RGB565:
align_bytes = 32;
@@ -261,18 +253,16 @@ uint8_t vglite_get_alignment(lv_color_format_t cf)
return align_bytes;
}
bool vglite_buf_aligned(const void * buf, uint32_t stride, lv_color_format_t cf)
bool vglite_src_buf_aligned(const void * buf, uint32_t stride, lv_color_format_t cf)
{
uint8_t align_bytes = vglite_get_alignment(cf);
/* No alignment requirement for destination buffer when using mode VG_LITE_LINEAR */
/* Test for pointer alignment */
if((uintptr_t)buf % align_bytes)
if((uintptr_t)buf % LV_ATTRIBUTE_MEM_ALIGN_SIZE)
return false;
/* Test for stride alignment */
if(stride == 0 || stride % align_bytes)
if(stride == 0 || stride % vglite_get_stride_alignment(cf))
return false;
return true;
+4 -4
View File
@@ -128,17 +128,17 @@ vg_lite_blend_t vglite_get_blend_mode(lv_blend_mode_t lv_blend_mode);
vg_lite_buffer_format_t vglite_get_buf_format(lv_color_format_t cf);
/**
* Get vglite buffer alignment.
* Get vglite stride alignment.
*
* @param[in] cf Color format
*
* @retval Alignment requirement in bytes
*
*/
uint8_t vglite_get_alignment(lv_color_format_t cf);
uint8_t vglite_get_stride_alignment(lv_color_format_t cf);
/**
* Check memory and stride alignment.
* Check source start address and stride alignment.
*
* @param[in] buf Buffer address
* @param[in] stride Stride of buffer in bytes
@@ -147,7 +147,7 @@ uint8_t vglite_get_alignment(lv_color_format_t cf);
* @retval true Alignment OK
*
*/
bool vglite_buf_aligned(const void * buf, uint32_t stride, lv_color_format_t cf);
bool vglite_src_buf_aligned(const void * buf, uint32_t stride, lv_color_format_t cf);
/**********************
* MACROS