gfx/cairo/quartz-optimize-OVER.patch

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 From: Robert O'Callahan <robert@ocallahan.org>
michael@0 2 Bug 579885. Part 4: Paint opaque surfaces using kPrivateCGCompositeCopy when possible. r=jrmuizel,a=blocking
michael@0 3
michael@0 4 diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c
michael@0 5 --- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
michael@0 6 +++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
michael@0 7 @@ -122,16 +122,17 @@ static void (*CGContextClipToMaskPtr) (C
michael@0 8 static void (*CGContextDrawTiledImagePtr) (CGContextRef, CGRect, CGImageRef) = NULL;
michael@0 9 static unsigned int (*CGContextGetTypePtr) (CGContextRef) = NULL;
michael@0 10 static void (*CGContextSetShouldAntialiasFontsPtr) (CGContextRef, bool) = NULL;
michael@0 11 static bool (*CGContextGetShouldAntialiasFontsPtr) (CGContextRef) = NULL;
michael@0 12 static bool (*CGContextGetShouldSmoothFontsPtr) (CGContextRef) = NULL;
michael@0 13 static void (*CGContextSetAllowsFontSmoothingPtr) (CGContextRef, bool) = NULL;
michael@0 14 static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL;
michael@0 15 static void (*CGContextReplacePathWithClipPathPtr) (CGContextRef) = NULL;
michael@0 16 +static CGFloat (*CGContextGetAlphaPtr) (CGContextRef) = NULL;
michael@0 17
michael@0 18 static SInt32 _cairo_quartz_osx_version = 0x0;
michael@0 19
michael@0 20 static cairo_bool_t _cairo_quartz_symbol_lookup_done = FALSE;
michael@0 21
michael@0 22 /*
michael@0 23 * Utility functions
michael@0 24 */
michael@0 25 @@ -157,16 +158,17 @@ static void quartz_ensure_symbols(void)
michael@0 26 CGContextDrawTiledImagePtr = dlsym(RTLD_DEFAULT, "CGContextDrawTiledImage");
michael@0 27 CGContextGetTypePtr = dlsym(RTLD_DEFAULT, "CGContextGetType");
michael@0 28 CGContextSetShouldAntialiasFontsPtr = dlsym(RTLD_DEFAULT, "CGContextSetShouldAntialiasFonts");
michael@0 29 CGContextGetShouldAntialiasFontsPtr = dlsym(RTLD_DEFAULT, "CGContextGetShouldAntialiasFonts");
michael@0 30 CGContextGetShouldSmoothFontsPtr = dlsym(RTLD_DEFAULT, "CGContextGetShouldSmoothFonts");
michael@0 31 CGContextReplacePathWithClipPathPtr = dlsym(RTLD_DEFAULT, "CGContextReplacePathWithClipPath");
michael@0 32 CGContextGetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing");
michael@0 33 CGContextSetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing");
michael@0 34 + CGContextGetAlphaPtr = dlsym(RTLD_DEFAULT, "CGContextGetAlpha");
michael@0 35
michael@0 36 if (Gestalt(gestaltSystemVersion, &_cairo_quartz_osx_version) != noErr) {
michael@0 37 // assume 10.4
michael@0 38 _cairo_quartz_osx_version = 0x1040;
michael@0 39 }
michael@0 40
michael@0 41 _cairo_quartz_symbol_lookup_done = TRUE;
michael@0 42 }
michael@0 43 @@ -1698,16 +1700,28 @@ _cairo_quartz_setup_state (cairo_quartz_
michael@0 44
michael@0 45 if (source->type == CAIRO_PATTERN_TYPE_RADIAL) {
michael@0 46 const cairo_radial_pattern_t *rpat = (const cairo_radial_pattern_t *)source;
michael@0 47 _cairo_quartz_setup_radial_source (surface, rpat, extents, &state);
michael@0 48 return state;
michael@0 49 }
michael@0 50
michael@0 51 if (source->type == CAIRO_PATTERN_TYPE_SURFACE) {
michael@0 52 + if (op == CAIRO_OPERATOR_OVER && _cairo_pattern_is_opaque (source) &&
michael@0 53 + CGContextGetAlphaPtr &&
michael@0 54 + CGContextGetAlphaPtr (surface->cgContext) == 1.0) {
michael@0 55 + // Quartz won't touch pixels outside the bounds of the
michael@0 56 + // source surface, so we can just go ahead and use Copy here
michael@0 57 + // to accelerate things.
michael@0 58 + // Quartz won't necessarily be able to do this optimization internally;
michael@0 59 + // for CGLayer surfaces, we can know all the pixels are opaque
michael@0 60 + // (because it's CONTENT_COLOR), but Quartz won't know.
michael@0 61 + CGContextSetCompositeOperation (context, kPrivateCGCompositeCopy);
michael@0 62 + }
michael@0 63 +
michael@0 64 const cairo_surface_pattern_t *spat = (const cairo_surface_pattern_t *) source;
michael@0 65 _cairo_quartz_setup_surface_source (surface, spat, extents, &state);
michael@0 66 return state;
michael@0 67 }
michael@0 68
michael@0 69 state.action = DO_UNSUPPORTED;
michael@0 70 return state;
michael@0 71 }

mercurial