diff options
author | Andrea Canciani <ranma42@gmail.com> | 2011-07-30 15:53:59 +0200 |
---|---|---|
committer | Andrea Canciani <ranma42@gmail.com> | 2011-07-30 17:56:06 +0200 |
commit | 4f7293671a5e8a0b49655b1e2ef1d7b44cc863ae (patch) | |
tree | f9bb4441ca466c028f4e1a517f40630dc2ecfd2e | |
parent | f53bbb31bba1243f1d1acbb66372b0be28c8d2d3 (diff) |
-rw-r--r-- | src/cairo-default-context.c | 2 | ||||
-rw-r--r-- | src/cairo-device-private.h | 4 | ||||
-rw-r--r-- | src/cairo-device.c | 118 | ||||
-rw-r--r-- | src/cairo-font-face-private.h | 4 | ||||
-rw-r--r-- | src/cairo-font-face.c | 95 | ||||
-rw-r--r-- | src/cairo-mutex-list-private.h | 1 | ||||
-rw-r--r-- | src/cairo-object-wrappers-private.h | 44 | ||||
-rw-r--r-- | src/cairo-paginated-surface.c | 2 | ||||
-rw-r--r-- | src/cairo-pattern-private.h | 4 | ||||
-rw-r--r-- | src/cairo-pattern.c | 132 | ||||
-rw-r--r-- | src/cairo-private.h | 4 | ||||
-rw-r--r-- | src/cairo-region-private.h | 4 | ||||
-rw-r--r-- | src/cairo-region.c | 128 | ||||
-rw-r--r-- | src/cairo-scaled-font-private.h | 6 | ||||
-rw-r--r-- | src/cairo-scaled-font.c | 135 | ||||
-rw-r--r-- | src/cairo-surface-private.h | 5 | ||||
-rw-r--r-- | src/cairo-surface.c | 173 | ||||
-rw-r--r-- | src/cairo-svg-surface.c | 10 | ||||
-rw-r--r-- | src/cairo-toy-font-face.c | 5 | ||||
-rw-r--r-- | src/cairo-win32-font.c | 5 | ||||
-rw-r--r-- | src/cairo.c | 98 |
21 files changed, 120 insertions, 859 deletions
diff --git a/src/cairo-default-context.c b/src/cairo-default-context.c index 038679076..3dfa0a3bc 100644 --- a/src/cairo-default-context.c +++ b/src/cairo-default-context.c @@ -86,8 +86,6 @@ _cairo_default_context_destroy (void *abstract_cr) _cairo_fini (&cr->base); - /* mark the context as invalid to protect against misuse */ - cr->base.status = CAIRO_STATUS_NULL_POINTER; _freed_pool_put (&context_pool, cr); } diff --git a/src/cairo-device-private.h b/src/cairo-device-private.h index dc3884edf..38f57e823 100644 --- a/src/cairo-device-private.h +++ b/src/cairo-device-private.h @@ -42,9 +42,7 @@ #include "cairo-types-private.h" struct _cairo_device { - cairo_reference_count_t ref_count; - cairo_status_t status; - cairo_user_data_array_t user_data; + cairo_object_t base; const cairo_device_backend_t *backend; diff --git a/src/cairo-device.c b/src/cairo-device.c index 04e6c168c..68c190a05 100644 --- a/src/cairo-device.c +++ b/src/cairo-device.c @@ -173,81 +173,11 @@ slim_hidden_def (cairo_device_reference); **/ -static const cairo_device_t _nil_device = { - CAIRO_REFERENCE_COUNT_INVALID, - CAIRO_STATUS_NO_MEMORY, -}; - -static const cairo_device_t _mismatch_device = { - CAIRO_REFERENCE_COUNT_INVALID, - CAIRO_STATUS_DEVICE_TYPE_MISMATCH, -}; - -static const cairo_device_t _invalid_device = { - CAIRO_REFERENCE_COUNT_INVALID, - CAIRO_STATUS_DEVICE_ERROR, -}; - -cairo_device_t * -_cairo_device_create_in_error (cairo_status_t status) -{ - switch (status) { - case CAIRO_STATUS_NO_MEMORY: - return (cairo_device_t *) &_nil_device; - case CAIRO_STATUS_DEVICE_ERROR: - return (cairo_device_t *) &_invalid_device; - case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: - return (cairo_device_t *) &_mismatch_device; - - case CAIRO_STATUS_SUCCESS: - case CAIRO_STATUS_LAST_STATUS: - ASSERT_NOT_REACHED; - /* fall-through */ - case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: - case CAIRO_STATUS_INVALID_STATUS: - case CAIRO_STATUS_INVALID_FORMAT: - case CAIRO_STATUS_INVALID_VISUAL: - case CAIRO_STATUS_READ_ERROR: - case CAIRO_STATUS_WRITE_ERROR: - case CAIRO_STATUS_FILE_NOT_FOUND: - case CAIRO_STATUS_TEMP_FILE_ERROR: - case CAIRO_STATUS_INVALID_STRIDE: - case CAIRO_STATUS_INVALID_SIZE: - 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_CONTENT: - case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION: - case CAIRO_STATUS_DEVICE_FINISHED: - default: - return _cairo_device_create_in_error (CAIRO_ERROR_NO_MEMORY); - } -} - void _cairo_device_init (cairo_device_t *device, const cairo_device_backend_t *backend) { - CAIRO_REFERENCE_COUNT_INIT (&device->ref_count, 1); - device->status = CAIRO_STATUS_SUCCESS; + _cairo_object_init (&device->base, 1); device->backend = backend; @@ -255,8 +185,6 @@ _cairo_device_init (cairo_device_t *device, device->mutex_depth = 0; device->finished = FALSE; - - _cairo_user_data_array_init (&device->user_data); } /** @@ -279,7 +207,7 @@ cairo_device_flush (cairo_device_t *device) { cairo_status_t status; - if (device == NULL || _cairo_device_status (device)) + if (_cairo_device_status (device)) return; if (device->finished) @@ -315,11 +243,8 @@ slim_hidden_def (cairo_device_flush); void cairo_device_finish (cairo_device_t *device) { - if (device == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) - { + if (_cairo_object_is_nil (&device->base)) return; - } if (device->finished) return; @@ -352,16 +277,10 @@ slim_hidden_def (cairo_device_finish); void cairo_device_destroy (cairo_device_t *device) { - cairo_user_data_array_t user_data; - - if (device == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) - { + if (unlikely (device == NULL)) return; - } - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&device->ref_count)); - if (! _cairo_reference_count_dec_and_test (&device->ref_count)) + if (! _cairo_object_destroy (&device->base)) return; cairo_device_finish (device); @@ -369,11 +288,9 @@ cairo_device_destroy (cairo_device_t *device) assert (device->mutex_depth == 0); CAIRO_MUTEX_FINI (device->mutex); - user_data = device->user_data; - device->backend->destroy (device); - _cairo_user_data_array_fini (&user_data); + _cairo_object_fini (&device->base); } slim_hidden_def (cairo_device_destroy); @@ -392,11 +309,8 @@ slim_hidden_def (cairo_device_destroy); cairo_device_type_t cairo_device_get_type (cairo_device_t *device) { - if (device == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) - { + if (_cairo_object_is_nil (&device->base)) return CAIRO_DEVICE_TYPE_INVALID; - } return device->backend->type; } @@ -434,9 +348,6 @@ cairo_device_get_type (cairo_device_t *device) cairo_status_t cairo_device_acquire (cairo_device_t *device) { - if (device == NULL) - return CAIRO_STATUS_SUCCESS; - if (unlikely (_cairo_device_status (device))) return _cairo_device_status (device); @@ -465,9 +376,6 @@ slim_hidden_def (cairo_device_acquire); void cairo_device_release (cairo_device_t *device) { - if (device == NULL) - return; - assert (device->mutex_depth > 0); if (--device->mutex_depth == 0) { @@ -478,15 +386,3 @@ cairo_device_release (cairo_device_t *device) CAIRO_MUTEX_UNLOCK (device->mutex); } slim_hidden_def (cairo_device_release); - -cairo_status_t -_cairo_device_set_error (cairo_device_t *device, - cairo_status_t status) -{ - if (status == CAIRO_STATUS_SUCCESS) - return CAIRO_STATUS_SUCCESS; - - _cairo_status_set_error (&device->status, _cairo_error (status)); - - return status; -} diff --git a/src/cairo-font-face-private.h b/src/cairo-font-face-private.h index bda03f685..f45acfa0a 100644 --- a/src/cairo-font-face-private.h +++ b/src/cairo-font-face-private.h @@ -45,9 +45,7 @@ struct _cairo_font_face { /* hash_entry must be first */ cairo_hash_entry_t hash_entry; - cairo_status_t status; - cairo_reference_count_t ref_count; - cairo_user_data_array_t user_data; + cairo_object_t base; const cairo_font_face_backend_t *backend; }; CAIRO_OBJECT_WRAPPERS(cairo_font_face) diff --git a/src/cairo-font-face.c b/src/cairo-font-face.c index c213d2e88..1e2f248ee 100644 --- a/src/cairo-font-face.c +++ b/src/cairo-font-face.c @@ -134,93 +134,15 @@ slim_hidden_def (cairo_font_face_get_user_data); slim_hidden_def (cairo_font_face_set_user_data); -/* #cairo_font_face_t */ - -static const cairo_font_face_t _cairo_font_face_nil = { - { 0 }, /* hash_entry */ - CAIRO_STATUS_NO_MEMORY, /* status */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ - NULL -}; - -static const cairo_font_face_t _cairo_font_face_null_pointer = { - { 0 }, /* hash_entry */ - CAIRO_STATUS_NULL_POINTER, /* status */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ - NULL -}; - -static const cairo_font_face_t _cairo_font_face_invalid_string = { - { 0 }, /* hash_entry */ - CAIRO_STATUS_INVALID_STRING, /* status */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ - NULL -}; - -static const cairo_font_face_t _cairo_font_face_invalid_slant = { - { 0 }, /* hash_entry */ - CAIRO_STATUS_INVALID_SLANT, /* status */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ - NULL -}; - -static const cairo_font_face_t _cairo_font_face_invalid_weight = { - { 0 }, /* hash_entry */ - CAIRO_STATUS_INVALID_WEIGHT, /* status */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ - NULL -}; - -cairo_font_face_t * -_cairo_font_face_create_in_error (cairo_status_t status) -{ - assert (status != CAIRO_STATUS_SUCCESS); - - if (status == CAIRO_STATUS_NO_MEMORY) - return (cairo_font_face_t *) &_cairo_font_face_nil; - else if (status == CAIRO_STATUS_NULL_POINTER) - return (cairo_font_face_t *) &_cairo_font_face_null_pointer; - else if (status == CAIRO_STATUS_INVALID_STRING) - return (cairo_font_face_t *) &_cairo_font_face_invalid_string; - else if (status == CAIRO_STATUS_INVALID_SLANT) - return (cairo_font_face_t *) &_cairo_font_face_invalid_slant; - else if (status == CAIRO_STATUS_INVALID_WEIGHT) - return (cairo_font_face_t *) &_cairo_font_face_invalid_weight; - - /* XXX use shared error objects */ - return (cairo_font_face_t *) &_cairo_font_face_nil; -} - -cairo_status_t -_cairo_font_face_set_error (cairo_font_face_t *font_face, - cairo_status_t status) -{ - if (status == CAIRO_STATUS_SUCCESS) - return status; - - /* Don't overwrite an existing error. This preserves the first - * error, which is the most significant. */ - _cairo_status_set_error (&font_face->status, _cairo_error (status)); - - return status; -} - void _cairo_font_face_init (cairo_font_face_t *font_face, const cairo_font_face_backend_t *backend) { CAIRO_MUTEX_INITIALIZE (); - font_face->status = CAIRO_STATUS_SUCCESS; - CAIRO_REFERENCE_COUNT_INIT (&font_face->ref_count, 1); - font_face->backend = backend; + _cairo_object_init (&font_face->base, 1); - _cairo_user_data_array_init (&font_face->user_data); + font_face->backend = backend; } /** @@ -234,13 +156,10 @@ _cairo_font_face_init (cairo_font_face_t *font_face, void cairo_font_face_destroy (cairo_font_face_t *font_face) { - if (font_face == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->ref_count)) + if (unlikely (font_face == NULL)) return; - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&font_face->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&font_face->ref_count)) + if (! _cairo_object_destroy (&font_face->base)) return; if (font_face->backend->destroy) @@ -250,10 +169,10 @@ cairo_font_face_destroy (cairo_font_face_t *font_face) * FreeType backend where cairo_ft_font_face_t and cairo_ft_unscaled_font_t * need to effectively mutually reference each other */ - if (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&font_face->ref_count)) + if (_cairo_font_face_get_reference_count (font_face) != 0) return; - _cairo_user_data_array_fini (&font_face->user_data); + _cairo_object_fini (&font_face->base); free (font_face); } @@ -273,7 +192,7 @@ slim_hidden_def (cairo_font_face_destroy); cairo_font_type_t cairo_font_face_get_type (cairo_font_face_t *font_face) { - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->ref_count)) + if (_cairo_object_is_nil (&font_face->base)) return CAIRO_FONT_TYPE_TOY; return font_face->backend->type; diff --git a/src/cairo-mutex-list-private.h b/src/cairo-mutex-list-private.h index 4016f8e5e..779c2aaea 100644 --- a/src/cairo-mutex-list-private.h +++ b/src/cairo-mutex-list-private.h @@ -44,7 +44,6 @@ CAIRO_MUTEX_DECLARE (_cairo_toy_font_face_mutex) CAIRO_MUTEX_DECLARE (_cairo_intern_string_mutex) CAIRO_MUTEX_DECLARE (_cairo_scaled_font_map_mutex) CAIRO_MUTEX_DECLARE (_cairo_scaled_glyph_page_cache_mutex) -CAIRO_MUTEX_DECLARE (_cairo_scaled_font_error_mutex) #if CAIRO_HAS_FT_FONT CAIRO_MUTEX_DECLARE (_cairo_ft_unscaled_font_map_mutex) diff --git a/src/cairo-object-wrappers-private.h b/src/cairo-object-wrappers-private.h index c90b4bd61..80f30eb31 100644 --- a/src/cairo-object-wrappers-private.h +++ b/src/cairo-object-wrappers-private.h @@ -37,18 +37,17 @@ #ifndef CAIRO_OBJECT_WRAPPERS_PRIVATE_H #define CAIRO_OBJECT_WRAPPERS_PRIVATE_H -#include "cairo-reference-count-private.h" -#include "cairo-user-data-private.h" +#include "cairo-object-private.h" #define CAIRO_OBJECT_BASE_WRAPPERS(opt, type, prefix, c) \ opt type * \ prefix##_reference (type *obj) \ { \ - if (obj == NULL || \ - CAIRO_REFERENCE_COUNT_IS_INVALID (&obj->ref_count)) \ + /* Be friendlier in reference/destroy */ \ + if (unlikely (obj == NULL)) \ return obj; \ \ - _cairo_reference_count_inc (&obj->ref_count); \ + _cairo_object_reference (&obj->base); \ \ return obj; \ } \ @@ -56,25 +55,20 @@ opt unsigned int \ prefix##_get_reference_count (c type *obj) \ { \ - if (obj == NULL || \ - CAIRO_REFERENCE_COUNT_IS_INVALID (&obj->ref_count)) \ - return 0; \ - \ - return CAIRO_REFERENCE_COUNT_GET_VALUE (&obj->ref_count); \ + return _cairo_object_get_reference_count (&obj->base); \ } \ \ opt cairo_status_t \ prefix##_status (c type *obj) \ { \ - return obj->status; \ + return _cairo_object_status (&obj->base); \ } \ \ opt void * \ prefix##_get_user_data (type *obj, \ const cairo_user_data_key_t *key) \ { \ - return _cairo_user_data_array_get_data (&obj->user_data, \ - key); \ + return _cairo_object_get_user_data (&obj->base, key); \ } \ \ opt cairo_status_t \ @@ -83,19 +77,31 @@ void *user_data, \ cairo_destroy_func_t destroy) \ { \ - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&obj->ref_count)) \ - return obj->status; \ + return _cairo_object_set_user_data (&obj->base, key, \ + user_data, destroy); \ + } + +#define CAIRO_OBJECT_ERROR_WRAPPERS(opt, type, prefix, c) \ + opt type * \ + prefix##_create_in_error (cairo_status_t status) \ + { \ + cairo_object_t *obj; \ \ - return _cairo_user_data_array_set_data (&obj->user_data, \ - key, \ - user_data, \ - destroy); \ + obj = (cairo_object_t *)_cairo_object_create_in_error (status); \ + return cairo_container_of (obj, type, base); \ + } \ + \ + opt cairo_status_t \ + prefix##_set_error (type *obj, cairo_status_t status) \ + { \ + return _cairo_object_set_error (&obj->base, status); \ } #define CAIRO_OBJECT_PUBLIC_WRAPPERS(type) \ CAIRO_OBJECT_BASE_WRAPPERS(,type##_t, type,) #define CAIRO_OBJECT_WRAPPERS(type) \ + CAIRO_OBJECT_ERROR_WRAPPERS(static inline, type##_t, _##type, const) \ CAIRO_OBJECT_BASE_WRAPPERS(static inline, type##_t, _##type, const) #endif diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c index 1b5ffe883..b2edbfc06 100644 --- a/src/cairo-paginated-surface.c +++ b/src/cairo-paginated-surface.c @@ -207,7 +207,7 @@ _cairo_paginated_surface_finish (void *abstract_surface) * and check the status afterwards. However, we can only call finish() * on the target, if we own it. */ - if (CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->target->ref_count) == 1) + if (_cairo_surface_get_reference_count (surface->target) == 1) cairo_surface_finish (surface->target); if (status == CAIRO_STATUS_SUCCESS) status = _cairo_surface_status (surface->target); diff --git a/src/cairo-pattern-private.h b/src/cairo-pattern-private.h index 7d4ea1cc1..9f2e96b6c 100644 --- a/src/cairo-pattern-private.h +++ b/src/cairo-pattern-private.h @@ -59,10 +59,8 @@ struct _cairo_pattern_observer { }; struct _cairo_pattern { + cairo_object_t base; cairo_pattern_type_t type; - cairo_reference_count_t ref_count; - cairo_status_t status; - cairo_user_data_array_t user_data; cairo_matrix_t matrix; cairo_filter_t filter; diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index c1922c2c2..a33b882d2 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -136,31 +136,10 @@ slim_hidden_def (cairo_pattern_reference); static freed_pool_t freed_pattern_pool[5]; -static const cairo_solid_pattern_t _cairo_pattern_nil = { - { CAIRO_PATTERN_TYPE_SOLID, /* type */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_NO_MEMORY, /* status */ - { 0, 0, 0, NULL }, /* user_data */ - { 1., 0., 0., 1., 0., 0., }, /* matrix */ - CAIRO_FILTER_DEFAULT, /* filter */ - CAIRO_EXTEND_GRADIENT_DEFAULT }, /* extend */ -}; - -static const cairo_solid_pattern_t _cairo_pattern_nil_null_pointer = { - { CAIRO_PATTERN_TYPE_SOLID, /* type */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_NULL_POINTER, /* status */ - { 0, 0, 0, NULL }, /* user_data */ - { 1., 0., 0., 1., 0., 0., }, /* matrix */ - CAIRO_FILTER_DEFAULT, /* filter */ - CAIRO_EXTEND_GRADIENT_DEFAULT }, /* extend */ -}; const cairo_solid_pattern_t _cairo_pattern_black = { - { CAIRO_PATTERN_TYPE_SOLID, /* type */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_SUCCESS, /* status */ - { 0, 0, 0, NULL }, /* user_data */ + { CAIRO_OBJECT_SUCCESS, /* base */ + CAIRO_PATTERN_TYPE_SOLID, /* type */ { 1., 0., 0., 1., 0., 0., }, /* matrix */ CAIRO_FILTER_DEFAULT, /* filter */ CAIRO_EXTEND_GRADIENT_DEFAULT}, /* extend */ @@ -168,10 +147,8 @@ const cairo_solid_pattern_t _cairo_pattern_black = { }; const cairo_solid_pattern_t _cairo_pattern_clear = { - { CAIRO_PATTERN_TYPE_SOLID, /* type */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_SUCCESS, /* status */ - { 0, 0, 0, NULL }, /* user_data */ + { CAIRO_OBJECT_SUCCESS, /* base */ + CAIRO_PATTERN_TYPE_SOLID, /* type */ { 1., 0., 0., 1., 0., 0., }, /* matrix */ CAIRO_FILTER_DEFAULT, /* filter */ CAIRO_EXTEND_GRADIENT_DEFAULT}, /* extend */ @@ -179,10 +156,8 @@ const cairo_solid_pattern_t _cairo_pattern_clear = { }; const cairo_solid_pattern_t _cairo_pattern_white = { - { CAIRO_PATTERN_TYPE_SOLID, /* type */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_SUCCESS, /* status */ - { 0, 0, 0, NULL }, /* user_data */ + { CAIRO_OBJECT_SUCCESS, /* base */ + CAIRO_PATTERN_TYPE_SOLID, /* type */ { 1., 0., 0., 1., 0., 0., }, /* matrix */ CAIRO_FILTER_DEFAULT, /* filter */ CAIRO_EXTEND_GRADIENT_DEFAULT}, /* extend */ @@ -199,37 +174,6 @@ _cairo_pattern_notify_observers (cairo_pattern_t *pattern, pos->notify (pos, pattern, flags); } -/** - * _cairo_pattern_set_error: - * @pattern: a pattern - * @status: a status value indicating an error - * - * Atomically sets pattern->status to @status and calls _cairo_error; - * Does nothing if status is %CAIRO_STATUS_SUCCESS. - * - * All assignments of an error status to pattern->status should happen - * through _cairo_pattern_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. - **/ -static cairo_status_t -_cairo_pattern_set_error (cairo_pattern_t *pattern, - cairo_status_t status) -{ - if (status == CAIRO_STATUS_SUCCESS) - return status; - - /* Don't overwrite an existing error. This preserves the first - * error, which is the most significant. */ - _cairo_status_set_error (&pattern->status, _cairo_error (status)); - - return status; -} - static void _cairo_pattern_init (cairo_pattern_t *pattern, cairo_pattern_type_t type) { @@ -253,14 +197,11 @@ _cairo_pattern_init (cairo_pattern_t *pattern, cairo_pattern_type_t type) } #endif - pattern->type = type; - pattern->status = CAIRO_STATUS_SUCCESS; - /* Set the reference count to zero for on-stack patterns. * Callers needs to explicitly increment the count for heap allocations. */ - CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 0); + _cairo_object_init (&pattern->base, 0); - _cairo_user_data_array_init (&pattern->user_data); + pattern->type = type; if (type == CAIRO_PATTERN_TYPE_SURFACE) pattern->extend = CAIRO_EXTEND_SURFACE_DEFAULT; @@ -335,8 +276,10 @@ cairo_status_t _cairo_pattern_init_copy (cairo_pattern_t *pattern, const cairo_pattern_t *other) { - if (unlikely (_cairo_pattern_status (other))) + if (unlikely (_cairo_pattern_status (other))) { + _cairo_object_init (&pattern->base, 0); return _cairo_pattern_set_error (pattern, _cairo_pattern_status (other)); + } switch (other->type) { case CAIRO_PATTERN_TYPE_SOLID: { @@ -388,8 +331,7 @@ _cairo_pattern_init_copy (cairo_pattern_t *pattern, } /* The reference count and user_data array are unique to the copy. */ - CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 0); - _cairo_user_data_array_init (&pattern->user_data); + _cairo_object_init (&pattern->base, 0); return CAIRO_STATUS_SUCCESS; } @@ -424,8 +366,7 @@ _cairo_pattern_init_static_copy (cairo_pattern_t *pattern, memcpy (pattern, other, size); - CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 0); - _cairo_user_data_array_init (&pattern->user_data); + _cairo_object_init (&pattern->base, 0); } cairo_status_t @@ -461,7 +402,7 @@ _cairo_pattern_init_snapshot (cairo_pattern_t *pattern, void _cairo_pattern_fini (cairo_pattern_t *pattern) { - _cairo_user_data_array_fini (&pattern->user_data); + _cairo_object_fini (&pattern->base); switch (pattern->type) { case CAIRO_PATTERN_TYPE_SOLID: @@ -548,8 +489,8 @@ _cairo_pattern_create_copy (cairo_pattern_t **pattern_out, return status; } - CAIRO_REFERENCE_COUNT_INIT (&pattern->ref_count, 1); - *pattern_out = pattern; + *pattern_out = _cairo_pattern_reference (pattern); + return CAIRO_STATUS_SUCCESS; } @@ -631,26 +572,8 @@ _cairo_pattern_create_solid (const cairo_color_t *color) } _cairo_pattern_init_solid (pattern, color); - CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1); - - return &pattern->base; -} - -cairo_pattern_t * -_cairo_pattern_create_in_error (cairo_status_t status) -{ - cairo_pattern_t *pattern; - - if (status == CAIRO_STATUS_NO_MEMORY) - return (cairo_pattern_t *)&_cairo_pattern_nil.base; - - CAIRO_MUTEX_INITIALIZE (); - pattern = _cairo_pattern_create_solid (CAIRO_COLOR_BLACK); - if (_cairo_pattern_status (pattern) == CAIRO_STATUS_SUCCESS) - status = _cairo_pattern_set_error (pattern, status); - - return pattern; + return _cairo_pattern_reference (&pattern->base); } /** @@ -757,9 +680,8 @@ cairo_pattern_create_for_surface (cairo_surface_t *surface) CAIRO_MUTEX_INITIALIZE (); _cairo_pattern_init_for_surface (pattern, surface); - CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1); - return &pattern->base; + return _cairo_pattern_reference (&pattern->base); } slim_hidden_def (cairo_pattern_create_for_surface); @@ -805,9 +727,8 @@ cairo_pattern_create_linear (double x0, double y0, double x1, double y1) CAIRO_MUTEX_INITIALIZE (); _cairo_pattern_init_linear (pattern, x0, y0, x1, y1); - CAIRO_REFERENCE_COUNT_INIT (&pattern->base.base.ref_count, 1); - return &pattern->base.base; + return _cairo_pattern_reference (&pattern->base.base); } /** @@ -855,9 +776,8 @@ cairo_pattern_create_radial (double cx0, double cy0, double radius0, CAIRO_MUTEX_INITIALIZE (); _cairo_pattern_init_radial (pattern, cx0, cy0, radius0, cx1, cy1, radius1); - CAIRO_REFERENCE_COUNT_INIT (&pattern->base.base.ref_count, 1); - return &pattern->base.base; + return _cairo_pattern_reference (&pattern->base.base); } /* This order is specified in the diagram in the documentation for @@ -1033,9 +953,8 @@ cairo_pattern_create_mesh (void) _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_TYPE_MESH); _cairo_array_init (&pattern->patches, sizeof (cairo_mesh_patch_t)); pattern->current_patch = NULL; - CAIRO_REFERENCE_COUNT_INIT (&pattern->base.ref_count, 1); - return &pattern->base; + return _cairo_pattern_reference (&pattern->base); } /** @@ -1068,13 +987,10 @@ cairo_pattern_destroy (cairo_pattern_t *pattern) { cairo_pattern_type_t type; - if (pattern == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&pattern->ref_count)) + if (unlikely (pattern == NULL)) return; - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&pattern->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&pattern->ref_count)) + if (! _cairo_object_destroy (&pattern->base)) return; type = pattern->type; @@ -2311,7 +2227,7 @@ _cairo_pattern_solid_surface_matches ( if (cairo_surface_get_content (cache->surface) != _cairo_color_get_content (&pattern->color)) return FALSE; - if (CAIRO_REFERENCE_COUNT_GET_VALUE (&cache->surface->ref_count) != 1) + if (_cairo_surface_get_reference_count (cache->surface) != 1) return FALSE; if (! _cairo_surface_is_similar (cache->surface, dst)) diff --git a/src/cairo-private.h b/src/cairo-private.h index 4f29dc7fb..f91883b8b 100644 --- a/src/cairo-private.h +++ b/src/cairo-private.h @@ -42,9 +42,7 @@ CAIRO_BEGIN_DECLS struct _cairo { - cairo_reference_count_t ref_count; - cairo_status_t status; - cairo_user_data_array_t user_data; + cairo_object_t base; const cairo_backend_t *backend; }; diff --git a/src/cairo-region-private.h b/src/cairo-region-private.h index aa09634e6..7982847ed 100644 --- a/src/cairo-region-private.h +++ b/src/cairo-region-private.h @@ -47,9 +47,7 @@ CAIRO_BEGIN_DECLS struct _cairo_region { - cairo_reference_count_t ref_count; - cairo_status_t status; - cairo_user_data_array_t user_data; + cairo_object_t base; pixman_region32_t rgn; }; diff --git a/src/cairo-region.c b/src/cairo-region.c index 2123a8d0d..6df3f3bc4 100644 --- a/src/cairo-region.c +++ b/src/cairo-region.c @@ -131,104 +131,13 @@ slim_hidden_def (cairo_region_status); **/ -static const cairo_region_t _cairo_region_nil = { - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_NO_MEMORY, /* status */ -}; - -cairo_region_t * -_cairo_region_create_in_error (cairo_status_t status) -{ - switch (status) { - case CAIRO_STATUS_NO_MEMORY: - return (cairo_region_t *) &_cairo_region_nil; - - case CAIRO_STATUS_SUCCESS: - case CAIRO_STATUS_LAST_STATUS: - ASSERT_NOT_REACHED; - /* fall-through */ - case CAIRO_STATUS_SURFACE_TYPE_MISMATCH: - case CAIRO_STATUS_INVALID_STATUS: - case CAIRO_STATUS_INVALID_CONTENT: - case CAIRO_STATUS_INVALID_FORMAT: - case CAIRO_STATUS_INVALID_VISUAL: - case CAIRO_STATUS_READ_ERROR: - case CAIRO_STATUS_WRITE_ERROR: - case CAIRO_STATUS_FILE_NOT_FOUND: - case CAIRO_STATUS_TEMP_FILE_ERROR: - case CAIRO_STATUS_INVALID_STRIDE: - case CAIRO_STATUS_INVALID_SIZE: - case CAIRO_STATUS_DEVICE_TYPE_MISMATCH: - case CAIRO_STATUS_DEVICE_ERROR: - 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: - case CAIRO_STATUS_DEVICE_FINISHED: - default: - return _cairo_region_create_in_error (CAIRO_ERROR_NO_MEMORY); - } -} - -/** - * _cairo_region_set_error: - * @region: a region - * @status: a status value indicating an error - * - * Atomically sets region->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 region->status should happen - * through _cairo_region_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. - **/ -static cairo_status_t -_cairo_region_set_error (cairo_region_t *region, - cairo_status_t status) -{ - if (status == CAIRO_STATUS_SUCCESS) - return CAIRO_STATUS_SUCCESS; - - /* Don't overwrite an existing error. This preserves the first - * error, which is the most significant. */ - _cairo_status_set_error (®ion->status, _cairo_error (status)); - - return status; -} - void _cairo_region_init (cairo_region_t *region) { VG (VALGRIND_MAKE_MEM_UNDEFINED (region, sizeof (cairo_region_t))); - region->status = CAIRO_STATUS_SUCCESS; - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 0); + _cairo_object_init (®ion->base, 0); + pixman_region32_init (®ion->rgn); } @@ -238,8 +147,8 @@ _cairo_region_init_rectangle (cairo_region_t *region, { VG (VALGRIND_MAKE_MEM_UNDEFINED (region, sizeof (cairo_region_t))); - region->status = CAIRO_STATUS_SUCCESS; - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 0); + _cairo_object_init (®ion->base, 0); + pixman_region32_init_rect (®ion->rgn, rectangle->x, rectangle->y, rectangle->width, rectangle->height); @@ -248,8 +157,10 @@ _cairo_region_init_rectangle (cairo_region_t *region, void _cairo_region_fini (cairo_region_t *region) { - assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (®ion->ref_count)); pixman_region32_fini (®ion->rgn); + + _cairo_object_fini (®ion->base); + VG (VALGRIND_MAKE_MEM_NOACCESS (region, sizeof (cairo_region_t))); } @@ -275,12 +186,9 @@ cairo_region_create (void) if (region == NULL) return _cairo_region_create_in_error (CAIRO_ERROR_NO_MEMORY); - region->status = CAIRO_STATUS_SUCCESS; - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); - - pixman_region32_init (®ion->rgn); + _cairo_region_init (region); - return region; + return _cairo_region_reference (region); } slim_hidden_def (cairo_region_create); @@ -312,8 +220,7 @@ cairo_region_create_rectangles (const cairo_rectangle_int_t *rects, if (unlikely (region == NULL)) return _cairo_region_create_in_error (CAIRO_ERROR_NO_MEMORY); - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); - region->status = CAIRO_STATUS_SUCCESS; + _cairo_object_init (®ion->base, 1); if (count == 1) { pixman_region32_init_rect (®ion->rgn, @@ -375,14 +282,9 @@ cairo_region_create_rectangle (const cairo_rectangle_int_t *rectangle) if (unlikely (region == NULL)) return _cairo_region_create_in_error (CAIRO_ERROR_NO_MEMORY); - region->status = CAIRO_STATUS_SUCCESS; - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); - - pixman_region32_init_rect (®ion->rgn, - rectangle->x, rectangle->y, - rectangle->width, rectangle->height); + _cairo_region_init (region); - return region; + return _cairo_region_reference (region); } slim_hidden_def (cairo_region_create_rectangle); @@ -436,12 +338,10 @@ slim_hidden_def (cairo_region_copy); void cairo_region_destroy (cairo_region_t *region) { - if (region == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (®ion->ref_count)) + if (unlikely (region == NULL)) return; - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (®ion->ref_count)); - - if (! _cairo_reference_count_dec_and_test (®ion->ref_count)) + if (! _cairo_object_destroy (®ion->base)) return; _cairo_region_fini (region); diff --git a/src/cairo-scaled-font-private.h b/src/cairo-scaled-font-private.h index 246c9893d..01c3efeca 100644 --- a/src/cairo-scaled-font-private.h +++ b/src/cairo-scaled-font-private.h @@ -74,12 +74,10 @@ struct _cairo_scaled_font { * scaled_font->mutex in the generic scaled_font code. */ + /* hash_entry must be first */ cairo_hash_entry_t hash_entry; - /* useful bits for _cairo_scaled_font_nil */ - cairo_status_t status; - cairo_reference_count_t ref_count; - cairo_user_data_array_t user_data; + cairo_object_t base; cairo_font_face_t *original_font_face; /* may be NULL */ diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c index 6c172c84d..1af9939d4 100644 --- a/src/cairo-scaled-font.c +++ b/src/cairo-scaled-font.c @@ -297,69 +297,6 @@ _cairo_scaled_glyph_fini (cairo_scaled_font_t *scaled_font, } #define ZOMBIE 0 -static const cairo_scaled_font_t _cairo_scaled_font_nil = { - { ZOMBIE }, /* hash_entry */ - CAIRO_STATUS_NO_MEMORY, /* status */ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ - NULL, /* original_font_face */ - NULL, /* font_face */ - { 1., 0., 0., 1., 0, 0}, /* font_matrix */ - { 1., 0., 0., 1., 0, 0}, /* ctm */ - { CAIRO_ANTIALIAS_DEFAULT, /* options */ - CAIRO_SUBPIXEL_ORDER_DEFAULT, - CAIRO_HINT_STYLE_DEFAULT, - CAIRO_HINT_METRICS_DEFAULT} , - FALSE, /* placeholder */ - FALSE, /* holdover */ - TRUE, /* finished */ - { 1., 0., 0., 1., 0, 0}, /* scale */ - { 1., 0., 0., 1., 0, 0}, /* scale_inverse */ - 1., /* max_scale */ - { 0., 0., 0., 0., 0. }, /* extents */ - { 0., 0., 0., 0., 0. }, /* fs_extents */ - CAIRO_MUTEX_NIL_INITIALIZER,/* mutex */ - NULL, /* glyphs */ - { NULL, NULL }, /* pages */ - FALSE, /* cache_frozen */ - FALSE, /* global_cache_frozen */ - NULL, /* surface_backend */ - NULL, /* surface_private */ - NULL /* backend */ -}; - -/** - * _cairo_scaled_font_set_error: - * @scaled_font: a scaled_font - * @status: a status value indicating an error - * - * Atomically sets scaled_font->status to @status and calls _cairo_error; - * Does nothing if status is %CAIRO_STATUS_SUCCESS. - * - * All assignments of an error status to scaled_font->status should happen - * through _cairo_scaled_font_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_scaled_font_set_error (cairo_scaled_font_t *scaled_font, - cairo_status_t status) -{ - if (status == CAIRO_STATUS_SUCCESS) - return status; - - /* Don't overwrite an existing error. This preserves the first - * error, which is the most significant. */ - _cairo_status_set_error (&scaled_font->status, _cairo_error (status)); - - return status; -} /** * cairo_scaled_font_get_type: @@ -376,7 +313,7 @@ _cairo_scaled_font_set_error (cairo_scaled_font_t *scaled_font, cairo_font_type_t cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font) { - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count)) + if (_cairo_object_is_nil (&scaled_font->base)) return CAIRO_FONT_TYPE_TOY; return scaled_font->backend->type; @@ -478,7 +415,7 @@ _cairo_scaled_font_map_destroy (void) * is always in a consistent state when we release the mutex. */ while (font_map->num_holdovers) { scaled_font = font_map->holdovers[font_map->num_holdovers-1]; - assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)); + assert (_cairo_scaled_font_get_reference_count (scaled_font) == 0); _cairo_hash_table_remove (font_map->hash_table, &scaled_font->hash_entry); @@ -669,7 +606,6 @@ _cairo_scaled_font_init_key (cairo_scaled_font_t *scaled_font, { uint32_t hash = FNV1_32_INIT; - scaled_font->status = CAIRO_STATUS_SUCCESS; scaled_font->placeholder = FALSE; scaled_font->font_face = font_face; scaled_font->original_font_face = font_face; @@ -759,6 +695,8 @@ _cairo_scaled_font_init (cairo_scaled_font_t *scaled_font, if (unlikely (status)) return status; + _cairo_object_init (&scaled_font->base, 1); + _cairo_scaled_font_init_key (scaled_font, font_face, font_matrix, ctm, options); @@ -800,10 +738,6 @@ _cairo_scaled_font_init (cairo_scaled_font_t *scaled_font, scaled_font->holdover = FALSE; scaled_font->finished = FALSE; - CAIRO_REFERENCE_COUNT_INIT (&scaled_font->ref_count, 1); - - _cairo_user_data_array_init (&scaled_font->user_data); - cairo_font_face_reference (font_face); scaled_font->original_font_face = NULL; @@ -908,7 +842,7 @@ _cairo_scaled_font_fini_internal (cairo_scaled_font_t *scaled_font) if (scaled_font->backend != NULL && scaled_font->backend->fini != NULL) scaled_font->backend->fini (scaled_font); - _cairo_user_data_array_fini (&scaled_font->user_data); + _cairo_object_fini (&scaled_font->base); } /* XXX: allow multiple backends to share the font */ @@ -1064,7 +998,7 @@ cairo_scaled_font_create (cairo_font_face_t *font_face, * actually working). So now we remove it from the holdovers * array, unless we caught the font in the middle of destruction. */ - if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)) { + if (_cairo_scaled_font_get_reference_count (scaled_font) == 0) { if (scaled_font->holdover) { int i; @@ -1082,7 +1016,8 @@ cairo_scaled_font_create (cairo_font_face_t *font_face, } /* reset any error status */ - scaled_font->status = CAIRO_STATUS_SUCCESS; + /* XXX check me */ + scaled_font->base.mystatus = CAIRO_STATUS_SUCCESS; } if (likely (_cairo_scaled_font_status (scaled_font) == CAIRO_STATUS_SUCCESS)) { @@ -1176,52 +1111,9 @@ cairo_scaled_font_create (cairo_font_face_t *font_face, } slim_hidden_def (cairo_scaled_font_create); -static cairo_scaled_font_t *_cairo_scaled_font_nil_objects[CAIRO_STATUS_LAST_STATUS + 1]; - -/* XXX This should disappear in favour of a common pool of error objects. */ -cairo_scaled_font_t * -_cairo_scaled_font_create_in_error (cairo_status_t status) -{ - cairo_scaled_font_t *scaled_font; - - assert (status != CAIRO_STATUS_SUCCESS); - - if (status == CAIRO_STATUS_NO_MEMORY) - return (cairo_scaled_font_t *) &_cairo_scaled_font_nil; - - CAIRO_MUTEX_LOCK (_cairo_scaled_font_error_mutex); - scaled_font = _cairo_scaled_font_nil_objects[status]; - if (unlikely (scaled_font == NULL)) { - scaled_font = malloc (sizeof (cairo_scaled_font_t)); - if (unlikely (scaled_font == NULL)) { - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_error_mutex); - return _cairo_scaled_font_create_in_error (CAIRO_ERROR_NO_MEMORY); - } - - *scaled_font = _cairo_scaled_font_nil; - scaled_font->status = status; - _cairo_scaled_font_nil_objects[status] = scaled_font; - } - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_error_mutex); - - return scaled_font; -} - void _cairo_scaled_font_reset_static_data (void) { - int status; - - CAIRO_MUTEX_LOCK (_cairo_scaled_font_error_mutex); - for (status = CAIRO_STATUS_SUCCESS; - status <= CAIRO_STATUS_LAST_STATUS; - status++) - { - free (_cairo_scaled_font_nil_objects[status]); - _cairo_scaled_font_nil_objects[status] = NULL; - } - CAIRO_MUTEX_UNLOCK (_cairo_scaled_font_error_mutex); - CAIRO_MUTEX_LOCK (_cairo_scaled_glyph_page_cache_mutex); if (cairo_scaled_glyph_page_cache.hash_table != NULL) { _cairo_cache_fini (&cairo_scaled_glyph_page_cache); @@ -1246,20 +1138,17 @@ cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font) assert (CAIRO_MUTEX_IS_UNLOCKED (_cairo_scaled_font_map_mutex)); - if (scaled_font == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count)) + if (unlikely (scaled_font == NULL)) return; - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&scaled_font->ref_count)) + if (! _cairo_object_destroy (&scaled_font->base)) return; font_map = _cairo_scaled_font_map_lock (); assert (font_map != NULL); /* Another thread may have resurrected the font whilst we waited */ - if (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count)) { + if (_cairo_scaled_font_get_reference_count (scaled_font) == 0) { if (! scaled_font->placeholder && scaled_font->hash_entry.hash != ZOMBIE) { @@ -1276,7 +1165,7 @@ cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font) if (font_map->num_holdovers == CAIRO_SCALED_FONT_MAX_HOLDOVERS) { lru = font_map->holdovers[0]; - assert (! CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&lru->ref_count)); + assert (_cairo_scaled_font_get_reference_count (lru) == 0); _cairo_hash_table_remove (font_map->hash_table, &lru->hash_entry); diff --git a/src/cairo-surface-private.h b/src/cairo-surface-private.h index b815b0bff..ad6910ddd 100644 --- a/src/cairo-surface-private.h +++ b/src/cairo-surface-private.h @@ -48,6 +48,8 @@ typedef void (*cairo_surface_func_t) (cairo_surface_t *); struct _cairo_surface { + cairo_object_t base; + const cairo_surface_backend_t *backend; cairo_device_t *device; @@ -58,8 +60,6 @@ struct _cairo_surface { cairo_content_t content; - cairo_reference_count_t ref_count; - cairo_status_t status; unsigned int unique_id; unsigned finished : 1; @@ -67,7 +67,6 @@ struct _cairo_surface { unsigned has_font_options : 1; unsigned owns_device : 1; - cairo_user_data_array_t user_data; cairo_user_data_array_t mime_data; cairo_matrix_t device_transform; diff --git a/src/cairo-surface.c b/src/cairo-surface.c index 4a7359a59..720ddf579 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -170,93 +170,6 @@ slim_hidden_def (cairo_surface_status); **/ -#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 == (int)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, _cairo_error (status)); - - return status; -} - /** * cairo_surface_get_type: * @surface: a #cairo_surface_t @@ -454,19 +367,18 @@ _cairo_surface_init (cairo_surface_t *surface, { CAIRO_MUTEX_INITIALIZE (); + _cairo_object_init (&surface->base, 1); + surface->backend = backend; surface->device = cairo_device_reference (device); 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); @@ -852,13 +764,10 @@ _cairo_surface_repaint_solid_pattern_surface (cairo_surface_t *other, void cairo_surface_destroy (cairo_surface_t *surface) { - if (surface == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) + if (unlikely (surface == NULL)) 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); @@ -866,18 +775,16 @@ 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) - cairo_device_destroy (surface->device); + cairo_device_destroy (surface->device); assert (surface->snapshot_of == NULL); assert (!_cairo_surface_has_snapshots (surface)); + _cairo_object_fini (&surface->base); + free (surface); } slim_hidden_def(cairo_surface_destroy); @@ -909,7 +816,7 @@ cairo_surface_finish (cairo_surface_t *surface) if (surface == NULL) return; - if (CAIRO_REFERENCE_COUNT_IS_INVALID (&surface->ref_count)) + if (_cairo_object_is_nil (&surface->base)) return; if (surface->finished) @@ -3110,69 +3017,5 @@ _cairo_surface_set_resolution (cairo_surface_t *surface, 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: - case CAIRO_STATUS_DEVICE_FINISHED: - default: - return _cairo_surface_create_in_error (CAIRO_ERROR_NO_MEMORY); - } -} - /* LocalWords: rasterized */ diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c index ec1417fd2..be3be30c9 100644 --- a/src/cairo-svg-surface.c +++ b/src/cairo-svg-surface.c @@ -1381,8 +1381,8 @@ _cairo_svg_surface_emit_recording_surface (cairo_svg_document_t *document, cairo_output_stream_t *contents; - if (_cairo_user_data_array_get_data (&source->base.user_data, - (cairo_user_data_key_t *) document)) + if (_cairo_surface_get_user_data (&source->base, + (cairo_user_data_key_t *) document)) { return CAIRO_STATUS_SUCCESS; } @@ -1469,9 +1469,9 @@ _cairo_svg_surface_emit_recording_surface (cairo_svg_document_t *document, return status; /* and tag it */ - return _cairo_user_data_array_set_data (&source->base.user_data, - (cairo_user_data_key_t *) document, - document, NULL); + return _cairo_surface_set_user_data (&source->base, + (cairo_user_data_key_t *) document, + document, NULL); } static cairo_status_t diff --git a/src/cairo-toy-font-face.c b/src/cairo-toy-font-face.c index e9fb6e75f..5f2239a41 100644 --- a/src/cairo-toy-font-face.c +++ b/src/cairo-toy-font-face.c @@ -311,15 +311,14 @@ _cairo_toy_font_face_destroy (void *abstract_face) cairo_toy_font_face_t *font_face = abstract_face; cairo_hash_table_t *hash_table; - if (font_face == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->base.ref_count)) + if (_cairo_object_is_nil (&font_face->base.base)) return; hash_table = _cairo_toy_font_face_hash_table_lock (); /* All created objects must have been mapped in the hash table. */ assert (hash_table != NULL); - if (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&font_face->base.ref_count)) { + if (_cairo_font_face_get_reference_count (&font_face->base) != 0) { /* somebody recreated the font whilst we waited for the lock */ _cairo_toy_font_face_hash_table_unlock (); return; diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c index 1df850c54..ef8f5d481 100644 --- a/src/cairo-win32-font.c +++ b/src/cairo-win32-font.c @@ -2093,15 +2093,14 @@ _cairo_win32_font_face_destroy (void *abstract_face) cairo_win32_font_face_t *font_face = abstract_face; cairo_hash_table_t *hash_table; - if (font_face == NULL || - CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->base.ref_count)) + if (_cairo_object_is_nil (&font_face->base.base)) return; hash_table = _cairo_win32_font_face_hash_table_lock (); /* All created objects must have been mapped in the hash table. */ assert (hash_table != NULL); - if (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&font_face->base.ref_count)) { + if (_cairo_font_face_get_reference_count (&font_face->base) != 0) { /* somebody recreated the font whilst we waited for the lock */ _cairo_win32_font_face_hash_table_unlock (); return; diff --git a/src/cairo.c b/src/cairo.c index ba8604644..815f0ba95 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -182,92 +182,6 @@ slim_hidden_def (cairo_status); **/ -#define DEFINE_NIL_CONTEXT(status) \ - { \ - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ \ - status, /* status */ \ - { 0, 0, 0, NULL }, /* user_data */ \ - NULL \ - } - -static const cairo_t _cairo_nil[] = { - DEFINE_NIL_CONTEXT (CAIRO_STATUS_NO_MEMORY), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_RESTORE), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_POP_GROUP), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_NO_CURRENT_POINT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_MATRIX), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STATUS), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_NULL_POINTER), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STRING), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_PATH_DATA), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_READ_ERROR), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_WRITE_ERROR), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_SURFACE_FINISHED), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_SURFACE_TYPE_MISMATCH), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_PATTERN_TYPE_MISMATCH), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_CONTENT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_FORMAT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_VISUAL), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_FILE_NOT_FOUND), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_DASH), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_DSC_COMMENT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_INDEX), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_CLIP_NOT_REPRESENTABLE), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_TEMP_FILE_ERROR), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_STRIDE), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_FONT_TYPE_MISMATCH), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_IMMUTABLE), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_ERROR), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_NEGATIVE_COUNT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_CLUSTERS), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_SLANT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_WEIGHT), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_SIZE), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_TYPE_MISMATCH), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_ERROR), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_INVALID_MESH_CONSTRUCTION), - DEFINE_NIL_CONTEXT (CAIRO_STATUS_DEVICE_FINISHED) -}; -COMPILE_TIME_ASSERT (ARRAY_LENGTH (_cairo_nil) == CAIRO_STATUS_LAST_STATUS - 1); - -/** - * _cairo_set_error: - * @cr: a cairo context - * @status: a status value indicating an error - * - * Atomically sets cr->status to @status and calls _cairo_error; - * Does nothing if status is %CAIRO_STATUS_SUCCESS. - * - * All assignments of an error status to cr->status should happen - * through _cairo_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. - **/ -static void -_cairo_set_error (cairo_t *cr, cairo_status_t status) -{ - /* Don't overwrite an existing error. This preserves the first - * error, which is the most significant. */ - _cairo_status_set_error (&cr->status, _cairo_error (status)); -} - -cairo_t * -_cairo_create_in_error (cairo_status_t status) -{ - cairo_t *cr; - - assert (status != CAIRO_STATUS_SUCCESS); - - cr = (cairo_t *) &_cairo_nil[status - CAIRO_STATUS_NO_MEMORY]; - assert (status == _cairo_status (cr)); - - return cr; -} - /** * cairo_create: * @target: target surface for the context @@ -309,9 +223,7 @@ void _cairo_init (cairo_t *cr, const cairo_backend_t *backend) { - CAIRO_REFERENCE_COUNT_INIT (&cr->ref_count, 1); - cr->status = CAIRO_STATUS_SUCCESS; - _cairo_user_data_array_init (&cr->user_data); + _cairo_object_init (&cr->base, 1); cr->backend = backend; } @@ -319,7 +231,7 @@ _cairo_init (cairo_t *cr, void _cairo_fini (cairo_t *cr) { - _cairo_user_data_array_fini (&cr->user_data); + _cairo_object_fini (&cr->base); } /** @@ -333,12 +245,10 @@ _cairo_fini (cairo_t *cr) void cairo_destroy (cairo_t *cr) { - if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count)) + if (unlikely (cr == NULL)) return; - assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&cr->ref_count)); - - if (! _cairo_reference_count_dec_and_test (&cr->ref_count)) + if (! _cairo_object_destroy (&cr->base)) return; cr->backend->destroy (cr); |