From 72d98fd99f350d2592c63ee6e1ac28cd38fbcb93 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Fri, 10 Jun 2022 00:24:54 +0100 Subject: Avoid an unnecessary copy of the image buffer. By pointing Cairo at the mmap-ed file used to create wl_shm buffers, we can eliminate a memcpy() on every draw, providing a decent speedup (especially for large window sizes). This comes at the expense of having to keep track of two Cairo contexts, one for each of our two buffers used for double buffering. Additionally, a single memcpy() is still required for initialisation of the second buffer, so the startup latency isn't affected much. --- src/surface.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/surface.c') diff --git a/src/surface.c b/src/surface.c index d02fd4f..30a46cd 100644 --- a/src/surface.c +++ b/src/surface.c @@ -8,7 +8,7 @@ #undef MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) -void surface_initialise( +void surface_init( struct surface *surface, struct wl_shm *wl_shm) { @@ -47,8 +47,6 @@ void surface_initialise( log_debug("Created shm file with size %d KiB.\n", surface->shm_pool_size / 1024); - - surface->index = 0; } void surface_destroy(struct surface *surface) @@ -66,12 +64,9 @@ void surface_draw( struct color *color, struct image *texture) { - surface->index = !surface->index; - int offset = surface->height * surface->stride * surface->index; - uint32_t *pixels = (uint32_t *)&surface->shm_pool_data[offset]; - memcpy(pixels, texture->buffer, surface->height * surface->stride); - wl_surface_attach(surface->wl_surface, surface->buffers[surface->index], 0, 0); wl_surface_damage_buffer(surface->wl_surface, 0, 0, INT32_MAX, INT32_MAX); wl_surface_commit(surface->wl_surface); + + surface->index = !surface->index; } -- cgit v1.2.3