Commit graph

271 commits

Author SHA1 Message Date
Chris Wilson
c701d7813b [pattern] Compute zero extents for empty patterns
If the pattern is for example a repeating 0x0 image, then treat it as
having zero extents.

This should workaround the bug presented here:

  https://bugs.freedesktop.org/show_bug.cgi?id=24693
  Attached PDF crashes evince with a Floating point exception
2009-10-23 14:58:33 +01:00
M Joonas Pihlaja
43a775f60d [meta] Rename cairo_meta_surface_t to cairo_recording_surface_t.
The new name is more descriptive than the rather opaque meta surface.
Discussed with vigour on the mailing list and #cairo:

http://lists.cairographics.org/archives/cairo/2009-July/017571.html
2009-10-22 02:29:47 +03:00
Chris Wilson
df357f26ff Support component-alpha.
Within our code base we carried a few hacks to utilize the component
alpha capabilities of pixman, whilst not supporting the concept for our
own masks. Thus we were setting it upon the pixman_image_t that we
passed around through code that was blissfully unaware and indeed the
component-alpha property was forgotten (e.g. upgrading glyph masks).

The real issue is that without explicit support that a pattern carries
subpixel masking information, that information is lost when using that
pattern with composite. Again we can look at the example of compositing
a sub-pixel glyph mask onto a remote xlib surface for further failure.
2009-10-21 11:37:16 +01:00
Chris Wilson
54df07a3da [surface] Don't AND in the desired content.
Gah, that was a horrible mistake. It was a flawed hack to create Pixmaps
of the correct depth when cloning patterns for blitting to the xlib
backend. However, it had the nasty side-effect of discarding alpha when
targeting Window surfaces. The correct solution is to simply correct the
Pixmap of the desired depth and render a matching pattern onto the
surface - i.e. a reversal the current acquire -> clone. See the
forthcoming revised xcb backend on how I should have done it originally.
2009-10-16 17:04:16 +01:00
Chris Wilson
d85eda97dd [pattern] Compute extents for gradients
As noted in the comments we could also compute the pattern extents for
gradients with CAIRO_EXTEND_NONE under certain circumstances, i.e.
radial gradients and device axis aligned linear gradients.
2009-10-15 13:05:42 +01:00
Chris Wilson
af82670dd3 [pattern] Remove unused hidden symbol for cairo_pattern_status() 2009-09-01 13:31:52 +01:00
Chris Wilson
d1740d8782 [pattern] Ensure that no repeated pattern is clipped
Previously the pattern_acquire_surface routine only had to worry about
handling extend modes NONE or REPEAT and so the test for ! REPEAT
sufficed when what was actually intended was a test for NONE.
2009-08-29 17:07:37 +01:00
Chris Wilson
005b195f06 [pattern] Ignore matrix/filter/extend when comparing solids
Solid patterns do not use their matrices, filter or extend properties so
ignore them for the purposes of comparing and hashing.
2009-08-29 08:08:34 +01:00
Chris Wilson
1327df2cf2 [pattern] Invalid access beyond end of freed-pool
Oops, we were attempting to return a pointer from beyond the end of our
array.
2009-08-06 10:16:45 +01:00
Chris Wilson
bed2701e1c 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:14 +01:00
Chris Wilson
d80f5580ef [pattern] Mark _cairo_pattern_nil as static
Fixes check-def.sh failure.
2009-06-28 21:11:41 +01:00
Chris Wilson
2b1ec7a4d8 [cairo] Report true error via pattern from cairo_pop_group()
Report the correct error via the returned pattern->status rather than
simply returning the NO_MEMORY nil object.
2009-06-27 22:48:19 +01:00
Chris Wilson
f388028333 [gstate] Avoid temporary allocation for transformed patterns
Observe that patterns are not altered during an operation and so we are
safe to use the data from the original pattern without copying. (This is
enforced through the declaration that the backends operate on constant
patterns which are not allowed to be referenced or destroyed.)
2009-06-27 20:18:18 +01:00
Chris Wilson
c12533b135 [pattern] Add _cairo_pattern_fini_snapshot
Symmetric operation to _cairo_pattern_init_snapshot() this exists simply
to break the circular reference between the meta-surface and snapshot-cow.
2009-06-19 00:29:00 +01:00
Chris Wilson
f4d9a4482f [pattern] Generalise the freed pattern pool
Also cache recently freed surface and gradient patterns. With thanks to
Jonathan Morton for the inspiration and initial pointer pool code for
pixman.
2009-06-05 07:32:07 +01:00
Chris Wilson
132f44dce1 valgrindify init/fini routines
Annotate object init/fini routines to detect use-after-free for
on-stack/embedded objects.
2009-06-04 14:17:43 +01:00
Chris Wilson
8e5295979f [pattern] Typo in document
Remove extraneous markup from program-listing.

https://bugs.freedesktop.org/show_bug.cgi?id=20441
2009-06-03 20:17:59 +01:00
Chris Wilson
51193f1610 [pattern] Pass flags to _cairo_pattern_acquire_surface()
Allow the caller to choose whether or not various conversions take place.
The first flag is used to disable the expansion of reflected patterns into a
repeating surface.
2009-06-02 15:13:45 +01:00
Chris Wilson
e05097c604 [surface] Assign a unique id to the surface.
Allocate an ever-increasing, non-zero, unique identifier to each surface.
True for the first 4-billion...
2009-06-01 18:04:14 +01:00
Chris Wilson
b7f199fde2 [pattern] Trim REPEAT source size when applicable.
Some backends are quite constrained with surface sizes and so trigger
fallbacks when asked to clone large images. To avoid this we attempt
to trim ROIs (as these are often limited to the destination image, and
so can be accommodated by the hardware). This patch allows trimming
REPEAT sources both horizontally and vertically independently.
2009-05-25 22:14:56 +01:00
Chris Wilson
31596cf2b2 [debug] Check image contents using memcheck.
As an aide to tracking down the source of uninitialised reads, run
VALGRIND_CHECK_MEM_IS_DEFINED() over the contents of image surfaces at the
boundary between backends, e.g. upon setting a glyph image or acquiring
a source image.
2009-05-15 21:31:03 +01:00
Chris Wilson
c25992479a [xlib] Use minimal depth for similar clones.
Damian Frank noted
[http://lists.cairographics.org/archives/cairo/2009-May/017095.html]
a performance problem with an older XServer with an
unaccelerated composite - similar problems will be seen with non-XRender
servers which will trigger extraneous fallbacks. The problem he found was
that painting an ARGB32 image onto an RGB24 destination window (using
SOURCE) was going via the RENDER protocol and not core. He was able to
demonstrate that this could be worked around by declaring the pixel data as
an RGB24 image. The issue is that the image is uploaded into a temporary
pixmap of matching depth (i.e. 32 bit for ARGB32 and 24 bit for RGB23
data), however the core protocol can only blit between Drawables of
matching depth - so without the work-around the Drawables are mismatched
and we either need to use RENDER or fallback.

This patch adds a content mask to _cairo_surface_clone_similar() to
provide the extra bit of information to the backends for when it is
possible for them to drop channels from the clone. This is used by the
xlib backend to only create a 24 bit source when blitting to a Window.
2009-05-15 21:31:02 +01:00
Chris Wilson
1ae2ddc1dd [memfault] Manually inject faults when using stack allocations
Ensure that no assumptions are made that a small allocation will succeed
by manually injecting faults when we may be simply allocating from an
embedded memory pool.

The main advantage in manual fault injection is improved code coverage -
from within the test suite most allocations are handled by the embedded
memory pools.
2009-04-23 09:22:51 +01:00
Chris Wilson
8bf109bd2a [pattern] Silence compiler with impossible case.
Assert that the pattern is one of the four known types, and return an
error so that the compiler knows that the local variable can not be used
uninitialised.
2009-04-20 10:21:23 +01:00
Chris Wilson
75b06b8bdb [pattern] Do not modify outparam on error path.
The pdf backend was crashing as a failed pattern copy stored an invalid
pointer with the resource group.
2009-04-16 09:34:02 +01:00
Chris Wilson
a4b44ca89e [pattern] Report the true error status from getters.
As the getters actually return an error status, use it to report any
pre-existing error status on the pattern.
2009-03-18 09:44:33 +00:00
Chris Wilson
d295942b9d Inline _cairo_restrict_value()
This is one instance where the function call overhead dominated the
function call in both time and size.
2009-02-13 13:26:52 +00:00
Behdad Esfahbod
730ed68ec1 [pattern] Fix comment typo 2008-12-25 23:29:02 -05:00
Chris Wilson
2d790daa95 [pattern] Use a solid pattern for a uniform gradient.
If each color stop in a gradient is identical, replace the gradient
surface with a simple solid surface. As seen in the wild.
2008-12-18 10:40:13 +00:00
Chris Wilson
1d68ee73f8 [pattern] Compute the combined color content.
When multiplying two colors together, the combined content is simply the
or of the their contents.
2008-12-12 13:21:11 +00:00
Chris Wilson
e6963a5bfe Mark allocation failures as unlikely.
Use the gcc likelihood annotation to indicate that allocation failures are
extremely unlikely.
2008-11-29 11:20:34 +00:00
Chris Wilson
d1801c23fa Mark if(status) as being unlikely.
The error paths should be hit very rarely during normal operation, so mark
them as being unlikely so gcc may emit better code.
2008-11-29 11:20:33 +00:00
Chris Wilson
b6c371a47f [pattern] Cosmetic.
surface is equal to pattern->surface at this point.
2008-11-19 11:59:21 +00:00
Chris Wilson
a856371bef Add CairoScript backend.
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.)
2008-11-13 11:36:54 +00:00
Chris Wilson
b06c50cc54 [cairoint.h] Remove unused PLT entries.
Trim the slim_hidden_proto/def to match the currently used functions.
2008-11-13 11:36:43 +00:00
Chris Wilson
c95eebc923 [pattern] Split the translation between the matrix and [xy]_offset
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.
2008-11-05 10:00:13 +00:00
Chris Wilson
59bdeba9ab [matrix] Minimise pixman conversion error.
Minimise the error of the pixman matrix about the centre of the displayed
area rather than the origin.
2008-11-05 08:01:27 +00:00
Chris Wilson
6706590d4e [pattern] Reduce likelihood of range overflow with large downscaling.
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.
2008-10-30 17:52:12 +00:00
Chris Wilson
c0af8c7063 [pattern] Tweak REFLECT HACK
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.
2008-10-30 17:52:12 +00:00
Chris Wilson
234623b3d5 [pattern] Support unbounded surfaces.
An unbounded surface should just report an infinite pattern extent and not
return UNSUPPORTED from _cairo_pattern_get_extents().
2008-10-30 17:52:12 +00:00
Chris Wilson
6ed957fc24 [gstate] Use _cairo_pattern_black for the default source.
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().
2008-10-30 17:52:11 +00:00
Chris Wilson
7944601864 [pattern] Avoid needless copying of patterns.
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.
2008-10-30 17:52:05 +00:00
Chris Wilson
9d2189afbd [pattern] Do not recompute the inverse if setting an identical matrix.
More micro-optimisation.
2008-10-30 17:14:27 +00:00
Chris Wilson
4b29988939 Review users of cairo_rectangle_int_t for incorrect unsigned promotion.
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.
2008-10-30 16:19:38 +00:00
Chris Wilson
2464b8a0a9 [pattern] Allow the projected surface extents to be negative.
In order to handle projection of analysis surface with user-fonts we need
to accommodate patterns extending into negative coordinate space.
2008-10-30 16:19:11 +00:00
Chris Wilson
02a7ca80f9 [pattern] Correctly optimize away fractional translations.
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.
2008-10-14 11:08:43 +01:00
Chris Wilson
9886cb3353 [pattern] Only perform non-integer optimization for identity matrices.
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...
2008-10-14 10:27:21 +01:00
Chris Wilson
3eb4bc3757 [pattern] Optimize away fractional translation for NEAREST patterns.
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.
2008-10-13 23:34:51 +01:00
Chris Wilson
1d3453eee5 [pattern] Rescale the linear pattern matrix to avoid overflow.
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.
2008-10-12 11:38:42 +01:00
Chris Wilson
ddd1615a17 [pattern] Remove incorrect assert.
It's possible to reach that point without setting the filter to NEAREST,
for example if using FAST or GAUSSIAN.
2008-10-09 12:25:07 +01:00