summaryrefslogtreecommitdiffstats
path: root/gfx/cairo/04-subpixel-aa-api.patch
blob: 73e54e341821dc36631e2e38820c36b004642f2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# HG changeset patch
# User Jonathan Kew <jkew@mozilla.com>
# Date 1713886888 -3600
#      Tue Apr 23 16:41:28 2024 +0100
# Node ID 5795122842a66df4f6217e4b5e9aac0e20b4389e
# Parent  a0271c8e8524b6a3a11f76fe5854b402c71926a3
Apply cairo/04-subpixel-aa-api.patch (with modification in cairo-quartz-surface.c)

diff --git a/gfx/cairo/cairo/src/cairo-compositor-private.h b/gfx/cairo/cairo/src/cairo-compositor-private.h
--- a/gfx/cairo/cairo/src/cairo-compositor-private.h
+++ b/gfx/cairo/cairo/src/cairo-compositor-private.h
@@ -85,7 +85,8 @@ struct cairo_compositor {
 				 cairo_scaled_font_t		*scaled_font,
 				 cairo_glyph_t			*glyphs,
 				 int				 num_glyphs,
-				 cairo_bool_t			 overlap);
+				 cairo_bool_t			 overlap,
+				 cairo_bool_t                    permit_subpixel_antialiasing);
 };
 
 struct cairo_mask_compositor {
diff --git a/gfx/cairo/cairo/src/cairo-compositor.c b/gfx/cairo/cairo/src/cairo-compositor.c
--- a/gfx/cairo/cairo/src/cairo-compositor.c
+++ b/gfx/cairo/cairo/src/cairo-compositor.c
@@ -290,7 +290,8 @@ cairo_int_status_t
 	    compositor = compositor->delegate;
 
 	status = compositor->glyphs (compositor, &extents,
-				     scaled_font, glyphs, num_glyphs, overlap);
+				     scaled_font, glyphs, num_glyphs, overlap,
+				     surface->permit_subpixel_antialiasing);
 
 	compositor = compositor->delegate;
     } while (status == CAIRO_INT_STATUS_UNSUPPORTED);
diff --git a/gfx/cairo/cairo/src/cairo-no-compositor.c b/gfx/cairo/cairo/src/cairo-no-compositor.c
--- a/gfx/cairo/cairo/src/cairo-no-compositor.c
+++ b/gfx/cairo/cairo/src/cairo-no-compositor.c
@@ -91,7 +91,8 @@ static cairo_int_status_t
 			     cairo_scaled_font_t	*scaled_font,
 			     cairo_glyph_t		*glyphs,
 			     int			 num_glyphs,
-			     cairo_bool_t overlap)
+			     cairo_bool_t overlap,
+			     cairo_bool_t permit_subpixel_antialiasing)
 {
     ASSERT_NOT_REACHED;
     return CAIRO_INT_STATUS_NOTHING_TO_DO;
diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c
--- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
+++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
@@ -1871,7 +1871,8 @@ static cairo_int_status_t
 			 cairo_scaled_font_t *scaled_font,
 			 cairo_glyph_t *glyphs,
 			 int num_glyphs,
-			 cairo_bool_t overlap)
+			 cairo_bool_t overlap,
+			 cairo_bool_t permit_subpixel_antialiasing)
 {
     CGAffineTransform textTransform, invTextTransform;
     CGGlyph glyphs_static[CAIRO_STACK_ARRAY_LENGTH (CGPoint)];
@@ -1885,6 +1886,7 @@ static cairo_int_status_t
     CTFontRef ctFont = NULL;
 
     cairo_bool_t didForceFontSmoothing = FALSE;
+    cairo_antialias_t effective_antialiasing;
 
     if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_QUARTZ)
 	return CAIRO_INT_STATUS_UNSUPPORTED;
@@ -1904,6 +1906,14 @@ static cairo_int_status_t
     ctFont = _cairo_quartz_scaled_font_get_ct_font (scaled_font);
     _cairo_quartz_set_antialiasing (state.cgMaskContext, scaled_font->options.antialias);
 
+    effective_antialiasing = scaled_font->options.antialias;
+    if (effective_antialiasing == CAIRO_ANTIALIAS_SUBPIXEL &&
+        !permit_subpixel_antialiasing) {
+        effective_antialiasing = CAIRO_ANTIALIAS_GRAY;
+    }
+
+    _cairo_quartz_set_antialiasing (state.cgMaskContext, effective_antialiasing);
+
     if (num_glyphs > ARRAY_LENGTH (glyphs_static)) {
 	cg_glyphs = (CGGlyph*) _cairo_malloc_ab (num_glyphs, sizeof (CGGlyph) + sizeof (CGPoint));
 	if (unlikely (cg_glyphs == NULL)) {
diff --git a/gfx/cairo/cairo/src/cairo-surface-private.h b/gfx/cairo/cairo/src/cairo-surface-private.h
--- a/gfx/cairo/cairo/src/cairo-surface-private.h
+++ b/gfx/cairo/cairo/src/cairo-surface-private.h
@@ -71,6 +71,7 @@ struct _cairo_surface {
     unsigned has_font_options : 1;
     unsigned owns_device : 1;
     unsigned is_vector : 1;
+    unsigned permit_subpixel_antialiasing : 1;
 
     cairo_user_data_array_t user_data;
     cairo_user_data_array_t mime_data;
diff --git a/gfx/cairo/cairo/src/cairo-surface.c b/gfx/cairo/cairo/src/cairo-surface.c
--- a/gfx/cairo/cairo/src/cairo-surface.c
+++ b/gfx/cairo/cairo/src/cairo-surface.c
@@ -114,6 +114,7 @@ const cairo_surface_t name = {					\
     FALSE,				/* has_font_options */	\
     FALSE,				/* owns_device */ \
     FALSE,                              /* is_vector */ \
+    FALSE,                              /* permit_subpixel_antialiasing */ \
     { 0, 0, 0, NULL, },			/* user_data */		\
     { 0, 0, 0, NULL, },			/* mime_data */         \
     { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 },   /* device_transform */	\
@@ -426,6 +427,7 @@ void
     surface->serial = 0;
     surface->damage = NULL;
     surface->owns_device = (device != NULL);
+    surface->permit_subpixel_antialiasing = TRUE;
 
     _cairo_user_data_array_init (&surface->user_data);
     _cairo_user_data_array_init (&surface->mime_data);
@@ -461,6 +463,8 @@ static void
 	_cairo_font_options_fini (&options);
     }
 
+    surface->permit_subpixel_antialiasing = other->permit_subpixel_antialiasing;
+
     cairo_surface_set_fallback_resolution (surface,
 					   other->x_fallback_resolution,
 					   other->y_fallback_resolution);
@@ -1626,6 +1630,51 @@ cairo_surface_get_font_options (cairo_su
     _cairo_font_options_init_copy (options, &surface->font_options);
 }
 
+/**
+ * cairo_surface_set_subpixel_antialiasing:
+ * @surface: a #cairo_surface_t
+ *
+ * Sets whether the surface permits subpixel antialiasing. By default,
+ * surfaces permit subpixel antialiasing.
+ *
+ * Enabling subpixel antialiasing for CONTENT_COLOR_ALPHA surfaces generally
+ * requires that the pixels in the areas under a subpixel antialiasing
+ * operation already be opaque.
+ **/
+void
+cairo_surface_set_subpixel_antialiasing (cairo_surface_t *surface,
+                                         cairo_subpixel_antialiasing_t enabled)
+{
+    if (surface->status)
+        return;
+
+    if (surface->finished) {
+        _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED);
+        return;
+    }
+
+    surface->permit_subpixel_antialiasing =
+        enabled == CAIRO_SUBPIXEL_ANTIALIASING_ENABLED;
+}
+
+/**
+ * cairo_surface_get_subpixel_antialiasing:
+ * @surface: a #cairo_surface_t
+ *
+ * Gets whether the surface supports subpixel antialiasing. By default,
+ * CAIRO_CONTENT_COLOR surfaces support subpixel antialiasing but other
+ * surfaces do not.
+ **/
+cairo_subpixel_antialiasing_t
+cairo_surface_get_subpixel_antialiasing (cairo_surface_t *surface)
+{
+    if (surface->status)
+        return CAIRO_SUBPIXEL_ANTIALIASING_DISABLED;
+
+    return surface->permit_subpixel_antialiasing ?
+        CAIRO_SUBPIXEL_ANTIALIASING_ENABLED : CAIRO_SUBPIXEL_ANTIALIASING_DISABLED;
+}
+
 cairo_status_t
 _cairo_surface_flush (cairo_surface_t *surface, unsigned flags)
 {
diff --git a/gfx/cairo/cairo/src/cairo-xcb-private.h b/gfx/cairo/cairo/src/cairo-xcb-private.h
--- a/gfx/cairo/cairo/src/cairo-xcb-private.h
+++ b/gfx/cairo/cairo/src/cairo-xcb-private.h
@@ -443,7 +443,8 @@ cairo_private cairo_int_status_t
 				     cairo_scaled_font_t          *scaled_font,
 				     cairo_glyph_t                *glyphs,
 				     int                           num_glyphs,
-				     cairo_bool_t                  overlap);
+				     cairo_bool_t                  overlap,
+				     cairo_bool_t                  permit_subpixel_antialiasing);
 cairo_private void
 _cairo_xcb_surface_scaled_font_fini (cairo_scaled_font_t *scaled_font);
 
diff --git a/gfx/cairo/cairo/src/cairo-xcb-surface-render.c b/gfx/cairo/cairo/src/cairo-xcb-surface-render.c
--- a/gfx/cairo/cairo/src/cairo-xcb-surface-render.c
+++ b/gfx/cairo/cairo/src/cairo-xcb-surface-render.c
@@ -4814,7 +4814,8 @@ cairo_int_status_t
 				     cairo_scaled_font_t          *scaled_font,
 				     cairo_glyph_t                *glyphs,
 				     int                           num_glyphs,
-				     cairo_bool_t                  overlap)
+				     cairo_bool_t                  overlap,
+				     cairo_bool_t                  permit_subpixel_antialiasing)
 {
     cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) composite->surface;
     cairo_operator_t op = composite->op;
diff --git a/gfx/cairo/cairo/src/cairo-xcb-surface.c b/gfx/cairo/cairo/src/cairo-xcb-surface.c
--- a/gfx/cairo/cairo/src/cairo-xcb-surface.c
+++ b/gfx/cairo/cairo/src/cairo-xcb-surface.c
@@ -906,7 +906,8 @@ static cairo_int_status_t
 				       cairo_scaled_font_t          *scaled_font,
 				       cairo_glyph_t                *glyphs,
 				       int                           num_glyphs,
-				       cairo_bool_t                  overlap)
+				       cairo_bool_t                  overlap,
+				       cairo_bool_t                  permit_subpixel_antialiasing)
 {
     cairo_xcb_surface_t *surface = (cairo_xcb_surface_t *) extents->surface;
     cairo_surface_t *fallback = _cairo_xcb_surface_fallback (surface, extents);
diff --git a/gfx/cairo/cairo/src/cairo.h b/gfx/cairo/cairo/src/cairo.h
--- a/gfx/cairo/cairo/src/cairo.h
+++ b/gfx/cairo/cairo/src/cairo.h
@@ -2737,6 +2737,26 @@ cairo_surface_show_page (cairo_surface_t
 cairo_public cairo_bool_t
 cairo_surface_has_show_text_glyphs (cairo_surface_t *surface);
 
+/**
+ * _cairo_subpixel_antialiasing_t:
+ * @CAIRO_SUBPIXEL_ANTIALIASING_ENABLED: subpixel antialiasing is enabled
+ * for this surface.
+ * @CAIRO_SUBPIXEL_ANTIALIASING_DISABLED: subpixel antialiasing is disabled
+ * for this surface.
+ */
+typedef enum _cairo_subpixel_antialiasing_t {
+    CAIRO_SUBPIXEL_ANTIALIASING_ENABLED,
+    CAIRO_SUBPIXEL_ANTIALIASING_DISABLED
+} cairo_subpixel_antialiasing_t;
+
+cairo_public void
+cairo_surface_set_subpixel_antialiasing (cairo_surface_t *surface,
+                                         cairo_subpixel_antialiasing_t enabled);
+
+cairo_public cairo_subpixel_antialiasing_t
+cairo_surface_get_subpixel_antialiasing (cairo_surface_t *surface);
+
+
 /* Image-surface functions */
 
 cairo_public cairo_surface_t *