summaryrefslogtreecommitdiff
path: root/gsk/gskrendernodeparser.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2019-05-29 05:48:38 +0200
committerBenjamin Otte <otte@redhat.com>2019-05-30 15:32:36 +0200
commit53f23f8ae9b2b23c1f917fae0b25049552643b45 (patch)
tree670c7dc94316f98fa3ce8f81d2074ed60704318a /gsk/gskrendernodeparser.c
parent1e0c0c0ba7232af75b10f0b6b7185a0ca7bd921f (diff)
downloadgtk+-53f23f8ae9b2b23c1f917fae0b25049552643b45.tar.gz
rendernodeparser: Handle empty Cairo nodes
Cairo nodes can contain a NULL surface if they have never been drawn to. Make this the default Cairo node.
Diffstat (limited to 'gsk/gskrendernodeparser.c')
-rw-r--r--gsk/gskrendernodeparser.c58
1 files changed, 30 insertions, 28 deletions
diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c
index 6dc1d19448..4cdf70f630 100644
--- a/gsk/gskrendernodeparser.c
+++ b/gsk/gskrendernodeparser.c
@@ -1065,32 +1065,31 @@ parse_cairo_node (GtkCssParser *parser)
{ "script", parse_script, clear_surface, &surface }
};
GskRenderNode *node;
- cairo_t *cr;
parse_declarations (parser, declarations, G_N_ELEMENTS(declarations));
node = gsk_cairo_node_new (&bounds);
- cr = gsk_cairo_node_get_draw_context (node);
-
if (surface != NULL)
{
+ cairo_t *cr = gsk_cairo_node_get_draw_context (node);
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
+ cairo_destroy (cr);
}
else if (pixels != NULL)
{
+ cairo_t *cr = gsk_cairo_node_get_draw_context (node);
surface = gdk_texture_download_surface (pixels);
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
+ cairo_destroy (cr);
}
else
{
- gdk_cairo_set_source_rgba (cr, &GDK_RGBA ("FF00CC"));
- cairo_paint (cr);
+ /* do nothing */
}
- cairo_destroy (cr);
g_clear_object (&pixels);
g_clear_pointer (&surface, cairo_surface_destroy);
@@ -2380,36 +2379,39 @@ render_node_print (Printer *p,
start_node (p, "cairo");
append_rect_param (p, "bounds", &node->bounds);
- array = g_byte_array_new ();
- cairo_surface_write_to_png_stream (surface, cairo_write_array, array);
- b64 = g_base64_encode (array->data, array->len);
+ if (surface != NULL)
+ {
+ array = g_byte_array_new ();
+ cairo_surface_write_to_png_stream (surface, cairo_write_array, array);
+ b64 = g_base64_encode (array->data, array->len);
- _indent (p);
- g_string_append_printf (p->str, "pixels: url(\"data:image/png;base64,%s\");\n", b64);
+ _indent (p);
+ g_string_append_printf (p->str, "pixels: url(\"data:image/png;base64,%s\");\n", b64);
- g_free (b64);
- g_byte_array_free (array, TRUE);
+ g_free (b64);
+ g_byte_array_free (array, TRUE);
#ifdef CAIRO_HAS_SCRIPT_SURFACE
- if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_RECORDING)
- {
- cairo_device_t *script;
+ if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_RECORDING)
+ {
+ cairo_device_t *script;
- array = g_byte_array_new ();
- script = cairo_script_create_for_stream (cairo_write_array, array);
+ array = g_byte_array_new ();
+ script = cairo_script_create_for_stream (cairo_write_array, array);
- if (cairo_script_from_recording_surface (script, surface) == CAIRO_STATUS_SUCCESS)
- {
- b64 = g_base64_encode (array->data, array->len);
- _indent (p);
- g_string_append_printf (p->str, "script: url(\"data:;base64,%s\");\n", b64);
- g_free (b64);
- }
+ if (cairo_script_from_recording_surface (script, surface) == CAIRO_STATUS_SUCCESS)
+ {
+ b64 = g_base64_encode (array->data, array->len);
+ _indent (p);
+ g_string_append_printf (p->str, "script: url(\"data:;base64,%s\");\n", b64);
+ g_free (b64);
+ }
- cairo_device_destroy (script);
- g_byte_array_free (array, TRUE);
- }
+ cairo_device_destroy (script);
+ g_byte_array_free (array, TRUE);
+ }
#endif
+ }
end_node (p);
}