[pango] Refactor test-pangocairo-threads.c



commit 4ab0d57a7f7bfcd8a4b893d23f7a4923806a9113
Author: Behdad Esfahbod <behdad behdad org>
Date:   Fri Jan 4 00:23:42 2013 -0600

    Refactor test-pangocairo-threads.c

 tests/test-pangocairo-threads.c |   44 +++++++++++++++++++++++----------------
 1 files changed, 26 insertions(+), 18 deletions(-)
---
diff --git a/tests/test-pangocairo-threads.c b/tests/test-pangocairo-threads.c
index 400d565..97d5dfe 100644
--- a/tests/test-pangocairo-threads.c
+++ b/tests/test-pangocairo-threads.c
@@ -7,6 +7,29 @@ int num_iters = 100;
 
 GMutex mutex;
 
+static PangoLayout *
+create_layout (cairo_t *cr)
+{
+  PangoLayout *layout = pango_cairo_create_layout (cr);
+  pango_layout_set_text (layout, text, -1);
+  pango_layout_set_width (layout, 100 * PANGO_SCALE);
+  return layout;
+}
+
+static void
+draw (cairo_t *cr, PangoLayout *layout)
+{
+  cairo_set_source_rgba (cr, 1, 1, 1, 1);
+  cairo_paint (cr);
+  cairo_set_source_rgba (cr, 1, 1, 1, 0);
+  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+
+  /* force a relayout */
+  pango_layout_context_changed (layout);
+
+  pango_cairo_show_layout (cr, layout);
+}
+
 static gpointer
 thread_func (gpointer data)
 {
@@ -18,28 +41,13 @@ thread_func (gpointer data)
   cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_A8, 100, 100);
   cairo_t *cr = cairo_create (surface);
 
+  layout = 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_rgba (cr, 1, 1, 1, 1);
-      cairo_paint (cr);
-      cairo_set_source_rgba (cr, 1, 1, 1, 0);
-      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
-
-      /* force a relayout */
-      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);
-    }
+    draw (cr, layout);
 
   filename = g_strdup_printf ("%d.png", num);
   cairo_surface_write_to_png (surface, filename);



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