diff options
-rw-r--r-- | src/entry.c | 13 | ||||
-rw-r--r-- | src/main.c | 14 |
2 files changed, 21 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) @@ -819,6 +819,20 @@ int main(int argc, char *argv[]) &tofi.window.entry.background_color, &tofi.window.entry.image); + /* + * entry_init() left the second of the two buffers we use for + * double-buffering unpainted to lower startup time, as described + * there. Here, we flush our first, finished buffer to the screen, then + * copy over the image to the second buffer before we need to use it in + * the main loop. This ensures we paint to the screen as quickly as + * possible after startup. + */ + wl_display_roundtrip(tofi.wl_display); + memcpy( + cairo_image_surface_get_data(tofi.window.entry.cairo[1].surface), + cairo_image_surface_get_data(tofi.window.entry.cairo[0].surface), + tofi.window.entry.image.width * tofi.window.entry.image.height * sizeof(uint32_t) + ); /* We've just rendered, so we don't need to do it again right now. */ tofi.window.surface.redraw = false; |