michael@0: From: Robert O'Callahan michael@0: Bug 579885. Part 4: Paint opaque surfaces using kPrivateCGCompositeCopy when possible. r=jrmuizel,a=blocking michael@0: michael@0: diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c michael@0: --- a/gfx/cairo/cairo/src/cairo-quartz-surface.c michael@0: +++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c michael@0: @@ -122,16 +122,17 @@ static void (*CGContextClipToMaskPtr) (C michael@0: static void (*CGContextDrawTiledImagePtr) (CGContextRef, CGRect, CGImageRef) = NULL; michael@0: static unsigned int (*CGContextGetTypePtr) (CGContextRef) = NULL; michael@0: static void (*CGContextSetShouldAntialiasFontsPtr) (CGContextRef, bool) = NULL; michael@0: static bool (*CGContextGetShouldAntialiasFontsPtr) (CGContextRef) = NULL; michael@0: static bool (*CGContextGetShouldSmoothFontsPtr) (CGContextRef) = NULL; michael@0: static void (*CGContextSetAllowsFontSmoothingPtr) (CGContextRef, bool) = NULL; michael@0: static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL; michael@0: static void (*CGContextReplacePathWithClipPathPtr) (CGContextRef) = NULL; michael@0: +static CGFloat (*CGContextGetAlphaPtr) (CGContextRef) = NULL; michael@0: michael@0: static SInt32 _cairo_quartz_osx_version = 0x0; michael@0: michael@0: static cairo_bool_t _cairo_quartz_symbol_lookup_done = FALSE; michael@0: michael@0: /* michael@0: * Utility functions michael@0: */ michael@0: @@ -157,16 +158,17 @@ static void quartz_ensure_symbols(void) michael@0: CGContextDrawTiledImagePtr = dlsym(RTLD_DEFAULT, "CGContextDrawTiledImage"); michael@0: CGContextGetTypePtr = dlsym(RTLD_DEFAULT, "CGContextGetType"); michael@0: CGContextSetShouldAntialiasFontsPtr = dlsym(RTLD_DEFAULT, "CGContextSetShouldAntialiasFonts"); michael@0: CGContextGetShouldAntialiasFontsPtr = dlsym(RTLD_DEFAULT, "CGContextGetShouldAntialiasFonts"); michael@0: CGContextGetShouldSmoothFontsPtr = dlsym(RTLD_DEFAULT, "CGContextGetShouldSmoothFonts"); michael@0: CGContextReplacePathWithClipPathPtr = dlsym(RTLD_DEFAULT, "CGContextReplacePathWithClipPath"); michael@0: CGContextGetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing"); michael@0: CGContextSetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing"); michael@0: + CGContextGetAlphaPtr = dlsym(RTLD_DEFAULT, "CGContextGetAlpha"); michael@0: michael@0: if (Gestalt(gestaltSystemVersion, &_cairo_quartz_osx_version) != noErr) { michael@0: // assume 10.4 michael@0: _cairo_quartz_osx_version = 0x1040; michael@0: } michael@0: michael@0: _cairo_quartz_symbol_lookup_done = TRUE; michael@0: } michael@0: @@ -1698,16 +1700,28 @@ _cairo_quartz_setup_state (cairo_quartz_ michael@0: michael@0: if (source->type == CAIRO_PATTERN_TYPE_RADIAL) { michael@0: const cairo_radial_pattern_t *rpat = (const cairo_radial_pattern_t *)source; michael@0: _cairo_quartz_setup_radial_source (surface, rpat, extents, &state); michael@0: return state; michael@0: } michael@0: michael@0: if (source->type == CAIRO_PATTERN_TYPE_SURFACE) { michael@0: + if (op == CAIRO_OPERATOR_OVER && _cairo_pattern_is_opaque (source) && michael@0: + CGContextGetAlphaPtr && michael@0: + CGContextGetAlphaPtr (surface->cgContext) == 1.0) { michael@0: + // Quartz won't touch pixels outside the bounds of the michael@0: + // source surface, so we can just go ahead and use Copy here michael@0: + // to accelerate things. michael@0: + // Quartz won't necessarily be able to do this optimization internally; michael@0: + // for CGLayer surfaces, we can know all the pixels are opaque michael@0: + // (because it's CONTENT_COLOR), but Quartz won't know. michael@0: + CGContextSetCompositeOperation (context, kPrivateCGCompositeCopy); michael@0: + } michael@0: + michael@0: const cairo_surface_pattern_t *spat = (const cairo_surface_pattern_t *) source; michael@0: _cairo_quartz_setup_surface_source (surface, spat, extents, &state); michael@0: return state; michael@0: } michael@0: michael@0: state.action = DO_UNSUPPORTED; michael@0: return state; michael@0: }