refactor(draw_buf): update buf clear and copy API
This commit is contained in:
@@ -30,9 +30,12 @@ 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 * 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);
|
||||
|
||||
static void buf_clear(void * buf, uint32_t w, uint32_t h, lv_color_format_t color_format, const lv_area_t * a);
|
||||
|
||||
static void buf_copy(void * dest_buf, uint32_t dest_w, uint32_t dest_h, const lv_area_t * dest_area_to_copy,
|
||||
void * src_buf, uint32_t src_w, uint32_t src_h, const lv_area_t * src_area_to_copy,
|
||||
lv_color_format_t color_format);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -100,15 +103,18 @@ void * lv_draw_buf_go_to_xy(const void * buf, uint32_t stride, lv_color_format_t
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
void lv_draw_buf_clear(void * buf, uint32_t stride, lv_color_format_t color_format, const lv_area_t * a)
|
||||
void lv_draw_buf_clear(void * buf, uint32_t w, uint32_t h, lv_color_format_t color_format, const lv_area_t * a)
|
||||
{
|
||||
if(handlers.buf_clear_cb) handlers.buf_clear_cb(buf, stride, color_format, a);
|
||||
if(handlers.buf_clear_cb) handlers.buf_clear_cb(buf, w, h, color_format, a);
|
||||
}
|
||||
|
||||
void lv_draw_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)
|
||||
|
||||
void lv_draw_buf_copy(void * dest_buf, uint32_t dest_w, uint32_t dest_h, const lv_area_t * dest_area_to_copy,
|
||||
void * src_buf, uint32_t src_w, uint32_t src_h, const lv_area_t * src_area_to_copy,
|
||||
lv_color_format_t color_format)
|
||||
{
|
||||
if(handlers.buf_copy_cb) handlers.buf_copy_cb(dest_buf, dest_stride, dest_area, src_buf, src_stride, src_area,
|
||||
if(handlers.buf_copy_cb) handlers.buf_copy_cb(dest_buf, dest_w, dest_h, dest_area_to_copy,
|
||||
src_buf, src_w, src_h, src_area_to_copy,
|
||||
color_format);
|
||||
}
|
||||
|
||||
@@ -161,30 +167,52 @@ static void * buf_go_to_xy(const void * buf, uint32_t stride, lv_color_format_t
|
||||
return (void *)buf_tmp;
|
||||
}
|
||||
|
||||
static void buf_clear(void * buf, uint32_t stride, lv_color_format_t color_format, const lv_area_t * a)
|
||||
static void buf_clear(void * buf, uint32_t w, uint32_t h, lv_color_format_t color_format, const lv_area_t * a)
|
||||
{
|
||||
//TODO clear the area
|
||||
LV_UNUSED(color_format);
|
||||
lv_memzero(buf, stride * lv_area_get_height(a));
|
||||
|
||||
LV_UNUSED(h);
|
||||
|
||||
uint8_t px_size = lv_color_format_get_size(color_format);
|
||||
uint32_t stride = lv_draw_buf_width_to_stride(w, color_format);
|
||||
uint8_t * bufc = buf;
|
||||
|
||||
/*Got the first pixel of each buffer*/
|
||||
bufc += stride * a->y1;
|
||||
bufc += a->x1 * px_size;
|
||||
|
||||
uint32_t line_length = lv_area_get_width(a) * px_size;
|
||||
lv_coord_t y;
|
||||
for(y = a->y1; y <= a->y2; y++) {
|
||||
lv_memzero(bufc, line_length);
|
||||
bufc += stride;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
static void buf_copy(void * dest_buf, uint32_t dest_w, uint32_t dest_h, const lv_area_t * dest_area_to_copy,
|
||||
void * src_buf, uint32_t src_w, uint32_t src_h, const lv_area_t * src_area_to_copy,
|
||||
lv_color_format_t color_format)
|
||||
{
|
||||
LV_UNUSED(dest_h);
|
||||
LV_UNUSED(src_h);
|
||||
|
||||
uint8_t px_size = lv_color_format_get_size(color_format);
|
||||
uint8_t * dest_bufc = dest_buf;
|
||||
uint8_t * src_bufc = src_buf;
|
||||
|
||||
uint32_t dest_stride = lv_draw_buf_width_to_stride(dest_w, color_format);
|
||||
uint32_t src_stride = lv_draw_buf_width_to_stride(src_w, color_format);
|
||||
|
||||
/*Got the first pixel of each buffer*/
|
||||
dest_bufc += dest_stride * dest_area->y1;
|
||||
dest_bufc += dest_area->x1 * px_size;
|
||||
dest_bufc += dest_stride * dest_area_to_copy->y1;
|
||||
dest_bufc += dest_area_to_copy->x1 * px_size;
|
||||
|
||||
src_bufc += src_stride * src_area->y1;
|
||||
src_bufc += src_area->x1 * px_size;
|
||||
src_bufc += src_stride * src_area_to_copy->y1;
|
||||
src_bufc += src_area_to_copy->x1 * px_size;
|
||||
|
||||
uint32_t line_length = lv_area_get_width(dest_area) * px_size;
|
||||
uint32_t line_length = lv_area_get_width(dest_area_to_copy) * px_size;
|
||||
lv_coord_t y;
|
||||
for(y = dest_area->y1; y <= dest_area->y2; y++) {
|
||||
for(y = dest_area_to_copy->y1; y <= dest_area_to_copy->y2; y++) {
|
||||
lv_memcpy(dest_bufc, src_bufc, line_length);
|
||||
dest_bufc += dest_stride;
|
||||
src_bufc += src_stride;
|
||||
|
||||
Reference in New Issue
Block a user