/src/cairo/src/cairo-image-compositor.c
Line | Count | Source |
1 | | /* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ |
2 | | /* cairo - a vector graphics library with display and print output |
3 | | * |
4 | | * Copyright © 2003 University of Southern California |
5 | | * Copyright © 2009,2010,2011 Intel Corporation |
6 | | * |
7 | | * This library is free software; you can redistribute it and/or |
8 | | * modify it either under the terms of the GNU Lesser General Public |
9 | | * License version 2.1 as published by the Free Software Foundation |
10 | | * (the "LGPL") or, at your option, under the terms of the Mozilla |
11 | | * Public License Version 1.1 (the "MPL"). If you do not alter this |
12 | | * notice, a recipient may use your version of this file under either |
13 | | * the MPL or the LGPL. |
14 | | * |
15 | | * You should have received a copy of the LGPL along with this library |
16 | | * in the file COPYING-LGPL-2.1; if not, write to the Free Software |
17 | | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA |
18 | | * You should have received a copy of the MPL along with this library |
19 | | * in the file COPYING-MPL-1.1 |
20 | | * |
21 | | * The contents of this file are subject to the Mozilla Public License |
22 | | * Version 1.1 (the "License"); you may not use this file except in |
23 | | * compliance with the License. You may obtain a copy of the License at |
24 | | * http://www.mozilla.org/MPL/ |
25 | | * |
26 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY |
27 | | * OF ANY KIND, either express or implied. See the LGPL or the MPL for |
28 | | * the specific language governing rights and limitations. |
29 | | * |
30 | | * The Original Code is the cairo graphics library. |
31 | | * |
32 | | * The Initial Developer of the Original Code is University of Southern |
33 | | * California. |
34 | | * |
35 | | * Contributor(s): |
36 | | * Carl D. Worth <cworth@cworth.org> |
37 | | * Chris Wilson <chris@chris-wilson.co.uk> |
38 | | */ |
39 | | |
40 | | /* The primarily reason for keeping a traps-compositor around is |
41 | | * for validating cairo-xlib (which currently also uses traps). |
42 | | */ |
43 | | |
44 | | #include "cairoint.h" |
45 | | |
46 | | #include "cairo-image-surface-private.h" |
47 | | |
48 | | #include "cairo-compositor-private.h" |
49 | | #include "cairo-spans-compositor-private.h" |
50 | | |
51 | | #include "cairo-region-private.h" |
52 | | #include "cairo-traps-private.h" |
53 | | #include "cairo-tristrip-private.h" |
54 | | |
55 | | #include "cairo-pixman-private.h" |
56 | | |
57 | | static pixman_image_t * |
58 | | to_pixman_image (cairo_surface_t *s) |
59 | 75.4k | { |
60 | 75.4k | return ((cairo_image_surface_t *)s)->pixman_image; |
61 | 75.4k | } |
62 | | |
63 | | static cairo_int_status_t |
64 | | acquire (void *abstract_dst) |
65 | 11 | { |
66 | 11 | return CAIRO_STATUS_SUCCESS; |
67 | 11 | } |
68 | | |
69 | | static cairo_int_status_t |
70 | | release (void *abstract_dst) |
71 | 11 | { |
72 | 11 | return CAIRO_STATUS_SUCCESS; |
73 | 11 | } |
74 | | |
75 | | static cairo_int_status_t |
76 | | set_clip_region (void *_surface, |
77 | | cairo_region_t *region) |
78 | 22 | { |
79 | 22 | cairo_image_surface_t *surface = _surface; |
80 | 22 | pixman_region32_t *rgn = region ? ®ion->rgn : NULL; |
81 | | |
82 | 22 | if (! pixman_image_set_clip_region32 (surface->pixman_image, rgn)) |
83 | 0 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
84 | | |
85 | 22 | return CAIRO_STATUS_SUCCESS; |
86 | 22 | } |
87 | | |
88 | | static cairo_int_status_t |
89 | | draw_image_boxes (void *_dst, |
90 | | cairo_image_surface_t *image, |
91 | | cairo_boxes_t *boxes, |
92 | | int dx, int dy) |
93 | 483 | { |
94 | 483 | cairo_image_surface_t *dst = _dst; |
95 | 483 | struct _cairo_boxes_chunk *chunk; |
96 | 483 | int i; |
97 | | |
98 | 483 | TRACE ((stderr, "%s x %d\n", __FUNCTION__, boxes->num_boxes)); |
99 | | |
100 | 966 | for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { |
101 | 966 | for (i = 0; i < chunk->count; i++) { |
102 | 483 | cairo_box_t *b = &chunk->base[i]; |
103 | 483 | int x = _cairo_fixed_integer_part (b->p1.x); |
104 | 483 | int y = _cairo_fixed_integer_part (b->p1.y); |
105 | 483 | int w = _cairo_fixed_integer_part (b->p2.x) - x; |
106 | 483 | int h = _cairo_fixed_integer_part (b->p2.y) - y; |
107 | 483 | if (dst->pixman_format != image->pixman_format || |
108 | 483 | ! pixman_blt ((uint32_t *)image->data, (uint32_t *)dst->data, |
109 | 483 | image->stride / sizeof (uint32_t), |
110 | 483 | dst->stride / sizeof (uint32_t), |
111 | 483 | PIXMAN_FORMAT_BPP (image->pixman_format), |
112 | 483 | PIXMAN_FORMAT_BPP (dst->pixman_format), |
113 | 483 | x + dx, y + dy, |
114 | 483 | x, y, |
115 | 483 | w, h)) |
116 | 0 | { |
117 | 0 | pixman_image_composite32 (PIXMAN_OP_SRC, |
118 | 0 | image->pixman_image, NULL, dst->pixman_image, |
119 | 0 | x + dx, y + dy, |
120 | 0 | 0, 0, |
121 | 0 | x, y, |
122 | 0 | w, h); |
123 | 0 | } |
124 | 483 | } |
125 | 483 | } |
126 | 483 | return CAIRO_STATUS_SUCCESS; |
127 | 483 | } |
128 | | |
129 | | static inline uint32_t |
130 | | color_to_uint32 (const cairo_color_t *color) |
131 | 161k | { |
132 | 161k | return |
133 | 161k | ((uint32_t)color->alpha_short >> 8 << 24) | |
134 | 161k | (color->red_short >> 8 << 16) | |
135 | 161k | (color->green_short & 0xff00) | |
136 | 161k | (color->blue_short >> 8); |
137 | 161k | } |
138 | | |
139 | | static inline cairo_bool_t |
140 | | color_to_pixel (const cairo_color_t *color, |
141 | | pixman_format_code_t format, |
142 | | uint32_t *pixel) |
143 | 161k | { |
144 | 161k | uint32_t c; |
145 | | |
146 | 161k | if (!(format == PIXMAN_a8r8g8b8 || |
147 | 48.4k | format == PIXMAN_x8r8g8b8 || |
148 | 0 | format == PIXMAN_a8b8g8r8 || |
149 | 0 | format == PIXMAN_x8b8g8r8 || |
150 | 0 | format == PIXMAN_b8g8r8a8 || |
151 | 0 | format == PIXMAN_b8g8r8x8 || |
152 | 0 | format == PIXMAN_r5g6b5 || |
153 | 0 | format == PIXMAN_b5g6r5 || |
154 | 0 | format == PIXMAN_a8)) |
155 | 0 | { |
156 | 0 | return FALSE; |
157 | 0 | } |
158 | | |
159 | 161k | c = color_to_uint32 (color); |
160 | | |
161 | 161k | if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_ABGR) { |
162 | 0 | c = ((c & 0xff000000) >> 0) | |
163 | 0 | ((c & 0x00ff0000) >> 16) | |
164 | 0 | ((c & 0x0000ff00) >> 0) | |
165 | 0 | ((c & 0x000000ff) << 16); |
166 | 0 | } |
167 | | |
168 | 161k | if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_BGRA) { |
169 | 0 | c = ((c & 0xff000000) >> 24) | |
170 | 0 | ((c & 0x00ff0000) >> 8) | |
171 | 0 | ((c & 0x0000ff00) << 8) | |
172 | 0 | ((c & 0x000000ff) << 24); |
173 | 0 | } |
174 | | |
175 | 161k | if (format == PIXMAN_a8) { |
176 | 0 | c = c >> 24; |
177 | 161k | } else if (format == PIXMAN_r5g6b5 || format == PIXMAN_b5g6r5) { |
178 | 0 | c = ((((c) >> 3) & 0x001f) | |
179 | 0 | (((c) >> 5) & 0x07e0) | |
180 | 0 | (((c) >> 8) & 0xf800)); |
181 | 0 | } |
182 | | |
183 | 161k | *pixel = c; |
184 | 161k | return TRUE; |
185 | 161k | } |
186 | | |
187 | | static pixman_op_t |
188 | | _pixman_operator (cairo_operator_t op) |
189 | 273k | { |
190 | 273k | switch ((int) op) { |
191 | 0 | case CAIRO_OPERATOR_CLEAR: |
192 | 0 | return PIXMAN_OP_CLEAR; |
193 | | |
194 | 0 | case CAIRO_OPERATOR_SOURCE: |
195 | 0 | return PIXMAN_OP_SRC; |
196 | 273k | case CAIRO_OPERATOR_OVER: |
197 | 273k | return PIXMAN_OP_OVER; |
198 | 0 | case CAIRO_OPERATOR_IN: |
199 | 0 | return PIXMAN_OP_IN; |
200 | 0 | case CAIRO_OPERATOR_OUT: |
201 | 0 | return PIXMAN_OP_OUT; |
202 | 0 | case CAIRO_OPERATOR_ATOP: |
203 | 0 | return PIXMAN_OP_ATOP; |
204 | | |
205 | 0 | case CAIRO_OPERATOR_DEST: |
206 | 0 | return PIXMAN_OP_DST; |
207 | 0 | case CAIRO_OPERATOR_DEST_OVER: |
208 | 0 | return PIXMAN_OP_OVER_REVERSE; |
209 | 0 | case CAIRO_OPERATOR_DEST_IN: |
210 | 0 | return PIXMAN_OP_IN_REVERSE; |
211 | 0 | case CAIRO_OPERATOR_DEST_OUT: |
212 | 0 | return PIXMAN_OP_OUT_REVERSE; |
213 | 0 | case CAIRO_OPERATOR_DEST_ATOP: |
214 | 0 | return PIXMAN_OP_ATOP_REVERSE; |
215 | | |
216 | 0 | case CAIRO_OPERATOR_XOR: |
217 | 0 | return PIXMAN_OP_XOR; |
218 | 0 | case CAIRO_OPERATOR_ADD: |
219 | 0 | return PIXMAN_OP_ADD; |
220 | 0 | case CAIRO_OPERATOR_SATURATE: |
221 | 0 | return PIXMAN_OP_SATURATE; |
222 | | |
223 | 0 | case CAIRO_OPERATOR_MULTIPLY: |
224 | 0 | return PIXMAN_OP_MULTIPLY; |
225 | 0 | case CAIRO_OPERATOR_SCREEN: |
226 | 0 | return PIXMAN_OP_SCREEN; |
227 | 0 | case CAIRO_OPERATOR_OVERLAY: |
228 | 0 | return PIXMAN_OP_OVERLAY; |
229 | 0 | case CAIRO_OPERATOR_DARKEN: |
230 | 0 | return PIXMAN_OP_DARKEN; |
231 | 0 | case CAIRO_OPERATOR_LIGHTEN: |
232 | 0 | return PIXMAN_OP_LIGHTEN; |
233 | 0 | case CAIRO_OPERATOR_COLOR_DODGE: |
234 | 0 | return PIXMAN_OP_COLOR_DODGE; |
235 | 0 | case CAIRO_OPERATOR_COLOR_BURN: |
236 | 0 | return PIXMAN_OP_COLOR_BURN; |
237 | 0 | case CAIRO_OPERATOR_HARD_LIGHT: |
238 | 0 | return PIXMAN_OP_HARD_LIGHT; |
239 | 0 | case CAIRO_OPERATOR_SOFT_LIGHT: |
240 | 0 | return PIXMAN_OP_SOFT_LIGHT; |
241 | 0 | case CAIRO_OPERATOR_DIFFERENCE: |
242 | 0 | return PIXMAN_OP_DIFFERENCE; |
243 | 0 | case CAIRO_OPERATOR_EXCLUSION: |
244 | 0 | return PIXMAN_OP_EXCLUSION; |
245 | 0 | case CAIRO_OPERATOR_HSL_HUE: |
246 | 0 | return PIXMAN_OP_HSL_HUE; |
247 | 0 | case CAIRO_OPERATOR_HSL_SATURATION: |
248 | 0 | return PIXMAN_OP_HSL_SATURATION; |
249 | 0 | case CAIRO_OPERATOR_HSL_COLOR: |
250 | 0 | return PIXMAN_OP_HSL_COLOR; |
251 | 0 | case CAIRO_OPERATOR_HSL_LUMINOSITY: |
252 | 0 | return PIXMAN_OP_HSL_LUMINOSITY; |
253 | | |
254 | 0 | default: |
255 | 0 | ASSERT_NOT_REACHED; |
256 | 0 | return PIXMAN_OP_OVER; |
257 | 273k | } |
258 | 273k | } |
259 | | |
260 | | static cairo_bool_t |
261 | | __fill_reduces_to_source (cairo_operator_t op, |
262 | | const cairo_color_t *color, |
263 | | const cairo_image_surface_t *dst) |
264 | 366k | { |
265 | 366k | if (op == CAIRO_OPERATOR_SOURCE || op == CAIRO_OPERATOR_CLEAR) |
266 | 54.9k | return TRUE; |
267 | 311k | if (op == CAIRO_OPERATOR_OVER && CAIRO_COLOR_IS_OPAQUE (color)) |
268 | 84.3k | return TRUE; |
269 | 227k | if (dst->base.is_clear) |
270 | 22.2k | return op == CAIRO_OPERATOR_OVER || op == CAIRO_OPERATOR_ADD; |
271 | | |
272 | 205k | return FALSE; |
273 | 227k | } |
274 | | |
275 | | static cairo_bool_t |
276 | | fill_reduces_to_source (cairo_operator_t op, |
277 | | const cairo_color_t *color, |
278 | | const cairo_image_surface_t *dst, |
279 | | uint32_t *pixel) |
280 | 366k | { |
281 | 366k | if (__fill_reduces_to_source (op, color, dst)) { |
282 | 161k | return color_to_pixel (color, dst->pixman_format, pixel); |
283 | 161k | } |
284 | | |
285 | 205k | return FALSE; |
286 | 366k | } |
287 | | |
288 | | static cairo_int_status_t |
289 | | fill_rectangles (void *_dst, |
290 | | cairo_operator_t op, |
291 | | const cairo_color_t *color, |
292 | | cairo_rectangle_int_t *rects, |
293 | | int num_rects) |
294 | 0 | { |
295 | 0 | cairo_image_surface_t *dst = _dst; |
296 | 0 | uint32_t pixel; |
297 | 0 | int i; |
298 | |
|
299 | 0 | TRACE ((stderr, "%s\n", __FUNCTION__)); |
300 | |
|
301 | 0 | if (fill_reduces_to_source (op, color, dst, &pixel)) { |
302 | 0 | for (i = 0; i < num_rects; i++) { |
303 | 0 | pixman_fill ((uint32_t *) dst->data, dst->stride / sizeof (uint32_t), |
304 | 0 | PIXMAN_FORMAT_BPP (dst->pixman_format), |
305 | 0 | rects[i].x, rects[i].y, |
306 | 0 | rects[i].width, rects[i].height, |
307 | 0 | pixel); |
308 | 0 | } |
309 | 0 | } else { |
310 | 0 | pixman_image_t *src = _pixman_image_for_color (color); |
311 | 0 | if (unlikely (src == NULL)) |
312 | 0 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
313 | | |
314 | 0 | op = _pixman_operator (op); |
315 | 0 | for (i = 0; i < num_rects; i++) { |
316 | 0 | pixman_image_composite32 (op, |
317 | 0 | src, NULL, dst->pixman_image, |
318 | 0 | 0, 0, |
319 | 0 | 0, 0, |
320 | 0 | rects[i].x, rects[i].y, |
321 | 0 | rects[i].width, rects[i].height); |
322 | 0 | } |
323 | |
|
324 | 0 | pixman_image_unref (src); |
325 | 0 | } |
326 | | |
327 | 0 | return CAIRO_STATUS_SUCCESS; |
328 | 0 | } |
329 | | |
330 | | static cairo_int_status_t |
331 | | fill_boxes (void *_dst, |
332 | | cairo_operator_t op, |
333 | | const cairo_color_t *color, |
334 | | cairo_boxes_t *boxes) |
335 | 55.4k | { |
336 | 55.4k | cairo_image_surface_t *dst = _dst; |
337 | 55.4k | struct _cairo_boxes_chunk *chunk; |
338 | 55.4k | uint32_t pixel; |
339 | 55.4k | int i; |
340 | | |
341 | 55.4k | TRACE ((stderr, "%s x %d\n", __FUNCTION__, boxes->num_boxes)); |
342 | | |
343 | 55.4k | if (fill_reduces_to_source (op, color, dst, &pixel)) { |
344 | 109k | for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { |
345 | 109k | for (i = 0; i < chunk->count; i++) { |
346 | 55.0k | int x = _cairo_fixed_integer_part (chunk->base[i].p1.x); |
347 | 55.0k | int y = _cairo_fixed_integer_part (chunk->base[i].p1.y); |
348 | 55.0k | int w = _cairo_fixed_integer_part (chunk->base[i].p2.x) - x; |
349 | 55.0k | int h = _cairo_fixed_integer_part (chunk->base[i].p2.y) - y; |
350 | 55.0k | pixman_fill ((uint32_t *) dst->data, |
351 | 55.0k | dst->stride / sizeof (uint32_t), |
352 | 55.0k | PIXMAN_FORMAT_BPP (dst->pixman_format), |
353 | 55.0k | x, y, w, h, pixel); |
354 | 55.0k | } |
355 | 54.9k | } |
356 | 54.9k | } |
357 | 507 | else |
358 | 507 | { |
359 | 507 | pixman_image_t *src = _pixman_image_for_color (color); |
360 | 507 | if (unlikely (src == NULL)) |
361 | 0 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
362 | | |
363 | 507 | op = _pixman_operator (op); |
364 | 1.01k | for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { |
365 | 1.09k | for (i = 0; i < chunk->count; i++) { |
366 | 585 | int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); |
367 | 585 | int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); |
368 | 585 | int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); |
369 | 585 | int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); |
370 | 585 | pixman_image_composite32 (op, |
371 | 585 | src, NULL, dst->pixman_image, |
372 | 585 | 0, 0, |
373 | 585 | 0, 0, |
374 | 585 | x1, y1, |
375 | 585 | x2-x1, y2-y1); |
376 | 585 | } |
377 | 507 | } |
378 | | |
379 | 507 | pixman_image_unref (src); |
380 | 507 | } |
381 | | |
382 | 55.4k | return CAIRO_STATUS_SUCCESS; |
383 | 55.4k | } |
384 | | |
385 | | static cairo_int_status_t |
386 | | composite (void *_dst, |
387 | | cairo_operator_t op, |
388 | | cairo_surface_t *abstract_src, |
389 | | cairo_surface_t *abstract_mask, |
390 | | int src_x, |
391 | | int src_y, |
392 | | int mask_x, |
393 | | int mask_y, |
394 | | int dst_x, |
395 | | int dst_y, |
396 | | unsigned int width, |
397 | | unsigned int height) |
398 | 0 | { |
399 | 0 | cairo_image_source_t *src = (cairo_image_source_t *)abstract_src; |
400 | 0 | cairo_image_source_t *mask = (cairo_image_source_t *)abstract_mask; |
401 | |
|
402 | 0 | TRACE ((stderr, "%s\n", __FUNCTION__)); |
403 | |
|
404 | 0 | if (mask) { |
405 | 0 | pixman_image_composite32 (_pixman_operator (op), |
406 | 0 | src->pixman_image, mask->pixman_image, to_pixman_image (_dst), |
407 | 0 | src_x, src_y, |
408 | 0 | mask_x, mask_y, |
409 | 0 | dst_x, dst_y, |
410 | 0 | width, height); |
411 | 0 | } else { |
412 | 0 | pixman_image_composite32 (_pixman_operator (op), |
413 | 0 | src->pixman_image, NULL, to_pixman_image (_dst), |
414 | 0 | src_x, src_y, |
415 | 0 | 0, 0, |
416 | 0 | dst_x, dst_y, |
417 | 0 | width, height); |
418 | 0 | } |
419 | |
|
420 | 0 | return CAIRO_STATUS_SUCCESS; |
421 | 0 | } |
422 | | |
423 | | static cairo_int_status_t |
424 | | lerp (void *_dst, |
425 | | cairo_surface_t *abstract_src, |
426 | | cairo_surface_t *abstract_mask, |
427 | | int src_x, |
428 | | int src_y, |
429 | | int mask_x, |
430 | | int mask_y, |
431 | | int dst_x, |
432 | | int dst_y, |
433 | | unsigned int width, |
434 | | unsigned int height) |
435 | 0 | { |
436 | 0 | cairo_image_surface_t *dst = _dst; |
437 | 0 | cairo_image_source_t *src = (cairo_image_source_t *)abstract_src; |
438 | 0 | cairo_image_source_t *mask = (cairo_image_source_t *)abstract_mask; |
439 | |
|
440 | 0 | TRACE ((stderr, "%s\n", __FUNCTION__)); |
441 | |
|
442 | | #if PIXMAN_HAS_OP_LERP |
443 | | pixman_image_composite32 (PIXMAN_OP_LERP_SRC, |
444 | | src->pixman_image, mask->pixman_image, dst->pixman_image, |
445 | | src_x, src_y, |
446 | | mask_x, mask_y, |
447 | | dst_x, dst_y, |
448 | | width, height); |
449 | | #else |
450 | | /* Punch the clip out of the destination */ |
451 | 0 | TRACE ((stderr, "%s - OUT_REVERSE (mask=%d/%p, dst=%d/%p)\n", |
452 | 0 | __FUNCTION__, |
453 | 0 | mask->base.unique_id, mask->pixman_image, |
454 | 0 | dst->base.unique_id, dst->pixman_image)); |
455 | 0 | pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, |
456 | 0 | mask->pixman_image, NULL, dst->pixman_image, |
457 | 0 | mask_x, mask_y, |
458 | 0 | 0, 0, |
459 | 0 | dst_x, dst_y, |
460 | 0 | width, height); |
461 | | |
462 | | /* Now add the two results together */ |
463 | 0 | TRACE ((stderr, "%s - ADD (src=%d/%p, mask=%d/%p, dst=%d/%p)\n", |
464 | 0 | __FUNCTION__, |
465 | 0 | src->base.unique_id, src->pixman_image, |
466 | 0 | mask->base.unique_id, mask->pixman_image, |
467 | 0 | dst->base.unique_id, dst->pixman_image)); |
468 | 0 | pixman_image_composite32 (PIXMAN_OP_ADD, |
469 | 0 | src->pixman_image, mask->pixman_image, dst->pixman_image, |
470 | 0 | src_x, src_y, |
471 | 0 | mask_x, mask_y, |
472 | 0 | dst_x, dst_y, |
473 | 0 | width, height); |
474 | 0 | #endif |
475 | |
|
476 | 0 | return CAIRO_STATUS_SUCCESS; |
477 | 0 | } |
478 | | |
479 | | static cairo_int_status_t |
480 | | composite_boxes (void *_dst, |
481 | | cairo_operator_t op, |
482 | | cairo_surface_t *abstract_src, |
483 | | cairo_surface_t *abstract_mask, |
484 | | int src_x, |
485 | | int src_y, |
486 | | int mask_x, |
487 | | int mask_y, |
488 | | int dst_x, |
489 | | int dst_y, |
490 | | cairo_boxes_t *boxes, |
491 | | const cairo_rectangle_int_t *extents) |
492 | 75.4k | { |
493 | 75.4k | pixman_image_t *dst = to_pixman_image (_dst); |
494 | 75.4k | pixman_image_t *src = ((cairo_image_source_t *)abstract_src)->pixman_image; |
495 | 75.4k | pixman_image_t *mask = abstract_mask ? ((cairo_image_source_t *)abstract_mask)->pixman_image : NULL; |
496 | 75.4k | pixman_image_t *free_src = NULL; |
497 | 75.4k | struct _cairo_boxes_chunk *chunk; |
498 | 75.4k | int i; |
499 | | |
500 | | /* XXX consider using a region? saves multiple prepare-composite */ |
501 | 75.4k | TRACE ((stderr, "%s x %d\n", __FUNCTION__, boxes->num_boxes)); |
502 | | |
503 | 75.4k | if (((cairo_surface_t *)_dst)->is_clear && |
504 | 15.1k | (op == CAIRO_OPERATOR_SOURCE || |
505 | 15.1k | op == CAIRO_OPERATOR_OVER || |
506 | 15.1k | op == CAIRO_OPERATOR_ADD)) { |
507 | 15.1k | op = PIXMAN_OP_SRC; |
508 | 60.3k | } else if (mask) { |
509 | 9.49k | if (op == CAIRO_OPERATOR_CLEAR) { |
510 | | #if PIXMAN_HAS_OP_LERP |
511 | | op = PIXMAN_OP_LERP_CLEAR; |
512 | | #else |
513 | 0 | free_src = src = _pixman_image_for_color (CAIRO_COLOR_WHITE); |
514 | 0 | if (unlikely (src == NULL)) |
515 | 0 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
516 | 0 | op = PIXMAN_OP_OUT_REVERSE; |
517 | 0 | #endif |
518 | 9.49k | } else if (op == CAIRO_OPERATOR_SOURCE) { |
519 | | #if PIXMAN_HAS_OP_LERP |
520 | | op = PIXMAN_OP_LERP_SRC; |
521 | | #else |
522 | 0 | return CAIRO_INT_STATUS_UNSUPPORTED; |
523 | 0 | #endif |
524 | 9.49k | } else { |
525 | 9.49k | op = _pixman_operator (op); |
526 | 9.49k | } |
527 | 50.8k | } else { |
528 | 50.8k | op = _pixman_operator (op); |
529 | 50.8k | } |
530 | | |
531 | 150k | for (chunk = &boxes->chunks; chunk; chunk = chunk->next) { |
532 | 150k | for (i = 0; i < chunk->count; i++) { |
533 | 75.4k | int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x); |
534 | 75.4k | int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y); |
535 | 75.4k | int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x); |
536 | 75.4k | int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y); |
537 | | |
538 | 75.4k | pixman_image_composite32 (op, src, mask, dst, |
539 | 75.4k | x1 + src_x, y1 + src_y, |
540 | 75.4k | x1 + mask_x, y1 + mask_y, |
541 | 75.4k | x1 + dst_x, y1 + dst_y, |
542 | 75.4k | x2 - x1, y2 - y1); |
543 | 75.4k | } |
544 | 75.4k | } |
545 | | |
546 | 75.4k | if (free_src) |
547 | 0 | pixman_image_unref (free_src); |
548 | | |
549 | 75.4k | return CAIRO_STATUS_SUCCESS; |
550 | 75.4k | } |
551 | | |
552 | 0 | #define CAIRO_FIXED_16_16_MIN _cairo_fixed_from_int (-32768) |
553 | 0 | #define CAIRO_FIXED_16_16_MAX _cairo_fixed_from_int (32767) |
554 | | |
555 | | static cairo_bool_t |
556 | | line_exceeds_16_16 (const cairo_line_t *line) |
557 | 0 | { |
558 | 0 | return |
559 | 0 | line->p1.x <= CAIRO_FIXED_16_16_MIN || |
560 | 0 | line->p1.x >= CAIRO_FIXED_16_16_MAX || |
561 | | |
562 | 0 | line->p2.x <= CAIRO_FIXED_16_16_MIN || |
563 | 0 | line->p2.x >= CAIRO_FIXED_16_16_MAX || |
564 | | |
565 | 0 | line->p1.y <= CAIRO_FIXED_16_16_MIN || |
566 | 0 | line->p1.y >= CAIRO_FIXED_16_16_MAX || |
567 | | |
568 | 0 | line->p2.y <= CAIRO_FIXED_16_16_MIN || |
569 | 0 | line->p2.y >= CAIRO_FIXED_16_16_MAX; |
570 | 0 | } |
571 | | |
572 | | static void |
573 | | project_line_x_onto_16_16 (const cairo_line_t *line, |
574 | | cairo_fixed_t top, |
575 | | cairo_fixed_t bottom, |
576 | | pixman_line_fixed_t *out) |
577 | 0 | { |
578 | | /* XXX use fixed-point arithmetic? */ |
579 | 0 | cairo_point_double_t p1, p2; |
580 | 0 | double m; |
581 | |
|
582 | 0 | p1.x = _cairo_fixed_to_double (line->p1.x); |
583 | 0 | p1.y = _cairo_fixed_to_double (line->p1.y); |
584 | |
|
585 | 0 | p2.x = _cairo_fixed_to_double (line->p2.x); |
586 | 0 | p2.y = _cairo_fixed_to_double (line->p2.y); |
587 | |
|
588 | 0 | m = (p2.x - p1.x) / (p2.y - p1.y); |
589 | 0 | out->p1.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (top - line->p1.y)); |
590 | 0 | out->p2.x = _cairo_fixed_16_16_from_double (p1.x + m * _cairo_fixed_to_double (bottom - line->p1.y)); |
591 | 0 | } |
592 | | |
593 | | void |
594 | | _pixman_image_add_traps (pixman_image_t *image, |
595 | | int dst_x, int dst_y, |
596 | | cairo_traps_t *traps) |
597 | 0 | { |
598 | 0 | cairo_trapezoid_t *t = traps->traps; |
599 | 0 | int num_traps = traps->num_traps; |
600 | 0 | while (num_traps--) { |
601 | 0 | pixman_trapezoid_t trap; |
602 | | |
603 | | /* top/bottom will be clamped to surface bounds */ |
604 | 0 | trap.top = _cairo_fixed_to_16_16 (t->top); |
605 | 0 | trap.bottom = _cairo_fixed_to_16_16 (t->bottom); |
606 | | |
607 | | /* However, all the other coordinates will have been left untouched so |
608 | | * as not to introduce numerical error. Recompute them if they |
609 | | * exceed the 16.16 limits. |
610 | | */ |
611 | 0 | if (unlikely (line_exceeds_16_16 (&t->left))) { |
612 | 0 | project_line_x_onto_16_16 (&t->left, t->top, t->bottom, &trap.left); |
613 | 0 | trap.left.p1.y = trap.top; |
614 | 0 | trap.left.p2.y = trap.bottom; |
615 | 0 | } else { |
616 | 0 | trap.left.p1.x = _cairo_fixed_to_16_16 (t->left.p1.x); |
617 | 0 | trap.left.p1.y = _cairo_fixed_to_16_16 (t->left.p1.y); |
618 | 0 | trap.left.p2.x = _cairo_fixed_to_16_16 (t->left.p2.x); |
619 | 0 | trap.left.p2.y = _cairo_fixed_to_16_16 (t->left.p2.y); |
620 | 0 | } |
621 | |
|
622 | 0 | if (unlikely (line_exceeds_16_16 (&t->right))) { |
623 | 0 | project_line_x_onto_16_16 (&t->right, t->top, t->bottom, &trap.right); |
624 | 0 | trap.right.p1.y = trap.top; |
625 | 0 | trap.right.p2.y = trap.bottom; |
626 | 0 | } else { |
627 | 0 | trap.right.p1.x = _cairo_fixed_to_16_16 (t->right.p1.x); |
628 | 0 | trap.right.p1.y = _cairo_fixed_to_16_16 (t->right.p1.y); |
629 | 0 | trap.right.p2.x = _cairo_fixed_to_16_16 (t->right.p2.x); |
630 | 0 | trap.right.p2.y = _cairo_fixed_to_16_16 (t->right.p2.y); |
631 | 0 | } |
632 | |
|
633 | 0 | pixman_rasterize_trapezoid (image, &trap, -dst_x, -dst_y); |
634 | 0 | t++; |
635 | 0 | } |
636 | 0 | } |
637 | | |
638 | | static cairo_int_status_t |
639 | | composite_traps (void *_dst, |
640 | | cairo_operator_t op, |
641 | | cairo_surface_t *abstract_src, |
642 | | int src_x, |
643 | | int src_y, |
644 | | int dst_x, |
645 | | int dst_y, |
646 | | const cairo_rectangle_int_t *extents, |
647 | | cairo_antialias_t antialias, |
648 | | cairo_traps_t *traps) |
649 | 0 | { |
650 | 0 | cairo_image_surface_t *dst = (cairo_image_surface_t *) _dst; |
651 | 0 | cairo_image_source_t *src = (cairo_image_source_t *) abstract_src; |
652 | 0 | cairo_int_status_t status; |
653 | 0 | pixman_image_t *mask; |
654 | 0 | pixman_format_code_t format; |
655 | |
|
656 | 0 | TRACE ((stderr, "%s\n", __FUNCTION__)); |
657 | | |
658 | | /* pixman doesn't eliminate self-intersecting trapezoids/edges */ |
659 | 0 | status = _cairo_bentley_ottmann_tessellate_traps (traps, |
660 | 0 | CAIRO_FILL_RULE_WINDING); |
661 | 0 | if (status != CAIRO_INT_STATUS_SUCCESS) |
662 | 0 | return status; |
663 | | |
664 | | /* Special case adding trapezoids onto a mask surface; we want to avoid |
665 | | * creating an intermediate temporary mask unnecessarily. |
666 | | * |
667 | | * We make the assumption here that the portion of the trapezoids |
668 | | * contained within the surface is bounded by [dst_x,dst_y,width,height]; |
669 | | * the Cairo core code passes bounds based on the trapezoid extents. |
670 | | */ |
671 | 0 | format = antialias == CAIRO_ANTIALIAS_NONE ? PIXMAN_a1 : PIXMAN_a8; |
672 | 0 | if (dst->pixman_format == format && |
673 | 0 | (abstract_src == NULL || |
674 | 0 | (op == CAIRO_OPERATOR_ADD && src->is_opaque_solid))) |
675 | 0 | { |
676 | 0 | _pixman_image_add_traps (dst->pixman_image, dst_x, dst_y, traps); |
677 | 0 | return CAIRO_STATUS_SUCCESS; |
678 | 0 | } |
679 | | |
680 | 0 | mask = pixman_image_create_bits (format, |
681 | 0 | extents->width, extents->height, |
682 | 0 | NULL, 0); |
683 | 0 | if (unlikely (mask == NULL)) |
684 | 0 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
685 | | |
686 | 0 | _pixman_image_add_traps (mask, extents->x, extents->y, traps); |
687 | 0 | pixman_image_composite32 (_pixman_operator (op), |
688 | 0 | src->pixman_image, mask, dst->pixman_image, |
689 | 0 | extents->x + src_x, extents->y + src_y, |
690 | 0 | 0, 0, |
691 | 0 | extents->x - dst_x, extents->y - dst_y, |
692 | 0 | extents->width, extents->height); |
693 | |
|
694 | 0 | pixman_image_unref (mask); |
695 | |
|
696 | 0 | return CAIRO_STATUS_SUCCESS; |
697 | 0 | } |
698 | | |
699 | | static void |
700 | | set_point (pixman_point_fixed_t *p, cairo_point_t *c) |
701 | 0 | { |
702 | 0 | p->x = _cairo_fixed_to_16_16 (c->x); |
703 | 0 | p->y = _cairo_fixed_to_16_16 (c->y); |
704 | 0 | } |
705 | | |
706 | | void |
707 | | _pixman_image_add_tristrip (pixman_image_t *image, |
708 | | int dst_x, int dst_y, |
709 | | cairo_tristrip_t *strip) |
710 | 0 | { |
711 | 0 | pixman_triangle_t tri; |
712 | 0 | pixman_point_fixed_t *p[3] = {&tri.p1, &tri.p2, &tri.p3 }; |
713 | 0 | int n; |
714 | |
|
715 | 0 | set_point (p[0], &strip->points[0]); |
716 | 0 | set_point (p[1], &strip->points[1]); |
717 | 0 | set_point (p[2], &strip->points[2]); |
718 | 0 | pixman_add_triangles (image, -dst_x, -dst_y, 1, &tri); |
719 | 0 | for (n = 3; n < strip->num_points; n++) { |
720 | 0 | set_point (p[n%3], &strip->points[n]); |
721 | 0 | pixman_add_triangles (image, -dst_x, -dst_y, 1, &tri); |
722 | 0 | } |
723 | 0 | } |
724 | | |
725 | | static cairo_int_status_t |
726 | | composite_tristrip (void *_dst, |
727 | | cairo_operator_t op, |
728 | | cairo_surface_t *abstract_src, |
729 | | int src_x, |
730 | | int src_y, |
731 | | int dst_x, |
732 | | int dst_y, |
733 | | const cairo_rectangle_int_t *extents, |
734 | | cairo_antialias_t antialias, |
735 | | cairo_tristrip_t *strip) |
736 | 0 | { |
737 | 0 | cairo_image_surface_t *dst = (cairo_image_surface_t *) _dst; |
738 | 0 | cairo_image_source_t *src = (cairo_image_source_t *) abstract_src; |
739 | 0 | pixman_image_t *mask; |
740 | 0 | pixman_format_code_t format; |
741 | |
|
742 | 0 | TRACE ((stderr, "%s\n", __FUNCTION__)); |
743 | |
|
744 | 0 | if (strip->num_points < 3) |
745 | 0 | return CAIRO_STATUS_SUCCESS; |
746 | | |
747 | 0 | if (1) { /* pixman doesn't eliminate self-intersecting triangles/edges */ |
748 | 0 | cairo_int_status_t status; |
749 | 0 | cairo_traps_t traps; |
750 | 0 | int n; |
751 | |
|
752 | 0 | _cairo_traps_init (&traps); |
753 | 0 | for (n = 0; n < strip->num_points; n++) { |
754 | 0 | cairo_point_t p[4]; |
755 | |
|
756 | 0 | p[0] = strip->points[0]; |
757 | 0 | p[1] = strip->points[1]; |
758 | 0 | p[2] = strip->points[2]; |
759 | 0 | p[3] = strip->points[0]; |
760 | |
|
761 | 0 | _cairo_traps_tessellate_convex_quad (&traps, p); |
762 | 0 | } |
763 | 0 | status = composite_traps (_dst, op, abstract_src, |
764 | 0 | src_x, src_y, |
765 | 0 | dst_x, dst_y, |
766 | 0 | extents, antialias, &traps); |
767 | 0 | _cairo_traps_fini (&traps); |
768 | |
|
769 | 0 | return status; |
770 | 0 | } |
771 | | |
772 | 0 | format = antialias == CAIRO_ANTIALIAS_NONE ? PIXMAN_a1 : PIXMAN_a8; |
773 | 0 | if (dst->pixman_format == format && |
774 | 0 | (abstract_src == NULL || |
775 | 0 | (op == CAIRO_OPERATOR_ADD && src->is_opaque_solid))) |
776 | 0 | { |
777 | 0 | _pixman_image_add_tristrip (dst->pixman_image, dst_x, dst_y, strip); |
778 | 0 | return CAIRO_STATUS_SUCCESS; |
779 | 0 | } |
780 | | |
781 | 0 | mask = pixman_image_create_bits (format, |
782 | 0 | extents->width, extents->height, |
783 | 0 | NULL, 0); |
784 | 0 | if (unlikely (mask == NULL)) |
785 | 0 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
786 | | |
787 | 0 | _pixman_image_add_tristrip (mask, extents->x, extents->y, strip); |
788 | 0 | pixman_image_composite32 (_pixman_operator (op), |
789 | 0 | src->pixman_image, mask, dst->pixman_image, |
790 | 0 | extents->x + src_x, extents->y + src_y, |
791 | 0 | 0, 0, |
792 | 0 | extents->x - dst_x, extents->y - dst_y, |
793 | 0 | extents->width, extents->height); |
794 | |
|
795 | 0 | pixman_image_unref (mask); |
796 | |
|
797 | 0 | return CAIRO_STATUS_SUCCESS; |
798 | 0 | } |
799 | | |
800 | | static cairo_int_status_t |
801 | | check_composite_glyphs (const cairo_composite_rectangles_t *extents, |
802 | | cairo_scaled_font_t *scaled_font, |
803 | | cairo_glyph_t *glyphs, |
804 | | int *num_glyphs) |
805 | 11 | { |
806 | 11 | return CAIRO_STATUS_SUCCESS; |
807 | 11 | } |
808 | | |
809 | | #if HAS_PIXMAN_GLYPHS |
810 | | static pixman_glyph_cache_t *global_glyph_cache; |
811 | | |
812 | | static inline pixman_glyph_cache_t * |
813 | | get_glyph_cache (void) |
814 | 11 | { |
815 | 11 | if (!global_glyph_cache) |
816 | 1 | global_glyph_cache = pixman_glyph_cache_create (); |
817 | | |
818 | 11 | return global_glyph_cache; |
819 | 11 | } |
820 | | |
821 | | void |
822 | | _cairo_image_compositor_reset_static_data (void) |
823 | 0 | { |
824 | 0 | CAIRO_MUTEX_LOCK (_cairo_glyph_cache_mutex); |
825 | |
|
826 | 0 | if (global_glyph_cache) |
827 | 0 | pixman_glyph_cache_destroy (global_glyph_cache); |
828 | 0 | global_glyph_cache = NULL; |
829 | |
|
830 | 0 | CAIRO_MUTEX_UNLOCK (_cairo_glyph_cache_mutex); |
831 | 0 | } |
832 | | |
833 | | void |
834 | | _cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font, |
835 | | cairo_scaled_glyph_t *scaled_glyph) |
836 | 0 | { |
837 | 0 | CAIRO_MUTEX_LOCK (_cairo_glyph_cache_mutex); |
838 | |
|
839 | 0 | if (global_glyph_cache) { |
840 | 0 | pixman_glyph_cache_remove ( |
841 | 0 | global_glyph_cache, scaled_font, |
842 | 0 | (void *)scaled_glyph->hash_entry.hash); |
843 | 0 | } |
844 | |
|
845 | 0 | CAIRO_MUTEX_UNLOCK (_cairo_glyph_cache_mutex); |
846 | 0 | } |
847 | | |
848 | 176 | #define PHASE(x) ((int)(floor (4 * (x + 0.125)) - 4 * floor (x + 0.125))) |
849 | 176 | #define POSITION(x) ((int) floor (x + 0.125)) |
850 | | |
851 | | static cairo_int_status_t |
852 | | composite_glyphs (void *_dst, |
853 | | cairo_operator_t op, |
854 | | cairo_surface_t *_src, |
855 | | int src_x, |
856 | | int src_y, |
857 | | int dst_x, |
858 | | int dst_y, |
859 | | cairo_composite_glyphs_info_t *info) |
860 | 11 | { |
861 | 11 | cairo_int_status_t status = CAIRO_INT_STATUS_SUCCESS; |
862 | 11 | pixman_glyph_cache_t *glyph_cache; |
863 | 11 | pixman_glyph_t pglyphs_stack[CAIRO_STACK_ARRAY_LENGTH (pixman_glyph_t)]; |
864 | 11 | pixman_glyph_t *pglyphs = pglyphs_stack; |
865 | 11 | pixman_glyph_t *pg; |
866 | 11 | int i; |
867 | | |
868 | 11 | TRACE ((stderr, "%s\n", __FUNCTION__)); |
869 | | |
870 | 11 | CAIRO_MUTEX_LOCK (_cairo_glyph_cache_mutex); |
871 | | |
872 | 11 | glyph_cache = get_glyph_cache(); |
873 | 11 | if (unlikely (glyph_cache == NULL)) { |
874 | 0 | status = _cairo_error (CAIRO_STATUS_NO_MEMORY); |
875 | 0 | goto out_unlock; |
876 | 0 | } |
877 | | |
878 | 11 | pixman_glyph_cache_freeze (glyph_cache); |
879 | | |
880 | 11 | if (info->num_glyphs > ARRAY_LENGTH (pglyphs_stack)) { |
881 | 0 | pglyphs = _cairo_malloc_ab (info->num_glyphs, sizeof (pixman_glyph_t)); |
882 | 0 | if (unlikely (pglyphs == NULL)) { |
883 | 0 | status = _cairo_error (CAIRO_STATUS_NO_MEMORY); |
884 | 0 | goto out_thaw; |
885 | 0 | } |
886 | 0 | } |
887 | | |
888 | 11 | pg = pglyphs; |
889 | 99 | for (i = 0; i < info->num_glyphs; i++) { |
890 | 88 | unsigned long index = info->glyphs[i].index; |
891 | 88 | const void *glyph; |
892 | 88 | unsigned long xphase, yphase; |
893 | | |
894 | 88 | xphase = PHASE(info->glyphs[i].x); |
895 | 88 | yphase = PHASE(info->glyphs[i].y); |
896 | | |
897 | 88 | index = index | (xphase << 24) | (yphase << 26); |
898 | | |
899 | 88 | glyph = pixman_glyph_cache_lookup (glyph_cache, info->font, (void *)(uintptr_t)index); |
900 | 88 | if (!glyph) { |
901 | 26 | cairo_scaled_glyph_t *scaled_glyph; |
902 | 26 | cairo_image_surface_t *glyph_surface; |
903 | | |
904 | | /* This call can actually end up recursing, so we have to |
905 | | * drop the mutex around it. |
906 | | */ |
907 | 26 | CAIRO_MUTEX_UNLOCK (_cairo_glyph_cache_mutex); |
908 | 26 | status = _cairo_scaled_glyph_lookup (info->font, index, |
909 | 26 | CAIRO_SCALED_GLYPH_INFO_SURFACE, |
910 | 26 | NULL, /* foreground color */ |
911 | 26 | &scaled_glyph); |
912 | 26 | CAIRO_MUTEX_LOCK (_cairo_glyph_cache_mutex); |
913 | | |
914 | 26 | if (unlikely (status)) |
915 | 0 | goto out_thaw; |
916 | | |
917 | 26 | glyph_surface = scaled_glyph->surface; |
918 | 26 | glyph = pixman_glyph_cache_insert (glyph_cache, info->font, (void *)(uintptr_t)index, |
919 | 26 | glyph_surface->base.device_transform.x0, |
920 | 26 | glyph_surface->base.device_transform.y0, |
921 | 26 | glyph_surface->pixman_image); |
922 | 26 | if (unlikely (!glyph)) { |
923 | 0 | status = _cairo_error (CAIRO_STATUS_NO_MEMORY); |
924 | 0 | goto out_thaw; |
925 | 0 | } |
926 | 26 | } |
927 | | |
928 | 88 | pg->x = POSITION (info->glyphs[i].x); |
929 | 88 | pg->y = POSITION (info->glyphs[i].y); |
930 | 88 | pg->glyph = glyph; |
931 | 88 | pg++; |
932 | 88 | } |
933 | | |
934 | 11 | if (info->use_mask) { |
935 | 11 | pixman_format_code_t mask_format; |
936 | | |
937 | 11 | mask_format = pixman_glyph_get_mask_format (glyph_cache, pg - pglyphs, pglyphs); |
938 | | |
939 | 11 | pixman_composite_glyphs (_pixman_operator (op), |
940 | 11 | ((cairo_image_source_t *)_src)->pixman_image, |
941 | 11 | to_pixman_image (_dst), |
942 | 11 | mask_format, |
943 | 11 | info->extents.x + src_x, info->extents.y + src_y, |
944 | 11 | info->extents.x, info->extents.y, |
945 | 11 | info->extents.x - dst_x, info->extents.y - dst_y, |
946 | 11 | info->extents.width, info->extents.height, |
947 | 11 | glyph_cache, pg - pglyphs, pglyphs); |
948 | 11 | } else { |
949 | 0 | pixman_composite_glyphs_no_mask (_pixman_operator (op), |
950 | 0 | ((cairo_image_source_t *)_src)->pixman_image, |
951 | 0 | to_pixman_image (_dst), |
952 | 0 | src_x, src_y, |
953 | 0 | - dst_x, - dst_y, |
954 | 0 | glyph_cache, pg - pglyphs, pglyphs); |
955 | 0 | } |
956 | | |
957 | 11 | out_thaw: |
958 | 11 | pixman_glyph_cache_thaw (glyph_cache); |
959 | | |
960 | 11 | if (pglyphs != pglyphs_stack) |
961 | 0 | free(pglyphs); |
962 | | |
963 | 11 | out_unlock: |
964 | 11 | CAIRO_MUTEX_UNLOCK (_cairo_glyph_cache_mutex); |
965 | 11 | return status; |
966 | 11 | } |
967 | | #else |
968 | | void |
969 | | _cairo_image_compositor_reset_static_data (void) |
970 | | { |
971 | | } |
972 | | |
973 | | void |
974 | | _cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font, |
975 | | cairo_scaled_glyph_t *scaled_glyph) |
976 | | { |
977 | | } |
978 | | |
979 | | static cairo_int_status_t |
980 | | composite_one_glyph (void *_dst, |
981 | | cairo_operator_t op, |
982 | | cairo_surface_t *_src, |
983 | | int src_x, |
984 | | int src_y, |
985 | | int dst_x, |
986 | | int dst_y, |
987 | | cairo_composite_glyphs_info_t *info) |
988 | | { |
989 | | cairo_image_surface_t *glyph_surface; |
990 | | cairo_scaled_glyph_t *scaled_glyph; |
991 | | cairo_status_t status; |
992 | | int x, y; |
993 | | |
994 | | TRACE ((stderr, "%s\n", __FUNCTION__)); |
995 | | |
996 | | status = _cairo_scaled_glyph_lookup (info->font, |
997 | | info->glyphs[0].index, |
998 | | CAIRO_SCALED_GLYPH_INFO_SURFACE, |
999 | | NULL, /* foreground color */ |
1000 | | &scaled_glyph); |
1001 | | |
1002 | | if (unlikely (status)) |
1003 | | return status; |
1004 | | |
1005 | | glyph_surface = scaled_glyph->surface; |
1006 | | if (glyph_surface->width == 0 || glyph_surface->height == 0) |
1007 | | return CAIRO_INT_STATUS_NOTHING_TO_DO; |
1008 | | |
1009 | | /* round glyph locations to the nearest pixel */ |
1010 | | /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ |
1011 | | x = _cairo_lround (info->glyphs[0].x - |
1012 | | glyph_surface->base.device_transform.x0); |
1013 | | y = _cairo_lround (info->glyphs[0].y - |
1014 | | glyph_surface->base.device_transform.y0); |
1015 | | |
1016 | | pixman_image_composite32 (_pixman_operator (op), |
1017 | | ((cairo_image_source_t *)_src)->pixman_image, |
1018 | | glyph_surface->pixman_image, |
1019 | | to_pixman_image (_dst), |
1020 | | x + src_x, y + src_y, |
1021 | | 0, 0, |
1022 | | x - dst_x, y - dst_y, |
1023 | | glyph_surface->width, |
1024 | | glyph_surface->height); |
1025 | | |
1026 | | return CAIRO_INT_STATUS_SUCCESS; |
1027 | | } |
1028 | | |
1029 | | static cairo_int_status_t |
1030 | | composite_glyphs_via_mask (void *_dst, |
1031 | | cairo_operator_t op, |
1032 | | cairo_surface_t *_src, |
1033 | | int src_x, |
1034 | | int src_y, |
1035 | | int dst_x, |
1036 | | int dst_y, |
1037 | | cairo_composite_glyphs_info_t *info) |
1038 | | { |
1039 | | cairo_scaled_glyph_t *glyph_cache[64]; |
1040 | | pixman_image_t *white = _pixman_image_for_color (CAIRO_COLOR_WHITE); |
1041 | | cairo_scaled_glyph_t *scaled_glyph; |
1042 | | uint8_t buf[2048]; |
1043 | | pixman_image_t *mask; |
1044 | | pixman_format_code_t format; |
1045 | | cairo_status_t status; |
1046 | | int i; |
1047 | | |
1048 | | TRACE ((stderr, "%s\n", __FUNCTION__)); |
1049 | | |
1050 | | if (unlikely (white == NULL)) |
1051 | | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
1052 | | |
1053 | | /* XXX convert the glyphs to common formats a8/a8r8g8b8 to hit |
1054 | | * optimised paths through pixman. Should we increase the bit |
1055 | | * depth of the target surface, we should reconsider the appropriate |
1056 | | * mask formats. |
1057 | | */ |
1058 | | |
1059 | | status = _cairo_scaled_glyph_lookup (info->font, |
1060 | | info->glyphs[0].index, |
1061 | | CAIRO_SCALED_GLYPH_INFO_SURFACE, |
1062 | | NULL, /* foreground color */ |
1063 | | &scaled_glyph); |
1064 | | if (unlikely (status)) { |
1065 | | pixman_image_unref (white); |
1066 | | return status; |
1067 | | } |
1068 | | |
1069 | | memset (glyph_cache, 0, sizeof (glyph_cache)); |
1070 | | glyph_cache[info->glyphs[0].index % ARRAY_LENGTH (glyph_cache)] = scaled_glyph; |
1071 | | |
1072 | | format = PIXMAN_a8; |
1073 | | i = (info->extents.width + 3) & ~3; |
1074 | | if (scaled_glyph->surface->base.content & CAIRO_CONTENT_COLOR) { |
1075 | | format = PIXMAN_a8r8g8b8; |
1076 | | i = info->extents.width * 4; |
1077 | | } |
1078 | | |
1079 | | if (i * info->extents.height > (int) sizeof (buf)) { |
1080 | | mask = pixman_image_create_bits (format, |
1081 | | info->extents.width, |
1082 | | info->extents.height, |
1083 | | NULL, 0); |
1084 | | } else { |
1085 | | memset (buf, 0, i * info->extents.height); |
1086 | | mask = pixman_image_create_bits (format, |
1087 | | info->extents.width, |
1088 | | info->extents.height, |
1089 | | (uint32_t *)buf, i); |
1090 | | } |
1091 | | if (unlikely (mask == NULL)) { |
1092 | | pixman_image_unref (white); |
1093 | | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
1094 | | } |
1095 | | |
1096 | | status = CAIRO_STATUS_SUCCESS; |
1097 | | for (i = 0; i < info->num_glyphs; i++) { |
1098 | | unsigned long glyph_index = info->glyphs[i].index; |
1099 | | int cache_index = glyph_index % ARRAY_LENGTH (glyph_cache); |
1100 | | cairo_image_surface_t *glyph_surface; |
1101 | | int x, y; |
1102 | | |
1103 | | scaled_glyph = glyph_cache[cache_index]; |
1104 | | if (scaled_glyph == NULL || |
1105 | | _cairo_scaled_glyph_index (scaled_glyph) != glyph_index) |
1106 | | { |
1107 | | status = _cairo_scaled_glyph_lookup (info->font, glyph_index, |
1108 | | CAIRO_SCALED_GLYPH_INFO_SURFACE, |
1109 | | NULL, /* foreground color */ |
1110 | | &scaled_glyph); |
1111 | | |
1112 | | if (unlikely (status)) { |
1113 | | pixman_image_unref (mask); |
1114 | | pixman_image_unref (white); |
1115 | | return status; |
1116 | | } |
1117 | | |
1118 | | glyph_cache[cache_index] = scaled_glyph; |
1119 | | } |
1120 | | |
1121 | | glyph_surface = scaled_glyph->surface; |
1122 | | if (glyph_surface->width && glyph_surface->height) { |
1123 | | if (glyph_surface->base.content & CAIRO_CONTENT_COLOR && |
1124 | | format == PIXMAN_a8) { |
1125 | | pixman_image_t *ca_mask; |
1126 | | |
1127 | | format = PIXMAN_a8r8g8b8; |
1128 | | ca_mask = pixman_image_create_bits (format, |
1129 | | info->extents.width, |
1130 | | info->extents.height, |
1131 | | NULL, 0); |
1132 | | if (unlikely (ca_mask == NULL)) { |
1133 | | pixman_image_unref (mask); |
1134 | | pixman_image_unref (white); |
1135 | | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
1136 | | } |
1137 | | |
1138 | | pixman_image_composite32 (PIXMAN_OP_SRC, |
1139 | | white, mask, ca_mask, |
1140 | | 0, 0, |
1141 | | 0, 0, |
1142 | | 0, 0, |
1143 | | info->extents.width, |
1144 | | info->extents.height); |
1145 | | pixman_image_unref (mask); |
1146 | | mask = ca_mask; |
1147 | | } |
1148 | | |
1149 | | /* round glyph locations to the nearest pixel */ |
1150 | | /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ |
1151 | | x = _cairo_lround (info->glyphs[i].x - |
1152 | | glyph_surface->base.device_transform.x0); |
1153 | | y = _cairo_lround (info->glyphs[i].y - |
1154 | | glyph_surface->base.device_transform.y0); |
1155 | | |
1156 | | if (glyph_surface->pixman_format == format) { |
1157 | | pixman_image_composite32 (PIXMAN_OP_ADD, |
1158 | | glyph_surface->pixman_image, NULL, mask, |
1159 | | 0, 0, |
1160 | | 0, 0, |
1161 | | x - info->extents.x, y - info->extents.y, |
1162 | | glyph_surface->width, |
1163 | | glyph_surface->height); |
1164 | | } else { |
1165 | | pixman_image_composite32 (PIXMAN_OP_ADD, |
1166 | | white, glyph_surface->pixman_image, mask, |
1167 | | 0, 0, |
1168 | | 0, 0, |
1169 | | x - info->extents.x, y - info->extents.y, |
1170 | | glyph_surface->width, |
1171 | | glyph_surface->height); |
1172 | | } |
1173 | | } |
1174 | | } |
1175 | | |
1176 | | if (format == PIXMAN_a8r8g8b8) |
1177 | | pixman_image_set_component_alpha (mask, TRUE); |
1178 | | |
1179 | | pixman_image_composite32 (_pixman_operator (op), |
1180 | | ((cairo_image_source_t *)_src)->pixman_image, |
1181 | | mask, |
1182 | | to_pixman_image (_dst), |
1183 | | info->extents.x + src_x, info->extents.y + src_y, |
1184 | | 0, 0, |
1185 | | info->extents.x - dst_x, info->extents.y - dst_y, |
1186 | | info->extents.width, info->extents.height); |
1187 | | pixman_image_unref (mask); |
1188 | | pixman_image_unref (white); |
1189 | | |
1190 | | return CAIRO_STATUS_SUCCESS; |
1191 | | } |
1192 | | |
1193 | | static cairo_int_status_t |
1194 | | composite_glyphs (void *_dst, |
1195 | | cairo_operator_t op, |
1196 | | cairo_surface_t *_src, |
1197 | | int src_x, |
1198 | | int src_y, |
1199 | | int dst_x, |
1200 | | int dst_y, |
1201 | | cairo_composite_glyphs_info_t *info) |
1202 | | { |
1203 | | cairo_scaled_glyph_t *glyph_cache[64]; |
1204 | | pixman_image_t *dst, *src; |
1205 | | cairo_status_t status; |
1206 | | int i; |
1207 | | |
1208 | | TRACE ((stderr, "%s\n", __FUNCTION__)); |
1209 | | |
1210 | | if (info->num_glyphs == 1) |
1211 | | return composite_one_glyph(_dst, op, _src, src_x, src_y, dst_x, dst_y, info); |
1212 | | |
1213 | | if (info->use_mask) |
1214 | | return composite_glyphs_via_mask(_dst, op, _src, src_x, src_y, dst_x, dst_y, info); |
1215 | | |
1216 | | op = _pixman_operator (op); |
1217 | | dst = to_pixman_image (_dst); |
1218 | | src = ((cairo_image_source_t *)_src)->pixman_image; |
1219 | | |
1220 | | memset (glyph_cache, 0, sizeof (glyph_cache)); |
1221 | | status = CAIRO_STATUS_SUCCESS; |
1222 | | |
1223 | | for (i = 0; i < info->num_glyphs; i++) { |
1224 | | int x, y; |
1225 | | cairo_image_surface_t *glyph_surface; |
1226 | | cairo_scaled_glyph_t *scaled_glyph; |
1227 | | unsigned long glyph_index = info->glyphs[i].index; |
1228 | | int cache_index = glyph_index % ARRAY_LENGTH (glyph_cache); |
1229 | | |
1230 | | scaled_glyph = glyph_cache[cache_index]; |
1231 | | if (scaled_glyph == NULL || |
1232 | | _cairo_scaled_glyph_index (scaled_glyph) != glyph_index) |
1233 | | { |
1234 | | status = _cairo_scaled_glyph_lookup (info->font, glyph_index, |
1235 | | CAIRO_SCALED_GLYPH_INFO_SURFACE, |
1236 | | NULL, /* foreground color */ |
1237 | | &scaled_glyph); |
1238 | | |
1239 | | if (unlikely (status)) |
1240 | | break; |
1241 | | |
1242 | | glyph_cache[cache_index] = scaled_glyph; |
1243 | | } |
1244 | | |
1245 | | glyph_surface = scaled_glyph->surface; |
1246 | | if (glyph_surface->width && glyph_surface->height) { |
1247 | | /* round glyph locations to the nearest pixel */ |
1248 | | /* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */ |
1249 | | x = _cairo_lround (info->glyphs[i].x - |
1250 | | glyph_surface->base.device_transform.x0); |
1251 | | y = _cairo_lround (info->glyphs[i].y - |
1252 | | glyph_surface->base.device_transform.y0); |
1253 | | |
1254 | | pixman_image_composite32 (op, src, glyph_surface->pixman_image, dst, |
1255 | | x + src_x, y + src_y, |
1256 | | 0, 0, |
1257 | | x - dst_x, y - dst_y, |
1258 | | glyph_surface->width, |
1259 | | glyph_surface->height); |
1260 | | } |
1261 | | } |
1262 | | |
1263 | | return status; |
1264 | | } |
1265 | | #endif |
1266 | | |
1267 | | static cairo_int_status_t |
1268 | | check_composite (const cairo_composite_rectangles_t *extents) |
1269 | 11 | { |
1270 | 11 | return CAIRO_STATUS_SUCCESS; |
1271 | 11 | } |
1272 | | |
1273 | | const cairo_compositor_t * |
1274 | | _cairo_image_traps_compositor_get (void) |
1275 | 6 | { |
1276 | 6 | static cairo_atomic_once_t once = CAIRO_ATOMIC_ONCE_INIT; |
1277 | 6 | static cairo_traps_compositor_t compositor; |
1278 | | |
1279 | 6 | if (_cairo_atomic_init_once_enter(&once)) { |
1280 | 6 | _cairo_traps_compositor_init(&compositor, |
1281 | 6 | &__cairo_no_compositor); |
1282 | 6 | compositor.acquire = acquire; |
1283 | 6 | compositor.release = release; |
1284 | 6 | compositor.set_clip_region = set_clip_region; |
1285 | 6 | compositor.pattern_to_surface = _cairo_image_source_create_for_pattern; |
1286 | 6 | compositor.draw_image_boxes = draw_image_boxes; |
1287 | | //compositor.copy_boxes = copy_boxes; |
1288 | 6 | compositor.fill_boxes = fill_boxes; |
1289 | 6 | compositor.check_composite = check_composite; |
1290 | 6 | compositor.composite = composite; |
1291 | 6 | compositor.lerp = lerp; |
1292 | | //compositor.check_composite_boxes = check_composite_boxes; |
1293 | 6 | compositor.composite_boxes = composite_boxes; |
1294 | | //compositor.check_composite_traps = check_composite_traps; |
1295 | 6 | compositor.composite_traps = composite_traps; |
1296 | | //compositor.check_composite_tristrip = check_composite_traps; |
1297 | 6 | compositor.composite_tristrip = composite_tristrip; |
1298 | 6 | compositor.check_composite_glyphs = check_composite_glyphs; |
1299 | 6 | compositor.composite_glyphs = composite_glyphs; |
1300 | | |
1301 | 6 | _cairo_atomic_init_once_leave(&once); |
1302 | 6 | } |
1303 | | |
1304 | 6 | return &compositor.base; |
1305 | 6 | } |
1306 | | |
1307 | | const cairo_compositor_t * |
1308 | | _cairo_image_mask_compositor_get (void) |
1309 | 0 | { |
1310 | 0 | static cairo_atomic_once_t once = CAIRO_ATOMIC_ONCE_INIT; |
1311 | 0 | static cairo_mask_compositor_t compositor; |
1312 | |
|
1313 | 0 | if (_cairo_atomic_init_once_enter(&once)) { |
1314 | 0 | _cairo_mask_compositor_init (&compositor, |
1315 | 0 | _cairo_image_traps_compositor_get ()); |
1316 | 0 | compositor.acquire = acquire; |
1317 | 0 | compositor.release = release; |
1318 | 0 | compositor.set_clip_region = set_clip_region; |
1319 | 0 | compositor.pattern_to_surface = _cairo_image_source_create_for_pattern; |
1320 | 0 | compositor.draw_image_boxes = draw_image_boxes; |
1321 | 0 | compositor.fill_rectangles = fill_rectangles; |
1322 | 0 | compositor.fill_boxes = fill_boxes; |
1323 | 0 | compositor.check_composite = check_composite; |
1324 | 0 | compositor.composite = composite; |
1325 | | //compositor.lerp = lerp; |
1326 | | //compositor.check_composite_boxes = check_composite_boxes; |
1327 | 0 | compositor.composite_boxes = composite_boxes; |
1328 | 0 | compositor.check_composite_glyphs = check_composite_glyphs; |
1329 | 0 | compositor.composite_glyphs = composite_glyphs; |
1330 | |
|
1331 | 0 | _cairo_atomic_init_once_leave(&once); |
1332 | 0 | } |
1333 | |
|
1334 | 0 | return &compositor.base; |
1335 | 0 | } |
1336 | | |
1337 | | #if PIXMAN_HAS_COMPOSITOR |
1338 | | typedef struct _cairo_image_span_renderer { |
1339 | | cairo_span_renderer_t base; |
1340 | | |
1341 | | pixman_image_compositor_t *compositor; |
1342 | | pixman_image_t *src, *mask; |
1343 | | float opacity; |
1344 | | cairo_rectangle_int_t extents; |
1345 | | } cairo_image_span_renderer_t; |
1346 | | COMPILE_TIME_ASSERT (sizeof (cairo_image_span_renderer_t) <= sizeof (cairo_abstract_span_renderer_t)); |
1347 | | |
1348 | | static cairo_status_t |
1349 | | _cairo_image_bounded_opaque_spans (void *abstract_renderer, |
1350 | | int y, int height, |
1351 | | const cairo_half_open_span_t *spans, |
1352 | | unsigned num_spans) |
1353 | | { |
1354 | | cairo_image_span_renderer_t *r = abstract_renderer; |
1355 | | |
1356 | | if (num_spans == 0) |
1357 | | return CAIRO_STATUS_SUCCESS; |
1358 | | |
1359 | | do { |
1360 | | if (spans[0].coverage) |
1361 | | pixman_image_compositor_blt (r->compositor, |
1362 | | spans[0].x, y, |
1363 | | spans[1].x - spans[0].x, height, |
1364 | | spans[0].coverage); |
1365 | | spans++; |
1366 | | } while (--num_spans > 1); |
1367 | | |
1368 | | return CAIRO_STATUS_SUCCESS; |
1369 | | } |
1370 | | |
1371 | | static cairo_status_t |
1372 | | _cairo_image_bounded_spans (void *abstract_renderer, |
1373 | | int y, int height, |
1374 | | const cairo_half_open_span_t *spans, |
1375 | | unsigned num_spans) |
1376 | | { |
1377 | | cairo_image_span_renderer_t *r = abstract_renderer; |
1378 | | |
1379 | | if (num_spans == 0) |
1380 | | return CAIRO_STATUS_SUCCESS; |
1381 | | |
1382 | | do { |
1383 | | if (spans[0].coverage) { |
1384 | | pixman_image_compositor_blt (r->compositor, |
1385 | | spans[0].x, y, |
1386 | | spans[1].x - spans[0].x, height, |
1387 | | r->opacity * spans[0].coverage); |
1388 | | } |
1389 | | spans++; |
1390 | | } while (--num_spans > 1); |
1391 | | |
1392 | | return CAIRO_STATUS_SUCCESS; |
1393 | | } |
1394 | | |
1395 | | static cairo_status_t |
1396 | | _cairo_image_unbounded_spans (void *abstract_renderer, |
1397 | | int y, int height, |
1398 | | const cairo_half_open_span_t *spans, |
1399 | | unsigned num_spans) |
1400 | | { |
1401 | | cairo_image_span_renderer_t *r = abstract_renderer; |
1402 | | |
1403 | | assert (y + height <= r->extents.height); |
1404 | | if (y > r->extents.y) { |
1405 | | pixman_image_compositor_blt (r->compositor, |
1406 | | r->extents.x, r->extents.y, |
1407 | | r->extents.width, y - r->extents.y, |
1408 | | 0); |
1409 | | } |
1410 | | |
1411 | | if (num_spans == 0) { |
1412 | | pixman_image_compositor_blt (r->compositor, |
1413 | | r->extents.x, y, |
1414 | | r->extents.width, height, |
1415 | | 0); |
1416 | | } else { |
1417 | | if (spans[0].x != r->extents.x) { |
1418 | | pixman_image_compositor_blt (r->compositor, |
1419 | | r->extents.x, y, |
1420 | | spans[0].x - r->extents.x, |
1421 | | height, |
1422 | | 0); |
1423 | | } |
1424 | | |
1425 | | do { |
1426 | | assert (spans[0].x < r->extents.x + r->extents.width); |
1427 | | pixman_image_compositor_blt (r->compositor, |
1428 | | spans[0].x, y, |
1429 | | spans[1].x - spans[0].x, height, |
1430 | | r->opacity * spans[0].coverage); |
1431 | | spans++; |
1432 | | } while (--num_spans > 1); |
1433 | | |
1434 | | if (spans[0].x != r->extents.x + r->extents.width) { |
1435 | | assert (spans[0].x < r->extents.x + r->extents.width); |
1436 | | pixman_image_compositor_blt (r->compositor, |
1437 | | spans[0].x, y, |
1438 | | r->extents.x + r->extents.width - spans[0].x, height, |
1439 | | 0); |
1440 | | } |
1441 | | } |
1442 | | |
1443 | | r->extents.y = y + height; |
1444 | | return CAIRO_STATUS_SUCCESS; |
1445 | | } |
1446 | | |
1447 | | static cairo_status_t |
1448 | | _cairo_image_clipped_spans (void *abstract_renderer, |
1449 | | int y, int height, |
1450 | | const cairo_half_open_span_t *spans, |
1451 | | unsigned num_spans) |
1452 | | { |
1453 | | cairo_image_span_renderer_t *r = abstract_renderer; |
1454 | | |
1455 | | assert (num_spans); |
1456 | | |
1457 | | do { |
1458 | | if (! spans[0].inverse) |
1459 | | pixman_image_compositor_blt (r->compositor, |
1460 | | spans[0].x, y, |
1461 | | spans[1].x - spans[0].x, height, |
1462 | | r->opacity * spans[0].coverage); |
1463 | | spans++; |
1464 | | } while (--num_spans > 1); |
1465 | | |
1466 | | r->extents.y = y + height; |
1467 | | return CAIRO_STATUS_SUCCESS; |
1468 | | } |
1469 | | |
1470 | | static cairo_status_t |
1471 | | _cairo_image_finish_unbounded_spans (void *abstract_renderer) |
1472 | | { |
1473 | | cairo_image_span_renderer_t *r = abstract_renderer; |
1474 | | |
1475 | | if (r->extents.y < r->extents.height) { |
1476 | | pixman_image_compositor_blt (r->compositor, |
1477 | | r->extents.x, r->extents.y, |
1478 | | r->extents.width, |
1479 | | r->extents.height - r->extents.y, |
1480 | | 0); |
1481 | | } |
1482 | | |
1483 | | return CAIRO_STATUS_SUCCESS; |
1484 | | } |
1485 | | |
1486 | | static cairo_int_status_t |
1487 | | span_renderer_init (cairo_abstract_span_renderer_t *_r, |
1488 | | const cairo_composite_rectangles_t *composite, |
1489 | | cairo_bool_t needs_clip) |
1490 | | { |
1491 | | cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *)_r; |
1492 | | cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; |
1493 | | const cairo_pattern_t *source = &composite->source_pattern.base; |
1494 | | cairo_operator_t op = composite->op; |
1495 | | int src_x, src_y; |
1496 | | int mask_x, mask_y; |
1497 | | |
1498 | | TRACE ((stderr, "%s\n", __FUNCTION__)); |
1499 | | |
1500 | | if (op == CAIRO_OPERATOR_CLEAR) { |
1501 | | op = PIXMAN_OP_LERP_CLEAR; |
1502 | | } else if (dst->base.is_clear && |
1503 | | (op == CAIRO_OPERATOR_SOURCE || |
1504 | | op == CAIRO_OPERATOR_OVER || |
1505 | | op == CAIRO_OPERATOR_ADD)) { |
1506 | | op = PIXMAN_OP_SRC; |
1507 | | } else if (op == CAIRO_OPERATOR_SOURCE) { |
1508 | | op = PIXMAN_OP_LERP_SRC; |
1509 | | } else { |
1510 | | op = _pixman_operator (op); |
1511 | | } |
1512 | | |
1513 | | r->compositor = NULL; |
1514 | | r->mask = NULL; |
1515 | | r->src = _pixman_image_for_pattern (dst, source, FALSE, |
1516 | | &composite->unbounded, |
1517 | | &composite->source_sample_area, |
1518 | | &src_x, &src_y); |
1519 | | if (unlikely (r->src == NULL)) |
1520 | | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
1521 | | |
1522 | | r->opacity = 1.0; |
1523 | | if (composite->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { |
1524 | | r->opacity = composite->mask_pattern.solid.color.alpha; |
1525 | | } else { |
1526 | | r->mask = _pixman_image_for_pattern (dst, |
1527 | | &composite->mask_pattern.base, |
1528 | | TRUE, |
1529 | | &composite->unbounded, |
1530 | | &composite->mask_sample_area, |
1531 | | &mask_x, &mask_y); |
1532 | | if (unlikely (r->mask == NULL)) |
1533 | | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
1534 | | |
1535 | | /* XXX Component-alpha? */ |
1536 | | if ((dst->base.content & CAIRO_CONTENT_COLOR) == 0 && |
1537 | | _cairo_pattern_is_opaque (source, &composite->source_sample_area)) |
1538 | | { |
1539 | | pixman_image_unref (r->src); |
1540 | | r->src = r->mask; |
1541 | | src_x = mask_x; |
1542 | | src_y = mask_y; |
1543 | | r->mask = NULL; |
1544 | | } |
1545 | | } |
1546 | | |
1547 | | if (composite->is_bounded) { |
1548 | | if (r->opacity == 1.) |
1549 | | r->base.render_rows = _cairo_image_bounded_opaque_spans; |
1550 | | else |
1551 | | r->base.render_rows = _cairo_image_bounded_spans; |
1552 | | r->base.finish = NULL; |
1553 | | } else { |
1554 | | if (needs_clip) |
1555 | | r->base.render_rows = _cairo_image_clipped_spans; |
1556 | | else |
1557 | | r->base.render_rows = _cairo_image_unbounded_spans; |
1558 | | r->base.finish = _cairo_image_finish_unbounded_spans; |
1559 | | r->extents = composite->unbounded; |
1560 | | r->extents.height += r->extents.y; |
1561 | | } |
1562 | | |
1563 | | r->compositor = |
1564 | | pixman_image_create_compositor (op, r->src, r->mask, dst->pixman_image, |
1565 | | composite->unbounded.x + src_x, |
1566 | | composite->unbounded.y + src_y, |
1567 | | composite->unbounded.x + mask_x, |
1568 | | composite->unbounded.y + mask_y, |
1569 | | composite->unbounded.x, |
1570 | | composite->unbounded.y, |
1571 | | composite->unbounded.width, |
1572 | | composite->unbounded.height); |
1573 | | if (unlikely (r->compositor == NULL)) |
1574 | | return CAIRO_INT_STATUS_NOTHING_TO_DO; |
1575 | | |
1576 | | return CAIRO_STATUS_SUCCESS; |
1577 | | } |
1578 | | |
1579 | | static void |
1580 | | span_renderer_fini (cairo_abstract_span_renderer_t *_r, |
1581 | | cairo_int_status_t status) |
1582 | | { |
1583 | | cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *) _r; |
1584 | | |
1585 | | TRACE ((stderr, "%s\n", __FUNCTION__)); |
1586 | | |
1587 | | if (status == CAIRO_INT_STATUS_SUCCESS && r->base.finish) |
1588 | | r->base.finish (r); |
1589 | | |
1590 | | if (r->compositor) |
1591 | | pixman_image_compositor_destroy (r->compositor); |
1592 | | |
1593 | | if (r->src) |
1594 | | pixman_image_unref (r->src); |
1595 | | if (r->mask) |
1596 | | pixman_image_unref (r->mask); |
1597 | | } |
1598 | | #else |
1599 | | typedef struct _cairo_image_span_renderer { |
1600 | | cairo_span_renderer_t base; |
1601 | | |
1602 | | const cairo_composite_rectangles_t *composite; |
1603 | | |
1604 | | float opacity; |
1605 | | uint8_t op; |
1606 | | int bpp; |
1607 | | |
1608 | | pixman_image_t *src, *mask; |
1609 | | union { |
1610 | | struct fill { |
1611 | | ptrdiff_t stride; |
1612 | | uint8_t *data; |
1613 | | uint32_t pixel; |
1614 | | } fill; |
1615 | | struct blit { |
1616 | | int stride; |
1617 | | uint8_t *data; |
1618 | | int src_stride; |
1619 | | uint8_t *src_data; |
1620 | | } blit; |
1621 | | struct composite { |
1622 | | pixman_image_t *dst; |
1623 | | int src_x, src_y; |
1624 | | int mask_x, mask_y; |
1625 | | int run_length; |
1626 | | } composite; |
1627 | | struct finish { |
1628 | | cairo_rectangle_int_t extents; |
1629 | | int src_x, src_y; |
1630 | | ptrdiff_t stride; |
1631 | | uint8_t *data; |
1632 | | } mask; |
1633 | | } u; |
1634 | | uint8_t _buf[0]; |
1635 | 212k | #define SZ_BUF (int)(sizeof (cairo_abstract_span_renderer_t) - sizeof (cairo_image_span_renderer_t)) |
1636 | | } cairo_image_span_renderer_t; |
1637 | | COMPILE_TIME_ASSERT (sizeof (cairo_image_span_renderer_t) <= sizeof (cairo_abstract_span_renderer_t)); |
1638 | | |
1639 | | static cairo_status_t |
1640 | | _cairo_image_spans (void *abstract_renderer, |
1641 | | int y, int height, |
1642 | | const cairo_half_open_span_t *spans, |
1643 | | unsigned num_spans) |
1644 | 0 | { |
1645 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
1646 | 0 | uint8_t *mask, *row; |
1647 | 0 | int len; |
1648 | |
|
1649 | 0 | if (num_spans == 0) |
1650 | 0 | return CAIRO_STATUS_SUCCESS; |
1651 | | |
1652 | 0 | mask = r->u.mask.data + (y - r->u.mask.extents.y) * r->u.mask.stride; |
1653 | 0 | mask += spans[0].x - r->u.mask.extents.x; |
1654 | 0 | row = mask; |
1655 | |
|
1656 | 0 | do { |
1657 | 0 | len = spans[1].x - spans[0].x; |
1658 | 0 | if (spans[0].coverage) { |
1659 | 0 | *row++ = r->opacity * spans[0].coverage; |
1660 | 0 | if (--len) |
1661 | 0 | memset (row, row[-1], len); |
1662 | 0 | } |
1663 | 0 | row += len; |
1664 | 0 | spans++; |
1665 | 0 | } while (--num_spans > 1); |
1666 | |
|
1667 | 0 | len = row - mask; |
1668 | 0 | row = mask; |
1669 | 0 | while (--height) { |
1670 | 0 | mask += r->u.mask.stride; |
1671 | 0 | memcpy (mask, row, len); |
1672 | 0 | } |
1673 | |
|
1674 | 0 | return CAIRO_STATUS_SUCCESS; |
1675 | 0 | } |
1676 | | |
1677 | | static cairo_status_t |
1678 | | _cairo_image_spans_and_zero (void *abstract_renderer, |
1679 | | int y, int height, |
1680 | | const cairo_half_open_span_t *spans, |
1681 | | unsigned num_spans) |
1682 | 0 | { |
1683 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
1684 | 0 | uint8_t *mask; |
1685 | 0 | int len; |
1686 | |
|
1687 | 0 | mask = r->u.mask.data; |
1688 | 0 | if (y > r->u.mask.extents.y) { |
1689 | 0 | len = (y - r->u.mask.extents.y) * r->u.mask.stride; |
1690 | 0 | memset (mask, 0, len); |
1691 | 0 | mask += len; |
1692 | 0 | } |
1693 | |
|
1694 | 0 | r->u.mask.extents.y = y + height; |
1695 | 0 | r->u.mask.data = mask + height * r->u.mask.stride; |
1696 | 0 | if (num_spans == 0) { |
1697 | 0 | memset (mask, 0, height * r->u.mask.stride); |
1698 | 0 | } else { |
1699 | 0 | uint8_t *row = mask; |
1700 | |
|
1701 | 0 | if (spans[0].x != r->u.mask.extents.x) { |
1702 | 0 | len = spans[0].x - r->u.mask.extents.x; |
1703 | 0 | memset (row, 0, len); |
1704 | 0 | row += len; |
1705 | 0 | } |
1706 | |
|
1707 | 0 | do { |
1708 | 0 | len = spans[1].x - spans[0].x; |
1709 | 0 | *row++ = r->opacity * spans[0].coverage; |
1710 | 0 | if (len > 1) { |
1711 | 0 | memset (row, row[-1], --len); |
1712 | 0 | row += len; |
1713 | 0 | } |
1714 | 0 | spans++; |
1715 | 0 | } while (--num_spans > 1); |
1716 | |
|
1717 | 0 | if (spans[0].x != r->u.mask.extents.x + r->u.mask.extents.width) { |
1718 | 0 | len = r->u.mask.extents.x + r->u.mask.extents.width - spans[0].x; |
1719 | 0 | memset (row, 0, len); |
1720 | 0 | } |
1721 | |
|
1722 | 0 | row = mask; |
1723 | 0 | while (--height) { |
1724 | 0 | mask += r->u.mask.stride; |
1725 | 0 | memcpy (mask, row, r->u.mask.extents.width); |
1726 | 0 | } |
1727 | 0 | } |
1728 | |
|
1729 | 0 | return CAIRO_STATUS_SUCCESS; |
1730 | 0 | } |
1731 | | |
1732 | | static cairo_status_t |
1733 | | _cairo_image_finish_spans_and_zero (void *abstract_renderer) |
1734 | 0 | { |
1735 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
1736 | |
|
1737 | 0 | if (r->u.mask.extents.y < r->u.mask.extents.height) |
1738 | 0 | memset (r->u.mask.data, 0, (r->u.mask.extents.height - r->u.mask.extents.y) * r->u.mask.stride); |
1739 | |
|
1740 | 0 | return CAIRO_STATUS_SUCCESS; |
1741 | 0 | } |
1742 | | |
1743 | | static cairo_status_t |
1744 | | _fill8_spans (void *abstract_renderer, int y, int h, |
1745 | | const cairo_half_open_span_t *spans, unsigned num_spans) |
1746 | 0 | { |
1747 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
1748 | |
|
1749 | 0 | if (num_spans == 0) |
1750 | 0 | return CAIRO_STATUS_SUCCESS; |
1751 | | |
1752 | 0 | if (likely(h == 1)) { |
1753 | 0 | do { |
1754 | 0 | if (spans[0].coverage) { |
1755 | 0 | int len = spans[1].x - spans[0].x; |
1756 | 0 | uint8_t *d = r->u.fill.data + r->u.fill.stride*y + spans[0].x; |
1757 | 0 | if (len == 1) |
1758 | 0 | *d = r->u.fill.pixel; |
1759 | 0 | else |
1760 | 0 | memset(d, r->u.fill.pixel, len); |
1761 | 0 | } |
1762 | 0 | spans++; |
1763 | 0 | } while (--num_spans > 1); |
1764 | 0 | } else { |
1765 | 0 | do { |
1766 | 0 | if (spans[0].coverage) { |
1767 | 0 | int yy = y, hh = h; |
1768 | 0 | do { |
1769 | 0 | int len = spans[1].x - spans[0].x; |
1770 | 0 | uint8_t *d = r->u.fill.data + r->u.fill.stride*yy + spans[0].x; |
1771 | 0 | if (len == 1) |
1772 | 0 | *d = r->u.fill.pixel; |
1773 | 0 | else |
1774 | 0 | memset(d, r->u.fill.pixel, len); |
1775 | 0 | yy++; |
1776 | 0 | } while (--hh); |
1777 | 0 | } |
1778 | 0 | spans++; |
1779 | 0 | } while (--num_spans > 1); |
1780 | 0 | } |
1781 | |
|
1782 | 0 | return CAIRO_STATUS_SUCCESS; |
1783 | 0 | } |
1784 | | |
1785 | | static cairo_status_t |
1786 | | _fill16_spans (void *abstract_renderer, int y, int h, |
1787 | | const cairo_half_open_span_t *spans, unsigned num_spans) |
1788 | 0 | { |
1789 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
1790 | |
|
1791 | 0 | if (num_spans == 0) |
1792 | 0 | return CAIRO_STATUS_SUCCESS; |
1793 | | |
1794 | 0 | if (likely(h == 1)) { |
1795 | 0 | do { |
1796 | 0 | if (spans[0].coverage) { |
1797 | 0 | int len = spans[1].x - spans[0].x; |
1798 | 0 | uint16_t *d = (uint16_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*2); |
1799 | 0 | while (len-- > 0) |
1800 | 0 | *d++ = r->u.fill.pixel; |
1801 | 0 | } |
1802 | 0 | spans++; |
1803 | 0 | } while (--num_spans > 1); |
1804 | 0 | } else { |
1805 | 0 | do { |
1806 | 0 | if (spans[0].coverage) { |
1807 | 0 | int yy = y, hh = h; |
1808 | 0 | do { |
1809 | 0 | int len = spans[1].x - spans[0].x; |
1810 | 0 | uint16_t *d = (uint16_t*)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*2); |
1811 | 0 | while (len-- > 0) |
1812 | 0 | *d++ = r->u.fill.pixel; |
1813 | 0 | yy++; |
1814 | 0 | } while (--hh); |
1815 | 0 | } |
1816 | 0 | spans++; |
1817 | 0 | } while (--num_spans > 1); |
1818 | 0 | } |
1819 | |
|
1820 | 0 | return CAIRO_STATUS_SUCCESS; |
1821 | 0 | } |
1822 | | |
1823 | | static cairo_status_t |
1824 | | _fill32_spans (void *abstract_renderer, int y, int h, |
1825 | | const cairo_half_open_span_t *spans, unsigned num_spans) |
1826 | 0 | { |
1827 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
1828 | |
|
1829 | 0 | if (num_spans == 0) |
1830 | 0 | return CAIRO_STATUS_SUCCESS; |
1831 | | |
1832 | 0 | if (likely(h == 1)) { |
1833 | 0 | do { |
1834 | 0 | if (spans[0].coverage) { |
1835 | 0 | int len = spans[1].x - spans[0].x; |
1836 | 0 | if (len > 32) { |
1837 | 0 | pixman_fill ((uint32_t *)r->u.fill.data, r->u.fill.stride / sizeof(uint32_t), r->bpp, |
1838 | 0 | spans[0].x, y, len, 1, r->u.fill.pixel); |
1839 | 0 | } else { |
1840 | 0 | uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*4); |
1841 | 0 | while (len-- > 0) |
1842 | 0 | *d++ = r->u.fill.pixel; |
1843 | 0 | } |
1844 | 0 | } |
1845 | 0 | spans++; |
1846 | 0 | } while (--num_spans > 1); |
1847 | 0 | } else { |
1848 | 0 | do { |
1849 | 0 | if (spans[0].coverage) { |
1850 | 0 | if (spans[1].x - spans[0].x > 16) { |
1851 | 0 | pixman_fill ((uint32_t *)r->u.fill.data, r->u.fill.stride / sizeof(uint32_t), r->bpp, |
1852 | 0 | spans[0].x, y, spans[1].x - spans[0].x, h, |
1853 | 0 | r->u.fill.pixel); |
1854 | 0 | } else { |
1855 | 0 | int yy = y, hh = h; |
1856 | 0 | do { |
1857 | 0 | int len = spans[1].x - spans[0].x; |
1858 | 0 | uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*4); |
1859 | 0 | while (len-- > 0) |
1860 | 0 | *d++ = r->u.fill.pixel; |
1861 | 0 | yy++; |
1862 | 0 | } while (--hh); |
1863 | 0 | } |
1864 | 0 | } |
1865 | 0 | spans++; |
1866 | 0 | } while (--num_spans > 1); |
1867 | 0 | } |
1868 | |
|
1869 | 0 | return CAIRO_STATUS_SUCCESS; |
1870 | 0 | } |
1871 | | |
1872 | | #if 0 |
1873 | | static cairo_status_t |
1874 | | _fill_spans (void *abstract_renderer, int y, int h, |
1875 | | const cairo_half_open_span_t *spans, unsigned num_spans) |
1876 | | { |
1877 | | cairo_image_span_renderer_t *r = abstract_renderer; |
1878 | | |
1879 | | if (num_spans == 0) |
1880 | | return CAIRO_STATUS_SUCCESS; |
1881 | | |
1882 | | do { |
1883 | | if (spans[0].coverage) { |
1884 | | pixman_fill ((uint32_t *) r->data, r->stride, r->bpp, |
1885 | | spans[0].x, y, |
1886 | | spans[1].x - spans[0].x, h, |
1887 | | r->pixel); |
1888 | | } |
1889 | | spans++; |
1890 | | } while (--num_spans > 1); |
1891 | | |
1892 | | return CAIRO_STATUS_SUCCESS; |
1893 | | } |
1894 | | #endif |
1895 | | |
1896 | | static cairo_status_t |
1897 | | _blit_spans (void *abstract_renderer, int y, int h, |
1898 | | const cairo_half_open_span_t *spans, unsigned num_spans) |
1899 | 0 | { |
1900 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
1901 | 0 | int cpp; |
1902 | |
|
1903 | 0 | if (num_spans == 0) |
1904 | 0 | return CAIRO_STATUS_SUCCESS; |
1905 | | |
1906 | 0 | cpp = r->bpp/8; |
1907 | 0 | if (likely (h == 1)) { |
1908 | 0 | uint8_t *src = r->u.blit.src_data + y*r->u.blit.src_stride; |
1909 | 0 | uint8_t *dst = r->u.blit.data + y*r->u.blit.stride; |
1910 | 0 | do { |
1911 | 0 | if (spans[0].coverage) { |
1912 | 0 | void *s = src + spans[0].x*cpp; |
1913 | 0 | void *d = dst + spans[0].x*cpp; |
1914 | 0 | int len = (spans[1].x - spans[0].x) * cpp; |
1915 | 0 | switch (len) { |
1916 | 0 | case 1: |
1917 | 0 | *(uint8_t *)d = *(uint8_t *)s; |
1918 | 0 | break; |
1919 | 0 | case 2: |
1920 | 0 | *(uint16_t *)d = *(uint16_t *)s; |
1921 | 0 | break; |
1922 | 0 | case 4: |
1923 | 0 | *(uint32_t *)d = *(uint32_t *)s; |
1924 | 0 | break; |
1925 | 0 | #if HAVE_UINT64_T |
1926 | 0 | case 8: |
1927 | 0 | *(uint64_t *)d = *(uint64_t *)s; |
1928 | 0 | break; |
1929 | 0 | #endif |
1930 | 0 | default: |
1931 | 0 | memcpy(d, s, len); |
1932 | 0 | break; |
1933 | 0 | } |
1934 | 0 | } |
1935 | 0 | spans++; |
1936 | 0 | } while (--num_spans > 1); |
1937 | 0 | } else { |
1938 | 0 | do { |
1939 | 0 | if (spans[0].coverage) { |
1940 | 0 | int yy = y, hh = h; |
1941 | 0 | do { |
1942 | 0 | void *src = r->u.blit.src_data + yy*r->u.blit.src_stride + spans[0].x*cpp; |
1943 | 0 | void *dst = r->u.blit.data + yy*r->u.blit.stride + spans[0].x*cpp; |
1944 | 0 | int len = (spans[1].x - spans[0].x) * cpp; |
1945 | 0 | switch (len) { |
1946 | 0 | case 1: |
1947 | 0 | *(uint8_t *)dst = *(uint8_t *)src; |
1948 | 0 | break; |
1949 | 0 | case 2: |
1950 | 0 | *(uint16_t *)dst = *(uint16_t *)src; |
1951 | 0 | break; |
1952 | 0 | case 4: |
1953 | 0 | *(uint32_t *)dst = *(uint32_t *)src; |
1954 | 0 | break; |
1955 | 0 | #if HAVE_UINT64_T |
1956 | 0 | case 8: |
1957 | 0 | *(uint64_t *)dst = *(uint64_t *)src; |
1958 | 0 | break; |
1959 | 0 | #endif |
1960 | 0 | default: |
1961 | 0 | memcpy(dst, src, len); |
1962 | 0 | break; |
1963 | 0 | } |
1964 | 0 | yy++; |
1965 | 0 | } while (--hh); |
1966 | 0 | } |
1967 | 0 | spans++; |
1968 | 0 | } while (--num_spans > 1); |
1969 | 0 | } |
1970 | | |
1971 | 0 | return CAIRO_STATUS_SUCCESS; |
1972 | 0 | } |
1973 | | |
1974 | | static cairo_status_t |
1975 | | _mono_spans (void *abstract_renderer, int y, int h, |
1976 | | const cairo_half_open_span_t *spans, unsigned num_spans) |
1977 | 0 | { |
1978 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
1979 | |
|
1980 | 0 | if (num_spans == 0) |
1981 | 0 | return CAIRO_STATUS_SUCCESS; |
1982 | | |
1983 | 0 | do { |
1984 | 0 | if (spans[0].coverage) { |
1985 | 0 | pixman_image_composite32 (r->op, |
1986 | 0 | r->src, NULL, r->u.composite.dst, |
1987 | 0 | spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, |
1988 | 0 | 0, 0, |
1989 | 0 | spans[0].x, y, |
1990 | 0 | spans[1].x - spans[0].x, h); |
1991 | 0 | } |
1992 | 0 | spans++; |
1993 | 0 | } while (--num_spans > 1); |
1994 | |
|
1995 | 0 | return CAIRO_STATUS_SUCCESS; |
1996 | 0 | } |
1997 | | |
1998 | | static cairo_status_t |
1999 | | _mono_unbounded_spans (void *abstract_renderer, int y, int h, |
2000 | | const cairo_half_open_span_t *spans, unsigned num_spans) |
2001 | 0 | { |
2002 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
2003 | |
|
2004 | 0 | if (num_spans == 0) { |
2005 | 0 | pixman_image_composite32 (PIXMAN_OP_CLEAR, |
2006 | 0 | r->src, NULL, r->u.composite.dst, |
2007 | 0 | spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, |
2008 | 0 | 0, 0, |
2009 | 0 | r->composite->unbounded.x, y, |
2010 | 0 | r->composite->unbounded.width, h); |
2011 | 0 | r->u.composite.mask_y = y + h; |
2012 | 0 | return CAIRO_STATUS_SUCCESS; |
2013 | 0 | } |
2014 | | |
2015 | 0 | if (y != r->u.composite.mask_y) { |
2016 | 0 | pixman_image_composite32 (PIXMAN_OP_CLEAR, |
2017 | 0 | r->src, NULL, r->u.composite.dst, |
2018 | 0 | spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, |
2019 | 0 | 0, 0, |
2020 | 0 | r->composite->unbounded.x, r->u.composite.mask_y, |
2021 | 0 | r->composite->unbounded.width, y - r->u.composite.mask_y); |
2022 | 0 | } |
2023 | |
|
2024 | 0 | if (spans[0].x != r->composite->unbounded.x) { |
2025 | 0 | pixman_image_composite32 (PIXMAN_OP_CLEAR, |
2026 | 0 | r->src, NULL, r->u.composite.dst, |
2027 | 0 | spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, |
2028 | 0 | 0, 0, |
2029 | 0 | r->composite->unbounded.x, y, |
2030 | 0 | spans[0].x - r->composite->unbounded.x, h); |
2031 | 0 | } |
2032 | |
|
2033 | 0 | do { |
2034 | 0 | int op = spans[0].coverage ? r->op : PIXMAN_OP_CLEAR; |
2035 | 0 | pixman_image_composite32 (op, |
2036 | 0 | r->src, NULL, r->u.composite.dst, |
2037 | 0 | spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, |
2038 | 0 | 0, 0, |
2039 | 0 | spans[0].x, y, |
2040 | 0 | spans[1].x - spans[0].x, h); |
2041 | 0 | spans++; |
2042 | 0 | } while (--num_spans > 1); |
2043 | |
|
2044 | 0 | if (spans[0].x != r->composite->unbounded.x + r->composite->unbounded.width) { |
2045 | 0 | pixman_image_composite32 (PIXMAN_OP_CLEAR, |
2046 | 0 | r->src, NULL, r->u.composite.dst, |
2047 | 0 | spans[0].x + r->u.composite.src_x, y + r->u.composite.src_y, |
2048 | 0 | 0, 0, |
2049 | 0 | spans[0].x, y, |
2050 | 0 | r->composite->unbounded.x + r->composite->unbounded.width - spans[0].x, h); |
2051 | 0 | } |
2052 | |
|
2053 | 0 | r->u.composite.mask_y = y + h; |
2054 | 0 | return CAIRO_STATUS_SUCCESS; |
2055 | 0 | } |
2056 | | |
2057 | | static cairo_status_t |
2058 | | _mono_finish_unbounded_spans (void *abstract_renderer) |
2059 | 0 | { |
2060 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
2061 | |
|
2062 | 0 | if (r->u.composite.mask_y < r->composite->unbounded.y + r->composite->unbounded.height) { |
2063 | 0 | pixman_image_composite32 (PIXMAN_OP_CLEAR, |
2064 | 0 | r->src, NULL, r->u.composite.dst, |
2065 | 0 | r->composite->unbounded.x + r->u.composite.src_x, r->u.composite.mask_y + r->u.composite.src_y, |
2066 | 0 | 0, 0, |
2067 | 0 | r->composite->unbounded.x, r->u.composite.mask_y, |
2068 | 0 | r->composite->unbounded.width, |
2069 | 0 | r->composite->unbounded.y + r->composite->unbounded.height - r->u.composite.mask_y); |
2070 | 0 | } |
2071 | |
|
2072 | 0 | return CAIRO_STATUS_SUCCESS; |
2073 | 0 | } |
2074 | | |
2075 | | static cairo_int_status_t |
2076 | | mono_renderer_init (cairo_image_span_renderer_t *r, |
2077 | | const cairo_composite_rectangles_t *composite, |
2078 | | cairo_antialias_t antialias, |
2079 | | cairo_bool_t needs_clip) |
2080 | 320k | { |
2081 | 320k | cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; |
2082 | | |
2083 | 320k | if (antialias != CAIRO_ANTIALIAS_NONE) |
2084 | 320k | return CAIRO_INT_STATUS_UNSUPPORTED; |
2085 | | |
2086 | 0 | if (!_cairo_pattern_is_opaque_solid (&composite->mask_pattern.base)) |
2087 | 0 | return CAIRO_INT_STATUS_UNSUPPORTED; |
2088 | | |
2089 | 0 | r->base.render_rows = NULL; |
2090 | 0 | if (composite->source_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { |
2091 | 0 | const cairo_color_t *color; |
2092 | |
|
2093 | 0 | color = &composite->source_pattern.solid.color; |
2094 | 0 | if (composite->op == CAIRO_OPERATOR_CLEAR) |
2095 | 0 | color = CAIRO_COLOR_TRANSPARENT; |
2096 | |
|
2097 | 0 | if (fill_reduces_to_source (composite->op, color, dst, &r->u.fill.pixel)) { |
2098 | | /* Use plain C for the fill operations as the span length is |
2099 | | * typically small, too small to payback the startup overheads of |
2100 | | * using SSE2 etc. |
2101 | | */ |
2102 | 0 | switch (PIXMAN_FORMAT_BPP(dst->pixman_format)) { |
2103 | 0 | case 8: r->base.render_rows = _fill8_spans; break; |
2104 | 0 | case 16: r->base.render_rows = _fill16_spans; break; |
2105 | 0 | case 32: r->base.render_rows = _fill32_spans; break; |
2106 | 0 | default: break; |
2107 | 0 | } |
2108 | 0 | r->u.fill.data = dst->data; |
2109 | 0 | r->u.fill.stride = dst->stride; |
2110 | 0 | } |
2111 | 0 | } else if ((composite->op == CAIRO_OPERATOR_SOURCE || |
2112 | 0 | (composite->op == CAIRO_OPERATOR_OVER && |
2113 | 0 | (dst->base.is_clear || (dst->base.content & CAIRO_CONTENT_ALPHA) == 0))) && |
2114 | 0 | composite->source_pattern.base.type == CAIRO_PATTERN_TYPE_SURFACE && |
2115 | 0 | composite->source_pattern.surface.surface->backend->type == CAIRO_SURFACE_TYPE_IMAGE && |
2116 | 0 | to_image_surface(composite->source_pattern.surface.surface)->format == dst->format) |
2117 | 0 | { |
2118 | 0 | cairo_image_surface_t *src = |
2119 | 0 | to_image_surface(composite->source_pattern.surface.surface); |
2120 | 0 | int tx, ty; |
2121 | |
|
2122 | 0 | if (_cairo_matrix_is_integer_translation(&composite->source_pattern.base.matrix, |
2123 | 0 | &tx, &ty) && |
2124 | 0 | composite->bounded.x + tx >= 0 && |
2125 | 0 | composite->bounded.y + ty >= 0 && |
2126 | 0 | composite->bounded.x + composite->bounded.width + tx <= src->width && |
2127 | 0 | composite->bounded.y + composite->bounded.height + ty <= src->height) { |
2128 | |
|
2129 | 0 | r->u.blit.stride = dst->stride; |
2130 | 0 | r->u.blit.data = dst->data; |
2131 | 0 | r->u.blit.src_stride = src->stride; |
2132 | 0 | r->u.blit.src_data = src->data + src->stride * ty + tx * 4; |
2133 | 0 | r->base.render_rows = _blit_spans; |
2134 | 0 | } |
2135 | 0 | } |
2136 | | |
2137 | 0 | if (r->base.render_rows == NULL) { |
2138 | 0 | r->src = _pixman_image_for_pattern (dst, &composite->source_pattern.base, FALSE, |
2139 | 0 | &composite->unbounded, |
2140 | 0 | &composite->source_sample_area, |
2141 | 0 | &r->u.composite.src_x, &r->u.composite.src_y); |
2142 | 0 | if (unlikely (r->src == NULL)) |
2143 | 0 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
2144 | | |
2145 | 0 | r->u.composite.dst = to_pixman_image (composite->surface); |
2146 | 0 | r->op = _pixman_operator (composite->op); |
2147 | 0 | if (composite->is_bounded == 0) { |
2148 | 0 | r->base.render_rows = _mono_unbounded_spans; |
2149 | 0 | r->base.finish = _mono_finish_unbounded_spans; |
2150 | 0 | r->u.composite.mask_y = composite->unbounded.y; |
2151 | 0 | } else |
2152 | 0 | r->base.render_rows = _mono_spans; |
2153 | 0 | } |
2154 | 0 | r->bpp = PIXMAN_FORMAT_BPP(dst->pixman_format); |
2155 | |
|
2156 | 0 | return CAIRO_INT_STATUS_SUCCESS; |
2157 | 0 | } |
2158 | | |
2159 | 1.59k | #define ONE_HALF 0x7f |
2160 | 288M | #define RB_MASK 0x00ff00ff |
2161 | 72.1M | #define RB_ONE_HALF 0x007f007f |
2162 | 36.0M | #define RB_MASK_PLUS_ONE 0x01000100 |
2163 | 234M | #define G_SHIFT 8 |
2164 | | static inline uint32_t |
2165 | | mul8x2_8 (uint32_t a, uint8_t b) |
2166 | 72.1M | { |
2167 | 72.1M | uint32_t t = (a & RB_MASK) * b + RB_ONE_HALF; |
2168 | 72.1M | return ((t + ((t >> G_SHIFT) & RB_MASK)) >> G_SHIFT) & RB_MASK; |
2169 | 72.1M | } |
2170 | | |
2171 | | static inline uint32_t |
2172 | | add8x2_8x2 (uint32_t a, uint32_t b) |
2173 | 36.0M | { |
2174 | 36.0M | uint32_t t = a + b; |
2175 | 36.0M | t |= RB_MASK_PLUS_ONE - ((t >> G_SHIFT) & RB_MASK); |
2176 | 36.0M | return t & RB_MASK; |
2177 | 36.0M | } |
2178 | | |
2179 | | static inline uint8_t |
2180 | | mul8_8 (uint8_t a, uint8_t b) |
2181 | 1.59k | { |
2182 | 1.59k | uint16_t t = a * (uint16_t)b + ONE_HALF; |
2183 | 1.59k | return ((t >> G_SHIFT) + t) >> G_SHIFT; |
2184 | 1.59k | } |
2185 | | |
2186 | | static inline uint32_t |
2187 | | lerp8x4 (uint32_t src, uint8_t a, uint32_t dst) |
2188 | 18.0M | { |
2189 | 18.0M | return (add8x2_8x2 (mul8x2_8 (src, a), |
2190 | 18.0M | mul8x2_8 (dst, ~a)) | |
2191 | 18.0M | add8x2_8x2 (mul8x2_8 (src >> G_SHIFT, a), |
2192 | 18.0M | mul8x2_8 (dst >> G_SHIFT, ~a)) << G_SHIFT); |
2193 | 18.0M | } |
2194 | | |
2195 | | static cairo_status_t |
2196 | | _fill_a8_lerp_opaque_spans (void *abstract_renderer, int y, int h, |
2197 | | const cairo_half_open_span_t *spans, unsigned num_spans) |
2198 | 0 | { |
2199 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
2200 | |
|
2201 | 0 | if (num_spans == 0) |
2202 | 0 | return CAIRO_STATUS_SUCCESS; |
2203 | | |
2204 | 0 | if (likely(h == 1)) { |
2205 | 0 | uint8_t *d = r->u.fill.data + r->u.fill.stride*y; |
2206 | 0 | do { |
2207 | 0 | uint8_t a = spans[0].coverage; |
2208 | 0 | if (a) { |
2209 | 0 | int len = spans[1].x - spans[0].x; |
2210 | 0 | if (a == 0xff) { |
2211 | 0 | memset(d + spans[0].x, r->u.fill.pixel, len); |
2212 | 0 | } else { |
2213 | 0 | uint8_t s = mul8_8(a, r->u.fill.pixel); |
2214 | 0 | uint8_t *dst = d + spans[0].x; |
2215 | 0 | a = ~a; |
2216 | 0 | while (len-- > 0) { |
2217 | 0 | uint8_t t = mul8_8(*dst, a); |
2218 | 0 | *dst++ = t + s; |
2219 | 0 | } |
2220 | 0 | } |
2221 | 0 | } |
2222 | 0 | spans++; |
2223 | 0 | } while (--num_spans > 1); |
2224 | 0 | } else { |
2225 | 0 | do { |
2226 | 0 | uint8_t a = spans[0].coverage; |
2227 | 0 | if (a) { |
2228 | 0 | int yy = y, hh = h; |
2229 | 0 | if (a == 0xff) { |
2230 | 0 | do { |
2231 | 0 | int len = spans[1].x - spans[0].x; |
2232 | 0 | uint8_t *d = r->u.fill.data + r->u.fill.stride*yy + spans[0].x; |
2233 | 0 | memset(d, r->u.fill.pixel, len); |
2234 | 0 | yy++; |
2235 | 0 | } while (--hh); |
2236 | 0 | } else { |
2237 | 0 | uint8_t s = mul8_8(a, r->u.fill.pixel); |
2238 | 0 | a = ~a; |
2239 | 0 | do { |
2240 | 0 | int len = spans[1].x - spans[0].x; |
2241 | 0 | uint8_t *d = r->u.fill.data + r->u.fill.stride*yy + spans[0].x; |
2242 | 0 | while (len-- > 0) { |
2243 | 0 | uint8_t t = mul8_8(*d, a); |
2244 | 0 | *d++ = t + s; |
2245 | 0 | } |
2246 | 0 | yy++; |
2247 | 0 | } while (--hh); |
2248 | 0 | } |
2249 | 0 | } |
2250 | 0 | spans++; |
2251 | 0 | } while (--num_spans > 1); |
2252 | 0 | } |
2253 | |
|
2254 | 0 | return CAIRO_STATUS_SUCCESS; |
2255 | 0 | } |
2256 | | |
2257 | | static cairo_status_t |
2258 | | _fill_xrgb32_lerp_opaque_spans (void *abstract_renderer, int y, int h, |
2259 | | const cairo_half_open_span_t *spans, unsigned num_spans) |
2260 | 1.22M | { |
2261 | 1.22M | cairo_image_span_renderer_t *r = abstract_renderer; |
2262 | | |
2263 | 1.22M | if (num_spans == 0) |
2264 | 58.9k | return CAIRO_STATUS_SUCCESS; |
2265 | | |
2266 | 1.16M | if (likely(h == 1)) { |
2267 | 7.11M | do { |
2268 | 7.11M | uint8_t a = spans[0].coverage; |
2269 | 7.11M | if (a) { |
2270 | 6.49M | int len = spans[1].x - spans[0].x; |
2271 | 6.49M | uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*4); |
2272 | 6.49M | if (a == 0xff) { |
2273 | 1.28M | if (len > 31) { |
2274 | 704k | pixman_fill ((uint32_t *)r->u.fill.data, r->u.fill.stride / sizeof(uint32_t), 32, |
2275 | 704k | spans[0].x, y, len, 1, r->u.fill.pixel); |
2276 | 704k | } else { |
2277 | 579k | uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*4); |
2278 | 8.10M | while (len-- > 0) |
2279 | 7.52M | *d++ = r->u.fill.pixel; |
2280 | 579k | } |
2281 | 16.6M | } else while (len-- > 0) { |
2282 | 11.4M | *d = lerp8x4 (r->u.fill.pixel, a, *d); |
2283 | 11.4M | d++; |
2284 | 11.4M | } |
2285 | 6.49M | } |
2286 | 7.11M | spans++; |
2287 | 7.11M | } while (--num_spans > 1); |
2288 | 1.13M | } else { |
2289 | 120k | do { |
2290 | 120k | uint8_t a = spans[0].coverage; |
2291 | 120k | if (a) { |
2292 | 102k | if (a == 0xff) { |
2293 | 32.2k | if (spans[1].x - spans[0].x > 16) { |
2294 | 19.7k | pixman_fill ((uint32_t *)r->u.fill.data, r->u.fill.stride / sizeof(uint32_t), 32, |
2295 | 19.7k | spans[0].x, y, spans[1].x - spans[0].x, h, |
2296 | 19.7k | r->u.fill.pixel); |
2297 | 19.7k | } else { |
2298 | 12.4k | int yy = y, hh = h; |
2299 | 676k | do { |
2300 | 676k | int len = spans[1].x - spans[0].x; |
2301 | 676k | uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*4); |
2302 | 5.27M | while (len-- > 0) |
2303 | 4.60M | *d++ = r->u.fill.pixel; |
2304 | 676k | yy++; |
2305 | 676k | } while (--hh); |
2306 | 12.4k | } |
2307 | 70.0k | } else { |
2308 | 70.0k | int yy = y, hh = h; |
2309 | 6.55M | do { |
2310 | 6.55M | int len = spans[1].x - spans[0].x; |
2311 | 6.55M | uint32_t *d = (uint32_t *)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*4); |
2312 | 13.1M | while (len-- > 0) { |
2313 | 6.56M | *d = lerp8x4 (r->u.fill.pixel, a, *d); |
2314 | 6.56M | d++; |
2315 | 6.56M | } |
2316 | 6.55M | yy++; |
2317 | 6.55M | } while (--hh); |
2318 | 70.0k | } |
2319 | 102k | } |
2320 | 120k | spans++; |
2321 | 120k | } while (--num_spans > 1); |
2322 | 27.3k | } |
2323 | | |
2324 | 1.16M | return CAIRO_STATUS_SUCCESS; |
2325 | 1.22M | } |
2326 | | |
2327 | | static cairo_status_t |
2328 | | _fill_a8_lerp_spans (void *abstract_renderer, int y, int h, |
2329 | | const cairo_half_open_span_t *spans, unsigned num_spans) |
2330 | 0 | { |
2331 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
2332 | |
|
2333 | 0 | if (num_spans == 0) |
2334 | 0 | return CAIRO_STATUS_SUCCESS; |
2335 | | |
2336 | 0 | if (likely(h == 1)) { |
2337 | 0 | do { |
2338 | 0 | uint8_t a = mul8_8 (spans[0].coverage, r->bpp); |
2339 | 0 | if (a) { |
2340 | 0 | int len = spans[1].x - spans[0].x; |
2341 | 0 | uint8_t *d = r->u.fill.data + r->u.fill.stride*y + spans[0].x; |
2342 | 0 | uint16_t p = (uint16_t)a * r->u.fill.pixel + 0x7f; |
2343 | 0 | uint16_t ia = ~a; |
2344 | 0 | while (len-- > 0) { |
2345 | 0 | uint16_t t = *d*ia + p; |
2346 | 0 | *d++ = (t + (t>>8)) >> 8; |
2347 | 0 | } |
2348 | 0 | } |
2349 | 0 | spans++; |
2350 | 0 | } while (--num_spans > 1); |
2351 | 0 | } else { |
2352 | 0 | do { |
2353 | 0 | uint8_t a = mul8_8 (spans[0].coverage, r->bpp); |
2354 | 0 | if (a) { |
2355 | 0 | int yy = y, hh = h; |
2356 | 0 | uint16_t p = (uint16_t)a * r->u.fill.pixel + 0x7f; |
2357 | 0 | uint16_t ia = ~a; |
2358 | 0 | do { |
2359 | 0 | int len = spans[1].x - spans[0].x; |
2360 | 0 | uint8_t *d = r->u.fill.data + r->u.fill.stride*yy + spans[0].x; |
2361 | 0 | while (len-- > 0) { |
2362 | 0 | uint16_t t = *d*ia + p; |
2363 | 0 | *d++ = (t + (t>>8)) >> 8; |
2364 | 0 | } |
2365 | 0 | yy++; |
2366 | 0 | } while (--hh); |
2367 | 0 | } |
2368 | 0 | spans++; |
2369 | 0 | } while (--num_spans > 1); |
2370 | 0 | } |
2371 | |
|
2372 | 0 | return CAIRO_STATUS_SUCCESS; |
2373 | 0 | } |
2374 | | |
2375 | | static cairo_status_t |
2376 | | _fill_xrgb32_lerp_spans (void *abstract_renderer, int y, int h, |
2377 | | const cairo_half_open_span_t *spans, unsigned num_spans) |
2378 | 0 | { |
2379 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
2380 | |
|
2381 | 0 | if (num_spans == 0) |
2382 | 0 | return CAIRO_STATUS_SUCCESS; |
2383 | | |
2384 | 0 | if (likely(h == 1)) { |
2385 | 0 | do { |
2386 | 0 | uint8_t a = mul8_8 (spans[0].coverage, r->bpp); |
2387 | 0 | if (a) { |
2388 | 0 | int len = spans[1].x - spans[0].x; |
2389 | 0 | uint32_t *d = (uint32_t*)(r->u.fill.data + r->u.fill.stride*y + spans[0].x*4); |
2390 | 0 | while (len-- > 0) { |
2391 | 0 | *d = lerp8x4 (r->u.fill.pixel, a, *d); |
2392 | 0 | d++; |
2393 | 0 | } |
2394 | 0 | } |
2395 | 0 | spans++; |
2396 | 0 | } while (--num_spans > 1); |
2397 | 0 | } else { |
2398 | 0 | do { |
2399 | 0 | uint8_t a = mul8_8 (spans[0].coverage, r->bpp); |
2400 | 0 | if (a) { |
2401 | 0 | int yy = y, hh = h; |
2402 | 0 | do { |
2403 | 0 | int len = spans[1].x - spans[0].x; |
2404 | 0 | uint32_t *d = (uint32_t *)(r->u.fill.data + r->u.fill.stride*yy + spans[0].x*4); |
2405 | 0 | while (len-- > 0) { |
2406 | 0 | *d = lerp8x4 (r->u.fill.pixel, a, *d); |
2407 | 0 | d++; |
2408 | 0 | } |
2409 | 0 | yy++; |
2410 | 0 | } while (--hh); |
2411 | 0 | } |
2412 | 0 | spans++; |
2413 | 0 | } while (--num_spans > 1); |
2414 | 0 | } |
2415 | |
|
2416 | 0 | return CAIRO_STATUS_SUCCESS; |
2417 | 0 | } |
2418 | | |
2419 | | static cairo_status_t |
2420 | | _blit_xrgb32_lerp_spans (void *abstract_renderer, int y, int h, |
2421 | | const cairo_half_open_span_t *spans, unsigned num_spans) |
2422 | 1.14k | { |
2423 | 1.14k | cairo_image_span_renderer_t *r = abstract_renderer; |
2424 | | |
2425 | 1.14k | if (num_spans == 0) |
2426 | 55 | return CAIRO_STATUS_SUCCESS; |
2427 | | |
2428 | 1.08k | if (likely(h == 1)) { |
2429 | 1.08k | uint8_t *src = r->u.blit.src_data + y*r->u.blit.src_stride; |
2430 | 1.08k | uint8_t *dst = r->u.blit.data + y*r->u.blit.stride; |
2431 | 1.08k | do { |
2432 | 1.08k | uint8_t a = mul8_8 (spans[0].coverage, r->bpp); |
2433 | 1.08k | if (a) { |
2434 | 1.07k | uint32_t *s = (uint32_t*)src + spans[0].x; |
2435 | 1.07k | uint32_t *d = (uint32_t*)dst + spans[0].x; |
2436 | 1.07k | int len = spans[1].x - spans[0].x; |
2437 | 1.07k | if (a == 0xff) { |
2438 | 692 | if (len == 1) |
2439 | 692 | *d = *s; |
2440 | 0 | else |
2441 | 0 | memcpy(d, s, len*4); |
2442 | 692 | } else { |
2443 | 770 | while (len-- > 0) { |
2444 | 385 | *d = lerp8x4 (*s, a, *d); |
2445 | 385 | s++, d++; |
2446 | 385 | } |
2447 | 385 | } |
2448 | 1.07k | } |
2449 | 1.08k | spans++; |
2450 | 1.08k | } while (--num_spans > 1); |
2451 | 1.08k | } else { |
2452 | 0 | do { |
2453 | 0 | uint8_t a = mul8_8 (spans[0].coverage, r->bpp); |
2454 | 0 | if (a) { |
2455 | 0 | int yy = y, hh = h; |
2456 | 0 | do { |
2457 | 0 | uint32_t *s = (uint32_t *)(r->u.blit.src_data + yy*r->u.blit.src_stride + spans[0].x * 4); |
2458 | 0 | uint32_t *d = (uint32_t *)(r->u.blit.data + yy*r->u.blit.stride + spans[0].x * 4); |
2459 | 0 | int len = spans[1].x - spans[0].x; |
2460 | 0 | if (a == 0xff) { |
2461 | 0 | if (len == 1) |
2462 | 0 | *d = *s; |
2463 | 0 | else |
2464 | 0 | memcpy(d, s, len * 4); |
2465 | 0 | } else { |
2466 | 0 | while (len-- > 0) { |
2467 | 0 | *d = lerp8x4 (*s, a, *d); |
2468 | 0 | s++, d++; |
2469 | 0 | } |
2470 | 0 | } |
2471 | 0 | yy++; |
2472 | 0 | } while (--hh); |
2473 | 0 | } |
2474 | 0 | spans++; |
2475 | 0 | } while (--num_spans > 1); |
2476 | 0 | } |
2477 | | |
2478 | 1.08k | return CAIRO_STATUS_SUCCESS; |
2479 | 1.14k | } |
2480 | | |
2481 | | static cairo_status_t |
2482 | | _inplace_spans (void *abstract_renderer, |
2483 | | int y, int h, |
2484 | | const cairo_half_open_span_t *spans, |
2485 | | unsigned num_spans) |
2486 | 11.7M | { |
2487 | 11.7M | cairo_image_span_renderer_t *r = abstract_renderer; |
2488 | 11.7M | uint8_t *mask; |
2489 | 11.7M | int x0, x1; |
2490 | | |
2491 | 11.7M | if (num_spans == 0) |
2492 | 158k | return CAIRO_STATUS_SUCCESS; |
2493 | | |
2494 | 11.6M | if (num_spans == 2 && spans[0].coverage == 0xff) { |
2495 | 3.33k | pixman_image_composite32 (r->op, r->src, NULL, r->u.composite.dst, |
2496 | 3.33k | spans[0].x + r->u.composite.src_x, |
2497 | 3.33k | y + r->u.composite.src_y, |
2498 | 3.33k | 0, 0, |
2499 | 3.33k | spans[0].x, y, |
2500 | 3.33k | spans[1].x - spans[0].x, h); |
2501 | 3.33k | return CAIRO_STATUS_SUCCESS; |
2502 | 3.33k | } |
2503 | | |
2504 | 11.6M | mask = (uint8_t *)pixman_image_get_data (r->mask); |
2505 | 11.6M | x1 = x0 = spans[0].x; |
2506 | 71.9M | do { |
2507 | 71.9M | int len = spans[1].x - spans[0].x; |
2508 | 71.9M | *mask++ = spans[0].coverage; |
2509 | 71.9M | if (len > 1) { |
2510 | 16.6M | if (len >= r->u.composite.run_length && spans[0].coverage == 0xff) { |
2511 | 9.63M | if (x1 != x0) { |
2512 | 9.56M | pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, |
2513 | 9.56M | x0 + r->u.composite.src_x, |
2514 | 9.56M | y + r->u.composite.src_y, |
2515 | 9.56M | 0, 0, |
2516 | 9.56M | x0, y, |
2517 | 9.56M | x1 - x0, h); |
2518 | 9.56M | } |
2519 | 9.63M | pixman_image_composite32 (r->op, r->src, NULL, r->u.composite.dst, |
2520 | 9.63M | spans[0].x + r->u.composite.src_x, |
2521 | 9.63M | y + r->u.composite.src_y, |
2522 | 9.63M | 0, 0, |
2523 | 9.63M | spans[0].x, y, |
2524 | 9.63M | len, h); |
2525 | 9.63M | mask = (uint8_t *)pixman_image_get_data (r->mask); |
2526 | 9.63M | x0 = spans[1].x; |
2527 | 9.63M | } else if (spans[0].coverage == 0x0 && |
2528 | 4.18M | x1 - x0 > r->u.composite.run_length) { |
2529 | 1.31M | pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, |
2530 | 1.31M | x0 + r->u.composite.src_x, |
2531 | 1.31M | y + r->u.composite.src_y, |
2532 | 1.31M | 0, 0, |
2533 | 1.31M | x0, y, |
2534 | 1.31M | x1 - x0, h); |
2535 | 1.31M | mask = (uint8_t *)pixman_image_get_data (r->mask); |
2536 | 1.31M | x0 = spans[1].x; |
2537 | 5.69M | }else { |
2538 | 5.69M | memset (mask, spans[0].coverage, --len); |
2539 | 5.69M | mask += len; |
2540 | 5.69M | } |
2541 | 16.6M | } |
2542 | 71.9M | x1 = spans[1].x; |
2543 | 71.9M | spans++; |
2544 | 71.9M | } while (--num_spans > 1); |
2545 | | |
2546 | 11.6M | if (x1 != x0) { |
2547 | 11.6M | pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, |
2548 | 11.6M | x0 + r->u.composite.src_x, |
2549 | 11.6M | y + r->u.composite.src_y, |
2550 | 11.6M | 0, 0, |
2551 | 11.6M | x0, y, |
2552 | 11.6M | x1 - x0, h); |
2553 | 11.6M | } |
2554 | | |
2555 | 11.6M | return CAIRO_STATUS_SUCCESS; |
2556 | 11.6M | } |
2557 | | |
2558 | | static cairo_status_t |
2559 | | _inplace_opacity_spans (void *abstract_renderer, int y, int h, |
2560 | | const cairo_half_open_span_t *spans, |
2561 | | unsigned num_spans) |
2562 | 507 | { |
2563 | 507 | cairo_image_span_renderer_t *r = abstract_renderer; |
2564 | 507 | uint8_t *mask; |
2565 | 507 | int x0, x1; |
2566 | | |
2567 | 507 | if (num_spans == 0) |
2568 | 0 | return CAIRO_STATUS_SUCCESS; |
2569 | | |
2570 | 507 | mask = (uint8_t *)pixman_image_get_data (r->mask); |
2571 | 507 | x1 = x0 = spans[0].x; |
2572 | 507 | do { |
2573 | 507 | int len = spans[1].x - spans[0].x; |
2574 | 507 | uint8_t m = mul8_8(spans[0].coverage, r->bpp); |
2575 | 507 | *mask++ = m; |
2576 | 507 | if (len > 1) { |
2577 | 0 | if (m == 0 && |
2578 | 0 | x1 - x0 > r->u.composite.run_length) { |
2579 | 0 | pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, |
2580 | 0 | x0 + r->u.composite.src_x, |
2581 | 0 | y + r->u.composite.src_y, |
2582 | 0 | 0, 0, |
2583 | 0 | x0, y, |
2584 | 0 | x1 - x0, h); |
2585 | 0 | mask = (uint8_t *)pixman_image_get_data (r->mask); |
2586 | 0 | x0 = spans[1].x; |
2587 | 0 | }else { |
2588 | 0 | memset (mask, m, --len); |
2589 | 0 | mask += len; |
2590 | 0 | } |
2591 | 0 | } |
2592 | 507 | x1 = spans[1].x; |
2593 | 507 | spans++; |
2594 | 507 | } while (--num_spans > 1); |
2595 | | |
2596 | 507 | if (x1 != x0) { |
2597 | 507 | pixman_image_composite32 (r->op, r->src, r->mask, r->u.composite.dst, |
2598 | 507 | x0 + r->u.composite.src_x, |
2599 | 507 | y + r->u.composite.src_y, |
2600 | 507 | 0, 0, |
2601 | 507 | x0, y, |
2602 | 507 | x1 - x0, h); |
2603 | 507 | } |
2604 | | |
2605 | 507 | return CAIRO_STATUS_SUCCESS; |
2606 | 507 | } |
2607 | | |
2608 | | static cairo_status_t |
2609 | | _inplace_src_spans (void *abstract_renderer, int y, int h, |
2610 | | const cairo_half_open_span_t *spans, |
2611 | | unsigned num_spans) |
2612 | 0 | { |
2613 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
2614 | 0 | uint8_t *m, *base = (uint8_t*)pixman_image_get_data(r->mask); |
2615 | 0 | int x0; |
2616 | |
|
2617 | 0 | if (num_spans == 0) |
2618 | 0 | return CAIRO_STATUS_SUCCESS; |
2619 | | |
2620 | 0 | x0 = spans[0].x; |
2621 | 0 | m = base; |
2622 | 0 | do { |
2623 | 0 | int len = spans[1].x - spans[0].x; |
2624 | 0 | if (len >= r->u.composite.run_length && spans[0].coverage == 0xff) { |
2625 | 0 | if (spans[0].x != x0) { |
2626 | | #if PIXMAN_HAS_OP_LERP |
2627 | | pixman_image_composite32 (PIXMAN_OP_LERP_SRC, |
2628 | | r->src, r->mask, r->u.composite.dst, |
2629 | | x0 + r->u.composite.src_x, |
2630 | | y + r->u.composite.src_y, |
2631 | | 0, 0, |
2632 | | x0, y, |
2633 | | spans[0].x - x0, h); |
2634 | | #else |
2635 | 0 | pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, |
2636 | 0 | r->mask, NULL, r->u.composite.dst, |
2637 | 0 | 0, 0, |
2638 | 0 | 0, 0, |
2639 | 0 | x0, y, |
2640 | 0 | spans[0].x - x0, h); |
2641 | 0 | pixman_image_composite32 (PIXMAN_OP_ADD, |
2642 | 0 | r->src, r->mask, r->u.composite.dst, |
2643 | 0 | x0 + r->u.composite.src_x, |
2644 | 0 | y + r->u.composite.src_y, |
2645 | 0 | 0, 0, |
2646 | 0 | x0, y, |
2647 | 0 | spans[0].x - x0, h); |
2648 | 0 | #endif |
2649 | 0 | } |
2650 | |
|
2651 | 0 | pixman_image_composite32 (PIXMAN_OP_SRC, |
2652 | 0 | r->src, NULL, r->u.composite.dst, |
2653 | 0 | spans[0].x + r->u.composite.src_x, |
2654 | 0 | y + r->u.composite.src_y, |
2655 | 0 | 0, 0, |
2656 | 0 | spans[0].x, y, |
2657 | 0 | spans[1].x - spans[0].x, h); |
2658 | |
|
2659 | 0 | m = base; |
2660 | 0 | x0 = spans[1].x; |
2661 | 0 | } else if (spans[0].coverage == 0x0) { |
2662 | 0 | if (spans[0].x != x0) { |
2663 | | #if PIXMAN_HAS_OP_LERP |
2664 | | pixman_image_composite32 (PIXMAN_OP_LERP_SRC, |
2665 | | r->src, r->mask, r->u.composite.dst, |
2666 | | x0 + r->u.composite.src_x, |
2667 | | y + r->u.composite.src_y, |
2668 | | 0, 0, |
2669 | | x0, y, |
2670 | | spans[0].x - x0, h); |
2671 | | #else |
2672 | 0 | pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, |
2673 | 0 | r->mask, NULL, r->u.composite.dst, |
2674 | 0 | 0, 0, |
2675 | 0 | 0, 0, |
2676 | 0 | x0, y, |
2677 | 0 | spans[0].x - x0, h); |
2678 | 0 | pixman_image_composite32 (PIXMAN_OP_ADD, |
2679 | 0 | r->src, r->mask, r->u.composite.dst, |
2680 | 0 | x0 + r->u.composite.src_x, |
2681 | 0 | y + r->u.composite.src_y, |
2682 | 0 | 0, 0, |
2683 | 0 | x0, y, |
2684 | 0 | spans[0].x - x0, h); |
2685 | 0 | #endif |
2686 | 0 | } |
2687 | |
|
2688 | 0 | m = base; |
2689 | 0 | x0 = spans[1].x; |
2690 | 0 | } else { |
2691 | 0 | *m++ = spans[0].coverage; |
2692 | 0 | if (len > 1) { |
2693 | 0 | memset (m, spans[0].coverage, --len); |
2694 | 0 | m += len; |
2695 | 0 | } |
2696 | 0 | } |
2697 | 0 | spans++; |
2698 | 0 | } while (--num_spans > 1); |
2699 | |
|
2700 | 0 | if (spans[0].x != x0) { |
2701 | | #if PIXMAN_HAS_OP_LERP |
2702 | | pixman_image_composite32 (PIXMAN_OP_LERP_SRC, |
2703 | | r->src, r->mask, r->u.composite.dst, |
2704 | | x0 + r->u.composite.src_x, |
2705 | | y + r->u.composite.src_y, |
2706 | | 0, 0, |
2707 | | x0, y, |
2708 | | spans[0].x - x0, h); |
2709 | | #else |
2710 | 0 | pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, |
2711 | 0 | r->mask, NULL, r->u.composite.dst, |
2712 | 0 | 0, 0, |
2713 | 0 | 0, 0, |
2714 | 0 | x0, y, |
2715 | 0 | spans[0].x - x0, h); |
2716 | 0 | pixman_image_composite32 (PIXMAN_OP_ADD, |
2717 | 0 | r->src, r->mask, r->u.composite.dst, |
2718 | 0 | x0 + r->u.composite.src_x, |
2719 | 0 | y + r->u.composite.src_y, |
2720 | 0 | 0, 0, |
2721 | 0 | x0, y, |
2722 | 0 | spans[0].x - x0, h); |
2723 | 0 | #endif |
2724 | 0 | } |
2725 | |
|
2726 | 0 | return CAIRO_STATUS_SUCCESS; |
2727 | 0 | } |
2728 | | |
2729 | | static cairo_status_t |
2730 | | _inplace_src_opacity_spans (void *abstract_renderer, int y, int h, |
2731 | | const cairo_half_open_span_t *spans, |
2732 | | unsigned num_spans) |
2733 | 0 | { |
2734 | 0 | cairo_image_span_renderer_t *r = abstract_renderer; |
2735 | 0 | uint8_t *mask; |
2736 | 0 | int x0; |
2737 | |
|
2738 | 0 | if (num_spans == 0) |
2739 | 0 | return CAIRO_STATUS_SUCCESS; |
2740 | | |
2741 | 0 | x0 = spans[0].x; |
2742 | 0 | mask = (uint8_t *)pixman_image_get_data (r->mask); |
2743 | 0 | do { |
2744 | 0 | int len = spans[1].x - spans[0].x; |
2745 | 0 | uint8_t m = mul8_8(spans[0].coverage, r->bpp); |
2746 | 0 | if (m == 0) { |
2747 | 0 | if (spans[0].x != x0) { |
2748 | | #if PIXMAN_HAS_OP_LERP |
2749 | | pixman_image_composite32 (PIXMAN_OP_LERP_SRC, |
2750 | | r->src, r->mask, r->u.composite.dst, |
2751 | | x0 + r->u.composite.src_x, |
2752 | | y + r->u.composite.src_y, |
2753 | | 0, 0, |
2754 | | x0, y, |
2755 | | spans[0].x - x0, h); |
2756 | | #else |
2757 | 0 | pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, |
2758 | 0 | r->mask, NULL, r->u.composite.dst, |
2759 | 0 | 0, 0, |
2760 | 0 | 0, 0, |
2761 | 0 | x0, y, |
2762 | 0 | spans[0].x - x0, h); |
2763 | 0 | pixman_image_composite32 (PIXMAN_OP_ADD, |
2764 | 0 | r->src, r->mask, r->u.composite.dst, |
2765 | 0 | x0 + r->u.composite.src_x, |
2766 | 0 | y + r->u.composite.src_y, |
2767 | 0 | 0, 0, |
2768 | 0 | x0, y, |
2769 | 0 | spans[0].x - x0, h); |
2770 | 0 | #endif |
2771 | 0 | } |
2772 | |
|
2773 | 0 | mask = (uint8_t *)pixman_image_get_data (r->mask); |
2774 | 0 | x0 = spans[1].x; |
2775 | 0 | } else { |
2776 | 0 | *mask++ = m; |
2777 | 0 | if (len > 1) { |
2778 | 0 | memset (mask, m, --len); |
2779 | 0 | mask += len; |
2780 | 0 | } |
2781 | 0 | } |
2782 | 0 | spans++; |
2783 | 0 | } while (--num_spans > 1); |
2784 | |
|
2785 | 0 | if (spans[0].x != x0) { |
2786 | | #if PIXMAN_HAS_OP_LERP |
2787 | | pixman_image_composite32 (PIXMAN_OP_LERP_SRC, |
2788 | | r->src, r->mask, r->u.composite.dst, |
2789 | | x0 + r->u.composite.src_x, |
2790 | | y + r->u.composite.src_y, |
2791 | | 0, 0, |
2792 | | x0, y, |
2793 | | spans[0].x - x0, h); |
2794 | | #else |
2795 | 0 | pixman_image_composite32 (PIXMAN_OP_OUT_REVERSE, |
2796 | 0 | r->mask, NULL, r->u.composite.dst, |
2797 | 0 | 0, 0, |
2798 | 0 | 0, 0, |
2799 | 0 | x0, y, |
2800 | 0 | spans[0].x - x0, h); |
2801 | 0 | pixman_image_composite32 (PIXMAN_OP_ADD, |
2802 | 0 | r->src, r->mask, r->u.composite.dst, |
2803 | 0 | x0 + r->u.composite.src_x, |
2804 | 0 | y + r->u.composite.src_y, |
2805 | 0 | 0, 0, |
2806 | 0 | x0, y, |
2807 | 0 | spans[0].x - x0, h); |
2808 | 0 | #endif |
2809 | 0 | } |
2810 | |
|
2811 | 0 | return CAIRO_STATUS_SUCCESS; |
2812 | 0 | } |
2813 | | |
2814 | | static void free_pixels (pixman_image_t *image, void *data) |
2815 | 0 | { |
2816 | 0 | free (data); |
2817 | 0 | } |
2818 | | |
2819 | | static cairo_int_status_t |
2820 | | inplace_renderer_init (cairo_image_span_renderer_t *r, |
2821 | | const cairo_composite_rectangles_t *composite, |
2822 | | cairo_antialias_t antialias, |
2823 | | cairo_bool_t needs_clip) |
2824 | 320k | { |
2825 | 320k | cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; |
2826 | 320k | uint8_t *buf; |
2827 | | |
2828 | 320k | if (composite->mask_pattern.base.type != CAIRO_PATTERN_TYPE_SOLID) |
2829 | 0 | return CAIRO_INT_STATUS_UNSUPPORTED; |
2830 | | |
2831 | 320k | r->base.render_rows = NULL; |
2832 | 320k | r->bpp = composite->mask_pattern.solid.color.alpha_short >> 8; |
2833 | | |
2834 | 320k | if (composite->source_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { |
2835 | 311k | const cairo_color_t *color; |
2836 | | |
2837 | 311k | color = &composite->source_pattern.solid.color; |
2838 | 311k | if (composite->op == CAIRO_OPERATOR_CLEAR) |
2839 | 0 | color = CAIRO_COLOR_TRANSPARENT; |
2840 | | |
2841 | 311k | if (fill_reduces_to_source (composite->op, color, dst, &r->u.fill.pixel)) { |
2842 | | /* Use plain C for the fill operations as the span length is |
2843 | | * typically small, too small to payback the startup overheads of |
2844 | | * using SSE2 etc. |
2845 | | */ |
2846 | 106k | if (r->bpp == 0xff) { |
2847 | 106k | switch (dst->format) { |
2848 | 0 | case CAIRO_FORMAT_A8: |
2849 | 0 | r->base.render_rows = _fill_a8_lerp_opaque_spans; |
2850 | 0 | break; |
2851 | 0 | case CAIRO_FORMAT_RGB24: |
2852 | 106k | case CAIRO_FORMAT_ARGB32: |
2853 | 106k | r->base.render_rows = _fill_xrgb32_lerp_opaque_spans; |
2854 | 106k | break; |
2855 | 0 | case CAIRO_FORMAT_A1: |
2856 | 0 | case CAIRO_FORMAT_RGB16_565: |
2857 | 0 | case CAIRO_FORMAT_RGB30: |
2858 | 0 | case CAIRO_FORMAT_RGB96F: |
2859 | 0 | case CAIRO_FORMAT_RGBA128F: |
2860 | 0 | case CAIRO_FORMAT_INVALID: |
2861 | 0 | default: break; |
2862 | 106k | } |
2863 | 106k | } else { |
2864 | 0 | switch (dst->format) { |
2865 | 0 | case CAIRO_FORMAT_A8: |
2866 | 0 | r->base.render_rows = _fill_a8_lerp_spans; |
2867 | 0 | break; |
2868 | 0 | case CAIRO_FORMAT_RGB24: |
2869 | 0 | case CAIRO_FORMAT_ARGB32: |
2870 | 0 | r->base.render_rows = _fill_xrgb32_lerp_spans; |
2871 | 0 | break; |
2872 | 0 | case CAIRO_FORMAT_A1: |
2873 | 0 | case CAIRO_FORMAT_RGB16_565: |
2874 | 0 | case CAIRO_FORMAT_RGB30: |
2875 | 0 | case CAIRO_FORMAT_RGB96F: |
2876 | 0 | case CAIRO_FORMAT_RGBA128F: |
2877 | 0 | case CAIRO_FORMAT_INVALID: |
2878 | 0 | default: break; |
2879 | 0 | } |
2880 | 0 | } |
2881 | 106k | r->u.fill.data = dst->data; |
2882 | 106k | r->u.fill.stride = dst->stride; |
2883 | 106k | } |
2884 | 311k | } else if ((dst->format == CAIRO_FORMAT_ARGB32 || dst->format == CAIRO_FORMAT_RGB24) && |
2885 | 8.96k | (composite->op == CAIRO_OPERATOR_SOURCE || |
2886 | 8.96k | (composite->op == CAIRO_OPERATOR_OVER && |
2887 | 8.96k | (dst->base.is_clear || (dst->base.content & CAIRO_CONTENT_ALPHA) == 0))) && |
2888 | 1.37k | composite->source_pattern.base.type == CAIRO_PATTERN_TYPE_SURFACE && |
2889 | 1.24k | composite->source_pattern.surface.surface->backend->type == CAIRO_SURFACE_TYPE_IMAGE && |
2890 | 1.24k | to_image_surface(composite->source_pattern.surface.surface)->format == dst->format) |
2891 | 1.24k | { |
2892 | 1.24k | cairo_image_surface_t *src = |
2893 | 1.24k | to_image_surface(composite->source_pattern.surface.surface); |
2894 | 1.24k | int tx, ty; |
2895 | | |
2896 | 1.24k | if (_cairo_matrix_is_integer_translation(&composite->source_pattern.base.matrix, |
2897 | 1.24k | &tx, &ty) && |
2898 | 1.14k | composite->bounded.x + tx >= 0 && |
2899 | 1.14k | composite->bounded.y + ty >= 0 && |
2900 | 1.14k | composite->bounded.x + composite->bounded.width + tx <= src->width && |
2901 | 1.14k | composite->bounded.y + composite->bounded.height + ty <= src->height) { |
2902 | | |
2903 | 1.14k | assert(PIXMAN_FORMAT_BPP(dst->pixman_format) == 32); |
2904 | 1.14k | r->u.blit.stride = dst->stride; |
2905 | 1.14k | r->u.blit.data = dst->data; |
2906 | 1.14k | r->u.blit.src_stride = src->stride; |
2907 | 1.14k | r->u.blit.src_data = src->data + src->stride * ty + tx * 4; |
2908 | 1.14k | r->base.render_rows = _blit_xrgb32_lerp_spans; |
2909 | 1.14k | } |
2910 | 1.24k | } |
2911 | 320k | if (r->base.render_rows == NULL) { |
2912 | 212k | const cairo_pattern_t *src = &composite->source_pattern.base; |
2913 | 212k | unsigned int width; |
2914 | | |
2915 | 212k | if (composite->is_bounded == 0) |
2916 | 0 | return CAIRO_INT_STATUS_UNSUPPORTED; |
2917 | | |
2918 | 212k | r->base.render_rows = r->bpp == 0xff ? _inplace_spans : _inplace_opacity_spans; |
2919 | 212k | width = (composite->bounded.width + 3) & ~3; |
2920 | | |
2921 | 212k | r->u.composite.run_length = 8; |
2922 | 212k | if (src->type == CAIRO_PATTERN_TYPE_LINEAR || |
2923 | 208k | src->type == CAIRO_PATTERN_TYPE_RADIAL) |
2924 | 6.04k | r->u.composite.run_length = 256; |
2925 | 212k | if (dst->base.is_clear && |
2926 | 234 | (composite->op == CAIRO_OPERATOR_SOURCE || |
2927 | 234 | composite->op == CAIRO_OPERATOR_OVER || |
2928 | 234 | composite->op == CAIRO_OPERATOR_ADD)) { |
2929 | 234 | r->op = PIXMAN_OP_SRC; |
2930 | 212k | } else if (composite->op == CAIRO_OPERATOR_SOURCE) { |
2931 | 0 | r->base.render_rows = r->bpp == 0xff ? _inplace_src_spans : _inplace_src_opacity_spans; |
2932 | 0 | r->u.composite.mask_y = r->composite->unbounded.y; |
2933 | 0 | width = (composite->unbounded.width + 3) & ~3; |
2934 | 212k | } else if (composite->op == CAIRO_OPERATOR_CLEAR) { |
2935 | 0 | r->op = PIXMAN_OP_OUT_REVERSE; |
2936 | 0 | src = NULL; |
2937 | 212k | } else { |
2938 | 212k | r->op = _pixman_operator (composite->op); |
2939 | 212k | } |
2940 | | |
2941 | 212k | r->src = _pixman_image_for_pattern (dst, src, FALSE, |
2942 | 212k | &composite->bounded, |
2943 | 212k | &composite->source_sample_area, |
2944 | 212k | &r->u.composite.src_x, &r->u.composite.src_y); |
2945 | 212k | if (unlikely (r->src == NULL)) |
2946 | 1 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
2947 | | |
2948 | | /* Create an effectively unbounded mask by repeating the single line */ |
2949 | 212k | buf = r->_buf; |
2950 | 212k | if (width > SZ_BUF) { |
2951 | 0 | buf = _cairo_malloc (width); |
2952 | 0 | if (unlikely (buf == NULL)) { |
2953 | 0 | pixman_image_unref (r->src); |
2954 | 0 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
2955 | 0 | } |
2956 | 0 | } |
2957 | 212k | r->mask = pixman_image_create_bits (PIXMAN_a8, |
2958 | 212k | width, composite->unbounded.height, |
2959 | 212k | (uint32_t *)buf, 0); |
2960 | 212k | if (unlikely (r->mask == NULL)) { |
2961 | 0 | pixman_image_unref (r->src); |
2962 | 0 | if (buf != r->_buf) |
2963 | 0 | free (buf); |
2964 | 0 | return _cairo_error(CAIRO_STATUS_NO_MEMORY); |
2965 | 0 | } |
2966 | | |
2967 | 212k | if (buf != r->_buf) |
2968 | 0 | pixman_image_set_destroy_function (r->mask, free_pixels, buf); |
2969 | | |
2970 | 212k | r->u.composite.dst = dst->pixman_image; |
2971 | 212k | } |
2972 | | |
2973 | 320k | return CAIRO_INT_STATUS_SUCCESS; |
2974 | 320k | } |
2975 | | |
2976 | | static cairo_int_status_t |
2977 | | span_renderer_init (cairo_abstract_span_renderer_t *_r, |
2978 | | const cairo_composite_rectangles_t *composite, |
2979 | | cairo_antialias_t antialias, |
2980 | | cairo_bool_t needs_clip) |
2981 | 320k | { |
2982 | 320k | cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *)_r; |
2983 | 320k | cairo_image_surface_t *dst = (cairo_image_surface_t *)composite->surface; |
2984 | 320k | const cairo_pattern_t *source = &composite->source_pattern.base; |
2985 | 320k | cairo_operator_t op = composite->op; |
2986 | 320k | cairo_int_status_t status; |
2987 | | |
2988 | 320k | TRACE ((stderr, "%s: antialias=%d, needs_clip=%d\n", __FUNCTION__, |
2989 | 320k | antialias, needs_clip)); |
2990 | | |
2991 | 320k | if (needs_clip) |
2992 | 0 | return CAIRO_INT_STATUS_UNSUPPORTED; |
2993 | | |
2994 | 320k | r->composite = composite; |
2995 | 320k | r->mask = NULL; |
2996 | 320k | r->src = NULL; |
2997 | 320k | r->base.finish = NULL; |
2998 | | |
2999 | 320k | status = mono_renderer_init (r, composite, antialias, needs_clip); |
3000 | 320k | if (status != CAIRO_INT_STATUS_UNSUPPORTED) |
3001 | 0 | return status; |
3002 | | |
3003 | 320k | status = inplace_renderer_init (r, composite, antialias, needs_clip); |
3004 | 320k | if (status != CAIRO_INT_STATUS_UNSUPPORTED) |
3005 | 320k | return status; |
3006 | | |
3007 | 0 | r->bpp = 0; |
3008 | |
|
3009 | 0 | if (op == CAIRO_OPERATOR_CLEAR) { |
3010 | | #if PIXMAN_HAS_OP_LERP |
3011 | | op = PIXMAN_OP_LERP_CLEAR; |
3012 | | #else |
3013 | 0 | source = &_cairo_pattern_white.base; |
3014 | 0 | op = PIXMAN_OP_OUT_REVERSE; |
3015 | 0 | #endif |
3016 | 0 | } else if (dst->base.is_clear && |
3017 | 0 | (op == CAIRO_OPERATOR_SOURCE || |
3018 | 0 | op == CAIRO_OPERATOR_OVER || |
3019 | 0 | op == CAIRO_OPERATOR_ADD)) { |
3020 | 0 | op = PIXMAN_OP_SRC; |
3021 | 0 | } else if (op == CAIRO_OPERATOR_SOURCE) { |
3022 | 0 | if (_cairo_pattern_is_opaque (&composite->source_pattern.base, |
3023 | 0 | &composite->source_sample_area)) |
3024 | 0 | { |
3025 | 0 | op = PIXMAN_OP_OVER; |
3026 | 0 | } |
3027 | 0 | else |
3028 | 0 | { |
3029 | | #if PIXMAN_HAS_OP_LERP |
3030 | | op = PIXMAN_OP_LERP_SRC; |
3031 | | #else |
3032 | 0 | return CAIRO_INT_STATUS_UNSUPPORTED; |
3033 | 0 | #endif |
3034 | 0 | } |
3035 | 0 | } else { |
3036 | 0 | op = _pixman_operator (op); |
3037 | 0 | } |
3038 | 0 | r->op = op; |
3039 | |
|
3040 | 0 | r->src = _pixman_image_for_pattern (dst, source, FALSE, |
3041 | 0 | &composite->unbounded, |
3042 | 0 | &composite->source_sample_area, |
3043 | 0 | &r->u.mask.src_x, &r->u.mask.src_y); |
3044 | 0 | if (unlikely (r->src == NULL)) |
3045 | 0 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
3046 | | |
3047 | 0 | r->opacity = 1.0; |
3048 | 0 | if (composite->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID) { |
3049 | 0 | r->opacity = composite->mask_pattern.solid.color.alpha; |
3050 | 0 | } else { |
3051 | 0 | pixman_image_t *mask; |
3052 | 0 | int mask_x, mask_y; |
3053 | |
|
3054 | 0 | mask = _pixman_image_for_pattern (dst, |
3055 | 0 | &composite->mask_pattern.base, |
3056 | 0 | TRUE, |
3057 | 0 | &composite->unbounded, |
3058 | 0 | &composite->mask_sample_area, |
3059 | 0 | &mask_x, &mask_y); |
3060 | 0 | if (unlikely (mask == NULL)) |
3061 | 0 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
3062 | | |
3063 | | /* XXX Component-alpha? */ |
3064 | 0 | if ((dst->base.content & CAIRO_CONTENT_COLOR) == 0 && |
3065 | 0 | _cairo_pattern_is_opaque (source, &composite->source_sample_area)) |
3066 | 0 | { |
3067 | 0 | pixman_image_unref (r->src); |
3068 | 0 | r->src = mask; |
3069 | 0 | r->u.mask.src_x = mask_x; |
3070 | 0 | r->u.mask.src_y = mask_y; |
3071 | 0 | mask = NULL; |
3072 | 0 | } |
3073 | |
|
3074 | 0 | if (mask) { |
3075 | 0 | pixman_image_unref (mask); |
3076 | 0 | return CAIRO_INT_STATUS_UNSUPPORTED; |
3077 | 0 | } |
3078 | 0 | } |
3079 | | |
3080 | 0 | r->u.mask.extents = composite->unbounded; |
3081 | 0 | r->u.mask.stride = (r->u.mask.extents.width + 3) & ~3; |
3082 | 0 | if (r->u.mask.extents.height * r->u.mask.stride > SZ_BUF) { |
3083 | 0 | r->mask = pixman_image_create_bits (PIXMAN_a8, |
3084 | 0 | r->u.mask.extents.width, |
3085 | 0 | r->u.mask.extents.height, |
3086 | 0 | NULL, 0); |
3087 | |
|
3088 | 0 | r->base.render_rows = _cairo_image_spans; |
3089 | 0 | r->base.finish = NULL; |
3090 | 0 | } else { |
3091 | 0 | r->mask = pixman_image_create_bits (PIXMAN_a8, |
3092 | 0 | r->u.mask.extents.width, |
3093 | 0 | r->u.mask.extents.height, |
3094 | 0 | (uint32_t *)r->_buf, r->u.mask.stride); |
3095 | |
|
3096 | 0 | r->base.render_rows = _cairo_image_spans_and_zero; |
3097 | 0 | r->base.finish = _cairo_image_finish_spans_and_zero; |
3098 | 0 | } |
3099 | 0 | if (unlikely (r->mask == NULL)) |
3100 | 0 | return _cairo_error (CAIRO_STATUS_NO_MEMORY); |
3101 | | |
3102 | 0 | r->u.mask.data = (uint8_t *) pixman_image_get_data (r->mask); |
3103 | 0 | r->u.mask.stride = pixman_image_get_stride (r->mask); |
3104 | |
|
3105 | 0 | r->u.mask.extents.height += r->u.mask.extents.y; |
3106 | 0 | return CAIRO_STATUS_SUCCESS; |
3107 | 0 | } |
3108 | | |
3109 | | static void |
3110 | | span_renderer_fini (cairo_abstract_span_renderer_t *_r, |
3111 | | cairo_int_status_t status) |
3112 | 320k | { |
3113 | 320k | cairo_image_span_renderer_t *r = (cairo_image_span_renderer_t *) _r; |
3114 | | |
3115 | 320k | TRACE ((stderr, "%s\n", __FUNCTION__)); |
3116 | | |
3117 | 320k | if (likely (status == CAIRO_INT_STATUS_SUCCESS)) { |
3118 | 320k | if (r->base.finish) |
3119 | 0 | r->base.finish (r); |
3120 | 320k | } |
3121 | 320k | if (likely (status == CAIRO_INT_STATUS_SUCCESS && r->bpp == 0)) { |
3122 | 0 | const cairo_composite_rectangles_t *composite = r->composite; |
3123 | |
|
3124 | 0 | pixman_image_composite32 (r->op, r->src, r->mask, |
3125 | 0 | to_pixman_image (composite->surface), |
3126 | 0 | composite->unbounded.x + r->u.mask.src_x, |
3127 | 0 | composite->unbounded.y + r->u.mask.src_y, |
3128 | 0 | 0, 0, |
3129 | 0 | composite->unbounded.x, |
3130 | 0 | composite->unbounded.y, |
3131 | 0 | composite->unbounded.width, |
3132 | 0 | composite->unbounded.height); |
3133 | 0 | } |
3134 | | |
3135 | 320k | if (r->src) |
3136 | 212k | pixman_image_unref (r->src); |
3137 | 320k | if (r->mask) |
3138 | 212k | pixman_image_unref (r->mask); |
3139 | 320k | } |
3140 | | #endif |
3141 | | |
3142 | | const cairo_compositor_t * |
3143 | | _cairo_image_spans_compositor_get (void) |
3144 | 218k | { |
3145 | 218k | static cairo_atomic_once_t once = CAIRO_ATOMIC_ONCE_INIT; |
3146 | 218k | static cairo_spans_compositor_t spans; |
3147 | 218k | static cairo_compositor_t shape; |
3148 | | |
3149 | 218k | if (_cairo_atomic_init_once_enter(&once)) { |
3150 | 6 | _cairo_shape_mask_compositor_init (&shape, |
3151 | 6 | _cairo_image_traps_compositor_get()); |
3152 | 6 | shape.glyphs = NULL; |
3153 | | |
3154 | 6 | _cairo_spans_compositor_init (&spans, &shape); |
3155 | | |
3156 | 6 | spans.flags = 0; |
3157 | | #if PIXMAN_HAS_OP_LERP |
3158 | | spans.flags |= CAIRO_SPANS_COMPOSITOR_HAS_LERP; |
3159 | | #endif |
3160 | | |
3161 | | //spans.acquire = acquire; |
3162 | | //spans.release = release; |
3163 | 6 | spans.fill_boxes = fill_boxes; |
3164 | 6 | spans.draw_image_boxes = draw_image_boxes; |
3165 | | //spans.copy_boxes = copy_boxes; |
3166 | 6 | spans.pattern_to_surface = _cairo_image_source_create_for_pattern; |
3167 | | //spans.check_composite_boxes = check_composite_boxes; |
3168 | 6 | spans.composite_boxes = composite_boxes; |
3169 | | //spans.check_span_renderer = check_span_renderer; |
3170 | 6 | spans.renderer_init = span_renderer_init; |
3171 | 6 | spans.renderer_fini = span_renderer_fini; |
3172 | | |
3173 | 6 | _cairo_atomic_init_once_leave(&once); |
3174 | 6 | } |
3175 | | |
3176 | 218k | return &spans.base; |
3177 | 218k | } |