feat: Implement double buffering in LVGLHandler for improved display performance
This commit is contained in:
@@ -26,6 +26,10 @@ LVGLHandler::~LVGLHandler() {
|
|||||||
lv_draw_buf_destroy(lvgl_draw_buf_);
|
lv_draw_buf_destroy(lvgl_draw_buf_);
|
||||||
lvgl_draw_buf_ = nullptr;
|
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) {
|
esp_err_t LVGLHandler::initLVGL(EventGroupHandle_t system_event_group) {
|
||||||
@@ -217,17 +221,31 @@ esp_err_t LVGLHandler::initLVGLDisplay_() {
|
|||||||
return ESP_FAIL;
|
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);
|
lvgl_draw_buf_ = lv_draw_buf_create(DISPLAY_WIDTH, DISPLAY_HEIGHT, LV_COLOR_FORMAT_I1, LV_STRIDE_AUTO);
|
||||||
if (lvgl_draw_buf_ == nullptr) {
|
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_);
|
lv_display_delete(lvgl_display_);
|
||||||
lvgl_display_ = nullptr;
|
lvgl_display_ = nullptr;
|
||||||
lvgl_port_unlock();
|
lvgl_port_unlock();
|
||||||
return ESP_FAIL;
|
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);
|
lv_display_set_render_mode(lvgl_display_, LV_DISPLAY_RENDER_MODE);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Configure LVGL display
|
// Configure LVGL display
|
||||||
lv_display_set_color_format(lvgl_display_, LV_COLOR_FORMAT_I1);
|
lv_display_set_color_format(lvgl_display_, LV_COLOR_FORMAT_I1);
|
||||||
|
|||||||
@@ -31,4 +31,5 @@ private:
|
|||||||
lv_display_t* lvgl_display_ = nullptr;
|
lv_display_t* lvgl_display_ = nullptr;
|
||||||
lv_indev_t* lvgl_touch_indev_ = nullptr;
|
lv_indev_t* lvgl_touch_indev_ = nullptr;
|
||||||
lv_draw_buf_t* lvgl_draw_buf_ = nullptr;
|
lv_draw_buf_t* lvgl_draw_buf_ = nullptr;
|
||||||
|
lv_draw_buf_t* lvgl_draw_buf_2_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user