From d78aebf22474950e713a7770e6d509ed4b5dac9e Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 6 Mar 2023 11:51:32 +0100 Subject: [PATCH] feat(sdl): add PARTIAL_MODE to emulate setups with display controller --- lv_conf_template.h | 1 + src/dev/sdl/lv_sdl_window.c | 29 ++++++++++++++++++++++++++++- src/lv_conf_internal.h | 7 +++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lv_conf_template.h b/lv_conf_template.h index 8bb3c601f..f758e9fa2 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -752,6 +752,7 @@ #define LV_USE_SDL 0 #if LV_USE_SDL #define LV_SDL_INCLUDE_PATH + #define LV_SDL_PARTIAL_MODE 0 /*Recommended only to emulate a setup with a display controller*/ #endif /*Driver for /dev/fb*/ diff --git a/src/dev/sdl/lv_sdl_window.c b/src/dev/sdl/lv_sdl_window.c index 6d5efba3e..0490d4eee 100644 --- a/src/dev/sdl/lv_sdl_window.c +++ b/src/dev/sdl/lv_sdl_window.c @@ -17,6 +17,9 @@ * DEFINES *********************/ +/*Recommended only to emulate a setup with a display controller*/ +#define LV_SDL_PARTIAL_MODE 0 + /********************** * TYPEDEFS **********************/ @@ -85,8 +88,14 @@ lv_disp_t * lv_sdl_window_create(lv_coord_t hor_res, lv_coord_t ver_res) window_create(disp); lv_disp_set_flush_cb(disp, flush_cb); +#if LV_SDL_PARTIAL_MODE + uint8_t * buf = malloc(32 * 1024); + lv_disp_set_draw_buffers(disp, buf, NULL, + 32 * 1024, LV_DISP_RENDER_MODE_PARTIAL); +#else lv_disp_set_draw_buffers(disp, dsc->fb, NULL, lv_disp_get_hor_res(disp) * lv_disp_get_hor_res(disp) * sizeof(lv_color_t), LV_DISP_RENDER_MODE_DIRECT); +#endif lv_disp_add_event(disp, res_chg_event_cb, LV_EVENT_RESOLUTION_CHANGED, NULL); return disp; @@ -131,6 +140,22 @@ static void flush_cb(lv_disp_t * disp, const lv_area_t * area, lv_color_t * colo LV_UNUSED(area); LV_UNUSED(color_p); +#if LV_SDL_PARTIAL_MODE + int32_t y; + uint32_t w = lv_area_get_width(area); + lv_sdl_window_t * dsc = lv_disp_get_driver_data(disp); + lv_coord_t hor_res = lv_disp_get_hor_res(disp); + lv_color_t * fb_tmp = dsc->fb; + fb_tmp += area->y1 * hor_res; + fb_tmp += area->x1; + for(y = area->y1; y <= area->y2; y++) { + lv_memcpy(fb_tmp, color_p, w * sizeof(lv_color_t)); + color_p += w; + fb_tmp += hor_res; + } +#endif + + /* TYPICALLY YOU DO NOT NEED THIS * If it was the last part to refresh update the texture of the window.*/ if(lv_disp_flush_is_last(disp)) { @@ -238,8 +263,10 @@ static void texture_resize(lv_disp_t * disp) lv_sdl_window_t * dsc = lv_disp_get_driver_data(disp); dsc->fb = (lv_color_t *)realloc(dsc->fb, sizeof(lv_color_t) * hor_res * ver_res); - lv_disp_set_draw_buffers(disp, dsc->fb, NULL, hor_res * ver_res * sizeof(lv_color_t), LV_DISP_RENDER_MODE_DIRECT); +#if LV_SDL_PARTIAL_MODE == 0 + lv_disp_set_draw_buffers(disp, dsc->fb, NULL, hor_res * ver_res * sizeof(lv_color_t), LV_DISP_RENDER_MODE_DIRECT); +#endif if(dsc->texture) SDL_DestroyTexture(dsc->texture); #if LV_COLOR_DEPTH == 32 diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index dca302594..f1badf63a 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -2504,6 +2504,13 @@ #define LV_SDL_INCLUDE_PATH #endif #endif + #ifndef LV_SDL_PARTIAL_MODE + #ifdef CONFIG_LV_SDL_PARTIAL_MODE + #define LV_SDL_PARTIAL_MODE CONFIG_LV_SDL_PARTIAL_MODE + #else + #define LV_SDL_PARTIAL_MODE 0 /*Recommended only to emulate a setup with a display controller*/ + #endif + #endif #endif /*Driver for /dev/fb*/