Commit graph

120 commits

Author SHA1 Message Date
Adrian Johnson
0cae2a4a74 Use _cairo_calloc() to allocate structs
To avoid any possibility of uninitialized memory.

The exceptions are:
 - where the allocation is immediately overwritten by a memcpy or struct copy.
 - arrays of structs to avoid any performance impact (except when the
   array is returned by the public API).
2024-06-21 10:32:23 +09:30
Adrian Johnson
ba3823e6b8 Fix cast between incompatible function types warnings
warning: cast between incompatible function types from ‘cairo_status_t (*)(void *, const cairo_point_t *)’ {aka ‘enum _cairo_status (*)(void *, const struct _cairo_point *)’} to ‘cairo_status_t (*)(void *, const cairo_point_t *, const cairo_slope_t *)’ {aka ‘enum _cairo_status (*)(void *, const struct _cairo_point *, const struct _cairo_slope *)’} [-Wcast-function-type]
2021-08-22 12:07:36 +09:30
Adrian Johnson
9fbf427548 Use uintptr_t for all casts between pointer and integer
On 64-bit windows, long is 32-bit. When compiling there are a large
number of warnings about mismatched sizes when casting long to/from a
pointer.

Use the (u)intptr_t type for any integer that will have a pointer stored
in it. Use a (u)intptr_t cast when integers are stored in pointers to
silence warnings.

Fixes #263
2021-07-25 11:01:20 +09:30
George Matsumura
ed98414686 build: Fix various compiler warnings
This fixes a few compiler warnings that were encountered with gcc 9.3.0.

Signed-off-by: George Matsumura <gmmatsumura01@bvsd.org>
2020-11-07 06:45:01 -07:00
Adrian Johnson
1998239387 Use _cairo_malloc instead of malloc
_cairo_malloc(0) always returns NULL, but has not been used
consistently.  This patch replaces many calls to malloc() with
_cairo_malloc().

Fixes:  fdo# 101547
CVE: CVE-2017-9814 Heap buffer overflow at cairo-truetype-subset.c:1299
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2018-05-07 16:35:51 -07:00
John Lindgren
bb24f165ff Avoid indiscriminate use of VALGRIND_MAKE_MEM_NOACCESS.
Marking stack-allocated objects as no-access creates false positives,
which distract from finding real memory errors.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=52548

Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-06-26 16:12:33 -07:00
Behdad Esfahbod
5de25951a4 Preserve current-point in copy_path()/append_path() sequence
Fixes path-currentpoint test.
2014-01-27 17:34:00 -05:00
Martin Robinson
c60e23feb1 path: Fix a bug in line intersection
Before the intersection code was not taking into account that both
quotients are required to be in the range (0,1) for the segments to
intersect or handling the case of negative numerators and denominators.
2013-03-14 09:44:35 -07:00
Chris Wilson
a09b7c7927 path: Fix bbox computation for negative scale factors
The fast path for transforming a path by a simple scale factor, forgot
to fix up the orientation of the box if that scale factor was negative.

Reported-by: Edward Zimmermann <Edward.Zimmermann@cib.de>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2013-02-12 10:27:58 +00:00
Martin Robinson
cfe0e59663 gl/msaa: Add a fast path for fills that are simple quads
Instead of invoking Bentley-Ottman for fills that are simple
quadrilaterals, just pass the geometry straight to OpenGL.
2013-01-25 16:30:11 -08:00
Chris Wilson
b0c466e27a path: Update last_move_point after move-to
Reported-and-tested-by: Jussi Kukkonen <jku@linux.intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54549
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-09-05 14:55:55 +01:00
Chris Wilson
57cfdfd979 Split cairo-list into struct+inlines
References: https://bugs.freedesktop.org/show_bug.cgi?id=48577
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-04-19 13:17:29 +01:00
Chris Wilson
e9c9e28cd1 Split cairo-box-privates into struct+inlines
References: https://bugs.freedesktop.org/show_bug.cgi?id=48577
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2012-04-19 12:16:53 +01:00
Andrea Canciani
d3b6e151a2 path-fixed: Silence gcc warnings
_cairo_path_fixed_last_op() contains an assertion, which gcc doesn't
like to inline. Since it is a static function, which basically
accesses a value, gcc will inline it anyway when assertions are
disabled, so remove the "inline" hint to reduce gcc warning noise when
doing debug builds.

Fixes:

cairo-path-fixed.c: In function '_cairo_path_fixed_drop_line_to':
cairo-path-fixed.c:373:1: warning: inlining failed in call to
'_cairo_path_fixed_last_op.isra.5.part.6': call is unlikely and code
size would grow [-Winline]
cairo-path-fixed.c:400:1: warning: called from here [-Winline]
...
2012-02-20 12:32:53 +01:00
Uli Schlachter
84d1eac61f path: Fix a minor oversight in 1ce5d4707c
The plan was "path: Skip calls to zero-length memcpy". However, this skipped
calls if the buffer was still empty, which means that it skipped all calls.

Fixes: Half the test suite, lots of assertion failures

Signed-off-by: Uli Schlachter <psychon@znc.in>
2011-09-16 18:00:21 +02:00
Chris Wilson
1ce5d4707c path: Skip calls to zero-length memcpy
We attempt to copy 0 points onto the array of path points for a
close-path. This is pointless and an unnecessary function call under
MSVC at least.

Based on a patch by Steve Snyder, incorporating Behdad's review
comments.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=37836
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-09-16 16:11:42 +01:00
Chris Wilson
af9fbd176b Introduce a new compositor architecture
Having spent the last dev cycle looking at how we could specialize the
compositors for various backends, we once again look for the
commonalities in order to reduce the duplication. In part this is
motivated by the idea that spans is a good interface for both the
existent GL backend and pixman, and so they deserve a dedicated
compositor. xcb/xlib target an identical rendering system and so they
should be using the same compositor, and it should be possible to run
that same compositor locally against pixman to generate reference tests.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

P.S. This brings massive upheaval (read breakage) I've tried delaying in
order to fix as many things as possible but now this one patch does far,
far, far too much. Apologies in advance for breaking your favourite
backend, but trust me in that the end result will be much better. :)
2011-09-12 08:29:48 +01:00
Chris Wilson
545f30856a stroke: Convert the outlines into contour and then into a polygon
In step 1 of speeding up stroking, we introduce contours as a means for
tracking the connected edges around the stroke. By keeping track of
these chains, we can analyse the edges as we proceed and eliminate
redundant vertices speeding up rasterisation.

Coincidentally fixes line-width-tolerance (looks like a combination of
using spline tangent vectors and tolerance).

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-08-15 10:31:47 +01:00
Chris Wilson
34ce4680d1 fixed: Allow the implicit close of the last fill path to complete a fill-box
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-08-10 10:23:51 +01:00
Chris Wilson
323e48f8ec fill: A horizontal/vertical line is also a degenerate fill box
Since we discard empty fill boxes whilst filling, we can also treat
horizontal/vertical lines as a filled box and so proceed with the
rectangular fast path in the presence of
  cairo_rectangle (x, y, w, h)
with w == 0 || h == 0.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-08-09 16:06:50 +01:00
Andrea Canciani
c0fe556515 path: Fix _cairo_path_fixed_is_rectangle()
__cairo_path_fixed_is_rectangle() is used by the PS and PDF backends
to check if a path is equivalent to a rectangle when stroking. This is
different from being a rectangle when filling, because of the implicit
close_path appended to every subpath when filling.

Fixes stroke-open-box.

See https://bugs.freedesktop.org/show_bug.cgi?id=34560
2011-03-18 10:30:25 +01:00
Andrea Canciani
5eadc286d8 path: Silence warnings
gcc complains that:

cairo-path-fixed.c:400: warning: inlining failed in call to
  '_cairo_path_fixed_drop_line_to': call is unlikely and code size
  would grow
2010-12-13 11:09:20 +01:00
Andrea Canciani
df453b7aca path: Remove support for inverse direction interpretation
The previous commit guarantees that paths are always interpreted in
the forward direction, so the code allowing both directions is not
needed anymore.
2010-12-10 11:04:47 +01:00
Andrea Canciani
a8ae8759f5 path: Always interpret in forward direction
Path are always interpreted in forward direction, so the ability of
interpreting in the opposite direction (which is very unlikely to be
useful at all) can be removed.
2010-12-10 10:58:51 +01:00
Andrea Canciani
b8444a5c78 path: Tighten transformed extents
The transformation code should produce tight extents if they are to be
used in the new simple extents functions.
2010-10-29 17:31:24 +02:00
Andrea Canciani
958c56e2b4 path: Tighten curve_to extents
The additional time spent in the computation of tight extents for the
curve_to operation doesn't seem to be significant, but it makes the
extents computations faster and the approximations more accurate.
2010-10-29 17:31:23 +02:00
Andrea Canciani
a1d8763236 path: Replace _cairo_path_fixed_extents_add with _cairo_box_add_point
Path extents now satisfy _cairo_box_add_point requirements, so it can
be used instead of _cairo_path_fixed_extents_add.
2010-10-29 17:31:23 +02:00
Andrea Canciani
0268706550 path: Fix _cairo_path_fixed_transform
current_point and last_move_to were previously left in their old
position (which could lead to incorrect flag computation if other
operations were added to the path) and flags were not updated.
2010-10-29 17:31:23 +02:00
Andrea Canciani
29d5b18cba path: Recompute flags in _cairo_path_fixed_scale_and_offset
Only fill_maybe_region can change its value because the transformation
preserves vertical and horizontal lines, but can move the points and
make them integer if they were not or non-integer if they were.

Recomputing it is just as easy as checking if all the points are
integer and the path is fill_is_rectilinear.
2010-10-29 17:31:23 +02:00
Andrea Canciani
634fcf2c0a path: Transform current_point and last_move_to in _cairo_path_fixed_scale_and_offset
They were previously left in their old position (which could lead to
incorrect flag computation if other operations were added to the
path).
2010-10-29 17:31:23 +02:00
Andrea Canciani
9c0e4db570 path: Recompute flags in _cairo_path_fixed_translate
Only fill_maybe_region can change its value because the transformation
preserves vertical and horizontal lines, but can move the points and
make them integer if they were not or non-integer if they were.

Recomputing it is just as easy as checking if all the points are
integer and the path is fill_is_rectilinear.
2010-10-29 17:31:23 +02:00
Andrea Canciani
9d84dff0c6 path: Cleanup close_path
Instead of explicitly calling _cairo_fixed_move_to, setting the
needs_move_to flags is sufficient because the current_point is already
updeted correctly.
2010-10-29 17:31:23 +02:00
Andrea Canciani
17fef2fe4d path: Make _cairo_path_fixed_last_op assert on empty path
_cairo_path_fixed_last_op should now only be used on non-empty path
(to test if the previous operation was a line_to).
2010-10-29 17:31:23 +02:00
Andrea Canciani
568a975a62 path: Cleanup _cairo_path_fixed_iter_at_end
The last operation of a path cannot be a move_to anymore (since
move_to is only added if another operation is added after it).
2010-10-29 17:31:23 +02:00
Andrea Canciani
929571b4b5 path: Cleanup _cairo_path_fixed_transform
Clean up the code and make sure that _cairo_path_fixed_translate is
used whenever the _cairo_fixed_to_double rounding would result in the
matrix being approximated with a translation.
2010-10-29 17:31:23 +02:00
Andrea Canciani
34f1db13a1 path: Log flags
When logging path operations, also log computed flags.
2010-10-29 17:31:23 +02:00
Andrea Canciani
e8e614db92 path: Rename fill optimization flags
Rename fill optimization flags making fill_ their common prefix.
2010-10-29 17:31:23 +02:00
Andrea Canciani
e48cb95493 path: Add stroke_is_rectilinear flag
Stroke and fill rectilinearity cannot be represented by a single flag
without missing the opportunity of considering some strokes
rectilinear.
2010-10-29 17:31:22 +02:00
Andrea Canciani
166453c1ab path: New path construction logic
Now move_to's are actually added to the path when followed by a
drawing operation (line_to, curve_to or close_path).

This is implemented by updating the current_point and setting the
needs_move_to when a move_to operation is requested.

Whenever a drawing operation is requested and the needs_move_to flag
is set, a move_to is added before the drawing operation.
2010-10-29 17:31:22 +02:00
Andrea Canciani
a2ac91eb5f path: Drop degenerate line_to in _cairo_path_fixed_curve_to
When a degenerate line_to is followed by a curve_to operation, the
line_to can be safely dropped, just like for degenerate line_to
followed by line_to.
2010-10-29 17:31:22 +02:00
Andrea Canciani
2352b48f9e path: Move _cairo_path_fixed_add at the end of line_to and curve_to 2010-10-29 17:31:22 +02:00
Andrea Canciani
46584e01a8 box: Add box header
Add a new header implementing very simple box functions:
 - initialization with the two extrema
 - extension with a point
 - in/out test
2010-10-29 17:31:22 +02:00
Andrea Canciani
65d57313f0 path: Cleanup _cairo_path_fixed_line_to
The low-level line_to optimizations can be implemented in a more
abstract way using _cairo_path_fixed_penultimate_point and
_cairo_path_fixed_drop_line_to.
2010-10-29 17:31:22 +02:00
Andrea Canciani
f3e7677109 path: Simplify close_path
Instead of explicitly computing the flag in close_path, manually close
the path with a line_to, then drop the last operation if it is a
line_to (it might be another operation if the line_to was ignored
because it would have been degenerate).
2010-10-29 17:31:22 +02:00
Andrea Canciani
641d314b9a path: Add utility functions
Add a function to get the penultimate point and another one to drop
the last operation (assuming it is a line_to).

This allows some more abstraction in the line_to and close_path code.
2010-10-29 17:31:22 +02:00
Andrea Canciani
4075ed9686 path: Rename _cairo_path_last_op to _cairo_path_fixed_last_op
Aestetical change, to make the naming consistent with that of the
other functions.
2010-10-29 17:31:22 +02:00
Andrea Canciani
a8763d8fde path: Make path equality independent of flags
Flags for the same path can be different depending on its "history"
(in particular if it was constructed and transformed they might be
different from what they would be if each point was transformed and
then the path constructed).
2010-10-29 17:31:21 +02:00
Andrea Canciani
f4b2ce1c78 path: Improve hashing
Make the hash independent of buf bucketing, extents and flags.

This makes the hash depend only on the actual content of the path, not
on how it is stored or on any computed property.
2010-10-29 17:31:21 +02:00
Andrea Canciani
14cc9846b3 path: Replace _cairo_path_fixed_is_equal with _cairo_path_fixed_equal
Remove _cairo_path_fixed_is_equal and use _cairo_path_fixed_equal
instead.
The latter function can recognize that two paths are equal even if the
drawing commands have been partitioned in a different way in the buf
list.
2010-10-29 17:31:21 +02:00
Chris Wilson
eeafeebd2e path: Exponentially grow buffer based on populated points and ops.
Instead of simply doubling the buffer size every time we overflow a point
or an op, enlarge the buffer to fit twice the number of used points and
ops.  We expect paths to be fairly consistent in the mix of operations,
and this allows the buffer size to tune itself to actual usage and reduce
wastage.
2010-06-11 09:06:20 +01:00