From 236a2a2672e4d6fe79f3515f77d264d4a3186cd0 Mon Sep 17 00:00:00 2001 From: Gabriel Wang Date: Thu, 11 Jan 2024 19:33:19 +0000 Subject: [PATCH] fix(display): fix the support for partial mode in lv_display_set_buffers (#5286) --- src/display/lv_display.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/display/lv_display.c b/src/display/lv_display.c index 8a2823e8be..0f74785697 100644 --- a/src/display/lv_display.c +++ b/src/display/lv_display.c @@ -405,13 +405,22 @@ void lv_display_set_buffers(lv_display_t * disp, void * buf1, void * buf2, uint3 lv_color_format_t cf = lv_display_get_color_format(disp); uint32_t stride = lv_draw_buf_width_to_stride(w, cf); - if(stride * h > buf_size && render_mode != LV_DISPLAY_RENDER_MODE_PARTIAL) { + if(render_mode == LV_DISPLAY_RENDER_MODE_PARTIAL) { + /* for partial mode, we calculate the height based on the buf_size and stride */ + h = buf_size / stride; + } + else if(stride * h > buf_size) { LV_LOG_ERROR("%s mode requires screen sized buffer(s)", render_mode == LV_DISPLAY_RENDER_MODE_FULL ? "FULL" : "DIRECT"); LV_ASSERT(0); return; } + if(h == 0) { + LV_ASSERT_MSG(h != 0, "the buffer is too small"); + return; + } + lv_draw_buf_init(&disp->_static_buf1, w, h, cf, stride, buf1, buf_size); lv_draw_buf_init(&disp->_static_buf2, w, h, cf, stride, buf2, buf_size); lv_display_set_draw_buffers(disp, &disp->_static_buf1, buf2 ? &disp->_static_buf2 : NULL);