Merge m-c to b2g-inbound.
[gecko.git] / gfx / cairo / quartz-surface-mask-patch
blobd5ee7d8be3ca7d40b17cef45fde24377584c14f7
1 diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c
2 --- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
3 +++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
4 @@ -128,20 +128,22 @@ CG_EXTERN CGImageRef CGBitmapContextCrea
5   */
6  static void (*CGContextClipToMaskPtr) (CGContextRef, CGRect, CGImageRef) = NULL;
7  static void (*CGContextDrawTiledImagePtr) (CGContextRef, CGRect, CGImageRef) = NULL;
8  static unsigned int (*CGContextGetTypePtr) (CGContextRef) = NULL;
9  static void (*CGContextSetShouldAntialiasFontsPtr) (CGContextRef, bool) = NULL;
10  static void (*CGContextSetAllowsFontSmoothingPtr) (CGContextRef, bool) = NULL;
11  static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL;
12  static CGPathRef (*CGContextCopyPathPtr) (CGContextRef) = NULL;
13  static CGFloat (*CGContextGetAlphaPtr) (CGContextRef) = NULL;
15 +static SInt32 _cairo_quartz_osx_version = 0x0;
17  static cairo_bool_t _cairo_quartz_symbol_lookup_done = FALSE;
19  /*
20   * Utility functions
21   */
23  #ifdef QUARTZ_DEBUG
24  static void quartz_surface_to_png (cairo_quartz_surface_t *nq, char *dest);
25  static void quartz_image_to_png (CGImageRef, char *dest);
26  #endif
27 @@ -163,20 +165,25 @@ static void quartz_ensure_symbols(void)
29      CGContextClipToMaskPtr = dlsym(RTLD_DEFAULT, "CGContextClipToMask");
30      CGContextDrawTiledImagePtr = dlsym(RTLD_DEFAULT, "CGContextDrawTiledImage");
31      CGContextGetTypePtr = dlsym(RTLD_DEFAULT, "CGContextGetType");
32      CGContextSetShouldAntialiasFontsPtr = dlsym(RTLD_DEFAULT, "CGContextSetShouldAntialiasFonts");
33      CGContextCopyPathPtr = dlsym(RTLD_DEFAULT, "CGContextCopyPath");
34      CGContextGetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing");
35      CGContextSetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing");
36      CGContextGetAlphaPtr = dlsym(RTLD_DEFAULT, "CGContextGetAlpha");
38 +    if (Gestalt(gestaltSystemVersion, &_cairo_quartz_osx_version) != noErr) {
39 +        // assume 10.5
40 +        _cairo_quartz_osx_version = 0x1050;
41 +    }
43      _cairo_quartz_symbol_lookup_done = TRUE;
44  }
46  CGImageRef
47  _cairo_quartz_create_cgimage (cairo_format_t format,
48                               unsigned int width,
49                               unsigned int height,
50                               unsigned int stride,
51                               void *data,
52                               cairo_bool_t interpolate,
53 @@ -3028,22 +3035,25 @@ static cairo_int_status_t
54         CGContextSetAlpha (surface->cgContext, solid_mask->color.alpha);
55         rv = _cairo_quartz_surface_paint_cg (surface, op, source, clip);
56         CGContextSetAlpha (surface->cgContext, 1.0);
58         return rv;
59      }
61      /* If we have CGContextClipToMask, we can do more complex masks */
62      if (CGContextClipToMaskPtr) {
63         /* For these, we can skip creating a temporary surface, since we already have one */
64 -       if (mask->type == CAIRO_PATTERN_TYPE_SURFACE && mask->extend == CAIRO_EXTEND_NONE)
65 +       /* For some reason this doesn't work reliably on OS X 10.5.  See bug 721663. */
66 +       if (_cairo_quartz_osx_version >= 0x1060 && mask->type == CAIRO_PATTERN_TYPE_SURFACE &&
67 +           mask->extend == CAIRO_EXTEND_NONE) {
68             return _cairo_quartz_surface_mask_with_surface (surface, op, source, (cairo_surface_pattern_t *) mask, clip);
69 +       }
71         return _cairo_quartz_surface_mask_with_generic (surface, op, source, mask, clip);
72      }
74      /* So, CGContextClipToMask is not present in 10.3.9, so we're
75       * doomed; if we have imageData, we can do fallback, otherwise
76       * just pretend success.
77       */
78      if (surface->imageData)
79         return CAIRO_INT_STATUS_UNSUPPORTED;