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/main.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 39da872..f3fab1d 100644 --- a/src/main.c +++ b/src/main.c @@ -785,6 +785,15 @@ int main(int argc, char *argv[]) wl_display_roundtrip(tofi.wl_display); log_debug("Third roundtrip done.\n"); + + /* + * Create the various structures for our window surface. This needs to + * be done before calling entry_init as that performs some initial + * drawing, and surface_init allocates the buffers we'll be drawing to. + */ + log_debug("Initialising window surface.\n"); + surface_init(&tofi.window.surface, tofi.wl_shm); + /* * Initialise the structures for rendering the entry. * Cairo needs to know the size of the surface it's creating, and @@ -797,19 +806,14 @@ int main(int argc, char *argv[]) log_debug("Initialising renderer.\n"); entry_init( &tofi.window.entry, + tofi.window.surface.shm_pool_data, tofi.window.surface.width, tofi.window.surface.height, tofi.window.scale); entry_update(&tofi.window.entry); log_debug("Renderer initialised.\n"); - /* - * Create the various structures for each surface, and - * perform an initial render of everything. - */ - log_debug("Initialising main window surface.\n"); - - surface_initialise(&tofi.window.surface, tofi.wl_shm); + /* Perform an initial render. */ surface_draw( &tofi.window.surface, &tofi.window.entry.background_color, -- cgit v1.2.3