Skip to content

Commit

Permalink
add doubble buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
henkwiedig committed Nov 22, 2024
1 parent 62525f6 commit 1f07386
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions osd/util/Render_Rockchip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

}

Expand Down Expand Up @@ -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);
}


Expand Down

0 comments on commit 1f07386

Please sign in to comment.