[cairo] [PATCH 1/2 v2] pthread-same-source: Add ref image generation

Uli Schlachter psychon at znc.in
Sat Apr 12 03:11:54 PDT 2014


When the new GENERATE_REFERENCE symbol is defined to 1, no threads are involved
at all. In this case, all operations are done sequentially by the main thread.

Thus, in this mode no thread issues can occur and the result must be usable as
reference images.

Signed-off-by: Uli Schlachter <psychon at znc.in>
---
Hi everyone,

with this new version of the patch I got rid all pthread calls. It replaces
patches 1 and 2 of the series that I sent yesterday. I think that this version
is nicer than the one that I sent before.

Uli

 test/pthread-same-source.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/test/pthread-same-source.c b/test/pthread-same-source.c
index d0eda4a..2b26d18 100644
--- a/test/pthread-same-source.c
+++ b/test/pthread-same-source.c
@@ -24,8 +24,12 @@
  * Author: Benjamin Otte <otte at gnome.org>
  */
 
+#define GENERATE_REFERENCE 0
+
 #include "cairo-test.h"
+#if !GENERATE_REFERENCE
 #include <pthread.h>
+#endif
 
 #define N_THREADS 8
 
@@ -110,7 +114,9 @@ create_source (cairo_surface_t *similar)
 static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
 {
+#if !GENERATE_REFERENCE
     pthread_t threads[N_THREADS];
+#endif
     thread_data_t thread_data[N_THREADS];
     cairo_test_status_t test_status = CAIRO_TEST_SUCCESS;
     cairo_surface_t *source;
@@ -125,12 +131,16 @@ draw (cairo_t *cr, int width, int height)
 					      status);
     }
 
+    cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
+    cairo_paint (cr);
+
     for (i = 0; i < N_THREADS; i++) {
         thread_data[i].target = cairo_surface_create_similar (cairo_get_target (cr),
                                                               CAIRO_CONTENT_COLOR_ALPHA,
                                                               4 * WIDTH, 4 * HEIGHT);
         thread_data[i].source = cairo_surface_reference (source);
         thread_data[i].id = i;
+#if !GENERATE_REFERENCE
         if (pthread_create (&threads[i], NULL, draw_thread, &thread_data[i]) != 0) {
 	    threads[i] = pthread_self (); /* to indicate error */
             cairo_surface_destroy (thread_data[i].target);
@@ -138,13 +148,21 @@ draw (cairo_t *cr, int width, int height)
             test_status = CAIRO_TEST_FAILURE;
 	    break;
         }
+#else
+	{
+	    cairo_surface_t *surface = draw_thread(&thread_data[i]);
+	    cairo_set_source_surface (cr, surface, 0, 0);
+	    cairo_surface_destroy (surface);
+	    cairo_paint (cr);
+
+	    cairo_translate (cr, 0, 4 * HEIGHT);
+	}
+#endif
     }
 
     cairo_surface_destroy (source);
 
-    cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
-    cairo_paint (cr);
-
+#if !GENERATE_REFERENCE
     for (i = 0; i < N_THREADS; i++) {
 	void *surface;
 
@@ -161,6 +179,7 @@ draw (cairo_t *cr, int width, int height)
             test_status = CAIRO_TEST_FAILURE;
 	}
     }
+#endif
 
     return test_status;
 }
-- 
1.9.1



More information about the cairo mailing list