[gtk/wip/otte/reftests: 4/8] reftest: Be more careful about snapshotting
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/reftests: 4/8] reftest: Be more careful about snapshotting
- Date: Wed, 27 Mar 2019 02:58:06 +0000 (UTC)
commit 5a1bfa5dd6b14b441f456bd4f6b26bd31e04a206
Author: Benjamin Otte <otte redhat com>
Date: Wed Mar 27 03:19:05 2019 +0100
reftest: Be more careful about snapshotting
Instead of waiting for the first invalidate-contents signal, wait until
we get a render node. This will break spectacularly for reftests not
drawing anything at all, but we just hope that won't happen.
testsuite/reftests/reftest-snapshot.c | 59 +++++++++++++++++++++--------------
1 file changed, 35 insertions(+), 24 deletions(-)
---
diff --git a/testsuite/reftests/reftest-snapshot.c b/testsuite/reftests/reftest-snapshot.c
index b93c4e5233..7fb467b8ae 100644
--- a/testsuite/reftests/reftest-snapshot.c
+++ b/testsuite/reftests/reftest-snapshot.c
@@ -81,21 +81,48 @@ reftest_uninhibit_snapshot (void)
}
static void
-check_for_draw (GdkPaintable *paintable,
- gpointer unused)
+draw_paintable (GdkPaintable *paintable,
+ gpointer out_surface)
{
+ GtkSnapshot *snapshot;
+ GskRenderNode *node;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+
+
+ snapshot = gtk_snapshot_new ();
+ gdk_paintable_snapshot (paintable,
+ snapshot,
+ gdk_paintable_get_intrinsic_width (paintable),
+ gdk_paintable_get_intrinsic_height (paintable));
+ node = gtk_snapshot_free_to_node (snapshot);
+
+ /* If the window literally draws nothing, we assume it hasn't been mapped yet and as such
+ * the invalidations were only side effects of resizes.
+ */
+ if (node == NULL)
+ return;
+
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ gdk_paintable_get_intrinsic_width (paintable),
+ gdk_paintable_get_intrinsic_height (paintable));
+
+ cr = cairo_create (surface);
+ gsk_render_node_draw (node, cr);
+ cairo_destroy (cr);
+ gsk_render_node_unref (node);
+
reftest_uninhibit_snapshot ();
- g_signal_handlers_disconnect_by_func (paintable, check_for_draw, NULL);
+ g_signal_handlers_disconnect_by_func (paintable, draw_paintable, out_surface);
+
+ *(cairo_surface_t **) out_surface = surface;
}
static cairo_surface_t *
snapshot_widget (GtkWidget *widget)
{
- GtkSnapshot *snapshot;
GdkPaintable *paintable;
- GskRenderNode *node;
cairo_surface_t *surface;
- cairo_t *cr;
g_assert (gtk_widget_get_realized (widget));
@@ -108,27 +135,11 @@ snapshot_widget (GtkWidget *widget)
*/
reftest_inhibit_snapshot ();
paintable = gtk_widget_paintable_new (widget);
- g_signal_connect (paintable, "invalidate-contents", G_CALLBACK (check_for_draw), NULL);
+ g_signal_connect (paintable, "invalidate-contents", G_CALLBACK (draw_paintable), &surface);
g_main_loop_run (loop);
- surface = gdk_surface_create_similar_surface (gtk_widget_get_surface (widget),
- CAIRO_CONTENT_COLOR,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
-
- cr = cairo_create (surface);
-
- snapshot = gtk_snapshot_new ();
- gdk_paintable_snapshot (paintable,
- snapshot,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
- g_object_unref (paintable);
- node = gtk_snapshot_free_to_node (snapshot);
- gsk_render_node_draw (node, cr);
-
- cairo_destroy (cr);
g_main_loop_unref (loop);
+ g_object_unref (paintable);
gtk_widget_destroy (widget);
return surface;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]