Merge mozilla-central to autoland. CLOSED TREE
[gecko.git] / gfx / cairo / 04-subpixel-aa-api.patch
blobc4763638ebe7522fb5dea66cf2a6d28f7771c3b3
1 diff --git a/gfx/cairo/cairo/src/cairo-compositor-private.h b/gfx/cairo/cairo/src/cairo-compositor-private.h
2 --- a/gfx/cairo/cairo/src/cairo-compositor-private.h
3 +++ b/gfx/cairo/cairo/src/cairo-compositor-private.h
4 @@ -85,7 +85,8 @@ struct cairo_compositor {
5 cairo_scaled_font_t *scaled_font,
6 cairo_glyph_t *glyphs,
7 int num_glyphs,
8 - cairo_bool_t overlap);
9 + cairo_bool_t overlap,
10 + cairo_bool_t permit_subpixel_antialiasing);
13 struct cairo_mask_compositor {
14 diff --git a/gfx/cairo/cairo/src/cairo-compositor.c b/gfx/cairo/cairo/src/cairo-compositor.c
15 --- a/gfx/cairo/cairo/src/cairo-compositor.c
16 +++ b/gfx/cairo/cairo/src/cairo-compositor.c
17 @@ -248,7 +248,8 @@ cairo_int_status_t
18 compositor = compositor->delegate;
20 status = compositor->glyphs (compositor, &extents,
21 - scaled_font, glyphs, num_glyphs, overlap);
22 + scaled_font, glyphs, num_glyphs, overlap,
23 + surface->permit_subpixel_antialiasing);
25 compositor = compositor->delegate;
26 } while (status == CAIRO_INT_STATUS_UNSUPPORTED);
27 diff --git a/gfx/cairo/cairo/src/cairo-no-compositor.c b/gfx/cairo/cairo/src/cairo-no-compositor.c
28 --- a/gfx/cairo/cairo/src/cairo-no-compositor.c
29 +++ b/gfx/cairo/cairo/src/cairo-no-compositor.c
30 @@ -91,7 +91,8 @@ static cairo_int_status_t
31 cairo_scaled_font_t *scaled_font,
32 cairo_glyph_t *glyphs,
33 int num_glyphs,
34 - cairo_bool_t overlap)
35 + cairo_bool_t overlap,
36 + cairo_bool_t permit_subpixel_antialiasing)
38 ASSERT_NOT_REACHED;
39 return CAIRO_INT_STATUS_NOTHING_TO_DO;
40 diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c
41 --- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
42 +++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
43 @@ -1947,7 +1947,8 @@ static cairo_int_status_t
44 cairo_scaled_font_t *scaled_font,
45 cairo_glyph_t *glyphs,
46 int num_glyphs,
47 - cairo_bool_t overlap)
48 + cairo_bool_t overlap,
49 + cairo_bool_t permit_subpixel_antialiasing)
51 CGAffineTransform textTransform, invTextTransform;
52 CGGlyph glyphs_static[CAIRO_STACK_ARRAY_LENGTH (CGSize)];
53 @@ -1963,6 +1964,7 @@ static cairo_int_status_t
54 CGFontRef cgfref = NULL;
56 cairo_bool_t didForceFontSmoothing = FALSE;
57 + cairo_antialias_t effective_antialiasing;
59 if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_QUARTZ)
60 return CAIRO_INT_STATUS_UNSUPPORTED;
61 @@ -1983,7 +1985,12 @@ static cairo_int_status_t
62 CGContextSetFont (state.cgMaskContext, cgfref);
63 CGContextSetFontSize (state.cgMaskContext, 1.0);
65 - switch (scaled_font->options.antialias) {
66 + effective_antialiasing = scaled_font->options.antialias;
67 + if (effective_antialiasing == CAIRO_ANTIALIAS_SUBPIXEL &&
68 + !permit_subpixel_antialiasing) {
69 + effective_antialiasing = CAIRO_ANTIALIAS_GRAY;
70 + }
71 + switch (effective_antialiasing) {
72 case CAIRO_ANTIALIAS_SUBPIXEL:
73 case CAIRO_ANTIALIAS_BEST:
74 CGContextSetShouldAntialias (state.cgMaskContext, TRUE);
75 diff --git a/gfx/cairo/cairo/src/cairo-surface-private.h b/gfx/cairo/cairo/src/cairo-surface-private.h
76 --- a/gfx/cairo/cairo/src/cairo-surface-private.h
77 +++ b/gfx/cairo/cairo/src/cairo-surface-private.h
78 @@ -71,6 +71,7 @@ struct _cairo_surface {
79 unsigned has_font_options : 1;
80 unsigned owns_device : 1;
81 unsigned is_vector : 1;
82 + unsigned permit_subpixel_antialiasing : 1;
84 cairo_user_data_array_t user_data;
85 cairo_user_data_array_t mime_data;
86 diff --git a/gfx/cairo/cairo/src/cairo-surface.c b/gfx/cairo/cairo/src/cairo-surface.c
87 --- a/gfx/cairo/cairo/src/cairo-surface.c
88 +++ b/gfx/cairo/cairo/src/cairo-surface.c
89 @@ -115,6 +115,7 @@ const cairo_surface_t name = { \
90 FALSE, /* has_font_options */ \
91 FALSE, /* owns_device */ \
92 FALSE, /* is_vector */ \
93 + FALSE, /* permit_subpixel_antialiasing */ \
94 { 0, 0, 0, NULL, }, /* user_data */ \
95 { 0, 0, 0, NULL, }, /* mime_data */ \
96 { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, /* device_transform */ \
97 @@ -421,6 +422,7 @@ void
98 surface->serial = 0;
99 surface->damage = NULL;
100 surface->owns_device = (device != NULL);
101 + surface->permit_subpixel_antialiasing = TRUE;
103 _cairo_user_data_array_init (&surface->user_data);
104 _cairo_user_data_array_init (&surface->mime_data);
105 @@ -452,6 +454,8 @@ static void
106 _cairo_surface_set_font_options (surface, &options);
109 + surface->permit_subpixel_antialiasing = other->permit_subpixel_antialiasing;
111 cairo_surface_set_fallback_resolution (surface,
112 other->x_fallback_resolution,
113 other->y_fallback_resolution);
114 @@ -1619,6 +1623,51 @@ cairo_surface_get_font_options (cairo_su
116 slim_hidden_def (cairo_surface_get_font_options);
118 +/**
119 + * cairo_surface_set_subpixel_antialiasing:
120 + * @surface: a #cairo_surface_t
122 + * Sets whether the surface permits subpixel antialiasing. By default,
123 + * surfaces permit subpixel antialiasing.
125 + * Enabling subpixel antialiasing for CONTENT_COLOR_ALPHA surfaces generally
126 + * requires that the pixels in the areas under a subpixel antialiasing
127 + * operation already be opaque.
128 + **/
129 +void
130 +cairo_surface_set_subpixel_antialiasing (cairo_surface_t *surface,
131 + cairo_subpixel_antialiasing_t enabled)
133 + if (surface->status)
134 + return;
136 + if (surface->finished) {
137 + _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED);
138 + return;
141 + surface->permit_subpixel_antialiasing =
142 + enabled == CAIRO_SUBPIXEL_ANTIALIASING_ENABLED;
145 +/**
146 + * cairo_surface_get_subpixel_antialiasing:
147 + * @surface: a #cairo_surface_t
149 + * Gets whether the surface supports subpixel antialiasing. By default,
150 + * CAIRO_CONTENT_COLOR surfaces support subpixel antialiasing but other
151 + * surfaces do not.
152 + **/
153 +cairo_subpixel_antialiasing_t
154 +cairo_surface_get_subpixel_antialiasing (cairo_surface_t *surface)
156 + if (surface->status)
157 + return CAIRO_SUBPIXEL_ANTIALIASING_DISABLED;
159 + return surface->permit_subpixel_antialiasing ?
160 + CAIRO_SUBPIXEL_ANTIALIASING_ENABLED : CAIRO_SUBPIXEL_ANTIALIASING_DISABLED;
163 cairo_status_t
164 _cairo_surface_flush (cairo_surface_t *surface, unsigned flags)
166 diff --git a/gfx/cairo/cairo/src/cairo-xcb-private.h b/gfx/cairo/cairo/src/cairo-xcb-private.h
167 --- a/gfx/cairo/cairo/src/cairo-xcb-private.h
168 +++ b/gfx/cairo/cairo/src/cairo-xcb-private.h
169 @@ -453,7 +453,8 @@ cairo_private cairo_int_status_t
170 cairo_scaled_font_t *scaled_font,
171 cairo_glyph_t *glyphs,
172 int num_glyphs,
173 - cairo_bool_t overlap);
174 + cairo_bool_t overlap,
175 + cairo_bool_t permit_subpixel_antialiasing);
176 cairo_private void
177 _cairo_xcb_surface_scaled_font_fini (cairo_scaled_font_t *scaled_font);
179 diff --git a/gfx/cairo/cairo/src/cairo-xcb-surface-render.c b/gfx/cairo/cairo/src/cairo-xcb-surface-render.c
180 --- a/gfx/cairo/cairo/src/cairo-xcb-surface-render.c
181 +++ b/gfx/cairo/cairo/src/cairo-xcb-surface-render.c
182 @@ -4816,7 +4816,8 @@ cairo_int_status_t
183 cairo_scaled_font_t *scaled_font,
184 cairo_glyph_t *glyphs,
185 int num_glyphs,
186 - cairo_bool_t overlap)
187 + cairo_bool_t overlap,
188 + cairo_bool_t permit_subpixel_antialiasing)
190 cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface;
191 cairo_operator_t op = composite->op;
192 diff --git a/gfx/cairo/cairo/src/cairo-xcb-surface.c b/gfx/cairo/cairo/src/cairo-xcb-surface.c
193 --- a/gfx/cairo/cairo/src/cairo-xcb-surface.c
194 +++ b/gfx/cairo/cairo/src/cairo-xcb-surface.c
195 @@ -912,7 +912,8 @@ static cairo_int_status_t
196 cairo_scaled_font_t *scaled_font,
197 cairo_glyph_t *glyphs,
198 int num_glyphs,
199 - cairo_bool_t overlap)
200 + cairo_bool_t overlap,
201 + cairo_bool_t permit_subpixel_antialiasing)
203 cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface;
204 cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents);
205 diff --git a/gfx/cairo/cairo/src/cairo.h b/gfx/cairo/cairo/src/cairo.h
206 --- a/gfx/cairo/cairo/src/cairo.h
207 +++ b/gfx/cairo/cairo/src/cairo.h
208 @@ -2573,6 +2573,26 @@ cairo_surface_show_page (cairo_surface_t
209 cairo_public cairo_bool_t
210 cairo_surface_has_show_text_glyphs (cairo_surface_t *surface);
212 +/**
213 + * _cairo_subpixel_antialiasing_t:
214 + * @CAIRO_SUBPIXEL_ANTIALIASING_ENABLED: subpixel antialiasing is enabled
215 + * for this surface.
216 + * @CAIRO_SUBPIXEL_ANTIALIASING_DISABLED: subpixel antialiasing is disabled
217 + * for this surface.
218 + */
219 +typedef enum _cairo_subpixel_antialiasing_t {
220 + CAIRO_SUBPIXEL_ANTIALIASING_ENABLED,
221 + CAIRO_SUBPIXEL_ANTIALIASING_DISABLED
222 +} cairo_subpixel_antialiasing_t;
224 +cairo_public void
225 +cairo_surface_set_subpixel_antialiasing (cairo_surface_t *surface,
226 + cairo_subpixel_antialiasing_t enabled);
228 +cairo_public cairo_subpixel_antialiasing_t
229 +cairo_surface_get_subpixel_antialiasing (cairo_surface_t *surface);
232 /* Image-surface functions */
234 cairo_public cairo_surface_t *