diff --git a/generic/LVGL.cpp b/generic/LVGL.cpp index 55094ad..318975d 100644 --- a/generic/LVGL.cpp +++ b/generic/LVGL.cpp @@ -50,7 +50,6 @@ struct LVGLWidget::PrivateData { #if defined(DGL_CAIRO) cairo_surface_t* surface = nullptr; - uchar* surfacedata = nullptr; #elif defined(DGL_OPENGL) GLuint textureId = 0; #endif @@ -183,7 +182,10 @@ struct LVGLWidget::PrivateData { display = nullptr; } - #ifdef DGL_OPENGL + #if defined(DGL_CAIRO) + cairo_surface_destroy(surface); + surface = nullptr; + #elif defined(DGL_OPENGL) if (textureId != 0) { glDeleteTextures(1, &textureId); @@ -200,7 +202,8 @@ struct LVGLWidget::PrivateData { void recreateTextureData(const uint width, const uint height) { const lv_color_format_t lvformat = lv_display_get_color_format(display); - const uint32_t data_size = lv_draw_buf_width_to_stride(width, lvformat) * height; + const uint32_t stride = lv_draw_buf_width_to_stride(width, lvformat); + const uint32_t data_size = stride * height; textureData = static_cast(std::realloc(textureData, data_size)); std::memset(textureData, 0, data_size); @@ -208,7 +211,11 @@ struct LVGLWidget::PrivateData { textureSize = Size(width, height); lv_display_set_buffers(display, textureData, nullptr, data_size, LV_DISPLAY_RENDER_MODE_DIRECT); - // TODO create full-size cairo texture here + #ifdef DGL_CAIRO + cairo_surface_destroy(surface); + surface = cairo_image_surface_create_for_data(textureData, CAIRO_FORMAT_ARGB32, width, height, stride); + DISTRHO_SAFE_ASSERT(surface != nullptr); + #endif } void repaint(const Rectangle& rect); @@ -255,9 +262,6 @@ struct LVGLWidget::PrivateData { _lv_area_join(&evthis->updatedArea, &tmp, area); } - // TODO convert to cairo texture format here, only touching updated areas - // TODO use double-buffering, touching new area before swapping and notifying flush ready - evthis->repaint(Rectangle(evthis->updatedArea.x1, evthis->updatedArea.y1, evthis->updatedArea.x2 - evthis->updatedArea.x1, @@ -343,45 +347,14 @@ void LVGLWidget::onDisplay() #endif #if defined(DGL_CAIRO) - cairo_t* const handle = static_cast(BaseWidget::getGraphicsContext()).handle; - - // TODO move this into flush_cb and convert updated pixels directly - if (lvglData->updatedArea.x1 != lvglData->updatedArea.x2 || lvglData->updatedArea.y1 != lvglData->updatedArea.y2) - { - const lv_color_format_t lvformat = lv_display_get_color_format(lvglData->display); - const uint32_t stride = lv_draw_buf_width_to_stride(width, lvformat); - - delete[] lvglData->surfacedata; - lvglData->surfacedata = static_cast(std::malloc(static_cast(width * height * stride * sizeof(uint32_t)))); - - #if LV_COLOR_DEPTH == 32 - static constexpr const cairo_format_t format = CAIRO_FORMAT_ARGB32; - - for (int h = 0; h < height; ++h) - { - for (int w = 0; w < width; ++w) - { - const uchar a = lvglData->textureData[h*width*4+w*4+3]; - lvglData->surfacedata[h*width*4+w*4+0] = static_cast((lvglData->textureData[h*width*4+w*4+0] * a) >> 8); - lvglData->surfacedata[h*width*4+w*4+1] = static_cast((lvglData->textureData[h*width*4+w*4+1] * a) >> 8); - lvglData->surfacedata[h*width*4+w*4+2] = static_cast((lvglData->textureData[h*width*4+w*4+2] * a) >> 8); - lvglData->surfacedata[h*width*4+w*4+3] = a; - } - } - #else - #error Unsupported color format - #endif - - cairo_surface_destroy(lvglData->surface); - lvglData->surface = cairo_image_surface_create_for_data(lvglData->surfacedata, format, width, height, stride); - DISTRHO_SAFE_ASSERT_RETURN(lvglData->surface != nullptr,); - } - if (lvglData->surface != nullptr) { + cairo_t* const handle = static_cast(BaseWidget::getGraphicsContext()).handle; cairo_set_source_surface(handle, lvglData->surface, 0, 0); cairo_paint(handle); } + + lv_area_set(&lvglData->updatedArea, 0, 0, 0, 0); #elif defined(DGL_OPENGL) glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, lvglData->textureId); diff --git a/generic/LVGL.hpp b/generic/LVGL.hpp index 0225bff..026d99e 100644 --- a/generic/LVGL.hpp +++ b/generic/LVGL.hpp @@ -38,10 +38,16 @@ START_NAMESPACE_DGL # error LV_ENABLE_GLOBAL_CUSTOM must be set to 1 for DPF builds #endif -#if LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32 +#if defined(DGL_CAIRO) && LV_COLOR_DEPTH != 32 +# error LV_COLOR_DEPTH must be 32 for Cairo DPF builds +#elif LV_COLOR_DEPTH != 24 && LV_COLOR_DEPTH != 32 # error LV_COLOR_DEPTH must be 24 or 32 for DPF builds #endif +#if LV_DEF_REFR_PERIOD != 1 +# error LV_DEF_REFR_PERIOD must be 1 for DPF builds +#endif + #if LV_DPI_DEF != 160 # error LV_DPI_DEF must be 160 for DPF builds #endif