From 1f07386a9f09977516d2a81ba70604961221d1ef Mon Sep 17 00:00:00 2001 From: Henk Wiedig Date: Tue, 19 Nov 2024 22:13:20 +0100 Subject: [PATCH] add doubble buffering --- osd/util/Render_Rockchip.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/osd/util/Render_Rockchip.c b/osd/util/Render_Rockchip.c index 76c8590..e18ac50 100644 --- a/osd/util/Render_Rockchip.c +++ b/osd/util/Render_Rockchip.c @@ -19,8 +19,11 @@ cairo_surface_t* surface=NULL; cairo_surface_t* image_surface = NULL; +cairo_surface_t* surface_shm=NULL; + cairo_t* cr=NULL; -Pixmap backbuffer_pixmap; +cairo_t* cr_shm=NULL; + // Define the shared memory region structure typedef struct { @@ -81,17 +84,25 @@ int Init_x86(uint16_t *width, uint16_t *height) { } // Create a Cairo surface for the image data - surface = cairo_image_surface_create_for_data( - shm_region->data, CAIRO_FORMAT_ARGB32, shm_width, shm_height, shm_width * 4); + surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, shm_width, shm_width); if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { fprintf(stderr, "Failed to create Cairo surface\n"); + return -1; + } + + // Create a Cairo surface for the image data connecto to the shm + surface_shm = cairo_image_surface_create_for_data( + shm_region->data, CAIRO_FORMAT_ARGB32, shm_width, shm_height, shm_width * 4); + if (cairo_surface_status(surface_shm) != CAIRO_STATUS_SUCCESS) { + fprintf(stderr, "Failed to create Cairo surface_shm\n"); munmap(shm_region, shm_size); close(shm_fd); return -1; - } + } // Create a Cairo context - cr = cairo_create(surface); + cr = cairo_create(surface); + cr_shm = cairo_create(surface_shm); } @@ -175,14 +186,24 @@ void Render_x86_rect(unsigned char* rgbaData, int u32Width, int u32Height, int s void FlushDrawing_x86(){ + // Copy work buffer to the display surface do avoid flickering + cairo_set_operator(cr_shm, CAIRO_OPERATOR_SOURCE); + // Copy buffer to the display surface + cairo_set_source_surface(cr_shm, surface, 0, 0); + cairo_paint(cr_shm); + + cairo_surface_flush(surface_shm); + } void Close_x86(){ // Clean up resources cairo_destroy(cr); + cairo_destroy(cr_shm); cairo_surface_destroy(image_surface); cairo_surface_destroy(surface); + cairo_surface_destroy(surface_shm); }