summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2022-06-10 00:24:54 +0100
committerPhil Jones <philj56@gmail.com>2022-06-10 00:24:54 +0100
commit72d98fd99f350d2592c63ee6e1ac28cd38fbcb93 (patch)
tree106873ab06b2dff56563e2b77a24d437b7db6ff1 /src/main.c
parent34037743f70c6c5e2b8f916d992e70d42ca07b9b (diff)
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.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c18
1 files changed, 11 insertions, 7 deletions
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,