diff options
Diffstat (limited to 'src/cairo-surface.c')
-rw-r--r-- | src/cairo-surface.c | 617 |
1 files changed, 231 insertions, 386 deletions
diff --git a/src/cairo-surface.c b/src/cairo-surface.c index 3146c8cab..90749882e 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -46,6 +46,8 @@ #include "cairo-region-private.h" #include "cairo-tee-surface-private.h" +CAIRO_OBJECT_PUBLIC_WRAPPERS (cairo_surface) + /** * SECTION:cairo-surface * @Title: cairo_surface_t @@ -93,93 +95,6 @@ * devices. */ -#define DEFINE_NIL_SURFACE(status, name) \ -const cairo_surface_t name = { \ - NULL, /* backend */ \ - NULL, /* device */ \ - CAIRO_SURFACE_TYPE_IMAGE, /* type */ \ - CAIRO_CONTENT_COLOR, /* content */ \ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ \ - status, /* status */ \ - 0, /* unique id */ \ - FALSE, /* finished */ \ - TRUE, /* is_clear */ \ - FALSE, /* has_font_options */ \ - FALSE, /* owns_device */ \ - { 0, 0, 0, NULL, }, /* user_data */ \ - { 0, 0, 0, NULL, }, /* mime_data */ \ - { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, /* device_transform */ \ - { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, /* device_transform_inverse */ \ - { NULL, NULL }, /* device_transform_observers */ \ - 0.0, /* x_resolution */ \ - 0.0, /* y_resolution */ \ - 0.0, /* x_fallback_resolution */ \ - 0.0, /* y_fallback_resolution */ \ - NULL, /* snapshot_of */ \ - NULL, /* snapshot_detach */ \ - { NULL, NULL }, /* snapshots */ \ - { NULL, NULL }, /* snapshot */ \ - { CAIRO_ANTIALIAS_DEFAULT, /* antialias */ \ - CAIRO_SUBPIXEL_ORDER_DEFAULT, /* subpixel_order */ \ - CAIRO_LCD_FILTER_DEFAULT, /* lcd_filter */ \ - CAIRO_HINT_STYLE_DEFAULT, /* hint_style */ \ - CAIRO_HINT_METRICS_DEFAULT, /* hint_metrics */ \ - CAIRO_ROUND_GLYPH_POS_DEFAULT /* round_glyph_positions */ \ - } /* font_options */ \ -} - -/* XXX error object! */ - -static DEFINE_NIL_SURFACE(CAIRO_STATUS_NO_MEMORY, _cairo_surface_nil); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_SURFACE_TYPE_MISMATCH, _cairo_surface_nil_surface_type_mismatch); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_STATUS, _cairo_surface_nil_invalid_status); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_CONTENT, _cairo_surface_nil_invalid_content); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_FORMAT, _cairo_surface_nil_invalid_format); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_VISUAL, _cairo_surface_nil_invalid_visual); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_FILE_NOT_FOUND, _cairo_surface_nil_file_not_found); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_TEMP_FILE_ERROR, _cairo_surface_nil_temp_file_error); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_READ_ERROR, _cairo_surface_nil_read_error); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_WRITE_ERROR, _cairo_surface_nil_write_error); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_STRIDE, _cairo_surface_nil_invalid_stride); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_SIZE, _cairo_surface_nil_invalid_size); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_DEVICE_TYPE_MISMATCH, _cairo_surface_nil_device_type_mismatch); -static DEFINE_NIL_SURFACE(CAIRO_STATUS_DEVICE_ERROR, _cairo_surface_nil_device_error); - -/** - * _cairo_surface_set_error: - * @surface: a surface - * @status: a status value indicating an error - * - * Atomically sets surface->status to @status and calls _cairo_error; - * Does nothing if status is %CAIRO_STATUS_SUCCESS or any of the internal - * status values. - * - * All assignments of an error status to surface->status should happen - * through _cairo_surface_set_error(). Note that due to the nature of - * the atomic operation, it is not safe to call this function on the - * nil objects. - * - * The purpose of this function is to allow the user to set a - * breakpoint in _cairo_error() to generate a stack trace for when the - * user causes cairo to detect an error. - * - * Return value: the error status. - **/ -cairo_status_t -_cairo_surface_set_error (cairo_surface_t *surface, - cairo_status_t status) -{ - if (status == CAIRO_STATUS_SUCCESS || - status == CAIRO_INT_STATUS_NOTHING_TO_DO) - return CAIRO_STATUS_SUCCESS; - - /* Don't overwrite an existing error. This preserves the first - * error, which is the most significant. */ - _cairo_status_set_error (&surface->status, status); - - return _cairo_error (status); -} - /** * cairo_surface_get_type: * @surface: a #cairo_surface_t @@ -233,12 +148,6 @@ slim_hidden_def(cairo_surface_get_content); * %CAIRO_STATUS_INVALID_CONTENT, %CAIRO_STATUS_INVALID_FORMAT, or * %CAIRO_STATUS_INVALID_VISUAL. **/ -cairo_status_t -cairo_surface_status (cairo_surface_t *surface) -{ - return surface->status; -} -slim_hidden_def (cairo_surface_status); static unsigned int _cairo_surface_allocate_unique_id (void) @@ -278,8 +187,8 @@ _cairo_surface_allocate_unique_id (void) cairo_device_t * cairo_surface_get_device (cairo_surface_t *surface) { - if (unlikely (surface->status)) - return _cairo_device_create_in_error (surface->status); + if (unlikely (_cairo_surface_status (surface))) + return _cairo_device_create_in_error (_cairo_surface_status (surface)); return surface->device; } @@ -338,7 +247,7 @@ _cairo_surface_attach_snapshot (cairo_surface_t *surface, assert (surface != snapshot); assert (snapshot->snapshot_of != surface); - cairo_surface_reference (snapshot); + _cairo_surface_reference (snapshot); if (snapshot->snapshot_of != NULL) _cairo_surface_detach_snapshot (snapshot); @@ -380,7 +289,7 @@ _cairo_surface_is_writable (cairo_surface_t *surface) static void _cairo_surface_begin_modification (cairo_surface_t *surface) { - assert (surface->status == CAIRO_STATUS_SUCCESS); + assert (_cairo_surface_status (surface) == CAIRO_STATUS_SUCCESS); assert (! surface->finished); assert (surface->snapshot_of == NULL); @@ -396,6 +305,8 @@ _cairo_surface_init (cairo_surface_t *surface, { CAIRO_MUTEX_INITIALIZE (); + _cairo_object_init (&surface->base); + surface->backend = backend; if (device) @@ -405,14 +316,11 @@ _cairo_surface_init (cairo_surface_t *surface, surface->content = content; surface->type = backend->type; - CAIRO_REFERENCE_COUNT_INIT (&surface->ref_count, 1); - surface->status = CAIRO_STATUS_SUCCESS; surface->unique_id = _cairo_surface_allocate_unique_id (); surface->finished = FALSE; surface->is_clear = FALSE; surface->owns_device = (device != NULL); - _cairo_user_data_array_init (&surface->user_data); _cairo_user_data_array_init (&surface->mime_data); cairo_matrix_init_identity (&surface->device_transform); @@ -454,16 +362,18 @@ _cairo_surface_create_similar_scratch (cairo_surface_t *other, int height) { cairo_surface_t *surface; + cairo_status_t status; - if (unlikely (other->status)) - return _cairo_surface_create_in_error (other->status); + status = _cairo_surface_status (other); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); if (other->backend->create_similar == NULL) return NULL; surface = other->backend->create_similar (other, content, width, height); - if (surface == NULL || surface->status) + if (surface == NULL || _cairo_surface_status (surface)) return surface; _cairo_surface_copy_similar_properties (surface, other); @@ -502,8 +412,11 @@ cairo_surface_create_similar (cairo_surface_t *other, int width, int height) { - if (unlikely (other->status)) - return _cairo_surface_create_in_error (other->status); + cairo_status_t status; + + status = _cairo_surface_status (other); + if (unlikely (status)) + return _cairo_surface_create_in_error (status); if (unlikely (other->finished)) return _cairo_surface_create_in_error (CAIRO_ERROR_SURFACE_FINISHED); if (unlikely (width < 0 || height < 0)) @@ -535,7 +448,7 @@ _cairo_surface_create_similar_solid (cairo_surface_t *other, if (surface == NULL && allow_fallback) surface = _cairo_image_surface_create_with_content (content, width, height); - if (surface == NULL || surface->status) + if (surface == NULL || _cairo_surface_status (surface)) return surface; _cairo_pattern_init_solid (&pattern, color); @@ -609,20 +522,6 @@ _cairo_surface_repaint_solid_pattern_surface (cairo_surface_t *other, * * Return value: the referenced #cairo_surface_t. **/ -cairo_surface_t * -cairo_surface_reference (cairo_surface_t *surface) -{ - if (surface == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) - return surface; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)); - - _cairo_reference_count_inc (&surface->ref_count); - - return surface; -} -slim_hidden_def (cairo_surface_reference); /** * cairo_surface_destroy: @@ -635,13 +534,7 @@ slim_hidden_def (cairo_surface_reference); void cairo_surface_destroy (cairo_surface_t *surface) { - if (surface == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) - return; - - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&surface->ref_count)) + if (! _cairo_object_destroy (&surface->base)) return; assert (surface->snapshot_of == NULL); @@ -649,10 +542,6 @@ cairo_surface_destroy (cairo_surface_t *surface) if (! surface->finished) cairo_surface_finish (surface); - /* paranoid check that nobody took a reference whilst finishing */ - assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&surface->ref_count)); - - _cairo_user_data_array_fini (&surface->user_data); _cairo_user_data_array_fini (&surface->mime_data); if (surface->owns_device) @@ -661,6 +550,8 @@ cairo_surface_destroy (cairo_surface_t *surface) assert (surface->snapshot_of == NULL); assert (!_cairo_surface_has_snapshots (surface)); + _cairo_object_fini (&surface->base); + free (surface); } slim_hidden_def(cairo_surface_destroy); @@ -676,15 +567,6 @@ slim_hidden_def(cairo_surface_destroy); * * Since: 1.4 **/ -unsigned int -cairo_surface_get_reference_count (cairo_surface_t *surface) -{ - if (surface == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) - return 0; - - return CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->ref_count); -} /** * cairo_surface_finish: @@ -713,10 +595,10 @@ cairo_surface_finish (cairo_surface_t *surface) if (surface == NULL) return; - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) + if (unlikely (_cairo_object_is_static (&surface->base))) return; - if (surface->finished) + if (unlikely (surface->finished)) return; cairo_surface_flush (surface); @@ -732,7 +614,7 @@ cairo_surface_finish (cairo_surface_t *surface) if (surface->backend->finish) { status = surface->backend->finish (surface); if (unlikely (status)) - status = _cairo_surface_set_error (surface, status); + _cairo_surface_set_error (surface, status); } assert (surface->snapshot_of == NULL); @@ -773,13 +655,6 @@ _cairo_surface_release_device_reference (cairo_surface_t *surface) * * Return value: the user data previously attached or %NULL. **/ -void * -cairo_surface_get_user_data (cairo_surface_t *surface, - const cairo_user_data_key_t *key) -{ - return _cairo_user_data_array_get_data (&surface->user_data, - key); -} /** * cairo_surface_set_user_data: @@ -797,18 +672,6 @@ cairo_surface_get_user_data (cairo_surface_t *surface, * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a * slot could not be allocated for the user data. **/ -cairo_status_t -cairo_surface_set_user_data (cairo_surface_t *surface, - const cairo_user_data_key_t *key, - void *user_data, - cairo_destroy_func_t destroy) -{ - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) - return surface->status; - - return _cairo_user_data_array_set_data (&surface->user_data, - key, user_data, destroy); -} /** * cairo_surface_get_mime_data: @@ -834,7 +697,7 @@ cairo_surface_get_mime_data (cairo_surface_t *surface, *data = NULL; *length = 0; - if (unlikely (surface->status)) + if (unlikely (_cairo_surface_status (surface))) return; /* The number of mime-types attached to a surface is usually small, @@ -955,14 +818,17 @@ cairo_surface_set_mime_data (cairo_surface_t *surface, cairo_status_t status; cairo_mime_data_t *mime_data; - if (unlikely (surface->status)) - return surface->status; - if (surface->finished) + status = _cairo_surface_status (surface); + if (unlikely (status)) + return status; + if (unlikely (surface->finished)) return _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); status = _cairo_intern_string (&mime_type, -1); - if (unlikely (status)) - return _cairo_surface_set_error (surface, status); + if (unlikely (status)) { + _cairo_surface_set_error (surface, status); + return status; + } if (data != NULL) { mime_data = malloc (sizeof (cairo_mime_data_t)); @@ -986,10 +852,10 @@ cairo_surface_set_mime_data (cairo_surface_t *surface, if (mime_data != NULL) free (mime_data); - return _cairo_surface_set_error (surface, status); + _cairo_surface_set_error (surface, status); } - return CAIRO_STATUS_SUCCESS; + return status; } slim_hidden_def (cairo_surface_set_mime_data); @@ -1007,16 +873,22 @@ _cairo_surface_copy_mime_data (cairo_surface_t *dst, { cairo_status_t status; - if (dst->status) - return dst->status; + status = _cairo_surface_status (dst); + if (unlikely (status)) + return status; - if (src->status) - return _cairo_surface_set_error (dst, src->status); + status = _cairo_surface_status (src); + if (unlikely (status)) { + _cairo_surface_set_error (dst, status); + return status; + } /* first copy the mime-data, discarding any already set on dst */ status = _cairo_user_data_array_copy (&dst->mime_data, &src->mime_data); - if (unlikely (status)) - return _cairo_surface_set_error (dst, status); + if (unlikely (status)) { + _cairo_surface_set_error (dst, status); + return status; + } /* now increment the reference counters for the copies */ _cairo_user_data_array_foreach (&dst->mime_data, @@ -1045,16 +917,13 @@ void _cairo_surface_set_font_options (cairo_surface_t *surface, cairo_font_options_t *options) { - cairo_status_t status; - - if (surface->status) + if (unlikely (_cairo_surface_status (surface))) return; assert (surface->snapshot_of == NULL); - if (surface->finished) { - status = _cairo_surface_set_error (surface, - CAIRO_ERROR_SURFACE_FINISHED); + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); return; } @@ -1085,7 +954,7 @@ cairo_surface_get_font_options (cairo_surface_t *surface, if (cairo_font_options_status (options)) return; - if (surface->status) { + if (unlikely (_cairo_surface_status (surface))) { _cairo_font_options_init_default (options); return; } @@ -1120,10 +989,10 @@ cairo_surface_flush (cairo_surface_t *surface) { cairo_status_t status; - if (surface->status) + if (unlikely (_cairo_surface_status (surface))) return; - if (surface->finished) + if (unlikely (surface->finished)) return; /* update the current snapshots *before* the user updates the surface */ @@ -1132,7 +1001,7 @@ cairo_surface_flush (cairo_surface_t *surface) if (surface->backend->flush) { status = surface->backend->flush (surface); if (unlikely (status)) - status = _cairo_surface_set_error (surface, status); + _cairo_surface_set_error (surface, status); } } slim_hidden_def (cairo_surface_flush); @@ -1177,13 +1046,13 @@ cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface, { cairo_status_t status; - if (surface->status) + if (unlikely (_cairo_surface_status (surface))) return; assert (surface->snapshot_of == NULL); - if (surface->finished) { - status = _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); return; } @@ -1207,7 +1076,7 @@ cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface, width, height); if (unlikely (status)) - status = _cairo_surface_set_error (surface, status); + _cairo_surface_set_error (surface, status); } } slim_hidden_def (cairo_surface_mark_dirty_rectangle); @@ -1236,13 +1105,13 @@ _cairo_surface_set_device_scale (cairo_surface_t *surface, { cairo_status_t status; - if (surface->status) + if (unlikely (_cairo_surface_status (surface))) return; assert (surface->snapshot_of == NULL); - if (surface->finished) { - status = _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); return; } @@ -1286,13 +1155,13 @@ cairo_surface_set_device_offset (cairo_surface_t *surface, { cairo_status_t status; - if (surface->status) + if (unlikely (_cairo_surface_status (surface))) return; assert (surface->snapshot_of == NULL); - if (surface->finished) { - status = _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); return; } @@ -1371,15 +1240,13 @@ cairo_surface_set_fallback_resolution (cairo_surface_t *surface, double x_pixels_per_inch, double y_pixels_per_inch) { - cairo_status_t status; - - if (surface->status) + if (unlikely (_cairo_surface_status (surface))) return; assert (surface->snapshot_of == NULL); - if (surface->finished) { - status = _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); return; } @@ -1387,7 +1254,7 @@ cairo_surface_set_fallback_resolution (cairo_surface_t *surface, /* XXX Could delay raising the error until we fallback, but throwing * the error here means that we can catch the real culprit. */ - status = _cairo_surface_set_error (surface, CAIRO_ERROR_INVALID_MATRIX); + _cairo_surface_set_error (surface, CAIRO_ERROR_INVALID_MATRIX); return; } @@ -1451,8 +1318,8 @@ _cairo_surface_acquire_source_image (cairo_surface_t *surface, { cairo_status_t status; - if (surface->status) - return surface->status; + if (unlikely (_cairo_surface_status (surface))) + return _cairo_surface_status (surface); assert (!surface->finished); @@ -1461,8 +1328,10 @@ _cairo_surface_acquire_source_image (cairo_surface_t *surface, status = surface->backend->acquire_source_image (surface, image_out, image_extra); - if (unlikely (status)) - return _cairo_surface_set_error (surface, status); + if (unlikely (status)) { + _cairo_surface_set_error (surface, status); + return status; + } _cairo_debug_check_image_surface_is_defined (&(*image_out)->base); @@ -1477,8 +1346,8 @@ _cairo_surface_acquire_source_image_transformed (cairo_surface_t *surface, { cairo_status_t status; - if (surface->status) - return surface->status; + if (unlikely (_cairo_surface_status (surface))) + return _cairo_surface_status (surface); assert (!surface->finished); @@ -1488,8 +1357,10 @@ _cairo_surface_acquire_source_image_transformed (cairo_surface_t *surface, status = surface->backend->acquire_source_image_transformed (surface, device_transform, image_out, image_extra); - if (unlikely (status)) - return _cairo_surface_set_error (surface, status); + if (unlikely (status)) { + _cairo_surface_set_error (surface, status); + return status; + } _cairo_debug_check_image_surface_is_defined (&(*image_out)->base); @@ -1554,8 +1425,8 @@ _cairo_surface_acquire_dest_image (cairo_surface_t *surface, { cairo_status_t status; - if (surface->status) - return surface->status; + if (unlikely (_cairo_surface_status (surface))) + return _cairo_surface_status (surface); assert (_cairo_surface_is_writable (surface)); @@ -1567,8 +1438,10 @@ _cairo_surface_acquire_dest_image (cairo_surface_t *surface, image_out, image_rect, image_extra); - if (unlikely (status)) - return _cairo_surface_set_error (surface, status); + if (unlikely (status)) { + _cairo_surface_set_error (surface, status); + return status; + } _cairo_debug_check_image_surface_is_defined (&(*image_out)->base); @@ -1618,7 +1491,7 @@ _cairo_recording_surface_clone_similar (cairo_surface_t *surface, similar = _cairo_surface_has_snapshot (src, surface->backend); if (similar != NULL) { - *clone_out = cairo_surface_reference (similar); + *clone_out = _cairo_surface_reference (similar); *clone_offset_x = 0; *clone_offset_y = 0; return CAIRO_STATUS_SUCCESS; @@ -1634,8 +1507,9 @@ _cairo_recording_surface_clone_similar (cairo_surface_t *surface, FALSE); if (similar == NULL) return CAIRO_INT_STATUS_UNSUPPORTED; - if (unlikely (similar->status)) - return similar->status; + status = _cairo_surface_status (similar); + if (unlikely (status)) + return status; cairo_surface_set_device_offset (similar, -src_x, -src_y); @@ -1651,8 +1525,9 @@ _cairo_recording_surface_clone_similar (cairo_surface_t *surface, recorder->extents.height); if (similar == NULL) return CAIRO_INT_STATUS_UNSUPPORTED; - if (unlikely (similar->status)) - return similar->status; + status = _cairo_surface_status (similar); + if (unlikely (status)) + return status; status = _cairo_recording_surface_replay (src, similar); if (unlikely (status)) { @@ -1707,8 +1582,8 @@ _cairo_surface_clone_similar (cairo_surface_t *surface, cairo_image_surface_t *image; void *image_extra; - if (unlikely (surface->status)) - return surface->status; + if (unlikely (_cairo_surface_status (surface))) + return _cairo_surface_status (surface); if (unlikely (surface->finished)) return CAIRO_ERROR_SURFACE_FINISHED; @@ -1833,8 +1708,8 @@ _cairo_surface_composite (cairo_operator_t op, { cairo_int_status_t status; - if (unlikely (dst->status)) - return dst->status; + if (unlikely (_cairo_surface_status (dst))) + return _cairo_surface_status (dst); assert (_cairo_surface_is_writable (dst)); @@ -1853,18 +1728,23 @@ _cairo_surface_composite (cairo_operator_t op, dst_x, dst_y, width, height, clip_region); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return _cairo_surface_set_error (dst, status); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) { + _cairo_surface_set_error (dst, status); + return status; + } } - return _cairo_surface_set_error (dst, - _cairo_surface_fallback_composite (op, - src, mask, dst, - src_x, src_y, - mask_x, mask_y, - dst_x, dst_y, - width, height, - clip_region)); + status = _cairo_surface_fallback_composite (op, + src, mask, dst, + src_x, src_y, + mask_x, mask_y, + dst_x, dst_y, + width, height, + clip_region); + if (unlikely (status)) + _cairo_surface_set_error (dst, status); + + return status; } /** @@ -1892,8 +1772,8 @@ _cairo_surface_fill_region (cairo_surface_t *surface, cairo_status_t status; int i; - if (surface->status) - return surface->status; + if (unlikely (_cairo_surface_status (surface))) + return _cairo_surface_status (surface); assert (_cairo_surface_is_writable (surface)); @@ -1912,10 +1792,8 @@ _cairo_surface_fill_region (cairo_surface_t *surface, if (num_rects > ARRAY_LENGTH (stack_rects)) { rects = _cairo_malloc_ab (num_rects, sizeof (cairo_rectangle_int_t)); - if (rects == NULL) { - return _cairo_surface_set_error (surface, - CAIRO_ERROR_NO_MEMORY); - } + if (unlikely (rects == NULL)) + return _cairo_surface_set_error (surface, CAIRO_ERROR_NO_MEMORY); } for (i = 0; i < num_rects; i++) @@ -1927,7 +1805,10 @@ _cairo_surface_fill_region (cairo_surface_t *surface, if (rects != stack_rects) free (rects); - return _cairo_surface_set_error (surface, status); + if (unlikely (status)) + _cairo_surface_set_error (surface, status); + + return status; } /** @@ -1955,8 +1836,8 @@ _cairo_surface_fill_rectangles (cairo_surface_t *surface, { cairo_int_status_t status; - if (surface->status) - return surface->status; + if (unlikely (_cairo_surface_status (surface))) + return _cairo_surface_status (surface); assert (_cairo_surface_is_writable (surface)); @@ -1967,14 +1848,19 @@ _cairo_surface_fill_rectangles (cairo_surface_t *surface, status = surface->backend->fill_rectangles (surface, op, color, rects, num_rects); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return _cairo_surface_set_error (surface, status); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) { + _cairo_surface_set_error (surface, status); + return status; + } } - return _cairo_surface_set_error (surface, - _cairo_surface_fallback_fill_rectangles (surface, - op, color, - rects, num_rects)); + status = _cairo_surface_fallback_fill_rectangles (surface, + op, color, + rects, num_rects); + if (unlikely (status)) + _cairo_surface_set_error (surface, status); + + return status; } static cairo_status_t @@ -1991,8 +1877,8 @@ _pattern_has_error (const cairo_pattern_t *pattern) return CAIRO_STATUS_SUCCESS; spattern = (const cairo_surface_pattern_t *) pattern; - if (unlikely (spattern->surface->status)) - return spattern->surface->status; + if (unlikely (_cairo_surface_status (spattern->surface))) + return _cairo_surface_status (spattern->surface); if (unlikely (spattern->surface->finished)) return CAIRO_ERROR_SURFACE_FINISHED; @@ -2008,8 +1894,8 @@ _cairo_surface_paint (cairo_surface_t *surface, { cairo_status_t status; - if (unlikely (surface->status)) - return surface->status; + if (unlikely (_cairo_surface_status (surface))) + return _cairo_surface_status (surface); if (clip && clip->all_clipped) return CAIRO_STATUS_SUCCESS; @@ -2041,7 +1927,10 @@ _cairo_surface_paint (cairo_surface_t *surface, if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) surface->is_clear = op == CAIRO_OPERATOR_CLEAR && clip == NULL; - return _cairo_surface_set_error (surface, status); + if (unlikely (status)) + _cairo_surface_set_error (surface, status); + + return status; } cairo_status_t @@ -2053,8 +1942,8 @@ _cairo_surface_mask (cairo_surface_t *surface, { cairo_status_t status; - if (unlikely (surface->status)) - return surface->status; + if (unlikely (_cairo_surface_status (surface))) + return _cairo_surface_status (surface); if (clip && clip->all_clipped) return CAIRO_STATUS_SUCCESS; @@ -2097,7 +1986,10 @@ _cairo_surface_mask (cairo_surface_t *surface, if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) surface->is_clear = FALSE; - return _cairo_surface_set_error (surface, status); + if (unlikely (status)) + _cairo_surface_set_error (surface, status); + + return status; } cairo_status_t @@ -2119,8 +2011,8 @@ _cairo_surface_fill_stroke (cairo_surface_t *surface, { cairo_status_t status; - if (unlikely (surface->status)) - return surface->status; + if (unlikely (_cairo_surface_status (surface))) + return _cairo_surface_status (surface); if (clip && clip->all_clipped) return CAIRO_STATUS_SUCCESS; @@ -2177,7 +2069,10 @@ _cairo_surface_fill_stroke (cairo_surface_t *surface, if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) surface->is_clear = FALSE; - return _cairo_surface_set_error (surface, status); + if (unlikely (status)) + _cairo_surface_set_error (surface, status); + + return status; } cairo_status_t @@ -2194,8 +2089,8 @@ _cairo_surface_stroke (cairo_surface_t *surface, { cairo_status_t status; - if (unlikely (surface->status)) - return surface->status; + if (unlikely (_cairo_surface_status (surface))) + return _cairo_surface_status (surface); if (clip && clip->all_clipped) return CAIRO_STATUS_SUCCESS; @@ -2236,7 +2131,10 @@ _cairo_surface_stroke (cairo_surface_t *surface, if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) surface->is_clear = FALSE; - return _cairo_surface_set_error (surface, status); + if (unlikely (status)) + _cairo_surface_set_error (surface, status); + + return status; } cairo_status_t @@ -2251,8 +2149,8 @@ _cairo_surface_fill (cairo_surface_t *surface, { cairo_status_t status; - if (unlikely (surface->status)) - return surface->status; + if (unlikely (_cairo_surface_status (surface))) + return _cairo_surface_status (surface); if (clip && clip->all_clipped) return CAIRO_STATUS_SUCCESS; @@ -2291,7 +2189,10 @@ _cairo_surface_fill (cairo_surface_t *surface, if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) surface->is_clear = FALSE; - return _cairo_surface_set_error (surface, status); + if (unlikely (status)) + _cairo_surface_set_error (surface, status); + + return status; } cairo_status_t @@ -2311,8 +2212,8 @@ _cairo_surface_composite_trapezoids (cairo_operator_t op, { cairo_int_status_t status; - if (dst->status) - return dst->status; + if (unlikely (_cairo_surface_status (dst))) + return _cairo_surface_status (dst); assert (_cairo_surface_is_writable (dst)); @@ -2330,18 +2231,23 @@ _cairo_surface_composite_trapezoids (cairo_operator_t op, width, height, traps, num_traps, clip_region); - if (status != CAIRO_INT_STATUS_UNSUPPORTED) - return _cairo_surface_set_error (dst, status); + if (status != CAIRO_INT_STATUS_UNSUPPORTED) { + _cairo_surface_set_error (dst, status); + return status; + } } - return _cairo_surface_set_error (dst, - _cairo_surface_fallback_composite_trapezoids (op, pattern, dst, - antialias, - src_x, src_y, - dst_x, dst_y, - width, height, - traps, num_traps, - clip_region)); + status = _cairo_surface_fallback_composite_trapezoids (op, pattern, dst, + antialias, + src_x, src_y, + dst_x, dst_y, + width, height, + traps, num_traps, + clip_region); + if (unlikely (status)) + _cairo_surface_set_error (dst, status); + + return status; } cairo_span_renderer_t * @@ -2354,8 +2260,8 @@ _cairo_surface_create_span_renderer (cairo_operator_t op, { assert (dst->snapshot_of == NULL); - if (unlikely (dst->status)) - return _cairo_span_renderer_create_in_error (dst->status); + if (unlikely (_cairo_surface_status (dst))) + return _cairo_span_renderer_create_in_error (_cairo_surface_status (dst)); if (unlikely (dst->finished)) return _cairo_span_renderer_create_in_error (CAIRO_ERROR_SURFACE_FINISHED); @@ -2378,7 +2284,7 @@ _cairo_surface_check_span_renderer (cairo_operator_t op, cairo_antialias_t antialias) { assert (dst->snapshot_of == NULL); - assert (dst->status == CAIRO_STATUS_SUCCESS); + assert (_cairo_surface_status (dst) == CAIRO_STATUS_SUCCESS); assert (! dst->finished); /* XXX: Currently we have no mono span renderer */ @@ -2408,16 +2314,13 @@ _cairo_surface_check_span_renderer (cairo_operator_t op, void cairo_surface_copy_page (cairo_surface_t *surface) { - cairo_status_t status_ignored; - - if (surface->status) + if (unlikely (_cairo_surface_status (surface))) return; assert (surface->snapshot_of == NULL); - if (surface->finished) { - status_ignored = _cairo_surface_set_error (surface, - CAIRO_ERROR_SURFACE_FINISHED); + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); return; } @@ -2425,8 +2328,7 @@ cairo_surface_copy_page (cairo_surface_t *surface) if (surface->backend->copy_page == NULL) return; - status_ignored = _cairo_surface_set_error (surface, - surface->backend->copy_page (surface)); + _cairo_surface_set_error (surface, surface->backend->copy_page (surface)); } slim_hidden_def (cairo_surface_copy_page); @@ -2445,14 +2347,11 @@ slim_hidden_def (cairo_surface_copy_page); void cairo_surface_show_page (cairo_surface_t *surface) { - cairo_status_t status_ignored; - - if (surface->status) + if (unlikely (_cairo_surface_status (surface))) return; - if (surface->finished) { - status_ignored = _cairo_surface_set_error (surface, - CAIRO_ERROR_SURFACE_FINISHED); + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); return; } @@ -2462,8 +2361,7 @@ cairo_surface_show_page (cairo_surface_t *surface) if (surface->backend->show_page == NULL) return; - status_ignored = _cairo_surface_set_error (surface, - surface->backend->show_page (surface)); + _cairo_surface_set_error (surface, surface->backend->show_page (surface)); } slim_hidden_def (cairo_surface_show_page); @@ -2531,14 +2429,11 @@ _cairo_surface_get_extents (cairo_surface_t *surface, cairo_bool_t cairo_surface_has_show_text_glyphs (cairo_surface_t *surface) { - cairo_status_t status_ignored; - - if (surface->status) + if (unlikely (_cairo_surface_status (surface))) return FALSE; - if (surface->finished) { - status_ignored = _cairo_surface_set_error (surface, - CAIRO_ERROR_SURFACE_FINISHED); + if (unlikely (surface->finished)) { + _cairo_surface_set_error (surface, CAIRO_ERROR_SURFACE_FINISHED); return FALSE; } @@ -2581,8 +2476,8 @@ _cairo_surface_show_text_glyphs (cairo_surface_t *surface, cairo_status_t status; cairo_scaled_font_t *dev_scaled_font = scaled_font; - if (unlikely (surface->status)) - return surface->status; + if (unlikely (_cairo_surface_status (surface))) + return _cairo_surface_status (surface); if (num_glyphs == 0 && utf8_len == 0) return CAIRO_STATUS_SUCCESS; @@ -2615,8 +2510,10 @@ _cairo_surface_show_text_glyphs (cairo_surface_t *surface, &font_options); } status = cairo_scaled_font_status (dev_scaled_font); - if (unlikely (status)) - return _cairo_surface_set_error (surface, status); + if (unlikely (status)) { + _cairo_surface_set_error (surface, status); + return status; + } status = CAIRO_INT_STATUS_UNSUPPORTED; @@ -2696,7 +2593,10 @@ _cairo_surface_show_text_glyphs (cairo_surface_t *surface, if (status != CAIRO_INT_STATUS_NOTHING_TO_DO) surface->is_clear = FALSE; - return _cairo_surface_set_error (surface, status); + if (unlikely (status)) + _cairo_surface_set_error (surface, status); + + return status; } /* XXX: Previously, we had a function named _cairo_surface_show_glyphs @@ -2719,22 +2619,27 @@ _cairo_surface_old_show_glyphs (cairo_scaled_font_t *scaled_font, int num_glyphs, cairo_region_t *clip_region) { - if (unlikely (dst->status)) - return dst->status; + cairo_status_t status; + + if (unlikely (_cairo_surface_status (dst))) + return _cairo_surface_status (dst); assert (_cairo_surface_is_writable (dst)); if (dst->backend->old_show_glyphs == NULL) return CAIRO_INT_STATUS_UNSUPPORTED; - return _cairo_surface_set_error - (dst, dst->backend->old_show_glyphs (scaled_font, - op, pattern, dst, - source_x, source_y, - dest_x, dest_y, - width, height, - glyphs, num_glyphs, - clip_region)); + status = dst->backend->old_show_glyphs (scaled_font, + op, pattern, dst, + source_x, source_y, + dest_x, dest_y, + width, height, + glyphs, num_glyphs, + clip_region); + if (unlikely (status)) + _cairo_surface_set_error (dst, status); + + return status; } static cairo_status_t @@ -2790,7 +2695,10 @@ _cairo_surface_composite_fixup_unbounded_internal (cairo_surface_t *dst, CLEANUP_REGIONS: _cairo_region_fini (&clear_region); - return _cairo_surface_set_error (dst, status); + if (unlikely (status)) + _cairo_surface_set_error (dst, status); + + return status; } /** @@ -2839,8 +2747,8 @@ _cairo_surface_composite_fixup_unbounded (cairo_surface_t *dst, cairo_rectangle_int_t *src_rectangle = NULL; cairo_rectangle_int_t *mask_rectangle = NULL; - if (unlikely (dst->status)) - return dst->status; + if (unlikely (_cairo_surface_status (dst))) + return _cairo_surface_status (dst); assert (_cairo_surface_is_writable (dst)); @@ -2918,8 +2826,8 @@ _cairo_surface_composite_shape_fixup_unbounded (cairo_surface_t *dst, cairo_rectangle_int_t src_tmp, *src= NULL; cairo_rectangle_int_t mask; - if (dst->status) - return dst->status; + if (unlikely (_cairo_surface_status (dst))) + return _cairo_surface_status (dst); assert (_cairo_surface_is_writable (dst)); @@ -2962,75 +2870,12 @@ _cairo_surface_set_resolution (cairo_surface_t *surface, double x_res, double y_res) { - if (surface->status) + if (unlikely (_cairo_surface_status (surface))) return; surface->x_resolution = x_res; surface->y_resolution = y_res; } -cairo_surface_t * -_cairo_surface_create_in_error (cairo_status_t status) -{ - switch (status) { - case CAIRO_STATUS_NO_MEMORY: - return (cairo_surface_t *) &_cairo_surface_nil; - case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: - return (cairo_surface_t *) &_cairo_surface_nil_surface_type_mismatch; - case CAIRO_STATUS_INVALID_STATUS: - return (cairo_surface_t *) &_cairo_surface_nil_invalid_status; - case CAIRO_STATUS_INVALID_CONTENT: - return (cairo_surface_t *) &_cairo_surface_nil_invalid_content; - case CAIRO_STATUS_INVALID_FORMAT: - return (cairo_surface_t *) &_cairo_surface_nil_invalid_format; - case CAIRO_STATUS_INVALID_VISUAL: - return (cairo_surface_t *) &_cairo_surface_nil_invalid_visual; - case CAIRO_STATUS_READ_ERROR: - return (cairo_surface_t *) &_cairo_surface_nil_read_error; - case CAIRO_STATUS_WRITE_ERROR: - return (cairo_surface_t *) &_cairo_surface_nil_write_error; - case CAIRO_STATUS_FILE_NOT_FOUND: - return (cairo_surface_t *) &_cairo_surface_nil_file_not_found; - case CAIRO_STATUS_TEMP_FILE_ERROR: - return (cairo_surface_t *) &_cairo_surface_nil_temp_file_error; - case CAIRO_STATUS_INVALID_STRIDE: - return (cairo_surface_t *) &_cairo_surface_nil_invalid_stride; - case CAIRO_STATUS_INVALID_SIZE: - return (cairo_surface_t *) &_cairo_surface_nil_invalid_size; - case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: - return (cairo_surface_t *) &_cairo_surface_nil_device_type_mismatch; - case CAIRO_STATUS_DEVICE_ERROR: - return (cairo_surface_t *) &_cairo_surface_nil_device_error; - case CAIRO_STATUS_SUCCESS: - case CAIRO_STATUS_LAST_STATUS: - ASSERT_NOT_REACHED; - /* fall-through */ - case CAIRO_STATUS_INVALID_RESTORE: - case CAIRO_STATUS_INVALID_POP_GROUP: - case CAIRO_STATUS_NO_CURRENT_POINT: - case CAIRO_STATUS_INVALID_MATRIX: - case CAIRO_STATUS_NULL_POINTER: - case CAIRO_STATUS_INVALID_STRING: - case CAIRO_STATUS_INVALID_PATH_DATA: - case CAIRO_STATUS_SURFACE_FINISHED: - case CAIRO_STATUS_PATTERN_TYPE_MISMATCH: - case CAIRO_STATUS_INVALID_DASH: - case CAIRO_STATUS_INVALID_DSC_COMMENT: - case CAIRO_STATUS_INVALID_INDEX: - case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: - case CAIRO_STATUS_FONT_TYPE_MISMATCH: - case CAIRO_STATUS_USER_FONT_IMMUTABLE: - case CAIRO_STATUS_USER_FONT_ERROR: - case CAIRO_STATUS_NEGATIVE_COUNT: - case CAIRO_STATUS_INVALID_CLUSTERS: - case CAIRO_STATUS_INVALID_SLANT: - case CAIRO_STATUS_INVALID_WEIGHT: - case CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED: - case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: - default: - return _cairo_surface_create_in_error (CAIRO_ERROR_NO_MEMORY); - } -} - /* LocalWords: rasterized */ |