fix(refr): reshape using draw_buf stride (#6567)

Signed-off-by: liujp <liujp@xiaomi.com>
Co-authored-by: liujp <liujp@xiaomi.com>
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
This commit is contained in:
Lemon 2024-08-13 16:08:05 +08:00 committed by GitHub
parent 90cfb6c61b
commit 0e60911f8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 43 additions and 35 deletions

View File

@ -588,14 +588,14 @@ static void refr_invalid_areas(void)
* Reshape the draw buffer if required
* @param layer pointer to a layer which will be drawn
*/
static void layer_reshape_draw_buf(lv_layer_t * layer)
static void layer_reshape_draw_buf(lv_layer_t * layer, uint32_t stride)
{
lv_draw_buf_t * ret = lv_draw_buf_reshape(
layer->draw_buf,
layer->color_format,
lv_area_get_width(&layer->buf_area),
lv_area_get_height(&layer->buf_area),
0);
stride);
LV_UNUSED(ret);
LV_ASSERT_NULL(ret);
}
@ -621,18 +621,19 @@ static void refr_area(const lv_area_t * area_p)
layer->buf_area.y1 = 0;
layer->buf_area.x2 = lv_display_get_horizontal_resolution(disp_refr) - 1;
layer->buf_area.y2 = lv_display_get_vertical_resolution(disp_refr) - 1;
layer_reshape_draw_buf(layer);
lv_area_t disp_area;
lv_area_set(&disp_area, 0, 0, lv_display_get_horizontal_resolution(disp_refr) - 1,
lv_display_get_vertical_resolution(disp_refr) - 1);
if(disp_refr->render_mode == LV_DISPLAY_RENDER_MODE_FULL) {
disp_refr->last_part = 1;
layer_reshape_draw_buf(layer, layer->draw_buf->header.stride);
layer->_clip_area = disp_area;
refr_area_part(layer);
}
else if(disp_refr->render_mode == LV_DISPLAY_RENDER_MODE_DIRECT) {
disp_refr->last_part = disp_refr->last_area;
layer_reshape_draw_buf(layer, layer->draw_buf->header.stride);
layer->_clip_area = *area_p;
refr_area_part(layer);
}
@ -661,7 +662,7 @@ static void refr_area(const lv_area_t * area_p)
layer->draw_buf = disp_refr->buf_act;
layer->buf_area = sub_area;
layer->_clip_area = sub_area;
layer_reshape_draw_buf(layer);
layer_reshape_draw_buf(layer, LV_STRIDE_AUTO);
if(sub_area.y2 > y2) sub_area.y2 = y2;
row_last = sub_area.y2;
if(y2 == row_last) disp_refr->last_part = 1;
@ -678,7 +679,7 @@ static void refr_area(const lv_area_t * area_p)
layer->draw_buf = disp_refr->buf_act;
layer->buf_area = sub_area;
layer->_clip_area = sub_area;
layer_reshape_draw_buf(layer);
layer_reshape_draw_buf(layer, LV_STRIDE_AUTO);
disp_refr->last_part = 1;
refr_area_part(layer);
}

View File

@ -193,8 +193,7 @@ bool lv_draw_dispatch_layer(lv_display_t * disp, lv_layer_t * layer)
if(layer_drawn->draw_buf) {
int32_t h = lv_area_get_height(&layer_drawn->buf_area);
int32_t w = lv_area_get_width(&layer_drawn->buf_area);
uint32_t layer_size_byte = h * lv_draw_buf_width_to_stride(w, layer_drawn->color_format);
uint32_t layer_size_byte = h * layer_drawn->draw_buf->header.stride;
_draw_info.used_memory_for_layers_kb -= get_layer_size_kb(layer_size_byte);
LV_LOG_INFO("Layer memory used: %" LV_PRIu32 " kB\n", _draw_info.used_memory_for_layers_kb);

3
tests/.gitignore vendored
View File

@ -1,3 +1,4 @@
*.out
*_Runner.c
*.bin
*.bin
*_err.png

View File

@ -1 +0,0 @@
*_err.png

View File

@ -35,6 +35,17 @@ void lv_test_deinit(void)
lv_mem_deinit();
}
static void color_format_changled_event_cb(lv_event_t * e)
{
lv_display_t * disp = lv_event_get_target(e);
lv_color_format_t cf = lv_display_get_color_format(disp);
lv_draw_buf_t * draw_buf = lv_display_get_buf_active(NULL);
lv_display_set_buffers(disp, lv_draw_buf_align(draw_buf->unaligned_data, cf), NULL, draw_buf->data_size,
LV_DISPLAY_RENDER_MODE_DIRECT);
}
static void hal_init(void)
{
@ -43,7 +54,7 @@ static void hal_init(void)
lv_display_set_buffers(disp, lv_draw_buf_align(test_fb, LV_COLOR_FORMAT_ARGB8888), NULL, HOR_RES * VER_RES * 4,
LV_DISPLAY_RENDER_MODE_DIRECT);
lv_display_set_flush_cb(disp, dummy_flush_cb);
lv_display_add_event_cb(disp, color_format_changled_event_cb, LV_EVENT_COLOR_FORMAT_CHANGED, NULL);
lv_test_mouse_indev = lv_indev_create();
lv_indev_set_type(lv_test_mouse_indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(lv_test_mouse_indev, lv_test_mouse_read_cb);

View File

@ -23,11 +23,11 @@
#include <png.h>
#ifdef _WIN32
#include <direct.h>
#define mkdir(pathname, mode) _mkdir(pathname)
#define strtok_r strtok_s
#include <direct.h>
#define mkdir(pathname, mode) _mkdir(pathname)
#define strtok_r strtok_s
#else
#include <sys/stat.h>
#include <sys/stat.h>
#endif
/*********************
@ -35,11 +35,11 @@
*********************/
#ifndef REF_IMGS_PATH
#define REF_IMGS_PATH "ref_imgs/"
#define REF_IMGS_PATH "ref_imgs/"
#endif
#ifndef REF_IMG_TOLERANCE
#define REF_IMG_TOLERANCE 0
#define REF_IMG_TOLERANCE 0
#endif
#define ERR_FILE_NOT_FOUND -1
@ -66,7 +66,7 @@ static bool screenshot_compare(const char * fn_ref, const char * mode, uint8_t t
static int read_png_file(png_image_t * p, const char * file_name);
static int write_png_file(void * raw_img, uint32_t width, uint32_t height, char * file_name);
static void png_release(png_image_t * p);
static void buf_to_xrgb8888(const uint8_t * buf_in, uint8_t * buf_out, lv_color_format_t cf_in);
static void buf_to_xrgb8888(const lv_draw_buf_t * draw_buf, uint8_t * buf_out);
static void create_folders_if_needed(const char * path) ;
/**********************
@ -151,11 +151,8 @@ static bool screenshot_compare(const char * fn_ref, const char * mode, uint8_t t
lv_refr_now(NULL);
extern uint8_t * last_flushed_buf;
lv_color_format_t cf = lv_display_get_color_format(NULL);
uint8_t * screen_buf = lv_draw_buf_align(last_flushed_buf, cf);
buf_to_xrgb8888(screen_buf, screen_buf_xrgb8888, cf);
lv_draw_buf_t * draw_buf = lv_display_get_buf_active(NULL);
buf_to_xrgb8888(draw_buf, screen_buf_xrgb8888);
png_image_t p;
int res = read_png_file(&p, fn_ref_full);
@ -380,9 +377,12 @@ static void png_release(png_image_t * p)
png_destroy_read_struct(&p->png_ptr, &p->info_ptr, NULL);
}
static void buf_to_xrgb8888(const uint8_t * buf_in, uint8_t * buf_out, lv_color_format_t cf_in)
static void buf_to_xrgb8888(const lv_draw_buf_t * draw_buf, uint8_t * buf_out)
{
uint32_t stride = lv_draw_buf_width_to_stride(800, cf_in);
uint32_t stride = draw_buf->header.stride;
lv_color_format_t cf_in = draw_buf->header.cf;
const uint8_t * buf_in = draw_buf->data;
if(cf_in == LV_COLOR_FORMAT_RGB565) {
uint32_t y;
for(y = 0; y < 480; y++) {
@ -446,11 +446,11 @@ static void buf_to_xrgb8888(const uint8_t * buf_in, uint8_t * buf_out, lv_color_
buf_out += 800 * 4;
}
}
else if (cf_in == LV_COLOR_FORMAT_AL88) {
else if(cf_in == LV_COLOR_FORMAT_AL88) {
uint32_t y;
for (y = 0; y < 480; y++) {
for(y = 0; y < 480; y++) {
uint32_t x;
for (x = 0; x < 800; x++) {
for(x = 0; x < 800; x++) {
buf_out[x * 4 + 3] = buf_in[x * 2 + 1];
buf_out[x * 4 + 2] = buf_in[x * 2 + 0];
buf_out[x * 4 + 1] = buf_in[x * 2 + 0];
@ -461,14 +461,11 @@ static void buf_to_xrgb8888(const uint8_t * buf_in, uint8_t * buf_out, lv_color_
buf_out += 800 * 4;
}
}
else if (cf_in == LV_COLOR_FORMAT_I1)
{
else if(cf_in == LV_COLOR_FORMAT_I1) {
uint32_t y;
for (y = 0; y < 480; y++)
{
for(y = 0; y < 480; y++) {
uint32_t x;
for (x = 0; x < 800; x++)
{
for(x = 0; x < 800; x++) {
const uint8_t byte = buf_in[x / 8];
const uint8_t bit_pos = x % 8;
const uint8_t pixel = (byte >> (7 - bit_pos)) & 0x01;
@ -502,10 +499,10 @@ static void create_folders_if_needed(const char * path)
strcat(current_path, "/");
int mkdir_retval = mkdir(current_path, 0777);
if (mkdir_retval == 0) {
if(mkdir_retval == 0) {
printf("Created folder: %s\n", current_path);
}
else if (errno != EEXIST) {
else if(errno != EEXIST) {
perror("Error creating folder");
free(pathCopy);
exit(EXIT_FAILURE);