feat: Implement double buffering in LVGLHandler for improved display performance

This commit is contained in:
GW_MC
2026-02-02 21:26:21 +08:00
parent d0c9a7c4cc
commit 08daed936e
2 changed files with 22 additions and 3 deletions

View File

@@ -26,6 +26,10 @@ LVGLHandler::~LVGLHandler() {
lv_draw_buf_destroy(lvgl_draw_buf_);
lvgl_draw_buf_ = nullptr;
}
if (lvgl_draw_buf_2_ != nullptr) {
lv_draw_buf_destroy(lvgl_draw_buf_2_);
lvgl_draw_buf_2_ = nullptr;
}
}
esp_err_t LVGLHandler::initLVGL(EventGroupHandle_t system_event_group) {
@@ -217,17 +221,31 @@ esp_err_t LVGLHandler::initLVGLDisplay_() {
return ESP_FAIL;
}
// Create a draw buffer covering the entire display
// Create two draw buffers for double buffering to improve performance
lvgl_draw_buf_ = lv_draw_buf_create(DISPLAY_WIDTH, DISPLAY_HEIGHT, LV_COLOR_FORMAT_I1, LV_STRIDE_AUTO);
if (lvgl_draw_buf_ == nullptr) {
ESP_LOGE(TAG, "Failed to create LVGL draw buffer");
ESP_LOGE(TAG, "Failed to create LVGL draw buffer 1");
lv_display_delete(lvgl_display_);
lvgl_display_ = nullptr;
lvgl_port_unlock();
return ESP_FAIL;
}
lv_display_set_draw_buffers(lvgl_display_, lvgl_draw_buf_, nullptr);
lvgl_draw_buf_2_ = lv_draw_buf_create(DISPLAY_WIDTH, DISPLAY_HEIGHT, LV_COLOR_FORMAT_I1, LV_STRIDE_AUTO);
if (lvgl_draw_buf_2_ == nullptr) {
ESP_LOGE(TAG, "Failed to create LVGL draw buffer 2");
lv_draw_buf_destroy(lvgl_draw_buf_);
lvgl_draw_buf_ = nullptr;
lv_display_delete(lvgl_display_);
lvgl_display_ = nullptr;
lvgl_port_unlock();
return ESP_FAIL;
}
// Set both buffers for double buffering
lv_display_set_draw_buffers(lvgl_display_, lvgl_draw_buf_, lvgl_draw_buf_2_);
lv_display_set_render_mode(lvgl_display_, LV_DISPLAY_RENDER_MODE);
//
// Configure LVGL display
lv_display_set_color_format(lvgl_display_, LV_COLOR_FORMAT_I1);

View File

@@ -31,4 +31,5 @@ private:
lv_display_t* lvgl_display_ = nullptr;
lv_indev_t* lvgl_touch_indev_ = nullptr;
lv_draw_buf_t* lvgl_draw_buf_ = nullptr;
lv_draw_buf_t* lvgl_draw_buf_2_ = nullptr;
};