Skip to content

Commit 0f7fc29

Browse files
committed
rgb_lcd: Preserve full framebuffer across region updates and raw draws
When update_region, draw_rgb565_raw, or the RLE cover path write only their target region to the work framebuffer and then switch to it, the rest of the screen content is lost because the work FB contains stale data. Fix: copy the full active framebuffer to the work FB before writing the region pixels, so the entire screen state is preserved across all framebuffer switches. Signed-off-by: Ibrahim YILMAZ <ibrahim@drlinux.org>
1 parent dbff782 commit 0f7fc29

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

rgb_lcd_display_driver.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,16 @@ static void do_update_region(Context *ctx, int x0, int y0, int width, int height
518518

519519
if (driver->framebuffer_count > 1) {
520520
int work_fb = select_work_framebuffer(driver);
521-
if (work_fb >= 0
522-
&& render_items_to_framebuffer(driver, work_fb, x0, y0, width, height, items, len)) {
521+
if (work_fb >= 0) {
522+
// Copy entire active framebuffer to the work buffer so content
523+
// outside the updated region (e.g. cover image drawn via
524+
// draw_rgb565_raw) is preserved across framebuffer switches.
525+
uint16_t *active_fb = active_framebuffer(driver);
526+
if (active_fb) {
527+
size_t fb_bytes = (size_t) driver->screen.w * (size_t) driver->screen.h * sizeof(uint16_t);
528+
memcpy(driver->framebuffers[work_fb], active_fb, fb_bytes);
529+
}
530+
if (render_items_to_framebuffer(driver, work_fb, x0, y0, width, height, items, len)) {
523531
esp_err_t err = switch_to_framebuffer(driver, work_fb);
524532
if (err != ESP_OK) {
525533
ESP_LOGE(TAG, "region framebuffer switch failed: %s", esp_err_to_name(err));
@@ -710,6 +718,11 @@ static void do_draw_rgb565_rle_base64_scaled(
710718
ESP_LOGE(TAG, "cover framebuffer select failed.");
711719
return;
712720
}
721+
uint16_t *active_fb = active_framebuffer(driver);
722+
if (active_fb) {
723+
size_t fb_bytes = (size_t) driver->screen.w * (size_t) driver->screen.h * sizeof(uint16_t);
724+
memcpy(driver->framebuffers[work_fb], active_fb, fb_bytes);
725+
}
713726
copy_rgb565_region_to_framebuffer(driver, work_fb, x, y, draw_width, draw_height, draw_pixels);
714727
esp_err_t err = switch_to_framebuffer(driver, work_fb);
715728
if (err != ESP_OK) {
@@ -827,6 +840,13 @@ static void process_message(Message *message, Context *ctx)
827840
ESP_LOGE(TAG, "draw_rgb565_raw: framebuffer select failed.");
828841
return;
829842
}
843+
// Copy full active framebuffer to work buffer so the rest of
844+
// the screen (info, progress, controls) is preserved.
845+
uint16_t *active_fb = active_framebuffer(driver);
846+
if (active_fb) {
847+
size_t fb_bytes = (size_t) driver->screen.w * (size_t) driver->screen.h * sizeof(uint16_t);
848+
memcpy(driver->framebuffers[work_fb], active_fb, fb_bytes);
849+
}
830850
copy_rgb565_region_to_framebuffer(driver, work_fb, x, y, width, height, (const uint16_t *) raw);
831851
esp_err_t err = switch_to_framebuffer(driver, work_fb);
832852
if (err != ESP_OK) {

0 commit comments

Comments
 (0)