From e1307da8616027004dd6c901017a667b1503781d Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 8 Jan 2013 12:53:24 +0000 Subject: [PATCH] script: Simply exchange source/dest images for _set_source_image But note we can only do the exchange if they do indeed match and there are no other references (the objects are only on the stack). Signed-off-by: Chris Wilson --- util/cairo-script/cairo-script-operators.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/util/cairo-script/cairo-script-operators.c b/util/cairo-script/cairo-script-operators.c index efc1970cf..71d2b79b7 100644 --- a/util/cairo-script/cairo-script-operators.c +++ b/util/cairo-script/cairo-script-operators.c @@ -5356,11 +5356,20 @@ _set_source_image (csi_t *ctx) * principally to remove the pixman ops from the profiles. */ if (_csi_likely (_matching_images (surface, source))) { - cairo_surface_flush (surface); - memcpy (cairo_image_surface_get_data (surface), - cairo_image_surface_get_data (source), - cairo_image_surface_get_height (source) * cairo_image_surface_get_stride (source)); - cairo_surface_mark_dirty (surface); + if (cairo_surface_get_reference_count (surface) == 1 && + cairo_surface_get_reference_count (source) == 1) + { + _csi_peek_ostack (ctx, 0)->datum.surface = surface; + _csi_peek_ostack (ctx, 1)->datum.surface = source; + } + else + { + cairo_surface_flush (surface); + memcpy (cairo_image_surface_get_data (surface), + cairo_image_surface_get_data (source), + cairo_image_surface_get_height (source) * cairo_image_surface_get_stride (source)); + cairo_surface_mark_dirty (surface); + } } else { cairo_t *cr;