[pango] Improve test-pangocairo-threads



commit 6978bb5c26147bea96af083c282dc95c67cfb257
Author: Behdad Esfahbod <behdad behdad org>
Date:   Fri Jan 4 00:19:23 2013 -0600

    Improve test-pangocairo-threads

 tests/test-pangocairo-threads.c |   28 +++++++++++++++++++---------
 1 files changed, 19 insertions(+), 9 deletions(-)
---
diff --git a/tests/test-pangocairo-threads.c b/tests/test-pangocairo-threads.c
index 7d2b68a..400d565 100644
--- a/tests/test-pangocairo-threads.c
+++ b/tests/test-pangocairo-threads.c
@@ -5,30 +5,38 @@
 const char *text = "The quick brown fox jumped over the lazy dog!";
 int num_iters = 100;
 
+GMutex mutex;
+
 static gpointer
 thread_func (gpointer data)
 {
   int num = GPOINTER_TO_INT (data);
   int i;
   char *filename;
+  PangoLayout *layout;
 
-  cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 100, 100);
+  cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_A8, 100, 100);
   cairo_t *cr = cairo_create (surface);
-  PangoLayout *layout = pango_cairo_create_layout (cr);
+
+  g_mutex_lock (&mutex);
+  g_mutex_unlock (&mutex);
+
+  layout = pango_cairo_create_layout (cr);
 
   pango_layout_set_text (layout, text, -1);
   pango_layout_set_width (layout, 100 * PANGO_SCALE);
 
   for (i = 0; i < num_iters; i++)
     {
-      cairo_set_source_rgb (cr, 1, 1, 1);
+      cairo_set_source_rgba (cr, 1, 1, 1, 1);
       cairo_paint (cr);
-      cairo_set_source_rgb (cr, 0, 0, 0);
+      cairo_set_source_rgba (cr, 1, 1, 1, 0);
+      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
 
       /* force a relayout */
-      PangoWrapMode wrap = pango_layout_get_wrap (layout);
-      wrap = wrap == PANGO_WRAP_WORD ? PANGO_WRAP_CHAR : PANGO_WRAP_WORD;
-      pango_layout_set_wrap (layout, wrap);
+      pango_layout_set_wrap (layout,
+			     pango_layout_get_wrap (layout) == PANGO_WRAP_WORD ?
+			     PANGO_WRAP_CHAR : PANGO_WRAP_WORD);
 
       pango_cairo_show_layout (cr, layout);
     }
@@ -52,8 +60,7 @@ main (int argc, char **argv)
   if (argc > 2)
     num_iters = atoi (argv[2]);
 
-  g_type_init ();
-  g_thread_init (NULL);
+  g_mutex_lock (&mutex);
 
   for (i = 0; i < num_threads; i++)
     g_ptr_array_add (threads,
@@ -61,6 +68,9 @@ main (int argc, char **argv)
 				   thread_func,
 				   GINT_TO_POINTER (i+1)));
 
+  /* Let them loose! */
+  g_mutex_unlock (&mutex);
+
   for (i = 0; i < num_threads; i++)
     g_thread_join (g_ptr_array_index (threads, i));
 



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