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.
This commit is contained in:
Matthias Clasen 2014-06-02 22:31:49 -04:00
parent 16c89eb5f7
commit b86f5a4086
3 changed files with 59 additions and 6 deletions

View File

@ -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

View File

@ -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),

View File

@ -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__ */