Commit 4ab0d57a authored by Behdad Esfahbod's avatar Behdad Esfahbod

Refactor test-pangocairo-threads.c

parent 6978bb5c
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment