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