feat(draw_buf) make lv_draw_buf_malloc a static function (#5318)

Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Neo Xu
2024-01-15 19:39:28 +08:00
committed by GitHub
parent d619d6b7f5
commit c8bd402192
4 changed files with 21 additions and 35 deletions

View File

@@ -26,6 +26,8 @@
static void * buf_malloc(size_t size, lv_color_format_t color_format);
static void buf_free(void * buf);
static void * buf_align(void * buf, lv_color_format_t color_format);
static void * draw_buf_malloc(size_t size_bytes, lv_color_format_t color_format);
static void draw_buf_free(void * buf);
static uint32_t width_to_stride(uint32_t w, lv_color_format_t color_format);
static uint32_t _calculate_draw_buf_size(uint32_t w, uint32_t h, lv_color_format_t cf, uint32_t stride);
@@ -62,17 +64,6 @@ 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_bytes, lv_color_format_t color_format)
{
if(handlers.buf_malloc_cb) return handlers.buf_malloc_cb(size_bytes, color_format);
else return NULL;
}
void lv_draw_buf_free(void * buf)
{
if(handlers.buf_free_cb) handlers.buf_free_cb(buf);
}
void * lv_draw_buf_align(void * data, lv_color_format_t color_format)
{
if(handlers.align_pointer_cb) return handlers.align_pointer_cb(data, color_format);
@@ -189,7 +180,7 @@ lv_draw_buf_t * lv_draw_buf_create(uint32_t w, uint32_t h, lv_color_format_t cf,
uint32_t size = _calculate_draw_buf_size(w, h, cf, stride);
void * buf = lv_draw_buf_malloc(size, cf);
void * buf = draw_buf_malloc(size, cf);
LV_ASSERT_MALLOC(buf);
if(buf == NULL) {
LV_LOG_WARN("No memory: %"LV_PRIu32"x%"LV_PRIu32", cf: %d, stride: %"LV_PRIu32", %"LV_PRIu32"Byte, ",
@@ -257,7 +248,7 @@ void lv_draw_buf_destroy(lv_draw_buf_t * buf)
if(buf == NULL) return;
if(buf->header.flags & LV_IMAGE_FLAGS_ALLOCATED) {
lv_draw_buf_free(buf->unaligned_data);
draw_buf_free(buf->unaligned_data);
lv_free(buf);
}
else {
@@ -417,6 +408,17 @@ static uint32_t width_to_stride(uint32_t w, lv_color_format_t color_format)
return (width_byte + LV_DRAW_BUF_STRIDE_ALIGN - 1) & ~(LV_DRAW_BUF_STRIDE_ALIGN - 1);
}
static void * draw_buf_malloc(size_t size_bytes, lv_color_format_t color_format)
{
if(handlers.buf_malloc_cb) return handlers.buf_malloc_cb(size_bytes, color_format);
else return NULL;
}
static void draw_buf_free(void * buf)
{
if(handlers.buf_free_cb) handlers.buf_free_cb(buf);
}
/**
* For given width, height, color format, and stride, calculate the size needed for a new draw buffer.
*/