feat(draw_buf): add color_format paramater to draw_buf_malloc and align
related to https://github.com/lvgl/lvgl/pull/4414#issuecomment-1707725195
This commit is contained in:
@@ -338,7 +338,7 @@ void * lv_draw_layer_alloc_buf(lv_layer_t * layer)
|
||||
uint32_t layer_size_byte = layer->draw_buf.height * lv_draw_buf_width_to_stride(layer->draw_buf.width,
|
||||
layer->draw_buf.color_format);
|
||||
size_t s = lv_draw_buf_get_stride(&layer->draw_buf) * layer->draw_buf.height;
|
||||
layer->draw_buf.buf = lv_draw_buf_malloc(s);
|
||||
layer->draw_buf.buf = lv_draw_buf_malloc(s, layer->draw_buf.color_format);
|
||||
|
||||
if(lv_draw_buf_get_buf(&layer->draw_buf) == NULL) {
|
||||
LV_LOG_WARN("Allocating %"LV_PRIu32" bytes of layer buffer failed. Try later", layer_size_byte);
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void buf_init(lv_draw_buf_t * draw_buf, lv_coord_t w, lv_coord_t h, lv_color_format_t color_format);
|
||||
static void * buf_malloc(size_t size);
|
||||
static void * buf_malloc(size_t size, lv_color_format_t color_format);
|
||||
static void buf_free(void * buf);
|
||||
static void * aligne_buf(void * buf);
|
||||
static void * align_buf(void * buf, lv_color_format_t color_format);
|
||||
static uint32_t width_to_stride(uint32_t w, lv_color_format_t color_format);
|
||||
static void * go_to_xy(lv_draw_buf_t * draw_buf, lv_coord_t x, lv_coord_t y);
|
||||
static void buf_clear(lv_draw_buf_t * draw_buf, const lv_area_t * a);
|
||||
@@ -52,7 +52,7 @@ void _lv_draw_buf_init_handlers(void)
|
||||
handlers.init_cb = buf_init;
|
||||
handlers.buf_malloc_cb = buf_malloc;
|
||||
handlers.buf_free_cb = buf_free;
|
||||
handlers.align_pointer_cb = aligne_buf;
|
||||
handlers.align_pointer_cb = align_buf;
|
||||
handlers.invalidate_cache_cb = NULL;
|
||||
handlers.width_to_stride_cb = width_to_stride;
|
||||
handlers.go_to_xy_cb = go_to_xy;
|
||||
@@ -76,7 +76,7 @@ void lv_draw_buf_init_alloc(lv_draw_buf_t * draw_buf, lv_coord_t w, lv_coord_t h
|
||||
lv_draw_buf_init(draw_buf, w, h, color_format);
|
||||
|
||||
size_t s = lv_draw_buf_get_stride(draw_buf) * h;
|
||||
draw_buf->buf = lv_draw_buf_malloc(s);
|
||||
draw_buf->buf = lv_draw_buf_malloc(s, color_format);
|
||||
}
|
||||
|
||||
uint32_t lv_draw_buf_width_to_stride(uint32_t w, lv_color_format_t color_format)
|
||||
@@ -85,9 +85,9 @@ uint32_t lv_draw_buf_width_to_stride(uint32_t w, lv_color_format_t color_format)
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void * lv_draw_buf_malloc(size_t size)
|
||||
void * lv_draw_buf_malloc(size_t size_bytes, lv_color_format_t color_format)
|
||||
{
|
||||
if(handlers.buf_malloc_cb) return handlers.buf_malloc_cb(size);
|
||||
if(handlers.buf_malloc_cb) return handlers.buf_malloc_cb(size_bytes, color_format);
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
@@ -96,9 +96,9 @@ void lv_draw_buf_free(void * buf)
|
||||
if(handlers.buf_free_cb) handlers.buf_free_cb(buf);
|
||||
}
|
||||
|
||||
void * lv_draw_buf_align_buf(void * data)
|
||||
void * lv_draw_buf_align_buf(void * data, lv_color_format_t color_format)
|
||||
{
|
||||
if(handlers.align_pointer_cb) return handlers.align_pointer_cb(data);
|
||||
if(handlers.align_pointer_cb) return handlers.align_pointer_cb(data, color_format);
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ void lv_draw_buf_copy(void * dest_buf, uint32_t dest_stride, const lv_area_t * d
|
||||
|
||||
void * lv_draw_buf_get_buf(lv_draw_buf_t * draw_buf)
|
||||
{
|
||||
if(draw_buf->buf) return lv_draw_buf_align_buf(draw_buf->buf);
|
||||
if(draw_buf->buf) return lv_draw_buf_align_buf(draw_buf->buf, draw_buf->color_format);
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
@@ -151,10 +151,13 @@ static void buf_init(lv_draw_buf_t * draw_buf, lv_coord_t w, lv_coord_t h, lv_co
|
||||
draw_buf->buf = NULL;
|
||||
}
|
||||
|
||||
static void * buf_malloc(size_t size)
|
||||
static void * buf_malloc(size_t size_bytes, lv_color_format_t color_format)
|
||||
{
|
||||
size += LV_DRAW_BUF_ALIGN - 1; /*Allocate larger memory to be sure it can be aligned as needed*/
|
||||
return lv_malloc(size);
|
||||
LV_UNUSED(color_format);
|
||||
|
||||
/*Allocate larger memory to be sure it can be aligned as needed*/
|
||||
size_bytes += LV_DRAW_BUF_ALIGN - 1;
|
||||
return lv_malloc(size_bytes);
|
||||
}
|
||||
|
||||
static void buf_free(void * buf)
|
||||
@@ -162,8 +165,10 @@ static void buf_free(void * buf)
|
||||
lv_free(buf);
|
||||
}
|
||||
|
||||
static void * aligne_buf(void * buf)
|
||||
static void * align_buf(void * buf, lv_color_format_t color_format)
|
||||
{
|
||||
LV_UNUSED(color_format);
|
||||
|
||||
uint8_t * buf_u8 = buf;
|
||||
if(buf_u8) {
|
||||
buf_u8 += LV_DRAW_BUF_ALIGN - 1;
|
||||
|
||||
@@ -36,11 +36,11 @@ typedef struct {
|
||||
typedef void (*lv_draw_buf_init_cb)(lv_draw_buf_t * draw_buf, lv_coord_t w, lv_coord_t h,
|
||||
lv_color_format_t color_format);
|
||||
|
||||
typedef void * (*lv_draw_buf_malloc_cb)(size_t size);
|
||||
typedef void * (*lv_draw_buf_malloc_cb)(size_t size, lv_color_format_t color_format);
|
||||
|
||||
typedef void (*lv_draw_buf_free_cb)(void * draw_buf);
|
||||
|
||||
typedef void * (*lv_draw_buf_align_buf_cb)(void * buf);
|
||||
typedef void * (*lv_draw_buf_align_buf_cb)(void * buf, lv_color_format_t color_format);
|
||||
|
||||
typedef void (*lv_draw_buf_invalidate_cache_cb)(lv_draw_buf_t * draw_buf, const char * area);
|
||||
|
||||
@@ -103,12 +103,13 @@ void lv_draw_buf_init_alloc(lv_draw_buf_t * draw_buf, lv_coord_t w, lv_coord_t h
|
||||
|
||||
/**
|
||||
* Allocate a buffer with the given size. It might allocate slightly larger buffer to fulfill the alignment requirements.
|
||||
* @param size the size to allocate in bytes
|
||||
* @param the allocated buffer.
|
||||
* @param size the size to allocate in bytes
|
||||
* @param color_format the color format of the buffer to allcoate
|
||||
* @return the allocated buffer.
|
||||
* @note The returned value can be saved in draw_buf->buf
|
||||
* @note lv_draw_buf_align_buf can be sued the align the returned pointer
|
||||
*/
|
||||
void * lv_draw_buf_malloc(size_t size);
|
||||
void * lv_draw_buf_malloc(size_t size_bytes, lv_color_format_t color_format);
|
||||
|
||||
/**
|
||||
* Free a buffer allocated by lv_draw_buf_malloc
|
||||
@@ -119,9 +120,10 @@ void lv_draw_buf_free(void * buf);
|
||||
/**
|
||||
* Align the address of a buffer. The buffer needs to be large enough for the real data after alignement
|
||||
* @param buf the data to align
|
||||
* @param color_format the color format of the buffer
|
||||
* @return the aligned buffer
|
||||
*/
|
||||
void * lv_draw_buf_align_buf(void * buf);
|
||||
void * lv_draw_buf_align_buf(void * buf, lv_color_format_t color_format);
|
||||
|
||||
/**
|
||||
* Get the buffer of the draw_buf.
|
||||
|
||||
@@ -400,9 +400,9 @@ static void draw_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * dsc,
|
||||
bitmap_size = (bitmap_size + 63) & (~63); /*Round up*/
|
||||
if(dsc->_bitmap_buf_size < bitmap_size) {
|
||||
lv_draw_buf_free(dsc->_bitmap_buf_unaligned);
|
||||
dsc->_bitmap_buf_unaligned = lv_draw_buf_malloc(bitmap_size);
|
||||
dsc->_bitmap_buf_unaligned = lv_draw_buf_malloc(bitmap_size, LV_COLOR_FORMAT_A8);
|
||||
LV_ASSERT_MALLOC(dsc->_bitmap_buf_unaligned);
|
||||
dsc->bitmap_buf = lv_draw_buf_align_buf(dsc->_bitmap_buf_unaligned);
|
||||
dsc->bitmap_buf = lv_draw_buf_align_buf(dsc->_bitmap_buf_unaligned, LV_COLOR_FORMAT_A8);
|
||||
dsc->_bitmap_buf_size = bitmap_size;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user