[clutter/wip/cogl-winsys-egl: 1/30] Add initial stab at x11 expose test



commit 38a606e7846f042c3753fb62a6d3bd3fb446e639
Author: Robert Bragg <robert linux intel com>
Date:   Tue Mar 15 16:22:25 2011 +0000

    Add initial stab at x11 expose test

 tests/conform/Makefile.am         |    5 +
 tests/conform/test-conform-main.c |    2 +
 tests/conform/test-x11-expose.c   |  156 +++++++++++++++++++++++++++++++++++++
 3 files changed, 163 insertions(+), 0 deletions(-)
---
diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
index fa00dc8..393fbd2 100644
--- a/tests/conform/Makefile.am
+++ b/tests/conform/Makefile.am
@@ -84,6 +84,11 @@ units_sources += \
 	test-script-parser.c		\
         $(NULL)
 
+# backend tests
+units_sources += \
+	test-x11-expose.c		\
+        $(NULL)
+
 test_conformance_SOURCES = $(common_sources) $(units_sources)
 
 if OS_WIN32
diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
index 7fa1e8d..f0e1cb9 100644
--- a/tests/conform/test-conform-main.c
+++ b/tests/conform/test-conform-main.c
@@ -128,6 +128,8 @@ main (int argc, char **argv)
   /* sanity check for the test suite itself */
   TEST_CONFORM_TODO ("/suite", verify_failure);
 
+  TEST_CONFORM_SIMPLE ("/backends", test_x11_expose);
+
   TEST_CONFORM_SIMPLE ("/actor", actor_destruction);
   TEST_CONFORM_SIMPLE ("/actor", actor_anchors);
   TEST_CONFORM_SIMPLE ("/actor", actor_picking);
diff --git a/tests/conform/test-x11-expose.c b/tests/conform/test-x11-expose.c
new file mode 100644
index 0000000..5b32d0d
--- /dev/null
+++ b/tests/conform/test-x11-expose.c
@@ -0,0 +1,156 @@
+#include <clutter/clutter.h>
+
+#include "test-conform-common.h"
+
+#ifdef COGL_HAS_XLIB
+
+#include <clutter/x11/clutter-x11.h>
+
+typedef struct _TestState
+{
+  ClutterActor *stage;
+  CoglColor color;
+  guint idle_handler;
+  gboolean expose_sent;
+} TestState;
+
+static gboolean
+check_stage_repaired_cb (void *user_data)
+{
+  TestState *state = user_data;
+  guchar *pixels;
+  int x, y;
+  const int stride = 100 * 4;
+
+  pixels = clutter_stage_read_pixels (CLUTTER_STAGE (state->stage),
+                                      100, 100, 100, 100);
+
+  for (y = 0; y < 100; y++)
+    for (x = 0; x < 100; x++)
+      {
+        g_assert_cmpint (pixels[stride + x * 4], ==,
+                         cogl_color_get_red_byte (&state->color));
+        g_assert_cmpint (pixels[stride + x * 4 + 1], ==,
+                         cogl_color_get_green_byte (&state->color));
+        g_assert_cmpint (pixels[stride + x * 4 + 2], ==,
+                         cogl_color_get_blue_byte (&state->color));
+      }
+
+  g_free (pixels);
+
+  clutter_main_quit ();
+
+  return FALSE;
+}
+
+static void
+on_paint (ClutterActor *actor, TestState *state)
+{
+  if (state->expose_sent)
+    g_idle_add (check_stage_repaired_cb, state);
+
+  cogl_clear (&state->color, COGL_BUFFER_BIT_COLOR);
+}
+
+static gboolean
+queue_redraw (gpointer stage)
+{
+  clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
+
+  return TRUE;
+}
+
+static gboolean
+send_expose_event_cb (void *user_data)
+{
+  TestState *state = user_data;
+  Window stage_xwin;
+  Display *xdpy;
+  XExposeEvent expose;
+
+  stage_xwin = clutter_x11_get_stage_window (CLUTTER_STAGE (state->stage));
+  xdpy = clutter_x11_get_default_display ();
+
+  expose.type = Expose;
+  expose.display = xdpy;
+  expose.window = stage_xwin;
+  expose.x = 100;
+  expose.y = 100;
+  expose.width = 100;
+  expose.height = 100;
+  expose.count = 0;
+
+  XSendEvent (xdpy, stage_xwin, False, ExposureMask, (XEvent *)&expose);
+
+  /* If a new frame is drawn in response it should be red... */
+  cogl_color_init_from_4ub (&state->color, 0xff, 0x00, 0x00, 0xff);
+  state->expose_sent = TRUE;
+
+  return FALSE;
+}
+
+static gboolean
+queue_expose_event_cb (void *user_data)
+{
+  TestState *state = user_data;
+
+  g_source_remove (state->idle_handler);
+
+  g_timeout_add (100, send_expose_event_cb, state);
+  return FALSE;
+}
+
+static gboolean
+timeout_cb (void *user_data)
+{
+  g_assert (0 && "test timed out before stage was repainted");
+}
+
+#endif /* COGL_HAS_XLIB */
+
+void
+test_x11_expose (TestConformSimpleFixture *fixture,
+                 gconstpointer data)
+{
+#ifdef COGL_HAS_XLIB
+
+  TestState state;
+
+  state.stage = clutter_stage_get_default ();
+  cogl_color_init_from_4ub (&state.color, 0x00, 0xff, 0x00, 0xff);
+  state.expose_sent = FALSE;
+
+  /* The control flow of this test is as follows:
+   * --------------------------------------------
+   *
+   * 100ms full throttle rendering (green)
+   * 100ms waiting for rendering to settle
+   * send expose event
+   * expect red frame to be drawn (see on_paint)
+   *  (if so we wait until we are next idle to verify)
+   *
+   * If the test hasn't passed in 500ms then fail
+   */
+
+  state.idle_handler = g_idle_add (queue_redraw, state.stage);
+
+  clutter_actor_show_all (state.stage);
+
+  g_signal_connect_after (state.stage, "paint",
+                          G_CALLBACK (on_paint), &state);
+
+  g_timeout_add (100, queue_expose_event_cb, &state);
+  g_timeout_add (500, timeout_cb, &state);
+  clutter_main ();
+
+  if (g_test_verbose ())
+    g_print ("OK\n");
+
+#else /* COGL_HAS_XLIB */
+
+  if (g_test_verbose ())
+   g_print ("Skipping\n");
+
+#endif /* COGL_HAS_XLIB */
+}
+



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