Bug 1632310 [wpt PR 23186] - Add test for computed versus resolved style., a=testonly
[gecko.git] / gfx / cairo / no-pixman-image-reuse-across-threads.patch
blobccaf5a5e63ddb3772b4c95fbbbf6b281d3be8a37
1 From
2 https://cgit.freedesktop.org/cairo/commit/?id=71e8a4c23019b01aa43b334fcb2784c70daae9b5
3 https://bugs.freedesktop.org/show_bug.cgi?id=34177
5 diff --git a/gfx/cairo/cairo/src/cairo-image-surface.c b/gfx/cairo/cairo/src/cairo-image-surface.c
6 --- a/gfx/cairo/cairo/src/cairo-image-surface.c
7 +++ b/gfx/cairo/cairo/src/cairo-image-surface.c
8 @@ -870,17 +870,17 @@ static cairo_bool_t
9 *ty = _pixman_nearest_sample (*ty);
10 } else {
11 if (*tx != floor (*tx) || *ty != floor (*ty))
12 return FALSE;
14 return fabs (*tx) < PIXMAN_MAX_INT && fabs (*ty) < PIXMAN_MAX_INT;
17 -#if HAS_ATOMIC_OPS
18 +#if PIXMAN_HAS_ATOMIC_OPS
19 static pixman_image_t *__pixman_transparent_image;
20 static pixman_image_t *__pixman_black_image;
21 static pixman_image_t *__pixman_white_image;
23 static pixman_image_t *
24 _pixman_transparent_image (void)
26 pixman_image_t *image;
27 @@ -964,56 +964,59 @@ static pixman_image_t *
28 pixman_image_ref (image);
30 } else {
31 pixman_image_ref (image);
34 return image;
36 -#else
37 -static pixman_image_t *
38 -_pixman_transparent_image (void)
40 - return _pixman_image_for_solid (&_cairo_pattern_clear);
42 -static pixman_image_t *
43 -_pixman_black_image (void)
45 - return _pixman_image_for_solid (&_cairo_pattern_black);
47 -static pixman_image_t *
48 -_pixman_white_image (void)
50 - return _pixman_image_for_solid (&_cairo_pattern_white);
52 -#endif
54 static uint32_t
55 hars_petruska_f54_1_random (void)
57 #define rol(x,k) ((x << k) | (x >> (32-k)))
58 static uint32_t x;
59 return x = (x ^ rol (x, 5) ^ rol (x, 24)) + 0x37798849;
60 #undef rol
63 static struct {
64 cairo_color_t color;
65 pixman_image_t *image;
66 } cache[16];
67 static int n_cached;
69 +#else /* !PIXMAN_HAS_ATOMIC_OPS */
70 +static pixman_image_t *
71 +_pixman_transparent_image (void)
73 + return _pixman_image_for_solid (&_cairo_pattern_clear);
76 +static pixman_image_t *
77 +_pixman_black_image (void)
79 + return _pixman_image_for_solid (&_cairo_pattern_black);
82 +static pixman_image_t *
83 +_pixman_white_image (void)
85 + return _pixman_image_for_solid (&_cairo_pattern_white);
87 +#endif /* !PIXMAN_HAS_ATOMIC_OPS */
89 void
90 _cairo_image_reset_static_data (void)
92 +#if PIXMAN_HAS_ATOMIC_OPS
93 while (n_cached)
94 pixman_image_unref (cache[--n_cached].image);
96 -#if HAS_ATOMIC_OPS
97 if (__pixman_transparent_image) {
98 pixman_image_unref (__pixman_transparent_image);
99 __pixman_transparent_image = NULL;
102 if (__pixman_black_image) {
103 pixman_image_unref (__pixman_black_image);
104 __pixman_black_image = NULL;
105 @@ -1026,19 +1029,20 @@ void
106 #endif
109 static pixman_image_t *
110 _pixman_image_for_solid (const cairo_solid_pattern_t *pattern)
112 pixman_color_t color;
113 pixman_image_t *image;
115 +#if PIXMAN_HAS_ATOMIC_OPS
116 int i;
118 -#if HAS_ATOMIC_OPS
119 if (pattern->color.alpha_short <= 0x00ff)
120 return _pixman_transparent_image ();
122 if (pattern->color.alpha_short >= 0xff00) {
123 if (pattern->color.red_short <= 0x00ff &&
124 pattern->color.green_short <= 0x00ff &&
125 pattern->color.blue_short <= 0x00ff)
127 @@ -1047,46 +1051,48 @@ static pixman_image_t *
129 if (pattern->color.red_short >= 0xff00 &&
130 pattern->color.green_short >= 0xff00 &&
131 pattern->color.blue_short >= 0xff00)
133 return _pixman_white_image ();
136 -#endif
138 CAIRO_MUTEX_LOCK (_cairo_image_solid_cache_mutex);
139 for (i = 0; i < n_cached; i++) {
140 if (_cairo_color_equal (&cache[i].color, &pattern->color)) {
141 image = pixman_image_ref (cache[i].image);
142 goto UNLOCK;
145 +#endif
147 color.red = pattern->color.red_short;
148 color.green = pattern->color.green_short;
149 color.blue = pattern->color.blue_short;
150 color.alpha = pattern->color.alpha_short;
152 image = pixman_image_create_solid_fill (&color);
153 +#if PIXMAN_HAS_ATOMIC_OPS
154 if (image == NULL)
155 goto UNLOCK;
157 if (n_cached < ARRAY_LENGTH (cache)) {
158 i = n_cached++;
159 } else {
160 i = hars_petruska_f54_1_random () % ARRAY_LENGTH (cache);
161 pixman_image_unref (cache[i].image);
163 cache[i].image = pixman_image_ref (image);
164 cache[i].color = pattern->color;
166 UNLOCK:
167 CAIRO_MUTEX_UNLOCK (_cairo_image_solid_cache_mutex);
168 +#endif
169 return image;
172 static double
173 clamp (double val, double min, double max)
175 return val < min ? min : (val > max ? max : val);
177 @@ -1423,25 +1429,27 @@ static pixman_image_t *
178 return _pixman_transparent_image ();
180 else
182 return _pixel_to_solid (source, sample.x, sample.y);
186 +#if PIXMAN_HAS_ATOMIC_OPS
187 /* avoid allocating a 'pattern' image if we can reuse the original */
188 if (extend == CAIRO_EXTEND_NONE &&
189 _cairo_matrix_is_translation (&pattern->base.matrix) &&
190 _nearest_sample (filter, &tx, &ty))
192 *ix = tx;
193 *iy = ty;
194 return pixman_image_ref (source->pixman_image);
196 +#endif
198 pixman_image = pixman_image_create_bits (source->pixman_format,
199 source->width,
200 source->height,
201 (uint32_t *) source->data,
202 source->stride);
203 if (unlikely (pixman_image == NULL))
204 return NULL;
205 @@ -1466,31 +1474,36 @@ static pixman_image_t *
206 sub->extents.x + sample.x,
207 sub->extents.y + sample.y);
208 } else {
209 if (extend == CAIRO_EXTEND_NONE)
210 return _pixman_transparent_image ();
214 +#if PIXMAN_HAS_ATOMIC_OPS
215 if (is_contained &&
216 _cairo_matrix_is_translation (&pattern->base.matrix) &&
217 _nearest_sample (filter, &tx, &ty))
219 *ix = tx + sub->extents.x;
220 *iy = ty + sub->extents.y;
221 return pixman_image_ref (source->pixman_image);
223 +#endif
225 /* Avoid sub-byte offsets, force a copy in that case. */
226 if (PIXMAN_FORMAT_BPP (source->pixman_format) >= 8) {
227 + void *data = source->data
228 + + sub->extents.x * PIXMAN_FORMAT_BPP(source->pixman_format)/8
229 + + sub->extents.y * source->stride;
230 pixman_image = pixman_image_create_bits (source->pixman_format,
231 sub->extents.width,
232 sub->extents.height,
233 - (uint32_t *) (source->data + sub->extents.x * PIXMAN_FORMAT_BPP(source->pixman_format)/8 + sub->extents.y * source->stride),
234 + data,
235 source->stride);
236 if (unlikely (pixman_image == NULL))
237 return NULL;
242 if (pixman_image == NULL) {