2007-06-18 16:30:09 -07:00
|
|
|
/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
|
2002-08-07 19:48:49 +00:00
|
|
|
/*
|
2004-10-21 18:40:50 +00:00
|
|
|
* Copyright © 2002 Keith Packard
|
2007-03-14 16:30:48 -07:00
|
|
|
* Copyright © 2007 Red Hat, Inc.
|
2002-08-07 19:48:49 +00:00
|
|
|
*
|
2004-10-12 14:17:23 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it either under the terms of the GNU Lesser General Public
|
|
|
|
|
* License version 2.1 as published by the Free Software Foundation
|
|
|
|
|
* (the "LGPL") or, at your option, under the terms of the Mozilla
|
|
|
|
|
* Public License Version 1.1 (the "MPL"). If you do not alter this
|
|
|
|
|
* notice, a recipient may use your version of this file under either
|
|
|
|
|
* the MPL or the LGPL.
|
2002-08-07 19:48:49 +00:00
|
|
|
*
|
2004-10-12 14:17:23 +00:00
|
|
|
* You should have received a copy of the LGPL along with this library
|
|
|
|
|
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
|
2010-04-27 10:17:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
|
2004-10-12 14:17:23 +00:00
|
|
|
* You should have received a copy of the MPL along with this library
|
|
|
|
|
* in the file COPYING-MPL-1.1
|
|
|
|
|
*
|
|
|
|
|
* The contents of this file are subject to the Mozilla Public License
|
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
|
|
|
|
|
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
|
|
|
|
|
* the specific language governing rights and limitations.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is the cairo graphics library.
|
|
|
|
|
*
|
|
|
|
|
* The Initial Developer of the Original Code is Keith Packard
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s):
|
|
|
|
|
* Keith R. Packard <keithp@keithp.com>
|
2005-02-22 11:35:03 +00:00
|
|
|
* Carl D. Worth <cworth@cworth.org>
|
2002-08-07 19:48:49 +00:00
|
|
|
*
|
2008-01-28 21:49:57 -05:00
|
|
|
* 2002-07-15: Converted from XRenderCompositeDoublePoly to #cairo_trap_t. Carl D. Worth
|
2002-08-07 19:48:49 +00:00
|
|
|
*/
|
|
|
|
|
|
2003-07-18 11:34:19 +00:00
|
|
|
#include "cairoint.h"
|
2002-08-07 19:48:49 +00:00
|
|
|
|
2010-01-22 17:56:26 +00:00
|
|
|
#include "cairo-boxes-private.h"
|
2010-01-18 16:58:40 +00:00
|
|
|
#include "cairo-error-private.h"
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
#include "cairo-region-private.h"
|
2009-08-11 13:43:32 +01:00
|
|
|
#include "cairo-slope-private.h"
|
2011-07-30 17:28:21 +01:00
|
|
|
#include "cairo-traps-private.h"
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
|
2002-08-07 19:48:49 +00:00
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
|
|
void
|
2003-08-26 07:40:17 +00:00
|
|
|
_cairo_traps_init (cairo_traps_t *traps)
|
2002-08-07 19:48:49 +00:00
|
|
|
{
|
2009-06-04 14:12:20 +01:00
|
|
|
VG (VALGRIND_MAKE_MEM_UNDEFINED (traps, sizeof (cairo_traps_t)));
|
|
|
|
|
|
2006-11-10 12:37:01 -08:00
|
|
|
traps->status = CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
traps->maybe_region = 1;
|
2009-08-25 20:51:06 +01:00
|
|
|
traps->is_rectilinear = 0;
|
2009-08-28 10:06:04 +01:00
|
|
|
traps->is_rectangular = 0;
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
|
2003-07-30 08:30:50 +00:00
|
|
|
traps->num_traps = 0;
|
2002-08-07 19:48:49 +00:00
|
|
|
|
2007-05-11 20:38:24 +01:00
|
|
|
traps->traps_size = ARRAY_LENGTH (traps->traps_embedded);
|
|
|
|
|
traps->traps = traps->traps_embedded;
|
2007-04-27 17:23:08 -07:00
|
|
|
|
2009-08-28 10:05:52 +01:00
|
|
|
traps->num_limits = 0;
|
2008-12-17 09:32:16 +00:00
|
|
|
traps->has_intersections = FALSE;
|
2007-04-27 17:23:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_cairo_traps_limit (cairo_traps_t *traps,
|
2009-08-28 10:05:52 +01:00
|
|
|
const cairo_box_t *limits,
|
|
|
|
|
int num_limits)
|
2007-04-27 17:23:08 -07:00
|
|
|
{
|
2009-08-28 10:05:52 +01:00
|
|
|
traps->limits = limits;
|
|
|
|
|
traps->num_limits = num_limits;
|
2002-08-07 19:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-14 21:19:54 +01:00
|
|
|
void
|
|
|
|
|
_cairo_traps_init_with_clip (cairo_traps_t *traps,
|
|
|
|
|
const cairo_clip_t *clip)
|
|
|
|
|
{
|
|
|
|
|
_cairo_traps_init (traps);
|
|
|
|
|
if (clip)
|
|
|
|
|
_cairo_traps_limit (traps, clip->boxes, clip->num_boxes);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-19 11:48:57 +01:00
|
|
|
void
|
|
|
|
|
_cairo_traps_clear (cairo_traps_t *traps)
|
|
|
|
|
{
|
|
|
|
|
traps->status = CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
traps->maybe_region = 1;
|
2009-08-25 20:51:06 +01:00
|
|
|
traps->is_rectilinear = 0;
|
2009-08-28 10:06:04 +01:00
|
|
|
traps->is_rectangular = 0;
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
|
2008-09-19 11:48:57 +01:00
|
|
|
traps->num_traps = 0;
|
2008-12-17 09:32:16 +00:00
|
|
|
traps->has_intersections = FALSE;
|
2008-09-19 11:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
2002-08-07 19:48:49 +00:00
|
|
|
void
|
2003-08-26 07:40:17 +00:00
|
|
|
_cairo_traps_fini (cairo_traps_t *traps)
|
2002-08-07 19:48:49 +00:00
|
|
|
{
|
2008-09-19 10:54:13 +01:00
|
|
|
if (traps->traps != traps->traps_embedded)
|
2003-07-30 08:30:50 +00:00
|
|
|
free (traps->traps);
|
2009-06-04 14:12:20 +01:00
|
|
|
|
|
|
|
|
VG (VALGRIND_MAKE_MEM_NOACCESS (traps, sizeof (cairo_traps_t)));
|
2002-08-07 19:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
2008-09-19 10:54:13 +01:00
|
|
|
/* make room for at least one more trap */
|
|
|
|
|
static cairo_bool_t
|
|
|
|
|
_cairo_traps_grow (cairo_traps_t *traps)
|
2007-04-10 12:06:09 -07:00
|
|
|
{
|
2008-09-19 10:54:13 +01:00
|
|
|
cairo_trapezoid_t *new_traps;
|
2009-07-25 07:38:04 +01:00
|
|
|
int new_size = 4 * traps->traps_size;
|
2008-09-19 10:54:13 +01:00
|
|
|
|
2009-04-16 17:19:12 +01:00
|
|
|
if (CAIRO_INJECT_FAULT ()) {
|
|
|
|
|
traps->status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-19 10:54:13 +01:00
|
|
|
if (traps->traps == traps->traps_embedded) {
|
|
|
|
|
new_traps = _cairo_malloc_ab (new_size, sizeof (cairo_trapezoid_t));
|
|
|
|
|
if (new_traps != NULL)
|
|
|
|
|
memcpy (new_traps, traps->traps, sizeof (traps->traps_embedded));
|
|
|
|
|
} else {
|
|
|
|
|
new_traps = _cairo_realloc_ab (traps->traps,
|
|
|
|
|
new_size, sizeof (cairo_trapezoid_t));
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-18 17:26:55 +00:00
|
|
|
if (unlikely (new_traps == NULL)) {
|
2008-09-19 10:54:13 +01:00
|
|
|
traps->status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
traps->traps = new_traps;
|
|
|
|
|
traps->traps_size = new_size;
|
|
|
|
|
return TRUE;
|
2007-04-10 12:06:09 -07:00
|
|
|
}
|
|
|
|
|
|
2008-09-19 10:54:13 +01:00
|
|
|
void
|
|
|
|
|
_cairo_traps_add_trap (cairo_traps_t *traps,
|
|
|
|
|
cairo_fixed_t top, cairo_fixed_t bottom,
|
2003-08-26 07:40:17 +00:00
|
|
|
cairo_line_t *left, cairo_line_t *right)
|
2002-08-07 19:48:49 +00:00
|
|
|
{
|
2003-07-30 08:30:50 +00:00
|
|
|
cairo_trapezoid_t *trap;
|
2002-08-07 19:48:49 +00:00
|
|
|
|
2009-07-25 07:38:04 +01:00
|
|
|
if (unlikely (traps->num_traps == traps->traps_size)) {
|
|
|
|
|
if (unlikely (! _cairo_traps_grow (traps)))
|
2009-07-24 13:51:23 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trap = &traps->traps[traps->num_traps++];
|
|
|
|
|
trap->top = top;
|
|
|
|
|
trap->bottom = bottom;
|
|
|
|
|
trap->left = *left;
|
|
|
|
|
trap->right = *right;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-28 10:05:52 +01:00
|
|
|
/**
|
|
|
|
|
* _cairo_traps_init_box:
|
|
|
|
|
* @traps: a #cairo_traps_t
|
|
|
|
|
* @box: an array box that will each be converted to a single trapezoid
|
|
|
|
|
* to store in @traps.
|
|
|
|
|
*
|
|
|
|
|
* Initializes a #cairo_traps_t to contain an array of rectangular
|
|
|
|
|
* trapezoids.
|
|
|
|
|
**/
|
|
|
|
|
cairo_status_t
|
|
|
|
|
_cairo_traps_init_boxes (cairo_traps_t *traps,
|
2010-01-22 17:56:26 +00:00
|
|
|
const cairo_boxes_t *boxes)
|
2009-08-28 10:05:52 +01:00
|
|
|
{
|
|
|
|
|
cairo_trapezoid_t *trap;
|
2010-01-22 17:56:26 +00:00
|
|
|
const struct _cairo_boxes_chunk *chunk;
|
2009-08-28 10:05:52 +01:00
|
|
|
|
|
|
|
|
_cairo_traps_init (traps);
|
|
|
|
|
|
2010-01-22 17:56:26 +00:00
|
|
|
while (traps->traps_size < boxes->num_boxes) {
|
2009-08-28 10:05:52 +01:00
|
|
|
if (unlikely (! _cairo_traps_grow (traps))) {
|
|
|
|
|
_cairo_traps_fini (traps);
|
|
|
|
|
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-22 17:56:26 +00:00
|
|
|
traps->num_traps = boxes->num_boxes;
|
2009-08-28 10:05:52 +01:00
|
|
|
traps->is_rectilinear = TRUE;
|
2009-08-28 10:06:04 +01:00
|
|
|
traps->is_rectangular = TRUE;
|
2010-01-22 17:56:26 +00:00
|
|
|
traps->maybe_region = boxes->is_pixel_aligned;
|
2009-08-28 10:05:52 +01:00
|
|
|
|
|
|
|
|
trap = &traps->traps[0];
|
2010-01-22 17:56:26 +00:00
|
|
|
for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) {
|
|
|
|
|
const cairo_box_t *box;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
box = chunk->base;
|
|
|
|
|
for (i = 0; i < chunk->count; i++) {
|
|
|
|
|
trap->top = box->p1.y;
|
|
|
|
|
trap->bottom = box->p2.y;
|
|
|
|
|
|
|
|
|
|
trap->left.p1 = box->p1;
|
|
|
|
|
trap->left.p2.x = box->p1.x;
|
|
|
|
|
trap->left.p2.y = box->p2.y;
|
2009-08-28 10:05:52 +01:00
|
|
|
|
2010-01-22 17:56:26 +00:00
|
|
|
trap->right.p1.x = box->p2.x;
|
|
|
|
|
trap->right.p1.y = box->p1.y;
|
|
|
|
|
trap->right.p2 = box->p2;
|
|
|
|
|
|
|
|
|
|
box++, trap++;
|
|
|
|
|
}
|
2009-08-28 10:05:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-24 13:51:23 +01:00
|
|
|
cairo_status_t
|
|
|
|
|
_cairo_traps_tessellate_rectangle (cairo_traps_t *traps,
|
|
|
|
|
const cairo_point_t *top_left,
|
|
|
|
|
const cairo_point_t *bottom_right)
|
|
|
|
|
{
|
|
|
|
|
cairo_line_t left;
|
|
|
|
|
cairo_line_t right;
|
|
|
|
|
cairo_fixed_t top, bottom;
|
|
|
|
|
|
2009-08-28 10:06:04 +01:00
|
|
|
if (top_left->y == bottom_right->y)
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
|
|
if (top_left->x == bottom_right->x)
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
2009-07-24 13:51:23 +01:00
|
|
|
left.p1.x = left.p2.x = top_left->x;
|
|
|
|
|
left.p1.y = right.p1.y = top_left->y;
|
|
|
|
|
right.p1.x = right.p2.x = bottom_right->x;
|
|
|
|
|
left.p2.y = right.p2.y = bottom_right->y;
|
|
|
|
|
|
|
|
|
|
top = top_left->y;
|
|
|
|
|
bottom = bottom_right->y;
|
|
|
|
|
|
2009-08-28 10:05:52 +01:00
|
|
|
if (traps->num_limits) {
|
2009-08-28 10:06:04 +01:00
|
|
|
cairo_bool_t reversed;
|
2009-08-28 10:05:52 +01:00
|
|
|
int n;
|
|
|
|
|
|
2009-08-28 10:06:04 +01:00
|
|
|
/* support counter-clockwise winding for rectangular tessellation */
|
|
|
|
|
reversed = top_left->x > bottom_right->x;
|
|
|
|
|
if (reversed) {
|
|
|
|
|
right.p1.x = right.p2.x = top_left->x;
|
|
|
|
|
left.p1.x = left.p2.x = bottom_right->x;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-28 10:05:52 +01:00
|
|
|
for (n = 0; n < traps->num_limits; n++) {
|
|
|
|
|
const cairo_box_t *limits = &traps->limits[n];
|
|
|
|
|
cairo_line_t _left, _right;
|
|
|
|
|
cairo_fixed_t _top, _bottom;
|
|
|
|
|
|
|
|
|
|
if (top >= limits->p2.y)
|
|
|
|
|
continue;
|
|
|
|
|
if (bottom <= limits->p1.y)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Trivially reject if trapezoid is entirely to the right or
|
|
|
|
|
* to the left of the limits. */
|
|
|
|
|
if (left.p1.x >= limits->p2.x)
|
|
|
|
|
continue;
|
|
|
|
|
if (right.p1.x <= limits->p1.x)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Otherwise, clip the trapezoid to the limits. */
|
|
|
|
|
_top = top;
|
|
|
|
|
if (_top < limits->p1.y)
|
|
|
|
|
_top = limits->p1.y;
|
|
|
|
|
|
|
|
|
|
_bottom = bottom;
|
|
|
|
|
if (_bottom > limits->p2.y)
|
|
|
|
|
_bottom = limits->p2.y;
|
|
|
|
|
|
|
|
|
|
if (_bottom <= _top)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
_left = left;
|
2009-08-29 14:15:07 +01:00
|
|
|
if (_left.p1.x < limits->p1.x) {
|
2009-08-28 10:05:52 +01:00
|
|
|
_left.p1.x = limits->p1.x;
|
|
|
|
|
_left.p1.y = limits->p1.y;
|
|
|
|
|
_left.p2.x = limits->p1.x;
|
|
|
|
|
_left.p2.y = limits->p2.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_right = right;
|
2009-08-29 14:15:07 +01:00
|
|
|
if (_right.p1.x > limits->p2.x) {
|
2009-08-28 10:05:52 +01:00
|
|
|
_right.p1.x = limits->p2.x;
|
|
|
|
|
_right.p1.y = limits->p1.y;
|
|
|
|
|
_right.p2.x = limits->p2.x;
|
|
|
|
|
_right.p2.y = limits->p2.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left.p1.x >= right.p1.x)
|
|
|
|
|
continue;
|
|
|
|
|
|
2009-08-28 10:06:04 +01:00
|
|
|
if (reversed)
|
|
|
|
|
_cairo_traps_add_trap (traps, _top, _bottom, &_right, &_left);
|
|
|
|
|
else
|
|
|
|
|
_cairo_traps_add_trap (traps, _top, _bottom, &_left, &_right);
|
2009-08-28 10:05:52 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
_cairo_traps_add_trap (traps, top, bottom, &left, &right);
|
|
|
|
|
}
|
2002-08-07 19:48:49 +00:00
|
|
|
|
2009-07-24 13:51:23 +01:00
|
|
|
return traps->status;
|
2002-08-07 19:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
2005-08-04 22:45:59 +00:00
|
|
|
void
|
|
|
|
|
_cairo_traps_translate (cairo_traps_t *traps, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
cairo_fixed_t xoff, yoff;
|
|
|
|
|
cairo_trapezoid_t *t;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Ugh. The cairo_composite/(Render) interface doesn't allow
|
|
|
|
|
an offset for the trapezoids. Need to manually shift all
|
|
|
|
|
the coordinates to align with the offset origin of the
|
|
|
|
|
intermediate surface. */
|
|
|
|
|
|
|
|
|
|
xoff = _cairo_fixed_from_int (x);
|
|
|
|
|
yoff = _cairo_fixed_from_int (y);
|
|
|
|
|
|
|
|
|
|
for (i = 0, t = traps->traps; i < traps->num_traps; i++, t++) {
|
|
|
|
|
t->top += yoff;
|
|
|
|
|
t->bottom += yoff;
|
|
|
|
|
t->left.p1.x += xoff;
|
|
|
|
|
t->left.p1.y += yoff;
|
|
|
|
|
t->left.p2.x += xoff;
|
|
|
|
|
t->left.p2.y += yoff;
|
|
|
|
|
t->right.p1.x += xoff;
|
|
|
|
|
t->right.p1.y += yoff;
|
|
|
|
|
t->right.p2.x += xoff;
|
|
|
|
|
t->right.p2.y += yoff;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-04 01:45:41 -07:00
|
|
|
void
|
|
|
|
|
_cairo_trapezoid_array_translate_and_scale (cairo_trapezoid_t *offset_traps,
|
|
|
|
|
cairo_trapezoid_t *src_traps,
|
|
|
|
|
int num_traps,
|
|
|
|
|
double tx, double ty,
|
|
|
|
|
double sx, double sy)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
cairo_fixed_t xoff = _cairo_fixed_from_double (tx);
|
|
|
|
|
cairo_fixed_t yoff = _cairo_fixed_from_double (ty);
|
|
|
|
|
|
|
|
|
|
if (sx == 1.0 && sy == 1.0) {
|
|
|
|
|
for (i = 0; i < num_traps; i++) {
|
|
|
|
|
offset_traps[i].top = src_traps[i].top + yoff;
|
|
|
|
|
offset_traps[i].bottom = src_traps[i].bottom + yoff;
|
|
|
|
|
offset_traps[i].left.p1.x = src_traps[i].left.p1.x + xoff;
|
|
|
|
|
offset_traps[i].left.p1.y = src_traps[i].left.p1.y + yoff;
|
|
|
|
|
offset_traps[i].left.p2.x = src_traps[i].left.p2.x + xoff;
|
|
|
|
|
offset_traps[i].left.p2.y = src_traps[i].left.p2.y + yoff;
|
|
|
|
|
offset_traps[i].right.p1.x = src_traps[i].right.p1.x + xoff;
|
|
|
|
|
offset_traps[i].right.p1.y = src_traps[i].right.p1.y + yoff;
|
|
|
|
|
offset_traps[i].right.p2.x = src_traps[i].right.p2.x + xoff;
|
|
|
|
|
offset_traps[i].right.p2.y = src_traps[i].right.p2.y + yoff;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
cairo_fixed_t xsc = _cairo_fixed_from_double (sx);
|
|
|
|
|
cairo_fixed_t ysc = _cairo_fixed_from_double (sy);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < num_traps; i++) {
|
2007-06-18 16:30:09 -07:00
|
|
|
offset_traps[i].top = _cairo_fixed_mul (src_traps[i].top + yoff, ysc);
|
|
|
|
|
offset_traps[i].bottom = _cairo_fixed_mul (src_traps[i].bottom + yoff, ysc);
|
|
|
|
|
offset_traps[i].left.p1.x = _cairo_fixed_mul (src_traps[i].left.p1.x + xoff, xsc);
|
|
|
|
|
offset_traps[i].left.p1.y = _cairo_fixed_mul (src_traps[i].left.p1.y + yoff, ysc);
|
|
|
|
|
offset_traps[i].left.p2.x = _cairo_fixed_mul (src_traps[i].left.p2.x + xoff, xsc);
|
|
|
|
|
offset_traps[i].left.p2.y = _cairo_fixed_mul (src_traps[i].left.p2.y + yoff, ysc);
|
|
|
|
|
offset_traps[i].right.p1.x = _cairo_fixed_mul (src_traps[i].right.p1.x + xoff, xsc);
|
|
|
|
|
offset_traps[i].right.p1.y = _cairo_fixed_mul (src_traps[i].right.p1.y + yoff, ysc);
|
|
|
|
|
offset_traps[i].right.p2.x = _cairo_fixed_mul (src_traps[i].right.p2.x + xoff, xsc);
|
|
|
|
|
offset_traps[i].right.p2.y = _cairo_fixed_mul (src_traps[i].right.p2.y + yoff, ysc);
|
2006-05-04 01:45:41 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-01 15:06:33 +00:00
|
|
|
static cairo_bool_t
|
2003-11-06 18:33:28 +00:00
|
|
|
_cairo_trap_contains (cairo_trapezoid_t *t, cairo_point_t *pt)
|
|
|
|
|
{
|
|
|
|
|
cairo_slope_t slope_left, slope_pt, slope_right;
|
2006-06-06 15:25:49 -07:00
|
|
|
|
2003-11-06 18:33:28 +00:00
|
|
|
if (t->top > pt->y)
|
2005-02-01 15:06:33 +00:00
|
|
|
return FALSE;
|
2003-11-06 18:33:28 +00:00
|
|
|
if (t->bottom < pt->y)
|
2005-02-01 15:06:33 +00:00
|
|
|
return FALSE;
|
2006-06-06 15:25:49 -07:00
|
|
|
|
2003-11-06 18:33:28 +00:00
|
|
|
_cairo_slope_init (&slope_left, &t->left.p1, &t->left.p2);
|
|
|
|
|
_cairo_slope_init (&slope_pt, &t->left.p1, pt);
|
|
|
|
|
|
|
|
|
|
if (_cairo_slope_compare (&slope_left, &slope_pt) < 0)
|
2005-02-01 15:06:33 +00:00
|
|
|
return FALSE;
|
2003-11-06 18:33:28 +00:00
|
|
|
|
|
|
|
|
_cairo_slope_init (&slope_right, &t->right.p1, &t->right.p2);
|
|
|
|
|
_cairo_slope_init (&slope_pt, &t->right.p1, pt);
|
|
|
|
|
|
|
|
|
|
if (_cairo_slope_compare (&slope_pt, &slope_right) < 0)
|
2005-02-01 15:06:33 +00:00
|
|
|
return FALSE;
|
2003-11-06 18:33:28 +00:00
|
|
|
|
2005-02-01 15:06:33 +00:00
|
|
|
return TRUE;
|
2003-11-06 18:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-01 15:06:33 +00:00
|
|
|
cairo_bool_t
|
2008-05-09 13:16:13 +02:00
|
|
|
_cairo_traps_contain (const cairo_traps_t *traps,
|
|
|
|
|
double x, double y)
|
2003-11-06 18:33:28 +00:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
cairo_point_t point;
|
|
|
|
|
|
|
|
|
|
point.x = _cairo_fixed_from_double (x);
|
|
|
|
|
point.y = _cairo_fixed_from_double (y);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < traps->num_traps; i++) {
|
|
|
|
|
if (_cairo_trap_contains (&traps->traps[i], &point))
|
2005-02-01 15:06:33 +00:00
|
|
|
return TRUE;
|
2003-11-06 18:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-01 15:06:33 +00:00
|
|
|
return FALSE;
|
2003-11-06 18:33:28 +00:00
|
|
|
}
|
2004-04-06 09:36:12 +00:00
|
|
|
|
2009-07-24 13:51:23 +01:00
|
|
|
static cairo_fixed_t
|
|
|
|
|
_line_compute_intersection_x_for_y (const cairo_line_t *line,
|
|
|
|
|
cairo_fixed_t y)
|
|
|
|
|
{
|
|
|
|
|
return _cairo_edge_compute_intersection_x_for_y (&line->p1, &line->p2, y);
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-06 09:36:12 +00:00
|
|
|
void
|
2008-05-09 13:16:13 +02:00
|
|
|
_cairo_traps_extents (const cairo_traps_t *traps,
|
2009-07-24 13:51:23 +01:00
|
|
|
cairo_box_t *extents)
|
2004-04-06 09:36:12 +00:00
|
|
|
{
|
2009-07-24 13:51:23 +01:00
|
|
|
int i;
|
|
|
|
|
|
2008-01-05 19:33:21 +00:00
|
|
|
if (traps->num_traps == 0) {
|
2009-07-24 13:51:23 +01:00
|
|
|
extents->p1.x = extents->p1.y = 0;
|
|
|
|
|
extents->p2.x = extents->p2.y = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extents->p1.x = extents->p1.y = INT32_MAX;
|
|
|
|
|
extents->p2.x = extents->p2.y = INT32_MIN;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < traps->num_traps; i++) {
|
|
|
|
|
const cairo_trapezoid_t *trap = &traps->traps[i];
|
|
|
|
|
|
|
|
|
|
if (trap->top < extents->p1.y)
|
|
|
|
|
extents->p1.y = trap->top;
|
|
|
|
|
if (trap->bottom > extents->p2.y)
|
|
|
|
|
extents->p2.y = trap->bottom;
|
|
|
|
|
|
|
|
|
|
if (trap->left.p1.x < extents->p1.x) {
|
|
|
|
|
cairo_fixed_t x = trap->left.p1.x;
|
|
|
|
|
if (trap->top != trap->left.p1.y) {
|
|
|
|
|
x = _line_compute_intersection_x_for_y (&trap->left,
|
|
|
|
|
trap->top);
|
|
|
|
|
if (x < extents->p1.x)
|
|
|
|
|
extents->p1.x = x;
|
|
|
|
|
} else
|
|
|
|
|
extents->p1.x = x;
|
|
|
|
|
}
|
|
|
|
|
if (trap->left.p2.x < extents->p1.x) {
|
|
|
|
|
cairo_fixed_t x = trap->left.p2.x;
|
|
|
|
|
if (trap->bottom != trap->left.p2.y) {
|
|
|
|
|
x = _line_compute_intersection_x_for_y (&trap->left,
|
|
|
|
|
trap->bottom);
|
|
|
|
|
if (x < extents->p1.x)
|
|
|
|
|
extents->p1.x = x;
|
|
|
|
|
} else
|
|
|
|
|
extents->p1.x = x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (trap->right.p1.x > extents->p2.x) {
|
|
|
|
|
cairo_fixed_t x = trap->right.p1.x;
|
|
|
|
|
if (trap->top != trap->right.p1.y) {
|
|
|
|
|
x = _line_compute_intersection_x_for_y (&trap->right,
|
|
|
|
|
trap->top);
|
|
|
|
|
if (x > extents->p2.x)
|
|
|
|
|
extents->p2.x = x;
|
|
|
|
|
} else
|
|
|
|
|
extents->p2.x = x;
|
|
|
|
|
}
|
|
|
|
|
if (trap->right.p2.x > extents->p2.x) {
|
|
|
|
|
cairo_fixed_t x = trap->right.p2.x;
|
|
|
|
|
if (trap->bottom != trap->right.p2.y) {
|
|
|
|
|
x = _line_compute_intersection_x_for_y (&trap->right,
|
|
|
|
|
trap->bottom);
|
|
|
|
|
if (x > extents->p2.x)
|
|
|
|
|
extents->p2.x = x;
|
|
|
|
|
} else
|
|
|
|
|
extents->p2.x = x;
|
2008-09-24 00:49:03 +01:00
|
|
|
}
|
|
|
|
|
}
|
2004-04-06 09:36:12 +00:00
|
|
|
}
|
2005-04-13 11:23:43 +00:00
|
|
|
|
2011-07-14 21:19:54 +01:00
|
|
|
static cairo_bool_t
|
|
|
|
|
_mono_edge_is_vertical (const cairo_line_t *line)
|
|
|
|
|
{
|
|
|
|
|
return _cairo_fixed_integer_round_down (line->p1.x) == _cairo_fixed_integer_round_down (line->p2.x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static cairo_bool_t
|
|
|
|
|
_traps_are_pixel_aligned (cairo_traps_t *traps,
|
|
|
|
|
cairo_antialias_t antialias)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (antialias == CAIRO_ANTIALIAS_NONE) {
|
|
|
|
|
for (i = 0; i < traps->num_traps; i++) {
|
|
|
|
|
if (! _mono_edge_is_vertical (&traps->traps[i].left) ||
|
|
|
|
|
! _mono_edge_is_vertical (&traps->traps[i].right))
|
|
|
|
|
{
|
|
|
|
|
traps->maybe_region = FALSE;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (i = 0; i < traps->num_traps; i++) {
|
|
|
|
|
if (traps->traps[i].left.p1.x != traps->traps[i].left.p2.x ||
|
|
|
|
|
traps->traps[i].right.p1.x != traps->traps[i].right.p2.x ||
|
|
|
|
|
! _cairo_fixed_is_integer (traps->traps[i].top) ||
|
|
|
|
|
! _cairo_fixed_is_integer (traps->traps[i].bottom) ||
|
|
|
|
|
! _cairo_fixed_is_integer (traps->traps[i].left.p1.x) ||
|
|
|
|
|
! _cairo_fixed_is_integer (traps->traps[i].right.p1.x))
|
|
|
|
|
{
|
|
|
|
|
traps->maybe_region = FALSE;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2009-07-24 13:51:23 +01:00
|
|
|
|
2005-04-13 11:23:43 +00:00
|
|
|
/**
|
|
|
|
|
* _cairo_traps_extract_region:
|
|
|
|
|
* @traps: a #cairo_traps_t
|
2007-06-18 18:33:29 -07:00
|
|
|
* @region: a #cairo_region_t
|
2006-06-06 15:35:48 -07:00
|
|
|
*
|
2005-04-13 11:23:43 +00:00
|
|
|
* Determines if a set of trapezoids are exactly representable as a
|
2007-06-18 18:33:29 -07:00
|
|
|
* cairo region. If so, the passed-in region is initialized to
|
|
|
|
|
* the area representing the given traps. It should be finalized
|
2009-02-17 23:52:18 -05:00
|
|
|
* with cairo_region_fini(). If not, %CAIRO_INT_STATUS_UNSUPPORTED
|
2007-06-18 18:33:29 -07:00
|
|
|
* is returned.
|
2006-06-06 15:35:48 -07:00
|
|
|
*
|
2007-03-14 00:40:44 +01:00
|
|
|
* Return value: %CAIRO_STATUS_SUCCESS, %CAIRO_INT_STATUS_UNSUPPORTED
|
|
|
|
|
* or %CAIRO_STATUS_NO_MEMORY
|
2005-04-13 11:23:43 +00:00
|
|
|
**/
|
2007-03-14 00:40:44 +01:00
|
|
|
cairo_int_status_t
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
_cairo_traps_extract_region (cairo_traps_t *traps,
|
2011-07-14 21:19:54 +01:00
|
|
|
cairo_antialias_t antialias,
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
cairo_region_t **region)
|
2005-04-13 11:23:43 +00:00
|
|
|
{
|
2009-05-26 17:53:37 -04:00
|
|
|
cairo_rectangle_int_t stack_rects[CAIRO_STACK_ARRAY_LENGTH (cairo_rectangle_int_t)];
|
|
|
|
|
cairo_rectangle_int_t *rects = stack_rects;
|
2009-03-30 10:46:37 +01:00
|
|
|
cairo_int_status_t status;
|
2009-05-26 17:53:37 -04:00
|
|
|
int i, rect_count;
|
2008-10-24 17:06:04 +01:00
|
|
|
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
/* we only treat this a hint... */
|
2011-07-14 21:19:54 +01:00
|
|
|
if (antialias != CAIRO_ANTIALIAS_NONE && ! traps->maybe_region)
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
|
|
|
|
|
2011-07-14 21:19:54 +01:00
|
|
|
if (! _traps_are_pixel_aligned (traps, antialias)) {
|
|
|
|
|
traps->maybe_region = FALSE;
|
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
2008-10-24 17:06:04 +01:00
|
|
|
}
|
2006-06-06 15:25:49 -07:00
|
|
|
|
2009-05-26 17:53:37 -04:00
|
|
|
if (traps->num_traps > ARRAY_LENGTH (stack_rects)) {
|
|
|
|
|
rects = _cairo_malloc_ab (traps->num_traps, sizeof (cairo_rectangle_int_t));
|
2009-03-30 10:46:37 +01:00
|
|
|
|
2009-05-26 17:53:37 -04:00
|
|
|
if (unlikely (rects == NULL))
|
|
|
|
|
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
|
|
|
|
}
|
2009-03-30 10:46:37 +01:00
|
|
|
|
2009-05-26 17:53:37 -04:00
|
|
|
rect_count = 0;
|
|
|
|
|
for (i = 0; i < traps->num_traps; i++) {
|
2011-07-14 21:19:54 +01:00
|
|
|
int x1, y1, x2, y2;
|
|
|
|
|
|
|
|
|
|
if (antialias == CAIRO_ANTIALIAS_NONE) {
|
|
|
|
|
x1 = _cairo_fixed_integer_round_down (traps->traps[i].left.p1.x);
|
|
|
|
|
y1 = _cairo_fixed_integer_round_down (traps->traps[i].top);
|
|
|
|
|
x2 = _cairo_fixed_integer_round_down (traps->traps[i].right.p1.x);
|
|
|
|
|
y2 = _cairo_fixed_integer_round_down (traps->traps[i].bottom);
|
|
|
|
|
} else {
|
|
|
|
|
x1 = _cairo_fixed_integer_part (traps->traps[i].left.p1.x);
|
|
|
|
|
y1 = _cairo_fixed_integer_part (traps->traps[i].top);
|
|
|
|
|
x2 = _cairo_fixed_integer_part (traps->traps[i].right.p1.x);
|
|
|
|
|
y2 = _cairo_fixed_integer_part (traps->traps[i].bottom);
|
|
|
|
|
}
|
2006-06-06 15:25:49 -07:00
|
|
|
|
2011-07-14 21:19:54 +01:00
|
|
|
if (x2 > x1 && y2 > y1) {
|
|
|
|
|
rects[rect_count].x = x1;
|
|
|
|
|
rects[rect_count].y = y1;
|
|
|
|
|
rects[rect_count].width = x2 - x1;
|
|
|
|
|
rects[rect_count].height = y2 - y1;
|
|
|
|
|
rect_count++;
|
|
|
|
|
}
|
2007-06-18 13:58:15 -07:00
|
|
|
}
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
|
2011-07-14 21:19:54 +01:00
|
|
|
|
2009-05-26 17:53:37 -04:00
|
|
|
*region = cairo_region_create_rectangles (rects, rect_count);
|
Remove clip handling from generic surface layer.
Handling clip as part of the surface state, as opposed to being part of
the operation state, is cumbersome and a hindrance to providing true proxy
surface support. For example, the clip must be copied from the surface
onto the fallback image, but this was forgotten causing undue hassle in
each backend. Another example is the contortion the meta surface
endures to ensure the clip is correctly recorded. By contrast passing the
clip along with the operation is quite simple and enables us to write
generic handlers for providing surface wrappers. (And in the future, we
should be able to write more esoteric wrappers, e.g. automatic 2x FSAA,
trivially.)
In brief, instead of the surface automatically applying the clip before
calling the backend, the backend can call into a generic helper to apply
clipping. For raster surfaces, clip regions are handled automatically as
part of the composite interface. For vector surfaces, a clip helper is
introduced to replay and callback into an intersect_clip_path() function
as necessary.
Whilst this is not primarily a performance related change (the change
should just move the computation of the clip from the moment it is applied
by the user to the moment it is required by the backend), it is important
to track any potential regression:
ppc:
Speedups
========
image-rgba evolution-20090607-0 1026085.22 0.18% -> 672972.07 0.77%: 1.52x speedup
▌
image-rgba evolution-20090618-0 680579.98 0.12% -> 573237.66 0.16%: 1.19x speedup
▎
image-rgba swfdec-fill-rate-4xaa-0 460296.92 0.36% -> 407464.63 0.42%: 1.13x speedup
▏
image-rgba swfdec-fill-rate-2xaa-0 128431.95 0.47% -> 115051.86 0.42%: 1.12x speedup
▏
Slowdowns
=========
image-rgba firefox-periodic-table-0 56837.61 0.78% -> 66055.17 3.20%: 1.09x slowdown
▏
2009-07-23 15:32:13 +01:00
|
|
|
status = (*region)->status;
|
2007-06-18 13:58:15 -07:00
|
|
|
|
2009-05-26 17:53:37 -04:00
|
|
|
if (rects != stack_rects)
|
|
|
|
|
free (rects);
|
|
|
|
|
|
|
|
|
|
return status;
|
2005-04-13 11:23:43 +00:00
|
|
|
}
|
2008-05-09 15:31:45 +02:00
|
|
|
|
2011-07-30 17:28:21 +01:00
|
|
|
cairo_bool_t
|
|
|
|
|
_cairo_traps_to_boxes (cairo_traps_t *traps,
|
|
|
|
|
cairo_antialias_t antialias,
|
|
|
|
|
cairo_boxes_t *boxes)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < traps->num_traps; i++) {
|
|
|
|
|
if (traps->traps[i].left.p1.x != traps->traps[i].left.p2.x ||
|
|
|
|
|
traps->traps[i].right.p1.x != traps->traps[i].right.p2.x)
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cairo_boxes_init (boxes);
|
|
|
|
|
|
|
|
|
|
boxes->num_boxes = traps->num_traps;
|
|
|
|
|
boxes->chunks.base = (cairo_box_t *) traps->traps;
|
|
|
|
|
boxes->chunks.count = traps->num_traps;
|
|
|
|
|
boxes->chunks.size = traps->num_traps;
|
|
|
|
|
|
|
|
|
|
if (antialias != CAIRO_ANTIALIAS_NONE) {
|
|
|
|
|
for (i = 0; i < traps->num_traps; i++) {
|
|
|
|
|
/* Note the traps and boxes alias so we need to take the local copies first. */
|
|
|
|
|
cairo_fixed_t x1 = traps->traps[i].left.p1.x;
|
|
|
|
|
cairo_fixed_t x2 = traps->traps[i].right.p1.x;
|
|
|
|
|
cairo_fixed_t y1 = traps->traps[i].top;
|
|
|
|
|
cairo_fixed_t y2 = traps->traps[i].bottom;
|
|
|
|
|
|
|
|
|
|
boxes->chunks.base[i].p1.x = x1;
|
|
|
|
|
boxes->chunks.base[i].p1.y = y1;
|
|
|
|
|
boxes->chunks.base[i].p2.x = x2;
|
|
|
|
|
boxes->chunks.base[i].p2.y = y2;
|
|
|
|
|
|
|
|
|
|
if (boxes->is_pixel_aligned) {
|
|
|
|
|
boxes->is_pixel_aligned =
|
|
|
|
|
_cairo_fixed_is_integer (x1) && _cairo_fixed_is_integer (y1) &&
|
|
|
|
|
_cairo_fixed_is_integer (x2) && _cairo_fixed_is_integer (y2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
boxes->is_pixel_aligned = TRUE;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < traps->num_traps; i++) {
|
|
|
|
|
/* Note the traps and boxes alias so we need to take the local copies first. */
|
|
|
|
|
cairo_fixed_t x1 = traps->traps[i].left.p1.x;
|
|
|
|
|
cairo_fixed_t x2 = traps->traps[i].right.p1.x;
|
|
|
|
|
cairo_fixed_t y1 = traps->traps[i].top;
|
|
|
|
|
cairo_fixed_t y2 = traps->traps[i].bottom;
|
|
|
|
|
|
|
|
|
|
/* round down here to match Pixman's behavior when using traps. */
|
|
|
|
|
boxes->chunks.base[i].p1.x = _cairo_fixed_round_down (x1);
|
|
|
|
|
boxes->chunks.base[i].p1.y = _cairo_fixed_round_down (y1);
|
|
|
|
|
boxes->chunks.base[i].p2.x = _cairo_fixed_round_down (x2);
|
|
|
|
|
boxes->chunks.base[i].p2.y = _cairo_fixed_round_down (y2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-09 15:31:45 +02:00
|
|
|
/* moves trap points such that they become the actual corners of the trapezoid */
|
|
|
|
|
static void
|
2008-05-15 20:03:05 -04:00
|
|
|
_sanitize_trap (cairo_trapezoid_t *t)
|
2008-05-09 15:31:45 +02:00
|
|
|
{
|
2008-05-15 20:03:05 -04:00
|
|
|
cairo_trapezoid_t s = *t;
|
|
|
|
|
|
|
|
|
|
#define FIX(lr, tb, p) \
|
2008-05-09 15:31:45 +02:00
|
|
|
if (t->lr.p.y != t->tb) { \
|
2009-07-24 13:51:23 +01:00
|
|
|
t->lr.p.x = s.lr.p2.x + _cairo_fixed_mul_div_floor (s.lr.p1.x - s.lr.p2.x, s.tb - s.lr.p2.y, s.lr.p1.y - s.lr.p2.y); \
|
2008-05-15 20:03:05 -04:00
|
|
|
t->lr.p.y = s.tb; \
|
2008-05-09 15:31:45 +02:00
|
|
|
}
|
2008-05-15 20:03:05 -04:00
|
|
|
FIX (left, top, p1);
|
|
|
|
|
FIX (left, bottom, p2);
|
|
|
|
|
FIX (right, top, p1);
|
|
|
|
|
FIX (right, bottom, p2);
|
2008-05-09 15:31:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cairo_private cairo_status_t
|
|
|
|
|
_cairo_traps_path (const cairo_traps_t *traps,
|
|
|
|
|
cairo_path_fixed_t *path)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < traps->num_traps; i++) {
|
|
|
|
|
cairo_status_t status;
|
|
|
|
|
cairo_trapezoid_t trap = traps->traps[i];
|
|
|
|
|
|
|
|
|
|
if (trap.top == trap.bottom)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
_sanitize_trap (&trap);
|
|
|
|
|
|
|
|
|
|
status = _cairo_path_fixed_move_to (path, trap.left.p1.x, trap.top);
|
2008-11-18 15:38:37 +00:00
|
|
|
if (unlikely (status)) return status;
|
2008-05-09 15:31:45 +02:00
|
|
|
status = _cairo_path_fixed_line_to (path, trap.right.p1.x, trap.top);
|
2008-11-18 15:38:37 +00:00
|
|
|
if (unlikely (status)) return status;
|
2008-05-09 15:31:45 +02:00
|
|
|
status = _cairo_path_fixed_line_to (path, trap.right.p2.x, trap.bottom);
|
2008-11-18 15:38:37 +00:00
|
|
|
if (unlikely (status)) return status;
|
2008-05-09 15:31:45 +02:00
|
|
|
status = _cairo_path_fixed_line_to (path, trap.left.p2.x, trap.bottom);
|
2008-11-18 15:38:37 +00:00
|
|
|
if (unlikely (status)) return status;
|
2008-05-09 15:31:45 +02:00
|
|
|
status = _cairo_path_fixed_close_path (path);
|
2008-11-18 15:38:37 +00:00
|
|
|
if (unlikely (status)) return status;
|
2008-05-09 15:31:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
}
|