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 | changeset: 29338:f2a10f325734 |
michael@0 | 2 | tag: qtip |
michael@0 | 3 | tag: tip |
michael@0 | 4 | tag: win32-raster-mask2.patch |
michael@0 | 5 | tag: qbase |
michael@0 | 6 | user: Jeff Muizelaar <jmuizelaar@mozilla.com> |
michael@0 | 7 | date: Mon Jun 22 14:26:07 2009 -0400 |
michael@0 | 8 | summary: imported patch win32-raster-mask2.patch |
michael@0 | 9 | |
michael@0 | 10 | diff --git a/gfx/cairo/cairo/src/cairo-image-surface.c b/gfx/cairo/cairo/src/cairo-image-surface.c |
michael@0 | 11 | --- a/gfx/cairo/cairo/src/cairo-image-surface.c |
michael@0 | 12 | +++ b/gfx/cairo/cairo/src/cairo-image-surface.c |
michael@0 | 13 | @@ -1232,27 +1232,27 @@ typedef struct _cairo_image_surface_span |
michael@0 | 14 | cairo_composite_rectangles_t composite_rectangles; |
michael@0 | 15 | } cairo_image_surface_span_renderer_t; |
michael@0 | 16 | |
michael@0 | 17 | -static cairo_status_t |
michael@0 | 18 | -_cairo_image_surface_span_renderer_render_row ( |
michael@0 | 19 | - void *abstract_renderer, |
michael@0 | 20 | +void |
michael@0 | 21 | +_cairo_image_surface_span_render_row ( |
michael@0 | 22 | int y, |
michael@0 | 23 | const cairo_half_open_span_t *spans, |
michael@0 | 24 | - unsigned num_spans) |
michael@0 | 25 | + unsigned num_spans, |
michael@0 | 26 | + cairo_image_surface_t *mask, |
michael@0 | 27 | + const cairo_composite_rectangles_t *rects) |
michael@0 | 28 | { |
michael@0 | 29 | - cairo_image_surface_span_renderer_t *renderer = abstract_renderer; |
michael@0 | 30 | - int xmin = renderer->composite_rectangles.mask.x; |
michael@0 | 31 | - int xmax = xmin + renderer->composite_rectangles.width; |
michael@0 | 32 | + int xmin = rects->mask.x; |
michael@0 | 33 | + int xmax = xmin + rects->width; |
michael@0 | 34 | uint8_t *row; |
michael@0 | 35 | int prev_x = xmin; |
michael@0 | 36 | int prev_alpha = 0; |
michael@0 | 37 | unsigned i; |
michael@0 | 38 | |
michael@0 | 39 | /* Make sure we're within y-range. */ |
michael@0 | 40 | - y -= renderer->composite_rectangles.mask.y; |
michael@0 | 41 | - if (y < 0 || y >= renderer->composite_rectangles.height) |
michael@0 | 42 | + y -= rects->mask.y; |
michael@0 | 43 | + if (y < 0 || y >= rects->height) |
michael@0 | 44 | return CAIRO_STATUS_SUCCESS; |
michael@0 | 45 | |
michael@0 | 46 | - row = (uint8_t*)(renderer->mask->data) + y*(size_t)renderer->mask->stride - xmin; |
michael@0 | 47 | + row = (uint8_t*)(mask->data) + y*(size_t)mask->stride - xmin; |
michael@0 | 48 | |
michael@0 | 49 | /* Find the first span within x-range. */ |
michael@0 | 50 | for (i=0; i < num_spans && spans[i].x < xmin; i++) {} |
michael@0 | 51 | @@ -1286,7 +1286,17 @@ _cairo_image_surface_span_renderer_rende |
michael@0 | 52 | if (prev_alpha != 0 && prev_x < xmax) { |
michael@0 | 53 | memset(row + prev_x, prev_alpha, xmax - prev_x); |
michael@0 | 54 | } |
michael@0 | 55 | +} |
michael@0 | 56 | |
michael@0 | 57 | +static cairo_status_t |
michael@0 | 58 | +_cairo_image_surface_span_renderer_render_row ( |
michael@0 | 59 | + void *abstract_renderer, |
michael@0 | 60 | + int y, |
michael@0 | 61 | + const cairo_half_open_span_t *spans, |
michael@0 | 62 | + unsigned num_spans) |
michael@0 | 63 | +{ |
michael@0 | 64 | + cairo_image_surface_span_renderer_t *renderer = abstract_renderer; |
michael@0 | 65 | + _cairo_image_surface_span_render_row (y, spans, num_spans, renderer->mask, &renderer->composite_rectangles); |
michael@0 | 66 | return CAIRO_STATUS_SUCCESS; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | diff --git a/gfx/cairo/cairo/src/cairo-tor-scan-converter.c b/gfx/cairo/cairo/src/cairo-tor-scan-converter.c |
michael@0 | 70 | --- a/gfx/cairo/cairo/src/cairo-tor-scan-converter.c |
michael@0 | 71 | +++ b/gfx/cairo/cairo/src/cairo-tor-scan-converter.c |
michael@0 | 72 | @@ -295,9 +295,9 @@ typedef int grid_area_t; |
michael@0 | 73 | #elif GRID_XY == 15 |
michael@0 | 74 | # define GRID_AREA_TO_ALPHA(c) (((c) << 4) + (c)) |
michael@0 | 75 | #elif GRID_XY == 2*256*15 |
michael@0 | 76 | -# define GRID_AREA_TO_ALPHA(c) (((c) + ((c)<<4)) >> 9) |
michael@0 | 77 | +# define GRID_AREA_TO_ALPHA(c) (((c) + ((c)<<4) + 256) >> 9) |
michael@0 | 78 | #else |
michael@0 | 79 | -# define GRID_AREA_TO_ALPHA(c) ((c)*255 / GRID_XY) /* tweak me for rounding */ |
michael@0 | 80 | +# define GRID_AREA_TO_ALPHA(c) (((c)*255 + GRID_XY/2) / GRID_XY) |
michael@0 | 81 | #endif |
michael@0 | 82 | |
michael@0 | 83 | #define UNROLL3(x) x x x |
michael@0 | 84 | diff --git a/gfx/cairo/cairo/src/cairo-win32-surface.c b/gfx/cairo/cairo/src/cairo-win32-surface.c |
michael@0 | 85 | --- a/gfx/cairo/cairo/src/cairo-win32-surface.c |
michael@0 | 86 | +++ b/gfx/cairo/cairo/src/cairo-win32-surface.c |
michael@0 | 87 | @@ -2048,6 +2048,148 @@ _cairo_win32_surface_reset (void *abstra |
michael@0 | 88 | return CAIRO_STATUS_SUCCESS; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | +typedef struct _cairo_win32_surface_span_renderer { |
michael@0 | 92 | + cairo_span_renderer_t base; |
michael@0 | 93 | + |
michael@0 | 94 | + cairo_operator_t op; |
michael@0 | 95 | + const cairo_pattern_t *pattern; |
michael@0 | 96 | + cairo_antialias_t antialias; |
michael@0 | 97 | + |
michael@0 | 98 | + cairo_image_surface_t *mask; |
michael@0 | 99 | + cairo_win32_surface_t *dst; |
michael@0 | 100 | + |
michael@0 | 101 | + cairo_composite_rectangles_t composite_rectangles; |
michael@0 | 102 | +} cairo_win32_surface_span_renderer_t; |
michael@0 | 103 | + |
michael@0 | 104 | +static cairo_status_t |
michael@0 | 105 | +_cairo_win32_surface_span_renderer_render_row ( |
michael@0 | 106 | + void *abstract_renderer, |
michael@0 | 107 | + int y, |
michael@0 | 108 | + const cairo_half_open_span_t *spans, |
michael@0 | 109 | + unsigned num_spans) |
michael@0 | 110 | +{ |
michael@0 | 111 | + cairo_win32_surface_span_renderer_t *renderer = abstract_renderer; |
michael@0 | 112 | + _cairo_image_surface_span_render_row (y, spans, num_spans, renderer->mask, &renderer->composite_rectangles); |
michael@0 | 113 | + return CAIRO_STATUS_SUCCESS; |
michael@0 | 114 | +} |
michael@0 | 115 | + |
michael@0 | 116 | +static void |
michael@0 | 117 | +_cairo_win32_surface_span_renderer_destroy (void *abstract_renderer) |
michael@0 | 118 | +{ |
michael@0 | 119 | + cairo_win32_surface_span_renderer_t *renderer = abstract_renderer; |
michael@0 | 120 | + if (!renderer) return; |
michael@0 | 121 | + |
michael@0 | 122 | + if (renderer->mask != NULL) |
michael@0 | 123 | + cairo_surface_destroy (&renderer->mask->base); |
michael@0 | 124 | + |
michael@0 | 125 | + free (renderer); |
michael@0 | 126 | +} |
michael@0 | 127 | + |
michael@0 | 128 | +static cairo_status_t |
michael@0 | 129 | +_cairo_win32_surface_span_renderer_finish (void *abstract_renderer) |
michael@0 | 130 | +{ |
michael@0 | 131 | + cairo_win32_surface_span_renderer_t *renderer = abstract_renderer; |
michael@0 | 132 | + cairo_status_t status = CAIRO_STATUS_SUCCESS; |
michael@0 | 133 | + |
michael@0 | 134 | + if (renderer->pattern == NULL || renderer->mask == NULL) |
michael@0 | 135 | + return CAIRO_STATUS_SUCCESS; |
michael@0 | 136 | + |
michael@0 | 137 | + status = cairo_surface_status (&renderer->mask->base); |
michael@0 | 138 | + if (status == CAIRO_STATUS_SUCCESS) { |
michael@0 | 139 | + cairo_composite_rectangles_t *rects = &renderer->composite_rectangles; |
michael@0 | 140 | + cairo_win32_surface_t *dst = renderer->dst; |
michael@0 | 141 | + cairo_pattern_t *mask_pattern = cairo_pattern_create_for_surface (&renderer->mask->base); |
michael@0 | 142 | + /* composite onto the image surface directly if we can */ |
michael@0 | 143 | + if (dst->image) { |
michael@0 | 144 | + GdiFlush(); |
michael@0 | 145 | + |
michael@0 | 146 | + status = dst->image->backend->composite (renderer->op, |
michael@0 | 147 | + renderer->pattern, mask_pattern, dst->image, |
michael@0 | 148 | + rects->src.x, |
michael@0 | 149 | + rects->src.y, |
michael@0 | 150 | + 0, 0, /* mask.x, mask.y */ |
michael@0 | 151 | + rects->dst.x, rects->dst.y, |
michael@0 | 152 | + rects->width, rects->height); |
michael@0 | 153 | + } else { |
michael@0 | 154 | + /* otherwise go through the fallback_composite path which |
michael@0 | 155 | + * will do the appropriate surface acquisition */ |
michael@0 | 156 | + status = _cairo_surface_fallback_composite ( |
michael@0 | 157 | + renderer->op, |
michael@0 | 158 | + renderer->pattern, mask_pattern, dst, |
michael@0 | 159 | + rects->src.x, |
michael@0 | 160 | + rects->src.y, |
michael@0 | 161 | + 0, 0, /* mask.x, mask.y */ |
michael@0 | 162 | + rects->dst.x, rects->dst.y, |
michael@0 | 163 | + rects->width, rects->height); |
michael@0 | 164 | + } |
michael@0 | 165 | + cairo_pattern_destroy (mask_pattern); |
michael@0 | 166 | + |
michael@0 | 167 | + } |
michael@0 | 168 | + if (status != CAIRO_STATUS_SUCCESS) |
michael@0 | 169 | + return _cairo_span_renderer_set_error (abstract_renderer, |
michael@0 | 170 | + status); |
michael@0 | 171 | + return CAIRO_STATUS_SUCCESS; |
michael@0 | 172 | +} |
michael@0 | 173 | + |
michael@0 | 174 | +static cairo_bool_t |
michael@0 | 175 | +_cairo_win32_surface_check_span_renderer (cairo_operator_t op, |
michael@0 | 176 | + const cairo_pattern_t *pattern, |
michael@0 | 177 | + void *abstract_dst, |
michael@0 | 178 | + cairo_antialias_t antialias, |
michael@0 | 179 | + const cairo_composite_rectangles_t *rects) |
michael@0 | 180 | +{ |
michael@0 | 181 | + (void) op; |
michael@0 | 182 | + (void) pattern; |
michael@0 | 183 | + (void) abstract_dst; |
michael@0 | 184 | + (void) antialias; |
michael@0 | 185 | + (void) rects; |
michael@0 | 186 | + return TRUE; |
michael@0 | 187 | +} |
michael@0 | 188 | + |
michael@0 | 189 | +static cairo_span_renderer_t * |
michael@0 | 190 | +_cairo_win32_surface_create_span_renderer (cairo_operator_t op, |
michael@0 | 191 | + const cairo_pattern_t *pattern, |
michael@0 | 192 | + void *abstract_dst, |
michael@0 | 193 | + cairo_antialias_t antialias, |
michael@0 | 194 | + const cairo_composite_rectangles_t *rects) |
michael@0 | 195 | +{ |
michael@0 | 196 | + cairo_win32_surface_t *dst = abstract_dst; |
michael@0 | 197 | + cairo_win32_surface_span_renderer_t *renderer |
michael@0 | 198 | + = calloc(1, sizeof(*renderer)); |
michael@0 | 199 | + cairo_status_t status; |
michael@0 | 200 | + int width = rects->width; |
michael@0 | 201 | + int height = rects->height; |
michael@0 | 202 | + |
michael@0 | 203 | + if (renderer == NULL) |
michael@0 | 204 | + return _cairo_span_renderer_create_in_error (CAIRO_STATUS_NO_MEMORY); |
michael@0 | 205 | + |
michael@0 | 206 | + renderer->base.destroy = _cairo_win32_surface_span_renderer_destroy; |
michael@0 | 207 | + renderer->base.finish = _cairo_win32_surface_span_renderer_finish; |
michael@0 | 208 | + renderer->base.render_row = |
michael@0 | 209 | + _cairo_win32_surface_span_renderer_render_row; |
michael@0 | 210 | + renderer->op = op; |
michael@0 | 211 | + renderer->pattern = pattern; |
michael@0 | 212 | + renderer->antialias = antialias; |
michael@0 | 213 | + renderer->dst = dst; |
michael@0 | 214 | + |
michael@0 | 215 | + renderer->composite_rectangles = *rects; |
michael@0 | 216 | + |
michael@0 | 217 | + /* TODO: support rendering to A1 surfaces (or: go add span |
michael@0 | 218 | + * compositing to pixman.) */ |
michael@0 | 219 | + renderer->mask = (cairo_image_surface_t *) |
michael@0 | 220 | + cairo_image_surface_create (CAIRO_FORMAT_A8, |
michael@0 | 221 | + width, height); |
michael@0 | 222 | + |
michael@0 | 223 | + status = cairo_surface_status (&renderer->mask->base); |
michael@0 | 224 | + |
michael@0 | 225 | + if (status != CAIRO_STATUS_SUCCESS) { |
michael@0 | 226 | + _cairo_win32_surface_span_renderer_destroy (renderer); |
michael@0 | 227 | + return _cairo_span_renderer_create_in_error (status); |
michael@0 | 228 | + } |
michael@0 | 229 | + return &renderer->base; |
michael@0 | 230 | +} |
michael@0 | 231 | + |
michael@0 | 232 | + |
michael@0 | 233 | static const cairo_surface_backend_t cairo_win32_surface_backend = { |
michael@0 | 234 | CAIRO_SURFACE_TYPE_WIN32, |
michael@0 | 235 | _cairo_win32_surface_create_similar, |
michael@0 | 236 | @@ -2060,8 +2202,8 @@ static const cairo_surface_backend_t cai |
michael@0 | 237 | _cairo_win32_surface_composite, |
michael@0 | 238 | _cairo_win32_surface_fill_rectangles, |
michael@0 | 239 | NULL, /* composite_trapezoids */ |
michael@0 | 240 | - NULL, /* create_span_renderer */ |
michael@0 | 241 | - NULL, /* check_span_renderer */ |
michael@0 | 242 | + _cairo_win32_surface_create_span_renderer, |
michael@0 | 243 | + _cairo_win32_surface_check_span_renderer, |
michael@0 | 244 | NULL, /* copy_page */ |
michael@0 | 245 | NULL, /* show_page */ |
michael@0 | 246 | _cairo_win32_surface_set_clip_region, |
michael@0 | 247 | diff --git a/gfx/cairo/cairo/src/cairoint.h b/gfx/cairo/cairo/src/cairoint.h |
michael@0 | 248 | --- a/gfx/cairo/cairo/src/cairoint.h |
michael@0 | 249 | +++ b/gfx/cairo/cairo/src/cairoint.h |
michael@0 | 250 | @@ -2193,6 +2193,12 @@ _cairo_image_surface_set_clip_region (vo |
michael@0 | 251 | cairo_private cairo_image_surface_t * |
michael@0 | 252 | _cairo_image_surface_coerce (cairo_image_surface_t *surface, |
michael@0 | 253 | cairo_format_t format); |
michael@0 | 254 | +cairo_private void |
michael@0 | 255 | +_cairo_image_surface_span_render_row (int y, |
michael@0 | 256 | + const cairo_half_open_span_t *spans, |
michael@0 | 257 | + unsigned num_spans, |
michael@0 | 258 | + cairo_image_surface_t *mask, |
michael@0 | 259 | + const cairo_composite_rectangles_t *rects); |
michael@0 | 260 | |
michael@0 | 261 | cairo_private cairo_image_transparency_t |
michael@0 | 262 | _cairo_image_analyze_transparency (cairo_image_surface_t *image); |