widgetpaintable: Add a hack to make recursion not infloop

Makes the GUADEC talk not crash that I'm supposed to give in 20 minutes.
This commit is contained in:
Benjamin Otte 2018-07-06 10:43:14 +02:00
parent bcfd1bbd24
commit a7cd1918a8
3 changed files with 62 additions and 2 deletions

View File

@ -3803,6 +3803,26 @@ gtk_widget_update_paintables (GtkWidget *widget)
gtk_widget_paintable_update_image (l->data);
}
static void
gtk_widget_push_paintables (GtkWidget *widget)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GSList *l;
for (l = priv->paintables; l; l = l->next)
gtk_widget_paintable_push_snapshot_count (l->data);
}
static void
gtk_widget_pop_paintables (GtkWidget *widget)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GSList *l;
for (l = priv->paintables; l; l = l->next)
gtk_widget_paintable_pop_snapshot_count (l->data);
}
/**
* gtk_widget_queue_draw:
* @widget: a #GtkWidget
@ -13134,6 +13154,8 @@ gtk_widget_snapshot (GtkWidget *widget,
{
GskRenderNode *render_node;
gtk_widget_push_paintables (widget);
render_node = gtk_widget_create_render_node (widget, snapshot);
/* This can happen when nested drawing happens and a widget contains itself
* or when we replace a clipped area */
@ -13142,6 +13164,7 @@ gtk_widget_snapshot (GtkWidget *widget,
priv->draw_needed = FALSE;
gtk_widget_pop_paintables (widget);
gtk_widget_update_paintables (widget);
}

View File

@ -58,7 +58,7 @@ struct _GtkWidgetPaintable
GObject parent_instance;
GtkWidget *widget;
guint loop_tracker;
guint snapshot_count;
GdkPaintable *current_image; /* the image that we are presenting */
GdkPaintable *pending_image; /* the image that we should be presenting */
@ -87,7 +87,29 @@ gtk_widget_paintable_paintable_snapshot (GdkPaintable *paintable,
{
GtkWidgetPaintable *self = GTK_WIDGET_PAINTABLE (paintable);
gdk_paintable_snapshot (self->current_image, snapshot, width, height);
if (self->snapshot_count > 4)
return;
else if (self->snapshot_count > 0)
{
graphene_matrix_t transform;
gtk_snapshot_push_clip (snapshot,
&GRAPHENE_RECT_INIT(0, 0, width, height));
graphene_matrix_init_scale (&transform,
width / gtk_widget_get_allocated_width (self->widget),
height / gtk_widget_get_allocated_height (self->widget),
1.0);
gtk_snapshot_push_transform (snapshot, &transform);
gtk_widget_snapshot (self->widget, snapshot);
gtk_snapshot_pop (snapshot);
gtk_snapshot_pop (snapshot);
}
else
{
gdk_paintable_snapshot (self->current_image, snapshot, width, height);
}
}
static GdkPaintable *
@ -366,3 +388,16 @@ gtk_widget_paintable_update_image (GtkWidgetPaintable *self)
g_set_object (&self->pending_image, pending_image);
g_object_unref (pending_image);
}
void
gtk_widget_paintable_push_snapshot_count (GtkWidgetPaintable *self)
{
self->snapshot_count++;
}
void
gtk_widget_paintable_pop_snapshot_count (GtkWidgetPaintable *self)
{
self->snapshot_count--;
}

View File

@ -25,5 +25,7 @@
void gtk_widget_paintable_update_image (GtkWidgetPaintable *self);
void gtk_widget_paintable_push_snapshot_count (GtkWidgetPaintable *self);
void gtk_widget_paintable_pop_snapshot_count (GtkWidgetPaintable *self);
#endif /* __GTK_WIDGET_PAINTABLE_PRIVATE_H__ */