Bug 579885. Part 4: Paint opaque surfaces using kPrivateCGCompositeCopy when possible. r=jrmuizel,a=blocking

This commit is contained in:
Robert O'Callahan 2010-11-12 14:43:42 +13:00
parent 2215e35a5d
commit 5dc58e0b07
3 changed files with 87 additions and 0 deletions

View File

@ -150,6 +150,8 @@ quartz-mask-non-OVER.patch: Don't use CGContextSetAlpha to optimize alpha maskin
quartz-layers-content.patch: Store cairo content type in CGLayer surfaces
quartz-optimize-OVER.patch: Optimize OVER to SOURCE for opaque patterns
==== pixman patches ====
pixman-android-cpu-detect.patch: Add CPU detection support for Android, where we can't reliably access /proc/self/auxv.

View File

@ -127,6 +127,7 @@ static bool (*CGContextGetShouldSmoothFontsPtr) (CGContextRef) = NULL;
static void (*CGContextSetAllowsFontSmoothingPtr) (CGContextRef, bool) = NULL;
static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL;
static void (*CGContextReplacePathWithClipPathPtr) (CGContextRef) = NULL;
static CGFloat (*CGContextGetAlphaPtr) (CGContextRef) = NULL;
static SInt32 _cairo_quartz_osx_version = 0x0;
@ -162,6 +163,7 @@ static void quartz_ensure_symbols(void)
CGContextReplacePathWithClipPathPtr = dlsym(RTLD_DEFAULT, "CGContextReplacePathWithClipPath");
CGContextGetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing");
CGContextSetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing");
CGContextGetAlphaPtr = dlsym(RTLD_DEFAULT, "CGContextGetAlpha");
if (Gestalt(gestaltSystemVersion, &_cairo_quartz_osx_version) != noErr) {
// assume 10.4
@ -1703,6 +1705,18 @@ _cairo_quartz_setup_state (cairo_quartz_surface_t *surface,
}
if (source->type == CAIRO_PATTERN_TYPE_SURFACE) {
if (op == CAIRO_OPERATOR_OVER && _cairo_pattern_is_opaque (source) &&
CGContextGetAlphaPtr &&
CGContextGetAlphaPtr (surface->cgContext) == 1.0) {
// Quartz won't touch pixels outside the bounds of the
// source surface, so we can just go ahead and use Copy here
// to accelerate things.
// Quartz won't necessarily be able to do this optimization internally;
// for CGLayer surfaces, we can know all the pixels are opaque
// (because it's CONTENT_COLOR), but Quartz won't know.
CGContextSetCompositeOperation (context, kPrivateCGCompositeCopy);
}
const cairo_surface_pattern_t *spat = (const cairo_surface_pattern_t *) source;
_cairo_quartz_setup_surface_source (surface, spat, extents, &state);
return state;

View File

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