From 3a18bed7d755aee39af3b51be2c3f8c45c55dc20 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 15 Nov 2016 07:01:27 +0100 Subject: [PATCH] gsk: Allow creating cairo contexts for 0x0 nodes This happens in regular code paths for example when trying to render the empty text string. We don't want to store a surface on the render node in such a case (so actual rendering isn't slowed down), but we do want to return a working cairo context that is not in an error state (so the cairo rendering can continue without error messages). --- gsk/gskrendernode.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/gsk/gskrendernode.c b/gsk/gskrendernode.c index 7c463a62ce..be64fbad46 100644 --- a/gsk/gskrendernode.c +++ b/gsk/gskrendernode.c @@ -1420,13 +1420,23 @@ cairo_t * gsk_render_node_get_draw_context (GskRenderNode *node, GskRenderer *renderer) { + int width, height; cairo_t *res; g_return_val_if_fail (GSK_IS_RENDER_NODE (node), NULL); g_return_val_if_fail (node->is_mutable, NULL); g_return_val_if_fail (renderer == NULL || GSK_IS_RENDERER (renderer), NULL); - if (node->surface == NULL) + width = ceilf (node->bounds.size.width); + height = ceilf (node->bounds.size.height); + + if (width <= 0 || height <= 0) + { + cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0); + res = cairo_create (surface); + cairo_surface_destroy (surface); + } + else if (node->surface == NULL) { if (renderer) { @@ -1443,9 +1453,12 @@ gsk_render_node_get_draw_context (GskRenderNode *node, ceilf (node->bounds.size.width), ceilf (node->bounds.size.height)); } + res = cairo_create (node->surface); + } + else + { + res = cairo_create (node->surface); } - - res = cairo_create (node->surface); cairo_translate (res, -node->bounds.origin.x, -node->bounds.origin.y);