summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-07-06 10:43:14 +0200
committerBenjamin Otte <otte@redhat.com>2018-07-13 14:56:04 +0200
commita7cd1918a89755552b89c184a578302fb3796484 (patch)
treea1ba9210b575ef72b462cce11fcbef02bcabb406
parentbcfd1bbd242823c1f3283df1e4bb534e8504a292 (diff)
downloadgtk+-a7cd1918a89755552b89c184a578302fb3796484.tar.gz
widgetpaintable: Add a hack to make recursion not infloop
Makes the GUADEC talk not crash that I'm supposed to give in 20 minutes.
-rw-r--r--gtk/gtkwidget.c23
-rw-r--r--gtk/gtkwidgetpaintable.c39
-rw-r--r--gtk/gtkwidgetpaintableprivate.h2
3 files changed, 62 insertions, 2 deletions
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 6f1cdba74a..c929701d94 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -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);
}
diff --git a/gtk/gtkwidgetpaintable.c b/gtk/gtkwidgetpaintable.c
index a57c16416c..976b29d2c7 100644
--- a/gtk/gtkwidgetpaintable.c
+++ b/gtk/gtkwidgetpaintable.c
@@ -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--;
+}
+
diff --git a/gtk/gtkwidgetpaintableprivate.h b/gtk/gtkwidgetpaintableprivate.h
index e971251abc..381d28a806 100644
--- a/gtk/gtkwidgetpaintableprivate.h
+++ b/gtk/gtkwidgetpaintableprivate.h
@@ -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__ */