From d3c4349730be991db0c85094103c744fc2d94836 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 27 Apr 2010 21:04:52 +0100 Subject: [PATCH] test: Mark surfaces as finished if the data goes out of scope. The issue being that as the on-stack data is being referenced via a zero-copy snapshot outside of the functions scope as the surface is only finished and the source written long after the draw() returns. The correct procedure is that the user must call cairo_surface_finish() prior to any surface becoming inaccessible. In this case, this triggers the snapshot to preserve a copy of the data whilst it is still valid. --- test/bilevel-image.c | 4 +++- test/filter-nearest-offset.c | 1 + test/mask-ctm.c | 4 +++- test/mask-surface-ctm.c | 1 + test/move-to-show-surface.c | 2 ++ test/paint-repeat.c | 1 + test/paint-source-alpha.c | 1 + test/paint-with-alpha.c | 1 + test/rgb24-ignore-alpha.c | 1 + test/scale-down-source-surface-paint.c | 1 + test/scale-source-surface-paint.c | 1 + test/set-source.c | 1 + test/smask-image-mask.c | 4 +++- test/smask.c | 4 +++- test/source-surface-scale-paint.c | 1 + test/translate-show-surface.c | 1 + test/zero-alpha.c | 1 + 17 files changed, 26 insertions(+), 4 deletions(-) diff --git a/test/bilevel-image.c b/test/bilevel-image.c index 7435a2bc3..4feff0e7a 100644 --- a/test/bilevel-image.c +++ b/test/bilevel-image.c @@ -46,10 +46,12 @@ draw (cairo_t *cr, int width, int height) cairo_set_source_surface (cr, mask, 0, 0); cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); - cairo_surface_destroy (mask); cairo_paint (cr); + cairo_surface_finish (mask); /* data goes out of scope */ + cairo_surface_destroy (mask); + return CAIRO_TEST_SUCCESS; } diff --git a/test/filter-nearest-offset.c b/test/filter-nearest-offset.c index f22dcf132..4df609702 100644 --- a/test/filter-nearest-offset.c +++ b/test/filter-nearest-offset.c @@ -94,6 +94,7 @@ draw (cairo_t *cr, int width, int height) } } + cairo_surface_finish (surface); /* data goes out of scope */ cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; diff --git a/test/mask-ctm.c b/test/mask-ctm.c index 7b3a39434..205ab0691 100644 --- a/test/mask-ctm.c +++ b/test/mask-ctm.c @@ -39,7 +39,6 @@ draw (cairo_t *cr, int width, int height) mask_surface = cairo_image_surface_create_for_data ((unsigned char *) data, CAIRO_FORMAT_ARGB32, 2, 2, 8); mask = cairo_pattern_create_for_surface (mask_surface); - cairo_surface_destroy (mask_surface); cairo_set_source_rgb (cr, 1.0, 0, 0); @@ -66,6 +65,9 @@ draw (cairo_t *cr, int width, int height) cairo_pattern_destroy (mask); + cairo_surface_finish (mask_surface); /* data goes out of scope */ + cairo_surface_destroy (mask_surface); + return CAIRO_TEST_SUCCESS; } diff --git a/test/mask-surface-ctm.c b/test/mask-surface-ctm.c index 50f6d0180..064de3c54 100644 --- a/test/mask-surface-ctm.c +++ b/test/mask-surface-ctm.c @@ -57,6 +57,7 @@ draw (cairo_t *cr, int width, int height) cairo_translate (cr, 2, 2); cairo_mask_surface (cr, mask, 4, 4); + cairo_surface_finish (mask); /* data goes out of scope */ cairo_surface_destroy (mask); return CAIRO_TEST_SUCCESS; diff --git a/test/move-to-show-surface.c b/test/move-to-show-surface.c index 6caad1b82..a52b46827 100644 --- a/test/move-to-show-surface.c +++ b/test/move-to-show-surface.c @@ -62,6 +62,8 @@ draw (cairo_t *cr, int width, int height) cairo_set_source_surface (cr, surface, i % 2, i / 2); cairo_paint (cr); + + cairo_surface_finish (surface); /* colors will go out of scope */ cairo_surface_destroy (surface); } diff --git a/test/paint-repeat.c b/test/paint-repeat.c index 35b383c47..c48d84c0e 100644 --- a/test/paint-repeat.c +++ b/test/paint-repeat.c @@ -47,6 +47,7 @@ draw (cairo_t *cr, int width, int height) cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT); cairo_paint (cr); + cairo_surface_finish (surface); /* data will go out of scope */ cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; diff --git a/test/paint-source-alpha.c b/test/paint-source-alpha.c index 09e82b0ad..cb2d488ca 100644 --- a/test/paint-source-alpha.c +++ b/test/paint-source-alpha.c @@ -49,6 +49,7 @@ draw (cairo_t *cr, int width, int height) cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); cairo_paint (cr); + cairo_surface_finish (surface); /* data will go out of scope */ cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; diff --git a/test/paint-with-alpha.c b/test/paint-with-alpha.c index 678d3133f..19b9e4478 100644 --- a/test/paint-with-alpha.c +++ b/test/paint-with-alpha.c @@ -49,6 +49,7 @@ draw (cairo_t *cr, int width, int height) cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); cairo_paint_with_alpha (cr, 0.5); + cairo_surface_finish (surface); /* data will go out of scope */ cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; diff --git a/test/rgb24-ignore-alpha.c b/test/rgb24-ignore-alpha.c index cd67ed3a7..1c9d57e9e 100644 --- a/test/rgb24-ignore-alpha.c +++ b/test/rgb24-ignore-alpha.c @@ -46,6 +46,7 @@ draw (cairo_t *cr, int width, int height) cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); + cairo_surface_finish (surface); /* colors will go out of scope */ cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; diff --git a/test/scale-down-source-surface-paint.c b/test/scale-down-source-surface-paint.c index 293cbda05..8cf0e06f2 100644 --- a/test/scale-down-source-surface-paint.c +++ b/test/scale-down-source-surface-paint.c @@ -51,6 +51,7 @@ draw (cairo_t *cr, int width, int height) cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); cairo_paint (cr); + cairo_surface_finish (surface); /* data will go out of scope */ cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; diff --git a/test/scale-source-surface-paint.c b/test/scale-source-surface-paint.c index 1e36afdb6..0c0a3acd8 100644 --- a/test/scale-source-surface-paint.c +++ b/test/scale-source-surface-paint.c @@ -46,6 +46,7 @@ draw (cairo_t *cr, int width, int height) cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); cairo_paint (cr); + cairo_surface_finish (surface); /* data will go out of scope */ cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; diff --git a/test/set-source.c b/test/set-source.c index f3261039f..7e54626a8 100644 --- a/test/set-source.c +++ b/test/set-source.c @@ -67,6 +67,7 @@ draw (cairo_t *cr, int width, int height) } cairo_pattern_destroy (pattern); + cairo_surface_finish (surface); /* data will go out of scope */ cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; diff --git a/test/smask-image-mask.c b/test/smask-image-mask.c index 141872178..3d8b5d5a8 100644 --- a/test/smask-image-mask.c +++ b/test/smask-image-mask.c @@ -63,7 +63,6 @@ draw (cairo_t *cr, int width, int height) mask2 = cairo_image_surface_create_for_data ((unsigned char *) data, CAIRO_FORMAT_ARGB32, 2, 2, 8); pattern = cairo_pattern_create_for_surface (mask2); - cairo_surface_destroy (mask2); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); cairo_mask (cr2, pattern); cairo_pattern_destroy (pattern); @@ -72,6 +71,9 @@ draw (cairo_t *cr, int width, int height) cairo_mask_surface (cr, cairo_get_target (cr2), 0, 0); cairo_destroy (cr2); + cairo_surface_finish (mask2); /* data will go out of scope */ + cairo_surface_destroy (mask2); + return CAIRO_TEST_SUCCESS; } diff --git a/test/smask.c b/test/smask.c index d28caca24..867fb696e 100644 --- a/test/smask.c +++ b/test/smask.c @@ -71,7 +71,6 @@ draw (cairo_t *cr, int width, int height) mask2 = cairo_image_surface_create_for_data ((unsigned char *) data, CAIRO_FORMAT_ARGB32, 2, 2, 8); pattern = cairo_pattern_create_for_surface (mask2); - cairo_surface_destroy (mask2); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); cairo_mask (cr2, pattern); cairo_pattern_destroy (pattern); @@ -110,6 +109,9 @@ draw (cairo_t *cr, int width, int height) cairo_mask_surface (cr, cairo_get_target (cr2), 0, 0); cairo_destroy (cr2); + cairo_surface_finish (mask2); /* data will go out of scope */ + cairo_surface_destroy (mask2); + return CAIRO_TEST_SUCCESS; } diff --git a/test/source-surface-scale-paint.c b/test/source-surface-scale-paint.c index 565a1ff47..4ac62490a 100644 --- a/test/source-surface-scale-paint.c +++ b/test/source-surface-scale-paint.c @@ -45,6 +45,7 @@ draw (cairo_t *cr, int width, int height) cairo_scale (cr, 2, 2); cairo_paint (cr); + cairo_surface_finish (surface); /* data will go out of scope */ cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS; diff --git a/test/translate-show-surface.c b/test/translate-show-surface.c index bf084feab..9f7af8db2 100644 --- a/test/translate-show-surface.c +++ b/test/translate-show-surface.c @@ -64,6 +64,7 @@ draw (cairo_t *cr, int width, int height) cairo_paint (cr); } cairo_restore (cr); + cairo_surface_finish (surface); /* colors will go out of scope */ cairo_surface_destroy (surface); } diff --git a/test/zero-alpha.c b/test/zero-alpha.c index 1c7c94b05..0105cc8e6 100644 --- a/test/zero-alpha.c +++ b/test/zero-alpha.c @@ -81,6 +81,7 @@ draw (cairo_t *cr, int width, int height) for (i=0; i < REPS; i++) cairo_paint (cr); + cairo_surface_finish (surface); /* zero will go out of scope */ cairo_surface_destroy (surface); return CAIRO_TEST_SUCCESS;