A new meta-surface backend for serialising drawing operations to a
CairoScript file. The principal use (as currently envisaged) is to provide
a round-trip testing mechanism for CairoScript - i.e. we can generate
script files for every test in the suite and check that we can replay them
with perfect fidelity. (Obviously this does not provide complete coverage
of CairoScript's syntax, but should give reasonable coverage over the
operators.)
pixman limits the src] co-ordinates (and thus [xy]_offset] to 16bits,
so we need to be careful how much of the translation vector to push into
[xy]_offset. Since the range is the same for both, split the integer
component between the matrix and the offset.
test/scale-offset* now at least shows the source image, even if it is
misplaced.
Exploit the auxiliary offset vector in the attributes to reduce
likelihood of range overflow in the translation components when converting
the pattern matrix to fixed-point pixman_matrix_t.
An example of this is bug 9148
Bug 9148 - invalid rendering when painting large scaled-down surfaces
(https://bugs.freedesktop.org/show_bug.cgi?id=9148)
but the issue is perhaps even more likely with high resolution fallback
images.
In order to workaound a directfb bug, tweak the reflect->repeat pattern so
that it covers the destination rectangle. Although the number of paint()
increases, the number of read/written pixels remain the same so that
performance should not deteriorate, but instead be improved by using a
cloned source. The early return of the REFLECT surface is discarded so
that the latter optimisations for surface sources can be applied. One side
effect of this is that acquire_source_image() is removed due to its lax
reference counting which thereby exposes the ROI optimisations for image
destinations as well.
Avoid allocating a default source pattern by using the static black pattern
object. The one complication is that we need to ensure that the static
pattern does leak to the application, so we replace it with an allocated
solid pattern within _cairo_gstate_get_source().
Only copy the pattern if we need to modify it, e.g. preserve a copy in a
snapshot or a soft-mask, or to modify the matrix. Otherwise we can
continue to use the original pattern and mark it as const in order to
generate compiler warnings if we do attempt to write to it.
Adrian Johnson discovered cases where we mistakenly compared the result
of unsigned arithmetic where we need signed quantities. Look for similar
cases in the users of cairo_rectangle_int_t.
As is so often the case, reading the commit log gives you fresh insight in
the problem - often called confessional debugging...
We can simplify the problem by ignoring attr->[xy]_offset, for the time
being, and focus on computing the correct matrix. This is comparatively
simple as all we need to do is perform the appropriate rounding on the
translation vector.
A complication I realised after pushing 3eb4bc3 was handling larger
sampled areas. Extending the test case revealed that the optimization
was broken for anything but the identity transform (after removing the
translation). Correctness first, leaving the "pixel-exact" solution for
interested reader...
As identified in bug 15479,
Unpredictable performance of cairo-xlib with non-integer translations of a
source surface pattern
(https://bugs.freedesktop.org/show_bug.cgi?id=15479),
source surfaces with a fractional translation hit slow paths for some
drivers, causing seemingly random performance variations. As a work-around
Owen Taylor proposed that cairo could convert non-integer translations on
NEAREST sources patterns to their integer equivalents.
The messy detail involved here is replicating the rounding mode used by
pixman for the sample offset, but otherwise the conversion is fairly
trivial.
As proof-of-principle, compute a scale factor to avoid overflow when
converting a linear pattern to pixman_fixed_t. Fixes test/huge-pattern,
but the principle should be extended to handle more cases of overflow.
For the simple case where the pattern matrix only contains an integer
translation then care is taken to convert that to a identity source matrix
with the translation applied to the [xy]_offsets. 5b97ee6525 broke this
guarantee by applying the clone offsets to the source matrix. So when the
source matrix is identity we can simply adjust the [xy]_offsets and
preserve the identity matrix. (This idea can be extended further by
removing any integer translation from the source matrix and storing it in
the [xy]_offsets as a means to extend the limited precision in
pixman_matrix_t - encountered when downscaling large images offset onto
the target surface.)
In the midst of porting 5eec3e378a I failed
to include the pad in the floor() and ceil() which introduces two
potential off-by-one errors into each dimension of the region of interest
of the source surface.
Factor out common filter analysis code from _cairo_pattern_get_extents()
so that we can share it with _cairo_pattern_acquire_surface_for_surface()
as well. During the analysis of the filter determine whether the pattern
matrix maps source pixels exactly onto destination pixels and if so convert
the filter to NEAREST - generalising the existing conversion to NEAREST.
(Patch ported to master by Chris Wilson, all bugs are his.)
This fixes the filter-bilinear-extents test case and the
related bug entry:
bad clipping with EXTEND_NONE
http://bugs.freedesktop.org/show_bug.cgi?id=15349
Though there are still differences in the PDF and PostScript
backends, (primarily because we can't capture cairo's filter
modes in those file formats).
Restrict the area we acquire from the source image to the bounds of
the source image, even when we have an identity matrix. This handles
circumstances where the pattern extents may be enlarged due to
filtering, for example when applying a bilinear filter.
This patch replaces the open-coded rectangle intersection which has
already proven itself to be a source of bugs.
(Patch ported to master by Chris Wilson, all bugs are his.)
Remove instances (abuses) of calling _cairo_pattern_acquire_surface() on
a known-surface-pattern with a hack to say "give me the entire surface".
If you know you just want the entire surface as an image surface, that
can be done more simply.
(Split from original patch on
https://bugs.freedesktop.org/attachment.cgi?id=15703, by Chris Wilson -
as usual all bugs are his.)
A little bit of sleep and reflection suggested that the use of
device_offset_[xy] was confusing and clone_offset_[xy] more consistent
with the function naming.
Previously the rule for clone_similar() was that the returned surface
had exactly the same size as the original, but only the contents within
the region of interest needed to be copied. This caused failures for very
large images in the xlib-backend (see test/large-source).
The obvious solution to allow cloning only the region of interest seemed
to be to simply set the device offset on the cloned surface. However, this
fails as a) nothing respects the device offset on the surface at that
layer in the compositing stack and b) possibly returning references to the
original source surface provides further confusion by mixing in another
source of device offset.
The second method was to add extra out parameters so that the
device offset could be returned separately and, for example, mixed into
the pattern matrix. Not as elegant, a couple of extra warts to the
interface, but it works - one less XFAIL...
A surface pattern under an extreme transformation could lie entirely in
the negative quadrant. This would trigger the fixup such that it's lower
left corner was clamped to the origin, but the upper right corner was left
unchecked. This could result in the width,height being negative and
wrapping around to large values instead of being clamped to 0.
Adding warn_unused_result to pixman detected a couple of instances where
we abused the knowledge that the code currently can not fail, but in
deference to its independent existence we should be more cautious.
Keep the reference count as zero for temporary, on-stack patterns in
order to detect attempts to keep references beyond their scope. (And
mismatched _init()/_destroy()).
Ickle knew something when he only extended cache size when we are
committed to inserting something into the cache. I broke that while
fixing other issues a while ago. This cache just doesn't want to
give us any rest...
This can be used by _cairo_pattern_acquire_surface_for_solid() to let
the backend create custom surfaces for solid fill instead of a 1x1
similar surface.
This was added in 41c6eebcd1, to avoid
allocating short-lived patterns. However, this was error prune as the
color information was duplicated in the pattern and could get out of
sync. Indeed, it was out of sync before this commit in the call from
cairo-clip.c.
By allocating the solid pattern on the stack we fix the original problem
without creating new ones.
The code in that cache is becoming uglier and uglier. But at least it
works correctly again. Time for a rewrite.
(Also move the destroy after unlocking)