refactor(draw_buf): remove lv_draw_buf_t and make all functions work on void * buffer directly
This commit is contained in:
@@ -24,13 +24,13 @@
|
||||
/**********************
|
||||
* 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, lv_color_format_t color_format);
|
||||
static void buf_free(void * buf);
|
||||
static void * align_buf(void * buf, lv_color_format_t color_format);
|
||||
static void * buf_align(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);
|
||||
static void * buf_go_to_xy(const void * buf, uint32_t stride, lv_color_format_t color_format, lv_coord_t x,
|
||||
lv_coord_t y);
|
||||
static void buf_clear(void * buf, uint32_t strid, lv_color_format_t color_format, const lv_area_t * a);
|
||||
static void buf_copy(void * dest_buf, uint32_t dest_stride, const lv_area_t * dest_area,
|
||||
void * src_buf, uint32_t src_stride, const lv_area_t * src_area, lv_color_format_t color_format);
|
||||
|
||||
@@ -49,13 +49,12 @@ static void buf_copy(void * dest_buf, uint32_t dest_stride, const lv_area_t * de
|
||||
void _lv_draw_buf_init_handlers(void)
|
||||
{
|
||||
lv_memzero(&handlers, sizeof(lv_draw_buf_handlers_t));
|
||||
handlers.init_cb = buf_init;
|
||||
handlers.buf_malloc_cb = buf_malloc;
|
||||
handlers.buf_free_cb = buf_free;
|
||||
handlers.align_pointer_cb = align_buf;
|
||||
handlers.align_pointer_cb = buf_align;
|
||||
handlers.invalidate_cache_cb = NULL;
|
||||
handlers.width_to_stride_cb = width_to_stride;
|
||||
handlers.go_to_xy_cb = go_to_xy;
|
||||
handlers.go_to_xy_cb = buf_go_to_xy;
|
||||
handlers.buf_clear_cb = buf_clear;
|
||||
handlers.buf_copy_cb = buf_copy;
|
||||
}
|
||||
@@ -65,19 +64,6 @@ lv_draw_buf_handlers_t * lv_draw_buf_get_handlers(void)
|
||||
return &handlers;
|
||||
}
|
||||
|
||||
void lv_draw_buf_init(lv_draw_buf_t * draw_buf, lv_coord_t w, lv_coord_t h, lv_color_format_t color_format)
|
||||
{
|
||||
lv_memzero(draw_buf, sizeof(lv_draw_buf_t));
|
||||
if(handlers.init_cb) handlers.init_cb(draw_buf, w, h, color_format);
|
||||
}
|
||||
|
||||
void lv_draw_buf_init_alloc(lv_draw_buf_t * draw_buf, lv_coord_t w, lv_coord_t h, lv_color_format_t color_format)
|
||||
{
|
||||
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, color_format);
|
||||
}
|
||||
|
||||
uint32_t lv_draw_buf_width_to_stride(uint32_t w, lv_color_format_t color_format)
|
||||
{
|
||||
@@ -96,7 +82,7 @@ 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, lv_color_format_t color_format)
|
||||
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);
|
||||
else return NULL;
|
||||
@@ -107,15 +93,16 @@ void lv_draw_buf_invalidate_cache(void * buf, size_t size)
|
||||
if(handlers.invalidate_cache_cb) handlers.invalidate_cache_cb(buf, size);
|
||||
}
|
||||
|
||||
void * lv_draw_buf_go_to_xy(lv_draw_buf_t * draw_buf, lv_coord_t x, lv_coord_t y)
|
||||
void * lv_draw_buf_go_to_xy(const void * buf, uint32_t stride, lv_color_format_t color_format, lv_coord_t x,
|
||||
lv_coord_t y)
|
||||
{
|
||||
if(handlers.go_to_xy_cb) return handlers.go_to_xy_cb(draw_buf, x, y);
|
||||
if(handlers.go_to_xy_cb) return handlers.go_to_xy_cb(buf, stride, color_format, x, y);
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
void lv_draw_buf_clear(lv_draw_buf_t * draw_buf, const lv_area_t * a)
|
||||
void lv_draw_buf_clear(void * buf, uint32_t stride, lv_color_format_t color_format, const lv_area_t * a)
|
||||
{
|
||||
if(handlers.buf_clear_cb) handlers.buf_clear_cb(draw_buf, a);
|
||||
if(handlers.buf_clear_cb) handlers.buf_clear_cb(buf, stride, color_format, a);
|
||||
}
|
||||
|
||||
void lv_draw_buf_copy(void * dest_buf, uint32_t dest_stride, const lv_area_t * dest_area,
|
||||
@@ -125,32 +112,11 @@ void lv_draw_buf_copy(void * dest_buf, uint32_t dest_stride, const lv_area_t * d
|
||||
color_format);
|
||||
}
|
||||
|
||||
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, draw_buf->color_format);
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
|
||||
uint32_t lv_draw_buf_get_stride(const lv_draw_buf_t * draw_buf)
|
||||
{
|
||||
return lv_draw_buf_width_to_stride(draw_buf->width, draw_buf->color_format);
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
|
||||
static void buf_init(lv_draw_buf_t * draw_buf, lv_coord_t w, lv_coord_t h, lv_color_format_t color_format)
|
||||
{
|
||||
draw_buf->width = w;
|
||||
draw_buf->height = h;
|
||||
draw_buf->color_format = color_format;
|
||||
draw_buf->buf = NULL;
|
||||
}
|
||||
|
||||
static void * buf_malloc(size_t size_bytes, lv_color_format_t color_format)
|
||||
{
|
||||
LV_UNUSED(color_format);
|
||||
@@ -165,7 +131,7 @@ static void buf_free(void * buf)
|
||||
lv_free(buf);
|
||||
}
|
||||
|
||||
static void * align_buf(void * buf, lv_color_format_t color_format)
|
||||
static void * buf_align(void * buf, lv_color_format_t color_format)
|
||||
{
|
||||
LV_UNUSED(color_format);
|
||||
|
||||
@@ -184,24 +150,21 @@ 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 * go_to_xy(lv_draw_buf_t * draw_buf, lv_coord_t x, lv_coord_t y)
|
||||
static void * buf_go_to_xy(const void * buf, uint32_t stride, lv_color_format_t color_format, lv_coord_t x,
|
||||
lv_coord_t y)
|
||||
{
|
||||
uint32_t px_size = lv_color_format_get_size(draw_buf->color_format);
|
||||
uint32_t stride = lv_draw_buf_get_stride(draw_buf);
|
||||
uint8_t * buf_tmp = lv_draw_buf_get_buf(draw_buf);
|
||||
const uint8_t * buf_tmp = buf;
|
||||
buf_tmp += stride * y;
|
||||
buf_tmp += x * px_size;
|
||||
buf_tmp += x * lv_color_format_get_size(color_format);
|
||||
|
||||
return buf_tmp;
|
||||
return (void *)buf_tmp;
|
||||
}
|
||||
|
||||
static void buf_clear(lv_draw_buf_t * draw_buf, const lv_area_t * a)
|
||||
static void buf_clear(void * buf, uint32_t stride, lv_color_format_t color_format, const lv_area_t * a)
|
||||
{
|
||||
//TODO clear the area
|
||||
LV_UNUSED(a);
|
||||
uint32_t stride = lv_draw_buf_get_stride(draw_buf);
|
||||
uint8_t * buf = lv_draw_buf_get_buf(draw_buf);
|
||||
lv_memzero(buf, stride * draw_buf->height);
|
||||
LV_UNUSED(color_format);
|
||||
lv_memzero(buf, stride * lv_area_get_height(a));
|
||||
}
|
||||
|
||||
static void buf_copy(void * dest_buf, uint32_t dest_stride, const lv_area_t * dest_area,
|
||||
|
||||
Reference in New Issue
Block a user