From 07ee9cfbf07deba228e73d26b419a4e130de24e3 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 23 Sep 2009 15:33:23 +0100 Subject: [PATCH] [image] Do assumption initial user data is cleared. Benjamin Otte pointed out the error of my ways that a clear on a cairo_image_surface_create_for_data() was not working. This is because I modified the image surface to skip clears when it knows the target data has been cleared. This flag must be reset when the user interacts with the surface, such as providing the initial surface data. --- src/cairo-image-surface.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index 3b232006c..8ad259d2a 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -542,6 +542,7 @@ cairo_image_surface_create_for_data (unsigned char *data, int stride) { pixman_format_code_t pixman_format; + cairo_surface_t *surface; int minstride; if (! CAIRO_FORMAT_VALID (format)) @@ -562,9 +563,16 @@ cairo_image_surface_create_for_data (unsigned char *data, } pixman_format = _cairo_format_to_pixman_format_code (format); + surface = _cairo_image_surface_create_with_pixman_format (data, + pixman_format, + width, height, + stride); + if (unlikely (surface->status)) + return surface; - return _cairo_image_surface_create_with_pixman_format (data, pixman_format, - width, height, stride); + /* we can not make any assumptions by the initial state of the data */ + ((cairo_image_surface_t *) surface)->is_clear = FALSE; + return surface; } slim_hidden_def (cairo_image_surface_create_for_data); @@ -1610,6 +1618,16 @@ _cairo_image_surface_get_font_options (void *abstract_surface, cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON); } +static cairo_status_t +_cairo_image_surface_mark_dirty_rectangle (void *abstract_surface, + int x, int y, + int width, int height) +{ + cairo_image_surface_t *surface = abstract_surface; + surface->is_clear = FALSE; + return CAIRO_STATUS_SUCCESS; +} + static cairo_int_status_t _cairo_image_surface_paint (void *abstract_surface, cairo_operator_t op, @@ -1663,7 +1681,7 @@ const cairo_surface_backend_t _cairo_image_surface_backend = { NULL, /* old_show_glyphs */ _cairo_image_surface_get_font_options, NULL, /* flush */ - NULL, /* mark_dirty_rectangle */ + _cairo_image_surface_mark_dirty_rectangle, NULL, /* font_fini */ NULL, /* glyph_fini */