mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-04 06:20:19 +01:00
[surface] Assign a unique id to the surface.
Allocate an ever-increasing, non-zero, unique identifier to each surface. True for the first 4-billion...
This commit is contained in:
parent
45835f623f
commit
e05097c604
3 changed files with 35 additions and 3 deletions
|
|
@ -2424,7 +2424,10 @@ static unsigned long
|
|||
_cairo_surface_pattern_hash (unsigned long hash,
|
||||
const cairo_pattern_t *pattern)
|
||||
{
|
||||
/* XXX requires cow-snapshots */
|
||||
const cairo_surface_pattern_t *surface = (cairo_surface_pattern_t *) pattern;
|
||||
|
||||
hash ^= surface->surface->unique_id;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
|
@ -2578,8 +2581,10 @@ static cairo_bool_t
|
|||
_cairo_surface_pattern_equal (const cairo_pattern_t *A,
|
||||
const cairo_pattern_t *B)
|
||||
{
|
||||
/* XXX requires cow-snapshots */
|
||||
return FALSE;
|
||||
const cairo_surface_pattern_t *a = (cairo_surface_pattern_t *) A;
|
||||
const cairo_surface_pattern_t *b = (cairo_surface_pattern_t *) B;
|
||||
|
||||
return a->surface->unique_id == b->surface->unique_id;
|
||||
}
|
||||
|
||||
cairo_bool_t
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ struct _cairo_surface {
|
|||
cairo_reference_count_t ref_count;
|
||||
cairo_status_t status;
|
||||
cairo_bool_t finished;
|
||||
unsigned int unique_id;
|
||||
|
||||
cairo_user_data_array_t user_data;
|
||||
cairo_user_data_array_t mime_data;
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ const cairo_surface_t name = { \
|
|||
CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ \
|
||||
status, /* status */ \
|
||||
FALSE, /* finished */ \
|
||||
0, /* unique id */ \
|
||||
{ 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 */ \
|
||||
|
|
@ -180,6 +181,29 @@ cairo_surface_status (cairo_surface_t *surface)
|
|||
}
|
||||
slim_hidden_def (cairo_surface_status);
|
||||
|
||||
static unsigned long
|
||||
_cairo_surface_allocate_unique_id (void)
|
||||
{
|
||||
static unsigned int unique_id;
|
||||
|
||||
#if CAIRO_NO_MUTEX
|
||||
if (++unique_id == 0)
|
||||
unique_id = 1;
|
||||
return unique_id;
|
||||
#else
|
||||
unsigned int old, id;
|
||||
|
||||
do {
|
||||
old = _cairo_atomic_int_get (&unique_id);
|
||||
id = old + 1;
|
||||
if (id == 0)
|
||||
id = 1;
|
||||
} while (! _cairo_atomic_int_cmpxchg (&unique_id, old, id));
|
||||
|
||||
return id;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
_cairo_surface_init (cairo_surface_t *surface,
|
||||
const cairo_surface_backend_t *backend,
|
||||
|
|
@ -194,6 +218,7 @@ _cairo_surface_init (cairo_surface_t *surface,
|
|||
CAIRO_REFERENCE_COUNT_INIT (&surface->ref_count, 1);
|
||||
surface->status = CAIRO_STATUS_SUCCESS;
|
||||
surface->finished = FALSE;
|
||||
surface->unique_id = _cairo_surface_allocate_unique_id ();
|
||||
|
||||
_cairo_user_data_array_init (&surface->user_data);
|
||||
_cairo_user_data_array_init (&surface->mime_data);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue