Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / cairo / 13-quartz-cglayer-surface.patch
blobf4edc5f36414513d4c3cc5560205a83476e6ec23
1 diff --git a/gfx/cairo/cairo/src/cairo-quartz-private.h b/gfx/cairo/cairo/src/cairo-quartz-private.h
2 --- a/gfx/cairo/cairo/src/cairo-quartz-private.h
3 +++ b/gfx/cairo/cairo/src/cairo-quartz-private.h
4 @@ -55,7 +55,8 @@ typedef enum {
5 DO_DIRECT,
6 DO_SHADING,
7 DO_IMAGE,
8 - DO_TILED_IMAGE
9 + DO_TILED_IMAGE,
10 + DO_LAYER
11 } cairo_quartz_action_t;
13 /* define CTFontRef for pre-10.5 SDKs */
14 @@ -72,6 +73,11 @@ typedef struct cairo_quartz_surface {
16 cairo_surface_clipper_t clipper;
18 + /**
19 + * If non-null, this is the CGLayer for the surface.
20 + */
21 + CGLayerRef cgLayer;
23 cairo_rectangle_int_t extents;
24 cairo_rectangle_int_t virtual_extents;
26 diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c
27 --- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
28 +++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
29 @@ -503,6 +503,7 @@ static CGBlendMode
30 default:
31 ASSERT_NOT_REACHED;
33 + return kCGBlendModeNormal; /* just to silence clang warning [-Wreturn-type] */
36 static cairo_int_status_t
37 @@ -1065,7 +1066,7 @@ typedef struct {
38 /* Destination rect */
39 CGRect rect;
41 - /* Used with DO_SHADING, DO_IMAGE and DO_TILED_IMAGE */
42 + /* Used with DO_SHADING, DO_IMAGE, DO_TILED_IMAGE, DO_LAYER */
43 CGAffineTransform transform;
45 /* Used with DO_IMAGE and DO_TILED_IMAGE */
46 @@ -1077,6 +1078,11 @@ typedef struct {
47 /* Temporary destination for unbounded operations */
48 CGLayerRef layer;
49 CGRect clipRect;
51 + /* Source layer to be rendered when using DO_LAYER.
52 + Unlike 'layer' above, this is not owned by the drawing state
53 + but by the source surface. */
54 + CGLayerRef sourceLayer;
55 } cairo_quartz_drawing_state_t;
58 @@ -1253,7 +1259,9 @@ static cairo_int_status_t
61 if (source->type == CAIRO_PATTERN_TYPE_SURFACE &&
62 - (source->extend == CAIRO_EXTEND_NONE || (CGContextDrawTiledImagePtr && source->extend == CAIRO_EXTEND_REPEAT)))
63 + (source->extend == CAIRO_EXTEND_NONE ||
64 + source->extend == CAIRO_EXTEND_PAD ||
65 + (CGContextDrawTiledImagePtr && source->extend == CAIRO_EXTEND_REPEAT)))
67 const cairo_surface_pattern_t *spat = (const cairo_surface_pattern_t *) source;
68 cairo_surface_t *pat_surf = spat->surface;
69 @@ -1265,6 +1273,20 @@ static cairo_int_status_t
70 cairo_fixed_t fw, fh;
71 cairo_bool_t is_bounded;
73 + /* Draw nonrepeating CGLayer surface using DO_LAYER */
74 + if (source->extend != CAIRO_EXTEND_REPEAT &&
75 + cairo_surface_get_type (pat_surf) == CAIRO_SURFACE_TYPE_QUARTZ) {
76 + cairo_quartz_surface_t *quartz_surf = (cairo_quartz_surface_t *) pat_surf;
77 + if (quartz_surf->cgLayer) {
78 + cairo_matrix_invert(&m);
79 + _cairo_quartz_cairo_matrix_to_quartz (&m, &state->transform);
80 + state->rect = CGRectMake (0, 0, quartz_surf->extents.width, quartz_surf->extents.height);
81 + state->sourceLayer = quartz_surf->cgLayer;
82 + state->action = DO_LAYER;
83 + return CAIRO_STATUS_SUCCESS;
84 + }
85 + }
87 _cairo_surface_get_extents (composite->surface, &extents);
88 status = _cairo_surface_to_cgimage (pat_surf, &extents, format,
89 &m, clip, &img);
90 @@ -1426,7 +1448,14 @@ static void
91 CGContextTranslateCTM (state->cgDrawContext, 0, state->rect.size.height);
92 CGContextScaleCTM (state->cgDrawContext, 1, -1);
94 - if (state->action == DO_IMAGE) {
95 + if (state->action == DO_LAYER) {
96 + /* Note that according to Apple docs it's completely legal to draw a CGLayer
97 + * to any CGContext, even one it wasn't created for.
98 + */
99 + assert (state->sourceLayer);
100 + CGContextDrawLayerAtPoint (state->cgDrawContext, state->rect.origin,
101 + state->sourceLayer);
102 + } else if (state->action == DO_IMAGE) {
103 CGContextDrawImage (state->cgDrawContext, state->rect, state->image);
104 if (op == CAIRO_OPERATOR_SOURCE &&
105 state->cgDrawContext == state->cgMaskContext)
106 @@ -1655,6 +1684,10 @@ static cairo_status_t
108 surface->imageData = NULL;
110 + if (surface->cgLayer) {
111 + CGLayerRelease (surface->cgLayer);
114 return CAIRO_STATUS_SUCCESS;
117 @@ -1693,9 +1726,14 @@ static cairo_surface_t *
118 int width,
119 int height)
121 - cairo_quartz_surface_t *surface, *similar_quartz;
122 + cairo_quartz_surface_t *similar_quartz;
123 cairo_surface_t *similar;
124 cairo_format_t format;
125 + cairo_quartz_surface_t *surface = (cairo_quartz_surface_t *) abstract_surface;
127 + if (surface->cgLayer)
128 + return cairo_quartz_surface_create_cg_layer (abstract_surface, content,
129 + width, height);
131 if (content == CAIRO_CONTENT_COLOR_ALPHA)
132 format = CAIRO_FORMAT_ARGB32;
133 @@ -2068,7 +2106,6 @@ static cairo_int_status_t
134 cairo_quartz_drawing_state_t state;
135 cairo_int_status_t rv = CAIRO_INT_STATUS_UNSUPPORTED;
136 int i;
137 - CGFontRef cgfref = NULL;
139 cairo_bool_t didForceFontSmoothing = FALSE;
140 cairo_antialias_t effective_antialiasing;
141 @@ -2087,10 +2124,12 @@ static cairo_int_status_t
142 CGContextSetTextDrawingMode (state.cgMaskContext, kCGTextClip);
145 - /* this doesn't addref */
146 - cgfref = _cairo_quartz_scaled_font_get_cg_font_ref (scaled_font);
147 - CGContextSetFont (state.cgMaskContext, cgfref);
148 - CGContextSetFontSize (state.cgMaskContext, 1.0);
149 + if (!CTFontDrawGlyphsPtr) {
150 + /* this doesn't addref */
151 + CGFontRef cgfref = _cairo_quartz_scaled_font_get_cg_font_ref (scaled_font);
152 + CGContextSetFont (state.cgMaskContext, cgfref);
153 + CGContextSetFontSize (state.cgMaskContext, 1.0);
156 effective_antialiasing = scaled_font->options.antialias;
157 if (effective_antialiasing == CAIRO_ANTIALIAS_SUBPIXEL &&
158 @@ -2625,6 +2664,79 @@ cairo_quartz_surface_create_for_cg_conte
162 + * cairo_quartz_surface_create_cg_layer
163 + * @surface: The returned surface can be efficiently drawn into this
164 + * destination surface (if tiling is not used)."
165 + * @content: the content type of the surface
166 + * @width: width of the surface, in pixels
167 + * @height: height of the surface, in pixels
169 + * Creates a Quartz surface backed by a CGLayer, if the given surface
170 + * is a Quartz surface; the CGLayer is created to match the surface's
171 + * Quartz context. Otherwise just calls cairo_surface_create_similar.
172 + * The returned surface can be efficiently blitted to the given surface,
173 + * but tiling and 'extend' modes other than NONE are not so efficient.
175 + * Return value: the newly created surface.
177 + * Since: 1.10
178 + **/
179 +cairo_surface_t *
180 +cairo_quartz_surface_create_cg_layer (cairo_surface_t *surface,
181 + cairo_content_t content,
182 + unsigned int width,
183 + unsigned int height)
185 + cairo_quartz_surface_t *surf;
186 + CGLayerRef layer;
187 + CGContextRef ctx;
188 + CGContextRef cgContext;
190 + cgContext = cairo_quartz_surface_get_cg_context (surface);
191 + if (!cgContext)
192 + return cairo_surface_create_similar (surface, content,
193 + width, height);
195 + if (!_cairo_quartz_verify_surface_size(width, height))
196 + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
198 + /* If we pass zero width or height into CGLayerCreateWithContext below,
199 + * it will fail.
200 + */
201 + if (width == 0 || height == 0) {
202 + return (cairo_surface_t*)
203 + _cairo_quartz_surface_create_internal (NULL, content,
204 + width, height);
207 + layer = CGLayerCreateWithContext (cgContext,
208 + CGSizeMake (width, height),
209 + NULL);
210 + if (!layer)
211 + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
213 + ctx = CGLayerGetContext (layer);
214 + /* Flip it when we draw into it, so that when we finally composite it
215 + * to a flipped target, the directions match and Quartz will optimize
216 + * the composition properly
217 + */
218 + CGContextTranslateCTM (ctx, 0, height);
219 + CGContextScaleCTM (ctx, 1, -1);
221 + CGContextRetain (ctx);
222 + surf = _cairo_quartz_surface_create_internal (ctx, content,
223 + width, height);
224 + if (surf->base.status) {
225 + CGLayerRelease (layer);
226 + // create_internal will have set an error
227 + return (cairo_surface_t*) surf;
229 + surf->cgLayer = layer;
231 + return (cairo_surface_t *) surf;
234 +/**
235 * cairo_quartz_surface_create:
236 * @format: format of pixels in the surface to create
237 * @width: width of the surface, in pixels
238 diff --git a/gfx/cairo/cairo/src/cairo-quartz.h b/gfx/cairo/cairo/src/cairo-quartz.h
239 --- a/gfx/cairo/cairo/src/cairo-quartz.h
240 +++ b/gfx/cairo/cairo/src/cairo-quartz.h
241 @@ -61,6 +61,12 @@ cairo_quartz_surface_create_for_data (un
242 unsigned int height,
243 unsigned int stride);
245 +cairo_public cairo_surface_t *
246 +cairo_quartz_surface_create_cg_layer (cairo_surface_t *surface,
247 + cairo_content_t content,
248 + unsigned int width,
249 + unsigned int height);
251 cairo_public CGContextRef
252 cairo_quartz_surface_get_cg_context (cairo_surface_t *surface);