mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2025-12-20 04:40:07 +01:00
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.
This commit is contained in:
parent
a5f54e48e3
commit
d3c4349730
17 changed files with 26 additions and 4 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue