mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
refactor(draw_buf): update buf clear and copy API
This commit is contained in:
parent
74ca34c8de
commit
6a7d2e651c
@ -477,10 +477,9 @@ static void refr_sync_areas(void)
|
||||
? disp_refr->buf_2
|
||||
: disp_refr->buf_1;
|
||||
|
||||
/*Get stride for buffer copy*/
|
||||
lv_coord_t stride = lv_draw_buf_width_to_stride(
|
||||
lv_display_get_horizontal_resolution(disp_refr),
|
||||
lv_display_get_color_format(disp_refr));
|
||||
uint32_t hor_res = lv_display_get_horizontal_resolution(disp_refr);
|
||||
uint32_t ver_res = lv_display_get_vertical_resolution(disp_refr);
|
||||
|
||||
|
||||
/*Iterate through invalidated areas to see if sync area should be copied*/
|
||||
uint16_t i;
|
||||
@ -521,8 +520,8 @@ static void refr_sync_areas(void)
|
||||
for(sync_area = _lv_ll_get_head(&disp_refr->sync_areas); sync_area != NULL;
|
||||
sync_area = _lv_ll_get_next(&disp_refr->sync_areas, sync_area)) {
|
||||
lv_draw_buf_copy(
|
||||
buf_off_screen, stride, sync_area,
|
||||
buf_on_screen, stride, sync_area,
|
||||
buf_off_screen, hor_res, ver_res, sync_area,
|
||||
buf_on_screen, hor_res, ver_res, sync_area,
|
||||
lv_display_get_color_format(disp_refr)
|
||||
);
|
||||
}
|
||||
@ -656,8 +655,9 @@ static void refr_area_part(lv_layer_t * layer)
|
||||
}
|
||||
/*If the screen is transparent initialize it when the flushing is ready*/
|
||||
if(lv_color_format_has_alpha(disp_refr->color_format)) {
|
||||
uint32_t stride = lv_draw_buf_width_to_stride(lv_area_get_width(&layer->buf_area), layer->color_format);
|
||||
lv_draw_buf_clear(layer->buf, stride, layer->color_format, &disp_refr->refreshed_area);
|
||||
uint32_t w = lv_area_get_width(&layer->buf_area);
|
||||
uint32_t h = lv_area_get_height(&layer->buf_area);
|
||||
lv_draw_buf_clear(layer->buf, w, h, layer->color_format, &disp_refr->refreshed_area);
|
||||
}
|
||||
|
||||
lv_obj_t * top_act_scr = NULL;
|
||||
|
@ -339,8 +339,8 @@ void * lv_draw_layer_alloc_buf(lv_layer_t * layer)
|
||||
{
|
||||
/*If the buffer of the layer is not allocated yet, allocate it now*/
|
||||
if(layer->buf == NULL) {
|
||||
int32_t h = lv_area_get_height(&layer->buf_area);
|
||||
int32_t w = lv_area_get_width(&layer->buf_area);
|
||||
int32_t h = lv_area_get_height(&layer->buf_area);
|
||||
int32_t stride = lv_draw_buf_width_to_stride(w, layer->color_format);
|
||||
uint32_t layer_size_byte = h * stride;
|
||||
layer->buf_unaligned = lv_draw_buf_malloc(layer_size_byte, layer->color_format);
|
||||
@ -358,7 +358,12 @@ void * lv_draw_layer_alloc_buf(lv_layer_t * layer)
|
||||
|
||||
|
||||
if(lv_color_format_has_alpha(layer->color_format)) {
|
||||
lv_draw_buf_clear(layer->buf, stride, layer->color_format, &layer->buf_area);
|
||||
lv_area_t a;
|
||||
a.x1 = 0;
|
||||
a.y1 = 0;
|
||||
a.x2 = w - 1;
|
||||
a.y2 = h - 1;
|
||||
lv_draw_buf_clear(layer->buf, w, h, layer->color_format, &a);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -38,10 +38,13 @@ typedef uint32_t (*lv_draw_buf_width_to_stride_cb)(uint32_t w, lv_color_format_t
|
||||
typedef void * (*lv_draw_buf_go_to_xy_cb)(const void * buf, uint32_t stride, lv_color_format_t color_format,
|
||||
lv_coord_t x, lv_coord_t y);
|
||||
|
||||
typedef void (*lv_draw_buf_clear_cb)(void * buf, uint32_t stride, lv_color_format_t color_format, const lv_area_t * a);
|
||||
typedef void (*lv_draw_buf_clear_cb)(void * buf, uint32_t w, uint32_t h, lv_color_format_t color_format,
|
||||
const lv_area_t * a);
|
||||
|
||||
typedef void (*lv_draw_buf_copy_cb)(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);
|
||||
typedef void (*lv_draw_buf_copy_cb)(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);
|
||||
|
||||
typedef struct {
|
||||
lv_draw_buf_malloc_cb buf_malloc_cb;
|
||||
@ -126,25 +129,29 @@ void * lv_draw_buf_go_to_xy(const void * buf, uint32_t stride, lv_color_format_t
|
||||
/**
|
||||
* Clear an area on the buffer
|
||||
* @param draw_buf pointer to draw buffer
|
||||
* @param stride stride of the buffer
|
||||
* @param w width of the buffer
|
||||
* @param h height of the buffer
|
||||
* @param color_format color format of the buffer
|
||||
* @param a the area to clear, or NULL to clear the whole buffer
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Copy an area from a buffer to an other
|
||||
* @param dest_buf pointer to the destination buffer (not draw_buf)
|
||||
* @param dest_stride the stride of the destination buffer in bytes
|
||||
* @param dest_area pointer to the destination area
|
||||
* @param src_buf pointer to the source buffer (not draw_buf)
|
||||
* @param src_stride the stride of the source buffer in bytes
|
||||
* @param src_area pointer to the source area
|
||||
* @param color_format the color format (should be the same for the source and destination)
|
||||
* @param dest_buf pointer to the destination buffer)
|
||||
* @param dest_w width of the destination buffer in pixels
|
||||
* @param dest_h height of the destination buffer in pixels
|
||||
* @param dest_area_to_copy the area to copy from the destination buffer
|
||||
* @param src_buf pointer to the source buffer
|
||||
* @param src_w width of the source buffer in pixels
|
||||
* @param src_h height of the source buffer in pixels
|
||||
* @param src_area_to_copy the area to copy from the destination buffer
|
||||
* @param color_format the color format, should be the same for both buffers
|
||||
* @note `dest_area_to_copy` and `src_area_to_copy` should have the same width and height
|
||||
*/
|
||||
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);
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
Loading…
x
Reference in New Issue
Block a user