summaryrefslogtreecommitdiff
path: root/src/entry.c
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2022-06-10 00:44:42 +0100
committerPhil Jones <philj56@gmail.com>2022-06-10 00:44:42 +0100
commitc980335b5858746772cb7b9588ca709c5d2dfa23 (patch)
treeba120d14c8aa760062e36392bfccafe63861724e /src/entry.c
parent72d98fd99f350d2592c63ee6e1ac28cd38fbcb93 (diff)
Delay second buffer initialisation.
We don't actually need to initialise our second Cairo context / surface until after the first one has been painted to the screen. This commit therefore delays this initialisation (or at least the expensive memcpy), granting a significant reduction in startup time. The downside is that main() and entry_init() are now tied together somewhat, but hopefully the comments help.
Diffstat (limited to 'src/entry.c')
-rw-r--r--src/entry.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/entry.c b/src/entry.c
index 0348d06..453f3c5 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -120,18 +120,19 @@ void entry_init(struct entry *entry, uint8_t *restrict buffer, uint32_t width, u
* Cairo context, we can copy over just the important state (the
* transformation matrix and clip rectangle) and perform a memcpy()
* to initialise the other context.
+ *
+ * This memcpy can pretty expensive however, and isn't needed until
+ * we need to draw our second buffer (i.e. when the user presses a
+ * key). In order to minimise startup time, the memcpy() isn't
+ * performed here, but instead happens later, just after the first
+ * frame has been displayed on screen (and while the user is unlikely
+ * to press another key for the <10ms it takes to memcpy).
*/
cairo_matrix_t mat;
cairo_get_matrix(cr, &mat);
cairo_set_matrix(entry->cairo[1].cr, &mat);
cairo_rectangle(entry->cairo[1].cr, 0, 0, width, height);
cairo_clip(entry->cairo[1].cr);
-
- memcpy(
- cairo_image_surface_get_data(entry->cairo[1].surface),
- cairo_image_surface_get_data(entry->cairo[0].surface),
- entry->image.width * entry->image.height * sizeof(uint32_t)
- );
}
void entry_destroy(struct entry *entry)