[cairo] Propagate surface->status on cairo_t creation.

Set the cairo_t status to be the surface->status when the context is
created, and special case the NO_MEMORY status in order to avoid a
redundant allocation.
This commit is contained in:
Chris Wilson 2007-05-11 15:15:11 +01:00
parent 9f4efa8a3a
commit de4dd4263c
2 changed files with 6 additions and 8 deletions

View file

@ -96,7 +96,7 @@ _cairo_gstate_init (cairo_gstate_t *gstate,
if (gstate->source->status)
return CAIRO_STATUS_NO_MEMORY;
return CAIRO_STATUS_SUCCESS;
return target ? target->status : CAIRO_STATUS_NULL_POINTER;
}
/**

View file

@ -191,6 +191,10 @@ cairo_create (cairo_surface_t *target)
cairo_t *cr;
cairo_status_t status;
/* special case OOM in order to avoid another allocation */
if (target && target->status == CAIRO_STATUS_NO_MEMORY)
return (cairo_t *) &_cairo_nil;
cr = malloc (sizeof (cairo_t));
if (cr == NULL)
return (cairo_t *) &_cairo_nil;
@ -200,17 +204,11 @@ cairo_create (cairo_surface_t *target)
cr->status = CAIRO_STATUS_SUCCESS;
_cairo_user_data_array_init (&cr->user_data);
_cairo_path_fixed_init (cr->path);
cr->gstate = cr->gstate_tail;
status = _cairo_gstate_init (cr->gstate, target);
_cairo_path_fixed_init (cr->path);
if (target == NULL) {
/* override status with user error */
status = CAIRO_STATUS_NULL_POINTER;
}
if (status)
_cairo_set_error (cr, status);