[cairo] Idle thoughts on error propagation

Chris Wilson chris at chris-wilson.co.uk
Fri May 9 00:38:14 PDT 2008


On Thu, 2008-05-01 at 15:13 -0700, Carl Worth wrote:
> I can imagine a case where this could be wrong.
> 
> The cairo_t context is conceptually transient for what could be a
> long-standing surface. For example, if I had an application creating a
> new context for the same surface on every expose event, would it be
> correct to force the surface to shutdown due to an error on the
> context?

I think we use surfaces in two entirely different ways and want
different error behaviour for each.

First, we have the long-lived surfaces that, for example, are bound to a
window and thus are used repeatedly as the target of multiple cairo_t.
As this is a destination, we don't care about error propagation and
having to rebuild the surface would be a hindrance (and error-prone).

The second case, we have short-lived surfaces that are used as
intermediate sources. These crucially require error propagation (or a
rigorous handling of errors by the application). However, I think this
could be satisfied by promoting this idiom:

cairo_surface_t *
_construct_source (cairo_surface_t *target)
{
	cairo_surface_t *surface;
	cairo_t *cr;
	
	surface = cairo_surface_create_similar (target, CAIRO_CONTENT_COLOUR, width, height);
	cr = cairo_create (surface);
	cairo_surface_destoy (surface);

	_draw_source (cr);

	surface = cairo_surface_reference (cairo_get_target (cr));
	cairo_destroy (cr);

	return surface;
}

-- 
Chris Wilson



More information about the cairo mailing list