Backed out changeset 5c8bf24bb247 (bug 1923942) for causing generate failures. CLOSED...
[gecko.git] / gfx / cairo / 04-subpixel-aa-api.patch
blob73e54e341821dc36631e2e38820c36b004642f2c
1 # HG changeset patch
2 # User Jonathan Kew <jkew@mozilla.com>
3 # Date 1713886888 -3600
4 # Tue Apr 23 16:41:28 2024 +0100
5 # Node ID 5795122842a66df4f6217e4b5e9aac0e20b4389e
6 # Parent a0271c8e8524b6a3a11f76fe5854b402c71926a3
7 Apply cairo/04-subpixel-aa-api.patch (with modification in cairo-quartz-surface.c)
9 diff --git a/gfx/cairo/cairo/src/cairo-compositor-private.h b/gfx/cairo/cairo/src/cairo-compositor-private.h
10 --- a/gfx/cairo/cairo/src/cairo-compositor-private.h
11 +++ b/gfx/cairo/cairo/src/cairo-compositor-private.h
12 @@ -85,7 +85,8 @@ struct cairo_compositor {
13 cairo_scaled_font_t *scaled_font,
14 cairo_glyph_t *glyphs,
15 int num_glyphs,
16 - cairo_bool_t overlap);
17 + cairo_bool_t overlap,
18 + cairo_bool_t permit_subpixel_antialiasing);
21 struct cairo_mask_compositor {
22 diff --git a/gfx/cairo/cairo/src/cairo-compositor.c b/gfx/cairo/cairo/src/cairo-compositor.c
23 --- a/gfx/cairo/cairo/src/cairo-compositor.c
24 +++ b/gfx/cairo/cairo/src/cairo-compositor.c
25 @@ -290,7 +290,8 @@ cairo_int_status_t
26 compositor = compositor->delegate;
28 status = compositor->glyphs (compositor, &extents,
29 - scaled_font, glyphs, num_glyphs, overlap);
30 + scaled_font, glyphs, num_glyphs, overlap,
31 + surface->permit_subpixel_antialiasing);
33 compositor = compositor->delegate;
34 } while (status == CAIRO_INT_STATUS_UNSUPPORTED);
35 diff --git a/gfx/cairo/cairo/src/cairo-no-compositor.c b/gfx/cairo/cairo/src/cairo-no-compositor.c
36 --- a/gfx/cairo/cairo/src/cairo-no-compositor.c
37 +++ b/gfx/cairo/cairo/src/cairo-no-compositor.c
38 @@ -91,7 +91,8 @@ static cairo_int_status_t
39 cairo_scaled_font_t *scaled_font,
40 cairo_glyph_t *glyphs,
41 int num_glyphs,
42 - cairo_bool_t overlap)
43 + cairo_bool_t overlap,
44 + cairo_bool_t permit_subpixel_antialiasing)
46 ASSERT_NOT_REACHED;
47 return CAIRO_INT_STATUS_NOTHING_TO_DO;
48 diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c
49 --- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
50 +++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
51 @@ -1871,7 +1871,8 @@ static cairo_int_status_t
52 cairo_scaled_font_t *scaled_font,
53 cairo_glyph_t *glyphs,
54 int num_glyphs,
55 - cairo_bool_t overlap)
56 + cairo_bool_t overlap,
57 + cairo_bool_t permit_subpixel_antialiasing)
59 CGAffineTransform textTransform, invTextTransform;
60 CGGlyph glyphs_static[CAIRO_STACK_ARRAY_LENGTH (CGPoint)];
61 @@ -1885,6 +1886,7 @@ static cairo_int_status_t
62 CTFontRef ctFont = NULL;
64 cairo_bool_t didForceFontSmoothing = FALSE;
65 + cairo_antialias_t effective_antialiasing;
67 if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_QUARTZ)
68 return CAIRO_INT_STATUS_UNSUPPORTED;
69 @@ -1904,6 +1906,14 @@ static cairo_int_status_t
70 ctFont = _cairo_quartz_scaled_font_get_ct_font (scaled_font);
71 _cairo_quartz_set_antialiasing (state.cgMaskContext, scaled_font->options.antialias);
73 + effective_antialiasing = scaled_font->options.antialias;
74 + if (effective_antialiasing == CAIRO_ANTIALIAS_SUBPIXEL &&
75 + !permit_subpixel_antialiasing) {
76 + effective_antialiasing = CAIRO_ANTIALIAS_GRAY;
77 + }
79 + _cairo_quartz_set_antialiasing (state.cgMaskContext, effective_antialiasing);
81 if (num_glyphs > ARRAY_LENGTH (glyphs_static)) {
82 cg_glyphs = (CGGlyph*) _cairo_malloc_ab (num_glyphs, sizeof (CGGlyph) + sizeof (CGPoint));
83 if (unlikely (cg_glyphs == NULL)) {
84 diff --git a/gfx/cairo/cairo/src/cairo-surface-private.h b/gfx/cairo/cairo/src/cairo-surface-private.h
85 --- a/gfx/cairo/cairo/src/cairo-surface-private.h
86 +++ b/gfx/cairo/cairo/src/cairo-surface-private.h
87 @@ -71,6 +71,7 @@ struct _cairo_surface {
88 unsigned has_font_options : 1;
89 unsigned owns_device : 1;
90 unsigned is_vector : 1;
91 + unsigned permit_subpixel_antialiasing : 1;
93 cairo_user_data_array_t user_data;
94 cairo_user_data_array_t mime_data;
95 diff --git a/gfx/cairo/cairo/src/cairo-surface.c b/gfx/cairo/cairo/src/cairo-surface.c
96 --- a/gfx/cairo/cairo/src/cairo-surface.c
97 +++ b/gfx/cairo/cairo/src/cairo-surface.c
98 @@ -114,6 +114,7 @@ const cairo_surface_t name = { \
99 FALSE, /* has_font_options */ \
100 FALSE, /* owns_device */ \
101 FALSE, /* is_vector */ \
102 + FALSE, /* permit_subpixel_antialiasing */ \
103 { 0, 0, 0, NULL, }, /* user_data */ \
104 { 0, 0, 0, NULL, }, /* mime_data */ \
105 { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, /* device_transform */ \
106 @@ -426,6 +427,7 @@ void
107 surface->serial = 0;
108 surface->damage = NULL;
109 surface->owns_device = (device != NULL);
110 + surface->permit_subpixel_antialiasing = TRUE;
112 _cairo_user_data_array_init (&surface->user_data);
113 _cairo_user_data_array_init (&surface->mime_data);
114 @@ -461,6 +463,8 @@ static void
115 _cairo_font_options_fini (&options);
118 + surface->permit_subpixel_antialiasing = other->permit_subpixel_antialiasing;
120 cairo_surface_set_fallback_resolution (surface,
121 other->x_fallback_resolution,
122 other->y_fallback_resolution);
123 @@ -1626,6 +1630,51 @@ cairo_surface_get_font_options (cairo_su
124 _cairo_font_options_init_copy (options, &surface->font_options);
127 +/**
128 + * cairo_surface_set_subpixel_antialiasing:
129 + * @surface: a #cairo_surface_t
131 + * Sets whether the surface permits subpixel antialiasing. By default,
132 + * surfaces permit subpixel antialiasing.
134 + * Enabling subpixel antialiasing for CONTENT_COLOR_ALPHA surfaces generally
135 + * requires that the pixels in the areas under a subpixel antialiasing
136 + * operation already be opaque.
137 + **/
138 +void
139 +cairo_surface_set_subpixel_antialiasing (cairo_surface_t *surface,
140 + cairo_subpixel_antialiasing_t enabled)
142 + if (surface->status)
143 + return;
145 + if (surface->finished) {
146 + _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED);
147 + return;
150 + surface->permit_subpixel_antialiasing =
151 + enabled == CAIRO_SUBPIXEL_ANTIALIASING_ENABLED;
154 +/**
155 + * cairo_surface_get_subpixel_antialiasing:
156 + * @surface: a #cairo_surface_t
158 + * Gets whether the surface supports subpixel antialiasing. By default,
159 + * CAIRO_CONTENT_COLOR surfaces support subpixel antialiasing but other
160 + * surfaces do not.
161 + **/
162 +cairo_subpixel_antialiasing_t
163 +cairo_surface_get_subpixel_antialiasing (cairo_surface_t *surface)
165 + if (surface->status)
166 + return CAIRO_SUBPIXEL_ANTIALIASING_DISABLED;
168 + return surface->permit_subpixel_antialiasing ?
169 + CAIRO_SUBPIXEL_ANTIALIASING_ENABLED : CAIRO_SUBPIXEL_ANTIALIASING_DISABLED;
172 cairo_status_t
173 _cairo_surface_flush (cairo_surface_t *surface, unsigned flags)
175 diff --git a/gfx/cairo/cairo/src/cairo-xcb-private.h b/gfx/cairo/cairo/src/cairo-xcb-private.h
176 --- a/gfx/cairo/cairo/src/cairo-xcb-private.h
177 +++ b/gfx/cairo/cairo/src/cairo-xcb-private.h
178 @@ -443,7 +443,8 @@ cairo_private cairo_int_status_t
179 cairo_scaled_font_t *scaled_font,
180 cairo_glyph_t *glyphs,
181 int num_glyphs,
182 - cairo_bool_t overlap);
183 + cairo_bool_t overlap,
184 + cairo_bool_t permit_subpixel_antialiasing);
185 cairo_private void
186 _cairo_xcb_surface_scaled_font_fini (cairo_scaled_font_t *scaled_font);
188 diff --git a/gfx/cairo/cairo/src/cairo-xcb-surface-render.c b/gfx/cairo/cairo/src/cairo-xcb-surface-render.c
189 --- a/gfx/cairo/cairo/src/cairo-xcb-surface-render.c
190 +++ b/gfx/cairo/cairo/src/cairo-xcb-surface-render.c
191 @@ -4814,7 +4814,8 @@ cairo_int_status_t
192 cairo_scaled_font_t *scaled_font,
193 cairo_glyph_t *glyphs,
194 int num_glyphs,
195 - cairo_bool_t overlap)
196 + cairo_bool_t overlap,
197 + cairo_bool_t permit_subpixel_antialiasing)
199 cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface;
200 cairo_operator_t op = composite->op;
201 diff --git a/gfx/cairo/cairo/src/cairo-xcb-surface.c b/gfx/cairo/cairo/src/cairo-xcb-surface.c
202 --- a/gfx/cairo/cairo/src/cairo-xcb-surface.c
203 +++ b/gfx/cairo/cairo/src/cairo-xcb-surface.c
204 @@ -906,7 +906,8 @@ static cairo_int_status_t
205 cairo_scaled_font_t *scaled_font,
206 cairo_glyph_t *glyphs,
207 int num_glyphs,
208 - cairo_bool_t overlap)
209 + cairo_bool_t overlap,
210 + cairo_bool_t permit_subpixel_antialiasing)
212 cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface;
213 cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents);
214 diff --git a/gfx/cairo/cairo/src/cairo.h b/gfx/cairo/cairo/src/cairo.h
215 --- a/gfx/cairo/cairo/src/cairo.h
216 +++ b/gfx/cairo/cairo/src/cairo.h
217 @@ -2737,6 +2737,26 @@ cairo_surface_show_page (cairo_surface_t
218 cairo_public cairo_bool_t
219 cairo_surface_has_show_text_glyphs (cairo_surface_t *surface);
221 +/**
222 + * _cairo_subpixel_antialiasing_t:
223 + * @CAIRO_SUBPIXEL_ANTIALIASING_ENABLED: subpixel antialiasing is enabled
224 + * for this surface.
225 + * @CAIRO_SUBPIXEL_ANTIALIASING_DISABLED: subpixel antialiasing is disabled
226 + * for this surface.
227 + */
228 +typedef enum _cairo_subpixel_antialiasing_t {
229 + CAIRO_SUBPIXEL_ANTIALIASING_ENABLED,
230 + CAIRO_SUBPIXEL_ANTIALIASING_DISABLED
231 +} cairo_subpixel_antialiasing_t;
233 +cairo_public void
234 +cairo_surface_set_subpixel_antialiasing (cairo_surface_t *surface,
235 + cairo_subpixel_antialiasing_t enabled);
237 +cairo_public cairo_subpixel_antialiasing_t
238 +cairo_surface_get_subpixel_antialiasing (cairo_surface_t *surface);
241 /* Image-surface functions */
243 cairo_public cairo_surface_t *