rendernodepaintable: Allow the node to be NULL

This can happen when creating paintables from GtkSnapshot when nothing
was drawn.
This commit is contained in:
Benjamin Otte 2023-03-04 18:11:36 +01:00 committed by Benjamin Otte
parent a899c0af6e
commit d3efd80b90
2 changed files with 11 additions and 5 deletions

View File

@ -45,7 +45,8 @@ gtk_render_node_paintable_paintable_snapshot (GdkPaintable *paintable,
GtkRenderNodePaintable *self = GTK_RENDER_NODE_PAINTABLE (paintable);
if (self->bounds.size.width <= 0 ||
self->bounds.size.height <= 0)
self->bounds.size.height <= 0 ||
self->node == NULL)
return;
gtk_snapshot_save (snapshot);
@ -141,12 +142,12 @@ gtk_render_node_paintable_new (GskRenderNode *node,
{
GtkRenderNodePaintable *self;
g_return_val_if_fail (GSK_IS_RENDER_NODE (node), NULL);
g_return_val_if_fail (node == NULL || GSK_IS_RENDER_NODE (node), NULL);
g_return_val_if_fail (bounds != NULL, NULL);
self = g_object_new (GTK_TYPE_RENDER_NODE_PAINTABLE, NULL);
self->node = gsk_render_node_ref (node);
self->node = node ? gsk_render_node_ref (node) : NULL;
self->bounds = *bounds;
return GDK_PAINTABLE (self);

View File

@ -1623,17 +1623,22 @@ gtk_snapshot_to_paintable (GtkSnapshot *snapshot,
{
graphene_size_init_from_size (&bounds.size, size);
}
else
else if (node)
{
gsk_render_node_get_bounds (node, &bounds);
bounds.size.width += bounds.origin.x;
bounds.size.height += bounds.origin.y;
}
else
{
bounds.size.width = 0;
bounds.size.height = 0;
}
bounds.origin.x = 0;
bounds.origin.y = 0;
paintable = gtk_render_node_paintable_new (node, &bounds);
gsk_render_node_unref (node);
g_clear_pointer (&node, gsk_render_node_unref);
return paintable;
}