snapshot: Always create an initial node

This way we ensure that there is only one root node and everybody can
append() with impunity.
This commit is contained in:
Benjamin Otte
2016-12-09 21:33:38 +01:00
parent 2faad03f2f
commit f8932d643d
3 changed files with 33 additions and 9 deletions

View File

@@ -99,17 +99,42 @@ gtk_snapshot_state_get_world_transform (GtkSnapshotState *state)
void
gtk_snapshot_init (GtkSnapshot *snapshot,
GskRenderer *renderer,
const cairo_region_t *clip)
const cairo_region_t *clip,
const char *name,
...)
{
cairo_rectangle_int_t extents;
cairo_region_get_extents (clip, &extents);
snapshot->state = NULL;
snapshot->root = NULL;
snapshot->renderer = renderer;
snapshot->clip_region = clip;
snapshot->root = gsk_renderer_create_render_node (renderer);
gsk_render_node_set_bounds (snapshot->root, &GRAPHENE_RECT_INIT (extents.x, extents.y, extents.width, extents.height));
if (name)
{
va_list args;
char *str;
va_start (args, name);
str = g_strdup_vprintf (name, args);
va_end (args);
gsk_render_node_set_name (snapshot->root, str);
g_free (str);
}
snapshot->state = gtk_snapshot_state_new (NULL, snapshot->root);
}
GskRenderNode *
gtk_snapshot_finish (GtkSnapshot *snapshot)
{
gtk_snapshot_pop (snapshot);
if (snapshot->state != NULL)
{
g_warning ("Too many gtk_snapshot_push() calls.");
@@ -305,10 +330,6 @@ gtk_snapshot_append_node (GtkSnapshot *snapshot,
gsk_render_node_append_child (snapshot->state->node, node);
gsk_render_node_set_transform (node, &snapshot->state->transform);
}
else if (snapshot->root == NULL)
{
snapshot->root = gsk_render_node_ref (node);
}
else
{
g_critical ("Tried appending a node to an already finished snapshot.");

View File

@@ -44,7 +44,9 @@ struct _GtkSnapshot {
void gtk_snapshot_init (GtkSnapshot *state,
GskRenderer *renderer,
const cairo_region_t *clip);
const cairo_region_t *clip,
const char *name,
...) G_GNUC_PRINTF (4, 5);
GskRenderNode * gtk_snapshot_finish (GtkSnapshot *state);
static inline const graphene_matrix_t *

View File

@@ -6338,7 +6338,7 @@ gtk_widget_draw_internal (GtkWidget *widget,
widget->priv->clip.width,
widget->priv->clip.height});
fallback = gsk_renderer_create_fallback (renderer, &viewport, cr);
gtk_snapshot_init (&snapshot, renderer, clip);
gtk_snapshot_init (&snapshot, renderer, clip, "Fallback<%s>", G_OBJECT_TYPE_NAME (widget));
gtk_widget_snapshot (widget, &snapshot);
node = gtk_snapshot_finish (&snapshot);
if (node != NULL)
@@ -15623,7 +15623,8 @@ gtk_widget_render (GtkWidget *widget,
gtk_snapshot_init (&snapshot,
renderer,
gdk_drawing_context_get_clip (context));
gdk_drawing_context_get_clip (context),
"Render<%s>", G_OBJECT_TYPE_NAME (widget));
gtk_widget_snapshot (widget, &snapshot);
root = gtk_snapshot_finish (&snapshot);
if (root != NULL)