[gtk+] Add a way to delay snapshots in reftests



commit b86f5a4086bfcf17bcb352b411fd7409c7e0d51b
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jun 2 22:31:49 2014 -0400

    Add a way to delay snapshots in reftests
    
    This adds an inhibit api that code from the reftest module
    can use to delay the taking of the snapshot. Also refactor
    the code in gtk-reftest to use the inhibit mechanism for
    its own delaying of the snapshot until after the first
    expose.

 testsuite/reftests/Makefile.am   |    3 ++-
 testsuite/reftests/gtk-reftest.c |   34 +++++++++++++++++++++++++++++-----
 testsuite/reftests/gtk-reftest.h |   28 ++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 6 deletions(-)
---
diff --git a/testsuite/reftests/Makefile.am b/testsuite/reftests/Makefile.am
index ea62364..e7e61a5 100644
--- a/testsuite/reftests/Makefile.am
+++ b/testsuite/reftests/Makefile.am
@@ -28,7 +28,8 @@ gtk_reftest_LDADD = \
 gtk_reftest_SOURCES = \
        reftest-module.c                \
        reftest-module.h                \
-       gtk-reftest.c
+       gtk-reftest.c                   \
+       gtk-reftest.h
 
 clean-local:
        rm -rf output/ || true
diff --git a/testsuite/reftests/gtk-reftest.c b/testsuite/reftests/gtk-reftest.c
index 74438c1..d432334 100644
--- a/testsuite/reftests/gtk-reftest.c
+++ b/testsuite/reftests/gtk-reftest.c
@@ -237,12 +237,31 @@ quit_when_idle (gpointer loop)
   return G_SOURCE_REMOVE;
 }
 
+static gint inhibit_count;
+static GMainLoop *loop;
+
+void
+reftest_inhibit_snapshot (void)
+{
+  inhibit_count++;
+}
+
+void
+reftest_uninhibit_snapshot (void)
+{
+  g_assert (inhibit_count > 0);
+  inhibit_count--;
+
+  if (inhibit_count == 0)
+    g_idle_add (quit_when_idle, loop);
+}
+
 static void
-check_for_draw (GdkEvent *event, gpointer loop)
+check_for_draw (GdkEvent *event, gpointer data)
 {
   if (event->type == GDK_EXPOSE)
     {
-      g_idle_add (quit_when_idle, loop);
+      reftest_uninhibit_snapshot ();
       gdk_event_handler_set ((GdkEventFunc) gtk_main_do_event, NULL, NULL);
     }
 
@@ -254,18 +273,23 @@ snapshot_widget (GtkWidget *widget, SnapshotMode mode)
 {
   cairo_surface_t *surface;
   cairo_pattern_t *bg;
-  GMainLoop *loop;
   cairo_t *cr;
 
   g_assert (gtk_widget_get_realized (widget));
 
   loop = g_main_loop_new (NULL, FALSE);
+
   /* We wait until the widget is drawn for the first time.
    * We can not wait for a GtkWidget::draw event, because that might not
    * happen if the window is fully obscured by windowed child widgets.
    * Alternatively, we could wait for an expose event on widget's window.
-   * Both of these are rather hairy, not sure what's best. */
-  gdk_event_handler_set (check_for_draw, loop, NULL);
+   * Both of these are rather hairy, not sure what's best.
+   *
+   * We also use an inhibit mechanism, to give module functions a chance
+   * to delay the snapshot.
+   */
+  reftest_inhibit_snapshot ();
+  gdk_event_handler_set (check_for_draw, NULL, NULL);
   g_main_loop_run (loop);
 
   surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
diff --git a/testsuite/reftests/gtk-reftest.h b/testsuite/reftests/gtk-reftest.h
new file mode 100644
index 0000000..aa527b6
--- /dev/null
+++ b/testsuite/reftests/gtk-reftest.h
@@ -0,0 +1,28 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_REFTEST_H__
+#define __GTK_REFTEST_H__
+
+G_BEGIN_DECLS
+
+void reftest_inhibit_snapshot   (void);
+void reftest_uninhibit_snapshot (void);
+
+G_END_DECLS
+
+#endif /* __GTK_REFTEST_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]