diff --git a/src/cairo.c b/src/cairo.c index 56f99e492..bd31063da 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -212,6 +212,8 @@ cairo_reference (cairo_t *cr) void cairo_destroy (cairo_t *cr) { + cairo_surface_t *surface; + if (cr == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&cr->ref_count)) return; @@ -225,6 +227,15 @@ cairo_destroy (cairo_t *cr) break; } + /* The context is expected (>99% of all use cases) to be held for the + * duration of a single expose event/sequence of graphic operations. + * Therefore, on destroy we explicitly flush the Cairo pipeline of any + * pending operations. + */ + surface = _cairo_gstate_get_original_target (cr->gstate); + if (surface != NULL) + cairo_surface_flush (surface); + _cairo_gstate_fini (cr->gstate); while (cr->gstate_freelist != NULL) { cairo_gstate_t *gstate = cr->gstate_freelist;