Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | # HG changeset patch |
michael@0 | 2 | # User Robert O'Callahan <robert@ocallahan.org> |
michael@0 | 3 | # Date 1294019288 -46800 |
michael@0 | 4 | # Node ID 8857392e37aea7475ed6d8ee4b45023e1233bcec |
michael@0 | 5 | # Parent c53f60831c43cca397dfed8adf8d350aeec7d3ca |
michael@0 | 6 | Bug 363861. Part 2: Introduce cairo_surface_get/set_subpixel_antialiasing. r=jrmuizel,sr=vlad,a=blocking |
michael@0 | 7 | |
michael@0 | 8 | diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c |
michael@0 | 9 | --- a/gfx/cairo/cairo/src/cairo-quartz-surface.c |
michael@0 | 10 | +++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c |
michael@0 | 11 | @@ -2473,16 +2473,17 @@ _cairo_quartz_surface_show_glyphs (void |
michael@0 | 12 | cairo_int_status_t rv = CAIRO_STATUS_SUCCESS; |
michael@0 | 13 | cairo_quartz_drawing_state_t state; |
michael@0 | 14 | float xprev, yprev; |
michael@0 | 15 | int i; |
michael@0 | 16 | CGFontRef cgfref = NULL; |
michael@0 | 17 | |
michael@0 | 18 | cairo_bool_t isClipping = FALSE; |
michael@0 | 19 | cairo_bool_t didForceFontSmoothing = FALSE; |
michael@0 | 20 | + cairo_antialias_t effective_antialiasing; |
michael@0 | 21 | |
michael@0 | 22 | if (IS_EMPTY(surface)) |
michael@0 | 23 | return CAIRO_STATUS_SUCCESS; |
michael@0 | 24 | |
michael@0 | 25 | if (num_glyphs <= 0) |
michael@0 | 26 | return CAIRO_STATUS_SUCCESS; |
michael@0 | 27 | |
michael@0 | 28 | if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_QUARTZ) |
michael@0 | 29 | @@ -2514,16 +2515,22 @@ _cairo_quartz_surface_show_glyphs (void |
michael@0 | 30 | goto BAIL; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | /* this doesn't addref */ |
michael@0 | 34 | cgfref = _cairo_quartz_scaled_font_get_cg_font_ref (scaled_font); |
michael@0 | 35 | CGContextSetFont (state.context, cgfref); |
michael@0 | 36 | CGContextSetFontSize (state.context, 1.0); |
michael@0 | 37 | |
michael@0 | 38 | + effective_antialiasing = scaled_font->options.antialias; |
michael@0 | 39 | + if (effective_antialiasing == CAIRO_ANTIALIAS_SUBPIXEL && |
michael@0 | 40 | + !surface->base.permit_subpixel_antialiasing) { |
michael@0 | 41 | + effective_antialiasing = CAIRO_ANTIALIAS_GRAY; |
michael@0 | 42 | + } |
michael@0 | 43 | + |
michael@0 | 44 | switch (scaled_font->options.antialias) { |
michael@0 | 45 | case CAIRO_ANTIALIAS_SUBPIXEL: |
michael@0 | 46 | CGContextSetShouldAntialias (state.context, TRUE); |
michael@0 | 47 | CGContextSetShouldSmoothFonts (state.context, TRUE); |
michael@0 | 48 | if (CGContextSetAllowsFontSmoothingPtr && |
michael@0 | 49 | !CGContextGetAllowsFontSmoothingPtr (state.context)) |
michael@0 | 50 | { |
michael@0 | 51 | didForceFontSmoothing = TRUE; |
michael@0 | 52 | diff --git a/gfx/cairo/cairo/src/cairo-surface-private.h b/gfx/cairo/cairo/src/cairo-surface-private.h |
michael@0 | 53 | --- a/gfx/cairo/cairo/src/cairo-surface-private.h |
michael@0 | 54 | +++ b/gfx/cairo/cairo/src/cairo-surface-private.h |
michael@0 | 55 | @@ -58,16 +58,17 @@ struct _cairo_surface { |
michael@0 | 56 | |
michael@0 | 57 | cairo_reference_count_t ref_count; |
michael@0 | 58 | cairo_status_t status; |
michael@0 | 59 | unsigned int unique_id; |
michael@0 | 60 | |
michael@0 | 61 | unsigned finished : 1; |
michael@0 | 62 | unsigned is_clear : 1; |
michael@0 | 63 | unsigned has_font_options : 1; |
michael@0 | 64 | + unsigned permit_subpixel_antialiasing : 1; |
michael@0 | 65 | |
michael@0 | 66 | cairo_user_data_array_t user_data; |
michael@0 | 67 | cairo_user_data_array_t mime_data; |
michael@0 | 68 | |
michael@0 | 69 | cairo_matrix_t device_transform; |
michael@0 | 70 | cairo_matrix_t device_transform_inverse; |
michael@0 | 71 | |
michael@0 | 72 | /* The actual resolution of the device, in dots per inch. */ |
michael@0 | 73 | diff --git a/gfx/cairo/cairo/src/cairo-surface.c b/gfx/cairo/cairo/src/cairo-surface.c |
michael@0 | 74 | --- a/gfx/cairo/cairo/src/cairo-surface.c |
michael@0 | 75 | +++ b/gfx/cairo/cairo/src/cairo-surface.c |
michael@0 | 76 | @@ -49,17 +49,18 @@ const cairo_surface_t name = { \ |
michael@0 | 77 | NULL, /* backend */ \ |
michael@0 | 78 | CAIRO_SURFACE_TYPE_IMAGE, /* type */ \ |
michael@0 | 79 | CAIRO_CONTENT_COLOR, /* content */ \ |
michael@0 | 80 | CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ \ |
michael@0 | 81 | status, /* status */ \ |
michael@0 | 82 | 0, /* unique id */ \ |
michael@0 | 83 | FALSE, /* finished */ \ |
michael@0 | 84 | TRUE, /* is_clear */ \ |
michael@0 | 85 | - FALSE, /* has_font_options */ \ |
michael@0 | 86 | + FALSE, /* has_font_options */ \ |
michael@0 | 87 | + FALSE, /* permit_subpixel_antialiasing */ \ |
michael@0 | 88 | { 0, 0, 0, NULL, }, /* user_data */ \ |
michael@0 | 89 | { 0, 0, 0, NULL, }, /* mime_data */ \ |
michael@0 | 90 | { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, /* device_transform */ \ |
michael@0 | 91 | { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, /* device_transform_inverse */ \ |
michael@0 | 92 | 0.0, /* x_resolution */ \ |
michael@0 | 93 | 0.0, /* y_resolution */ \ |
michael@0 | 94 | 0.0, /* x_fallback_resolution */ \ |
michael@0 | 95 | 0.0, /* y_fallback_resolution */ \ |
michael@0 | 96 | @@ -342,46 +343,48 @@ _cairo_surface_init (cairo_surface_t * |
michael@0 | 97 | surface->content = content; |
michael@0 | 98 | surface->type = backend->type; |
michael@0 | 99 | |
michael@0 | 100 | CAIRO_REFERENCE_COUNT_INIT (&surface->ref_count, 1); |
michael@0 | 101 | surface->status = CAIRO_STATUS_SUCCESS; |
michael@0 | 102 | surface->unique_id = _cairo_surface_allocate_unique_id (); |
michael@0 | 103 | surface->finished = FALSE; |
michael@0 | 104 | surface->is_clear = FALSE; |
michael@0 | 105 | + surface->has_font_options = FALSE; |
michael@0 | 106 | + surface->permit_subpixel_antialiasing = TRUE; |
michael@0 | 107 | |
michael@0 | 108 | _cairo_user_data_array_init (&surface->user_data); |
michael@0 | 109 | _cairo_user_data_array_init (&surface->mime_data); |
michael@0 | 110 | |
michael@0 | 111 | cairo_matrix_init_identity (&surface->device_transform); |
michael@0 | 112 | cairo_matrix_init_identity (&surface->device_transform_inverse); |
michael@0 | 113 | |
michael@0 | 114 | surface->x_resolution = CAIRO_SURFACE_RESOLUTION_DEFAULT; |
michael@0 | 115 | surface->y_resolution = CAIRO_SURFACE_RESOLUTION_DEFAULT; |
michael@0 | 116 | |
michael@0 | 117 | surface->x_fallback_resolution = CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT; |
michael@0 | 118 | surface->y_fallback_resolution = CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT; |
michael@0 | 119 | |
michael@0 | 120 | _cairo_array_init (&surface->snapshots, sizeof (cairo_surface_t *)); |
michael@0 | 121 | surface->snapshot_of = NULL; |
michael@0 | 122 | - |
michael@0 | 123 | - surface->has_font_options = FALSE; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | static void |
michael@0 | 127 | _cairo_surface_copy_similar_properties (cairo_surface_t *surface, |
michael@0 | 128 | cairo_surface_t *other) |
michael@0 | 129 | { |
michael@0 | 130 | if (other->has_font_options || other->backend != surface->backend) { |
michael@0 | 131 | cairo_font_options_t options; |
michael@0 | 132 | |
michael@0 | 133 | cairo_surface_get_font_options (other, &options); |
michael@0 | 134 | _cairo_surface_set_font_options (surface, &options); |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | + surface->permit_subpixel_antialiasing = other->permit_subpixel_antialiasing; |
michael@0 | 138 | + |
michael@0 | 139 | cairo_surface_set_fallback_resolution (surface, |
michael@0 | 140 | other->x_fallback_resolution, |
michael@0 | 141 | other->y_fallback_resolution); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | cairo_surface_t * |
michael@0 | 145 | _cairo_surface_create_similar_scratch (cairo_surface_t *other, |
michael@0 | 146 | cairo_content_t content, |
michael@0 | 147 | @@ -2482,16 +2485,67 @@ cairo_surface_has_show_text_glyphs (cair |
michael@0 | 148 | |
michael@0 | 149 | if (surface->backend->has_show_text_glyphs) |
michael@0 | 150 | return surface->backend->has_show_text_glyphs (surface); |
michael@0 | 151 | else |
michael@0 | 152 | return surface->backend->show_text_glyphs != NULL; |
michael@0 | 153 | } |
michael@0 | 154 | slim_hidden_def (cairo_surface_has_show_text_glyphs); |
michael@0 | 155 | |
michael@0 | 156 | +/** |
michael@0 | 157 | + * cairo_surface_set_subpixel_antialiasing: |
michael@0 | 158 | + * @surface: a #cairo_surface_t |
michael@0 | 159 | + * |
michael@0 | 160 | + * Sets whether the surface permits subpixel antialiasing. By default, |
michael@0 | 161 | + * surfaces permit subpixel antialiasing. |
michael@0 | 162 | + * |
michael@0 | 163 | + * Enabling subpixel antialiasing for CONTENT_COLOR_ALPHA surfaces generally |
michael@0 | 164 | + * requires that the pixels in the areas under a subpixel antialiasing |
michael@0 | 165 | + * operation already be opaque. |
michael@0 | 166 | + * |
michael@0 | 167 | + * Since: 1.12 |
michael@0 | 168 | + **/ |
michael@0 | 169 | +void |
michael@0 | 170 | +cairo_surface_set_subpixel_antialiasing (cairo_surface_t *surface, |
michael@0 | 171 | + cairo_subpixel_antialiasing_t enabled) |
michael@0 | 172 | +{ |
michael@0 | 173 | + if (surface->status) |
michael@0 | 174 | + return; |
michael@0 | 175 | + |
michael@0 | 176 | + if (surface->finished) { |
michael@0 | 177 | + _cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_FINISHED); |
michael@0 | 178 | + return; |
michael@0 | 179 | + } |
michael@0 | 180 | + |
michael@0 | 181 | + surface->permit_subpixel_antialiasing = |
michael@0 | 182 | + enabled == CAIRO_SUBPIXEL_ANTIALIASING_ENABLED; |
michael@0 | 183 | +} |
michael@0 | 184 | +slim_hidden_def (cairo_surface_set_subpixel_antialiasing); |
michael@0 | 185 | + |
michael@0 | 186 | +/** |
michael@0 | 187 | + * cairo_surface_get_subpixel_antialiasing: |
michael@0 | 188 | + * @surface: a #cairo_surface_t |
michael@0 | 189 | + * |
michael@0 | 190 | + * Gets whether the surface supports subpixel antialiasing. By default, |
michael@0 | 191 | + * CAIRO_CONTENT_COLOR surfaces support subpixel antialiasing but other |
michael@0 | 192 | + * surfaces do not. |
michael@0 | 193 | + * |
michael@0 | 194 | + * Since: 1.12 |
michael@0 | 195 | + **/ |
michael@0 | 196 | +cairo_subpixel_antialiasing_t |
michael@0 | 197 | +cairo_surface_get_subpixel_antialiasing (cairo_surface_t *surface) |
michael@0 | 198 | +{ |
michael@0 | 199 | + if (surface->status) |
michael@0 | 200 | + return CAIRO_SUBPIXEL_ANTIALIASING_DISABLED; |
michael@0 | 201 | + |
michael@0 | 202 | + return surface->permit_subpixel_antialiasing ? |
michael@0 | 203 | + CAIRO_SUBPIXEL_ANTIALIASING_ENABLED : CAIRO_SUBPIXEL_ANTIALIASING_DISABLED; |
michael@0 | 204 | +} |
michael@0 | 205 | +slim_hidden_def (cairo_surface_get_subpixel_antialiasing); |
michael@0 | 206 | + |
michael@0 | 207 | /* Note: the backends may modify the contents of the glyph array as long as |
michael@0 | 208 | * they do not return %CAIRO_INT_STATUS_UNSUPPORTED. This makes it possible to |
michael@0 | 209 | * avoid copying the array again and again, and edit it in-place. |
michael@0 | 210 | * Backends are in fact free to use the array as a generic buffer as they |
michael@0 | 211 | * see fit. |
michael@0 | 212 | * |
michael@0 | 213 | * For show_glyphs backend method, and NOT for show_text_glyphs method, |
michael@0 | 214 | * when they do return UNSUPPORTED, they may adjust remaining_glyphs to notify |
michael@0 | 215 | diff --git a/gfx/cairo/cairo/src/cairo-win32-font.c b/gfx/cairo/cairo/src/cairo-win32-font.c |
michael@0 | 216 | --- a/gfx/cairo/cairo/src/cairo-win32-font.c |
michael@0 | 217 | +++ b/gfx/cairo/cairo/src/cairo-win32-font.c |
michael@0 | 218 | @@ -1380,16 +1380,17 @@ _cairo_win32_scaled_font_show_glyphs (vo |
michael@0 | 219 | cairo_win32_surface_t *surface = (cairo_win32_surface_t *)generic_surface; |
michael@0 | 220 | cairo_status_t status; |
michael@0 | 221 | |
michael@0 | 222 | if (width == 0 || height == 0) |
michael@0 | 223 | return CAIRO_STATUS_SUCCESS; |
michael@0 | 224 | |
michael@0 | 225 | if (_cairo_surface_is_win32 (generic_surface) && |
michael@0 | 226 | surface->format == CAIRO_FORMAT_RGB24 && |
michael@0 | 227 | + (generic_surface->permit_subpixel_antialiasing || scaled_font->quality != CLEARTYPE_QUALITY) && |
michael@0 | 228 | op == CAIRO_OPERATOR_OVER && |
michael@0 | 229 | _cairo_pattern_is_opaque_solid (pattern)) { |
michael@0 | 230 | |
michael@0 | 231 | cairo_solid_pattern_t *solid_pattern = (cairo_solid_pattern_t *)pattern; |
michael@0 | 232 | |
michael@0 | 233 | /* When compositing OVER on a GDI-understood surface, with a |
michael@0 | 234 | * solid opaque color, we can just call ExtTextOut directly. |
michael@0 | 235 | */ |
michael@0 | 236 | @@ -1411,16 +1412,18 @@ _cairo_win32_scaled_font_show_glyphs (vo |
michael@0 | 237 | * surface by drawing the the glyphs onto a DIB, black-on-white then |
michael@0 | 238 | * inverting. GDI outputs gamma-corrected images so inverted black-on-white |
michael@0 | 239 | * is very different from white-on-black. We favor the more common |
michael@0 | 240 | * case where the final output is dark-on-light. |
michael@0 | 241 | */ |
michael@0 | 242 | cairo_win32_surface_t *tmp_surface; |
michael@0 | 243 | cairo_surface_t *mask_surface; |
michael@0 | 244 | cairo_surface_pattern_t mask; |
michael@0 | 245 | + cairo_bool_t use_subpixel_antialiasing = |
michael@0 | 246 | + scaled_font->quality == CLEARTYPE_QUALITY && generic_surface->permit_subpixel_antialiasing; |
michael@0 | 247 | RECT r; |
michael@0 | 248 | |
michael@0 | 249 | tmp_surface = (cairo_win32_surface_t *)cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32, width, height); |
michael@0 | 250 | if (tmp_surface->base.status) |
michael@0 | 251 | return tmp_surface->base.status; |
michael@0 | 252 | |
michael@0 | 253 | r.left = 0; |
michael@0 | 254 | r.top = 0; |
michael@0 | 255 | @@ -1432,17 +1435,17 @@ _cairo_win32_scaled_font_show_glyphs (vo |
michael@0 | 256 | scaled_font, RGB (0, 0, 0), |
michael@0 | 257 | dest_x, dest_y, |
michael@0 | 258 | glyphs, num_glyphs); |
michael@0 | 259 | if (status) { |
michael@0 | 260 | cairo_surface_destroy (&tmp_surface->base); |
michael@0 | 261 | return status; |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | - if (scaled_font->quality == CLEARTYPE_QUALITY) { |
michael@0 | 265 | + if (use_subpixel_antialiasing) { |
michael@0 | 266 | /* For ClearType, we need a 4-channel mask. If we are compositing on |
michael@0 | 267 | * a surface with alpha, we need to compute the alpha channel of |
michael@0 | 268 | * the mask (we just copy the green channel). But for a destination |
michael@0 | 269 | * surface without alpha the alpha channel of the mask is ignored |
michael@0 | 270 | */ |
michael@0 | 271 | |
michael@0 | 272 | if (surface->format != CAIRO_FORMAT_RGB24) |
michael@0 | 273 | _compute_argb32_mask_alpha (tmp_surface); |
michael@0 | 274 | @@ -1460,17 +1463,17 @@ _cairo_win32_scaled_font_show_glyphs (vo |
michael@0 | 275 | |
michael@0 | 276 | /* For op == OVER, no-cleartype, a possible optimization here is to |
michael@0 | 277 | * draw onto an intermediate ARGB32 surface and alpha-blend that with the |
michael@0 | 278 | * destination |
michael@0 | 279 | */ |
michael@0 | 280 | _cairo_pattern_init_for_surface (&mask, mask_surface); |
michael@0 | 281 | cairo_surface_destroy (mask_surface); |
michael@0 | 282 | |
michael@0 | 283 | - if (scaled_font->quality == CLEARTYPE_QUALITY) |
michael@0 | 284 | + if (use_subpixel_antialiasing) |
michael@0 | 285 | mask.base.has_component_alpha = TRUE; |
michael@0 | 286 | |
michael@0 | 287 | status = _cairo_surface_composite (op, pattern, |
michael@0 | 288 | &mask.base, |
michael@0 | 289 | &surface->base, |
michael@0 | 290 | source_x, source_y, |
michael@0 | 291 | 0, 0, |
michael@0 | 292 | dest_x, dest_y, |
michael@0 | 293 | diff --git a/gfx/cairo/cairo/src/cairo-xlib-surface.c b/gfx/cairo/cairo/src/cairo-xlib-surface.c |
michael@0 | 294 | --- a/gfx/cairo/cairo/src/cairo-xlib-surface.c |
michael@0 | 295 | +++ b/gfx/cairo/cairo/src/cairo-xlib-surface.c |
michael@0 | 296 | @@ -3570,16 +3570,17 @@ typedef struct _cairo_xlib_font_glyphset |
michael@0 | 297 | GlyphSet glyphset; |
michael@0 | 298 | cairo_format_t format; |
michael@0 | 299 | XRenderPictFormat *xrender_format; |
michael@0 | 300 | cairo_xlib_font_glyphset_free_glyphs_t *pending_free_glyphs; |
michael@0 | 301 | } cairo_xlib_font_glyphset_info_t; |
michael@0 | 302 | |
michael@0 | 303 | typedef struct _cairo_xlib_surface_font_private { |
michael@0 | 304 | cairo_scaled_font_t *scaled_font; |
michael@0 | 305 | + cairo_scaled_font_t *grayscale_font; |
michael@0 | 306 | cairo_xlib_hook_t close_display_hook; |
michael@0 | 307 | cairo_xlib_display_t *display; |
michael@0 | 308 | cairo_xlib_font_glyphset_info_t glyphset_info[NUM_GLYPHSETS]; |
michael@0 | 309 | } cairo_xlib_surface_font_private_t; |
michael@0 | 310 | |
michael@0 | 311 | /* callback from CloseDisplay */ |
michael@0 | 312 | static void |
michael@0 | 313 | _cairo_xlib_surface_remove_scaled_font (cairo_xlib_display_t *display, |
michael@0 | 314 | @@ -3599,16 +3600,20 @@ _cairo_xlib_surface_remove_scaled_font ( |
michael@0 | 315 | |
michael@0 | 316 | _cairo_scaled_font_reset_cache (scaled_font); |
michael@0 | 317 | CAIRO_MUTEX_UNLOCK (scaled_font->mutex); |
michael@0 | 318 | |
michael@0 | 319 | if (font_private != NULL) { |
michael@0 | 320 | Display *dpy; |
michael@0 | 321 | int i; |
michael@0 | 322 | |
michael@0 | 323 | + if (font_private->grayscale_font) { |
michael@0 | 324 | + cairo_scaled_font_destroy (font_private->grayscale_font); |
michael@0 | 325 | + } |
michael@0 | 326 | + |
michael@0 | 327 | dpy = _cairo_xlib_display_get_dpy (display); |
michael@0 | 328 | for (i = 0; i < NUM_GLYPHSETS; i++) { |
michael@0 | 329 | cairo_xlib_font_glyphset_info_t *glyphset_info; |
michael@0 | 330 | |
michael@0 | 331 | glyphset_info = &font_private->glyphset_info[i]; |
michael@0 | 332 | if (glyphset_info->glyphset) |
michael@0 | 333 | XRenderFreeGlyphSet (dpy, glyphset_info->glyphset); |
michael@0 | 334 | |
michael@0 | 335 | @@ -3629,16 +3634,17 @@ _cairo_xlib_surface_font_init (Display |
michael@0 | 336 | cairo_status_t status; |
michael@0 | 337 | int i; |
michael@0 | 338 | |
michael@0 | 339 | font_private = malloc (sizeof (cairo_xlib_surface_font_private_t)); |
michael@0 | 340 | if (unlikely (font_private == NULL)) |
michael@0 | 341 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
michael@0 | 342 | |
michael@0 | 343 | font_private->scaled_font = scaled_font; |
michael@0 | 344 | + font_private->grayscale_font = NULL; |
michael@0 | 345 | status = _cairo_xlib_display_get (dpy, &font_private->display); |
michael@0 | 346 | if (unlikely (status)) { |
michael@0 | 347 | free (font_private); |
michael@0 | 348 | return status; |
michael@0 | 349 | } |
michael@0 | 350 | |
michael@0 | 351 | /* initialize and hook into the CloseDisplay callback */ |
michael@0 | 352 | font_private->close_display_hook.func = |
michael@0 | 353 | @@ -3671,16 +3677,20 @@ _cairo_xlib_surface_scaled_font_fini (ca |
michael@0 | 354 | { |
michael@0 | 355 | cairo_xlib_surface_font_private_t *font_private; |
michael@0 | 356 | |
michael@0 | 357 | font_private = scaled_font->surface_private; |
michael@0 | 358 | if (font_private != NULL) { |
michael@0 | 359 | cairo_xlib_display_t *display; |
michael@0 | 360 | int i; |
michael@0 | 361 | |
michael@0 | 362 | + if (font_private->grayscale_font) { |
michael@0 | 363 | + cairo_scaled_font_destroy (font_private->grayscale_font); |
michael@0 | 364 | + } |
michael@0 | 365 | + |
michael@0 | 366 | display = font_private->display; |
michael@0 | 367 | _cairo_xlib_remove_close_display_hook (display, |
michael@0 | 368 | &font_private->close_display_hook); |
michael@0 | 369 | |
michael@0 | 370 | for (i = 0; i < NUM_GLYPHSETS; i++) { |
michael@0 | 371 | cairo_xlib_font_glyphset_info_t *glyphset_info; |
michael@0 | 372 | |
michael@0 | 373 | glyphset_info = &font_private->glyphset_info[i]; |
michael@0 | 374 | @@ -4417,16 +4427,62 @@ _cairo_xlib_surface_owns_font (cairo_xli |
michael@0 | 375 | (font_private != NULL && font_private->display != dst->display)) |
michael@0 | 376 | { |
michael@0 | 377 | return FALSE; |
michael@0 | 378 | } |
michael@0 | 379 | |
michael@0 | 380 | return TRUE; |
michael@0 | 381 | } |
michael@0 | 382 | |
michael@0 | 383 | +/* Gets a grayscale version of scaled_font. The grayscale version is cached |
michael@0 | 384 | + * in our surface_private data. |
michael@0 | 385 | + */ |
michael@0 | 386 | +static cairo_scaled_font_t * |
michael@0 | 387 | +_cairo_xlib_get_grayscale_font (cairo_xlib_surface_t *dst, |
michael@0 | 388 | + cairo_scaled_font_t *scaled_font) |
michael@0 | 389 | +{ |
michael@0 | 390 | + cairo_xlib_surface_font_private_t *font_private = scaled_font->surface_private; |
michael@0 | 391 | + cairo_bool_t needs_font; |
michael@0 | 392 | + |
michael@0 | 393 | + if (font_private == NULL) { |
michael@0 | 394 | + cairo_status_t status = _cairo_xlib_surface_font_init (dst->dpy, scaled_font); |
michael@0 | 395 | + if (unlikely (status)) |
michael@0 | 396 | + return _cairo_scaled_font_create_in_error (status); |
michael@0 | 397 | + font_private = scaled_font->surface_private; |
michael@0 | 398 | + } |
michael@0 | 399 | + |
michael@0 | 400 | + CAIRO_MUTEX_LOCK (scaled_font->mutex); |
michael@0 | 401 | + needs_font = !font_private->grayscale_font; |
michael@0 | 402 | + CAIRO_MUTEX_UNLOCK (scaled_font->mutex); |
michael@0 | 403 | + |
michael@0 | 404 | + if (needs_font) { |
michael@0 | 405 | + cairo_font_options_t options; |
michael@0 | 406 | + cairo_scaled_font_t *new_font; |
michael@0 | 407 | + |
michael@0 | 408 | + options = scaled_font->options; |
michael@0 | 409 | + options.antialias = CAIRO_ANTIALIAS_GRAY; |
michael@0 | 410 | + new_font = cairo_scaled_font_create (scaled_font->font_face, |
michael@0 | 411 | + &scaled_font->font_matrix, |
michael@0 | 412 | + &scaled_font->ctm, &options); |
michael@0 | 413 | + |
michael@0 | 414 | + CAIRO_MUTEX_LOCK (scaled_font->mutex); |
michael@0 | 415 | + if (!font_private->grayscale_font) { |
michael@0 | 416 | + font_private->grayscale_font = new_font; |
michael@0 | 417 | + new_font = NULL; |
michael@0 | 418 | + } |
michael@0 | 419 | + CAIRO_MUTEX_UNLOCK (scaled_font->mutex); |
michael@0 | 420 | + |
michael@0 | 421 | + if (new_font) { |
michael@0 | 422 | + cairo_scaled_font_destroy (new_font); |
michael@0 | 423 | + } |
michael@0 | 424 | + } |
michael@0 | 425 | + |
michael@0 | 426 | + return font_private->grayscale_font; |
michael@0 | 427 | +} |
michael@0 | 428 | + |
michael@0 | 429 | static cairo_int_status_t |
michael@0 | 430 | _cairo_xlib_surface_show_glyphs (void *abstract_dst, |
michael@0 | 431 | cairo_operator_t op, |
michael@0 | 432 | const cairo_pattern_t *src_pattern, |
michael@0 | 433 | cairo_glyph_t *glyphs, |
michael@0 | 434 | int num_glyphs, |
michael@0 | 435 | cairo_scaled_font_t *scaled_font, |
michael@0 | 436 | cairo_clip_t *clip, |
michael@0 | 437 | @@ -4475,16 +4531,21 @@ _cairo_xlib_surface_show_glyphs (void |
michael@0 | 438 | |
michael@0 | 439 | operation = _categorize_composite_operation (dst, op, src_pattern, TRUE); |
michael@0 | 440 | if (operation == DO_UNSUPPORTED) |
michael@0 | 441 | return UNSUPPORTED ("unsupported op"); |
michael@0 | 442 | |
michael@0 | 443 | if (! _cairo_xlib_surface_owns_font (dst, scaled_font)) |
michael@0 | 444 | return UNSUPPORTED ("unowned font"); |
michael@0 | 445 | |
michael@0 | 446 | + if (!dst->base.permit_subpixel_antialiasing && |
michael@0 | 447 | + scaled_font->options.antialias == CAIRO_ANTIALIAS_SUBPIXEL) { |
michael@0 | 448 | + scaled_font = _cairo_xlib_get_grayscale_font (dst, scaled_font); |
michael@0 | 449 | + } |
michael@0 | 450 | + |
michael@0 | 451 | X_DEBUG ((dst->dpy, "show_glyphs (dst=%x)", (unsigned int) dst->drawable)); |
michael@0 | 452 | |
michael@0 | 453 | if (clip_region != NULL && |
michael@0 | 454 | cairo_region_num_rectangles (clip_region) == 1) |
michael@0 | 455 | { |
michael@0 | 456 | cairo_rectangle_int_t glyph_extents; |
michael@0 | 457 | const cairo_rectangle_int_t *clip_extents; |
michael@0 | 458 | |
michael@0 | 459 | diff --git a/gfx/cairo/cairo/src/cairo.h b/gfx/cairo/cairo/src/cairo.h |
michael@0 | 460 | --- a/gfx/cairo/cairo/src/cairo.h |
michael@0 | 461 | +++ b/gfx/cairo/cairo/src/cairo.h |
michael@0 | 462 | @@ -2101,16 +2101,35 @@ cairo_public void |
michael@0 | 463 | cairo_surface_copy_page (cairo_surface_t *surface); |
michael@0 | 464 | |
michael@0 | 465 | cairo_public void |
michael@0 | 466 | cairo_surface_show_page (cairo_surface_t *surface); |
michael@0 | 467 | |
michael@0 | 468 | cairo_public cairo_bool_t |
michael@0 | 469 | cairo_surface_has_show_text_glyphs (cairo_surface_t *surface); |
michael@0 | 470 | |
michael@0 | 471 | +/** |
michael@0 | 472 | + * _cairo_subpixel_antialiasing_t: |
michael@0 | 473 | + * @CAIRO_SUBPIXEL_ANTIALIASING_ENABLED: subpixel antialiasing is enabled |
michael@0 | 474 | + * for this surface. |
michael@0 | 475 | + * @CAIRO_SUBPIXEL_ANTIALIASING_DISABLED: subpixel antialiasing is disabled |
michael@0 | 476 | + * for this surface. |
michael@0 | 477 | + */ |
michael@0 | 478 | +typedef enum _cairo_subpixel_antialiasing_t { |
michael@0 | 479 | + CAIRO_SUBPIXEL_ANTIALIASING_ENABLED, |
michael@0 | 480 | + CAIRO_SUBPIXEL_ANTIALIASING_DISABLED |
michael@0 | 481 | +} cairo_subpixel_antialiasing_t; |
michael@0 | 482 | + |
michael@0 | 483 | +cairo_public void |
michael@0 | 484 | +cairo_surface_set_subpixel_antialiasing (cairo_surface_t *surface, |
michael@0 | 485 | + cairo_subpixel_antialiasing_t enabled); |
michael@0 | 486 | + |
michael@0 | 487 | +cairo_public cairo_subpixel_antialiasing_t |
michael@0 | 488 | +cairo_surface_get_subpixel_antialiasing (cairo_surface_t *surface); |
michael@0 | 489 | + |
michael@0 | 490 | /* Image-surface functions */ |
michael@0 | 491 | |
michael@0 | 492 | /** |
michael@0 | 493 | * cairo_format_t: |
michael@0 | 494 | * @CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with |
michael@0 | 495 | * alpha in the upper 8 bits, then red, then green, then blue. |
michael@0 | 496 | * The 32-bit quantities are stored native-endian. Pre-multiplied |
michael@0 | 497 | * alpha is used. (That is, 50% transparent red is 0x80800000, |
michael@0 | 498 | diff --git a/gfx/cairo/cairo/src/cairoint.h b/gfx/cairo/cairo/src/cairoint.h |
michael@0 | 499 | --- a/gfx/cairo/cairo/src/cairoint.h |
michael@0 | 500 | +++ b/gfx/cairo/cairo/src/cairoint.h |
michael@0 | 501 | @@ -2750,16 +2750,18 @@ slim_hidden_proto (cairo_surface_destroy |
michael@0 | 502 | slim_hidden_proto (cairo_surface_finish); |
michael@0 | 503 | slim_hidden_proto (cairo_surface_flush); |
michael@0 | 504 | slim_hidden_proto (cairo_surface_get_content); |
michael@0 | 505 | slim_hidden_proto (cairo_surface_get_device_offset); |
michael@0 | 506 | slim_hidden_proto (cairo_surface_get_font_options); |
michael@0 | 507 | slim_hidden_proto (cairo_surface_get_mime_data); |
michael@0 | 508 | slim_hidden_proto (cairo_surface_get_type); |
michael@0 | 509 | slim_hidden_proto (cairo_surface_has_show_text_glyphs); |
michael@0 | 510 | +slim_hidden_proto (cairo_surface_set_subpixel_antialiasing); |
michael@0 | 511 | +slim_hidden_proto (cairo_surface_get_subpixel_antialiasing); |
michael@0 | 512 | slim_hidden_proto (cairo_surface_mark_dirty_rectangle); |
michael@0 | 513 | slim_hidden_proto_no_warn (cairo_surface_reference); |
michael@0 | 514 | slim_hidden_proto (cairo_surface_set_device_offset); |
michael@0 | 515 | slim_hidden_proto (cairo_surface_set_fallback_resolution); |
michael@0 | 516 | slim_hidden_proto (cairo_surface_set_mime_data); |
michael@0 | 517 | slim_hidden_proto (cairo_surface_show_page); |
michael@0 | 518 | slim_hidden_proto (cairo_surface_status); |
michael@0 | 519 | slim_hidden_proto (cairo_text_cluster_allocate); |