Commit graph

248 commits

Author SHA1 Message Date
Chris Wilson
6cc75cfe5b [cairo] Harden the text API against NULL strings.
Handle NULL strings in cairo_show_(text|glyph),
cairo_(text|glyph)_(extents|path) without crashing.
2008-01-12 10:30:15 +00:00
Chris Wilson
b796a2f69d [cairo] Update CAIRO_STATUS_LAST_STATUS
A couple of new errors have been added without updating the LAST_STATUS
value...
2008-01-03 23:00:27 +00:00
Adrian Johnson
bd44d114a6 Add CAIRO_STATUS_TEMP_FILE_ERROR 2007-12-29 00:12:44 +10:30
Chris Wilson
d4d3873bcc [cairo] Correct the documentation for cairo_get_group_target().
cairo_get_group_target() can never return NULL, but will always
return the current destination surface.
2007-12-20 21:21:46 +00:00
Carl Worth
5b0a0fe7a2 Mention cairo_new_sub_path in documentation of cairo_arc 2007-11-07 11:18:05 -08:00
Chris Wilson
b311c414a2 [cairo] Use NULL instead of a bare 0.
Silence a sparse warning.
2007-11-01 22:27:19 +00:00
Carl Worth
8d8724e804 Improve brace readability for multi-line conditional 2007-10-30 09:45:45 -07:00
Chris Wilson
6fdb7f129c Simplify return value from cairo_path_fixed_get_current_point().
The only caller of cairo_path_fixed_get_current_point(), used the status
return to determine whether or not the path had a current point (and did
not propagate the error) - for which we had already removed the
_cairo_error() markup. Now we reduce the boolean status return to a
cairo_bool_t, with a net reduction in code.
2007-10-30 10:43:55 +00:00
Chris Wilson
a4f20610af [cairo] Protect the getters when operating on the nil object.
Put a guard that checks the context's status at the start of each
getter that prevents the function from trying to dereference NULL state.
Use the status, as opposed to the invalid reference count, for
consistency with the existing guards on some of the getters.
2007-10-04 16:44:27 +01:00
Chris Wilson
bed8239f03 [cairo-error] Clean up all the warnings and missing _cairo_error() calls.
Every time we assign or return a hard-coded error status wrap that value
with a call to _cairo_error(). So the idiom becomes:
    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
or
    return _cairo_error (CAIRO_STATUS_INVALID_DASH);

This ensures that a breakpoint placed on _cairo_error() will trigger
immediately cairo detects the error.
2007-10-04 13:31:44 +01:00
Chris Wilson
d90d4bb6b9 [cairo-error] Make _cairo_error() return the error status.
As pointed out by Jeff Muizelaar, this allows for more concise code, as
    _cairo_error(CAIRO_STATUS_NO_MEMORY)
    return CAIRO_STATUS_NO_MEMORY
can become
    return _cairo_error(CAIRO_STATUS_NO_MEMORY);
2007-10-04 13:30:11 +01:00
Chris Wilson
71120727e1 [cairo-atomic] Use an atomic operation to set the status on a shared resource.
Since the objects can be shared and may be in use simultaneously across
multiple threads, setting the status needs to be atomic. We use a
locked compare and exchange in order to avoid overwriting an existing
error - that is we use an atomic operation that only sets the new status
value if the current value is CAIRO_STATUS_SUCCESS.
2007-10-04 11:26:44 +01:00
Chris Wilson
ef5f460eb1 [cairo-path] Check for an empty path in cairo_append_path().
As we now generate empty paths, we must be able to handle empty paths
in the user facing API. cairo_append_path() has an explicit check, and
raises an error, for a NULL path->data, so we need to check the
path->num_data first for empty paths.
2007-10-04 09:18:36 +01:00
Chris Wilson
8ad56b308a [malloc/error] Add call to _cairo_error() after a failed malloc.
Blitz all allocations to ensure that they raise a
_cairo_error(CAIRO_STATUS_NO_MEMORY) on failure.
2007-10-04 00:42:30 +01:00
Chris Wilson
03be41151d [cairo-atomic] Rewrite reference counting using atomic ops.
Introduce an opaque cairo_reference_count_t and define operations on it
in terms of atomic ops. Update all users of reference counters to use
the new opaque type.
2007-09-25 16:29:54 +01:00
Jeff Muizelaar
dca93eb76d Fix theoretical NULL return from cairo_pop_group()
This also makes the code more consistent as group_pattern always holds a valid
pattern.
2007-09-12 23:12:59 -04:00
Vladimir Vukicevic
9e975757a2 Export cairo_surface_{copy,show}_page
This patch adds cairo_surface_copy_page and cairo_surface_show_page
as public methods, leaving the previous cairo_show_page variants as
shorthands.  copy_page/show_page are specific to the surface, not
to the context, so they need to be surface methods.
2007-09-11 13:30:35 -07:00
Vladimir Vukicevic
be3516335c [fixpt] Replace cairo_rectangle_int16_t with cairo_rectangle_int_t
Mostly s/cairo_rectangle_int16_t/cairo_rectangle_int_t/,
as well as definitions to pick cairo_rectangle_int_t.
2007-07-18 22:45:21 +02:00
Chris Wilson
de4dd4263c [cairo] Propagate surface->status on cairo_t creation.
Set the cairo_t status to be the surface->status when the context is
created, and special case the NO_MEMORY status in order to avoid a
redundant allocation.
2007-05-30 14:11:04 +01:00
Kouhei Sutou
0898411d0a [doc] Minor documentation fixes 2007-05-28 17:05:40 -04:00
Chris Wilson
1a719d1189 [cairo] Use _cairo_clip_nil for CAIRO_STATUS_NO_MEMORY
When creating a error clip list for CAIRO_STATUS_NO_MEMORY, simply
reuse the nil object rather than allocate a fresh list.
2007-05-10 09:30:06 +01:00
Chris Wilson
b5d2506879 [cairo] cairo_pop_group() returns a NULL pattern
cairo_pop_group() checks for a NULL return from
cairo_pattern_create_for_surface() instead of the nil cairo_pattern_t,
and then returns a NULL pattern instead of the nil object.
2007-05-09 16:29:39 +01:00
Chris Wilson
ae5d4a1c17 [cairo] Return after detecting the invalid font-options.
Do not continue to copy the contents of the nil cairo_font_options_t,
but set the error on the context and return.
2007-05-09 16:28:52 +01:00
Chris Wilson
ede76a97ea [cairo-font-options] Check for the nil-object.
The design is for the user to create a cairo_font_options_t object with
cairo_font_options_create() and then is free to use it with any Cairo
operation. This requires us to check when we may be about to overwrite
the read-only nil object.
2007-05-08 22:00:46 +01:00
Carl Worth
a392cc8508 Clarify documentation of cairo_in_stroke and cairo_in_fill
Like cairo_stroke_extents and cairo_fill_extents, these functions
work without regard to the surface dimensions or the current clip
region.
2007-04-27 22:46:47 -07:00
Carl Worth
29670d3766 Add a content value to solid patterns
This allows for the surface acquired from the pattern to have the
same content. In particular, in a case such as cairo_paint_with_alpha
we can now acquire an A8 mask surface instead of an ARGB32 mask
surface which can be rendered much more efficiently. This results
in a 4x speedup when using the OVER operator with the recently
added paint-with-alpha test:

Speedups
========
image-rgb  paint-with-alpha_image_rgb_over-256 2.25 -> 0.60: 4.45x speedup
███▌

It does slowdown the same test when using the SOURCE operator, but
I don't think we care. Performing SOURCE with a mask is already a very
slow operation, (hitting compositeGeneral), so the slowdown here is
likely from having to convert from A8 back to ARGB32 before the
generalized compositing. So if someone cares about this slowdown,
(though SOURCE with cairo_paint_with_alpha doesn't seem extremely
useful), they will probably be motivated enough to contribute a
customized compositing function to replace compositeGeneral in which
case this slowdown should go away:

image-rgba paint-with-alpha_image_rgb_source-256 3.84 -> 8.86%: 1.94x slowdown
█
2007-04-25 11:09:31 -07:00
Carl Worth
302f1146da Fix two bugs in documentation code sample of cairo_arc
The sample code for drawing an ellipse had width and height
reversed in the call to cairo_scale, and also had both
incorrectly inverted.
2007-04-25 07:24:23 -07:00
Chris Wilson
b82e595449 pixman region operations can fail, propagate the error.
Copying the clip region could fail, add error returns and propagate up
the call stack.
2007-04-10 13:18:02 -07:00
Carl Worth
d317e8175d Prefer FALSE over 0 for initializing a cairo_bool_t value 2007-04-10 10:14:49 -07:00
Carl Worth
9077da99ab Make _cairo_gstate_user_to_device (and friends) void.
This is just multiplication after all, so there's nothing that can fail.
And we can get rid of a lot of useless error-checking code this way.
The corrected functions are:

	_cairo_gstate_user_to_device
	_cairo_gstate_user_to_device_distance
	_cairo_gstate_device_to_user
	_cairo_gstate_device_to_user_distance
2007-04-09 17:09:51 -07:00
Carl Worth
628ec8eb91 Make _cairo_gstate_identity_matrix void
Now that we have the warn_unused_result attribute enabled, (thanks
Chris!), it's actually harmful to have a function return an
uncoditional value of CAIRO_STATUS_SUCCESS. The harm is that
it would force lots of unnecessary error-checking paths that
just add clutter.

It is much better to simply give a function that cannot fail
a return type of void.
2007-04-09 17:03:29 -07:00
Chris Wilson
b2280c5ac2 Do not overwrite cr->status
The idiom for cairo.c is to do
    cr->status = _cairo_op ();
    if (cr->status) _cairo_set_error (cr, cr->status);

Unfortunately a trivial mistake for a _cairo_op () is to call a cairo_op ()
and forget to check cr->status but return CAIRO_STATUS_SUCCESS which will
mask the earlier error.

Obviously this is a bug in the lower level but the impact can be reduced
by chaning cairo.c to use a local status variable for its return:
    cairo_status_t status = _cairo_op ();
    if (status) _cairo_set_error (cr, cr->status);
2007-04-09 16:36:59 -07:00
Chris Wilson
79424fc646 cairo - add missing status checks
Add a few missing status checks and set the error on the context when
applicable.
2007-04-09 15:08:29 +01:00
Behdad Esfahbod
88dc0c5f19 Make sure all nil objects start with _cairo_
Previously, the convention was that static ones started with cairo_, but
renamed to start with _cairo_ when they were needed from other files and
became cairo_private instead of static...

This is error prune indeed, and two symbols were already violating.  Now
all nil objects start with _cairo_.
2007-04-03 19:26:18 -04:00
Benjamin Berg
c2b1908f9b Fix typo in cairo_arc_negative() docs (#10497) 2007-04-03 15:46:51 -04:00
Chris Wilson
256f3e09a8 Destroy the current pattern before replacing with cairo_set_source().
Frequently cairo_set_source_rgb[a]() is used to replace the current
solid-pattern source with a new one of a different colour. The current
pattern is very likely to be unshared and unmodified and so it is likely
just to be immediately freed [or rather simply moved to recently freed
cache]. However as the last active pattern it is likely to cache-warm and
suitable to satisfy the forthcoming allocation. So by setting the current
pattern to 'none' we can move the pattern to the freed list before we
create the new pattern and hopefully immediately reuse it.
2007-03-26 20:58:14 +01:00
Behdad Esfahbod
ef8515b4a6 cairo_push/pop_group(), bail out if cairo_t is in error status
Fixes the new test added to test/nil-surface to not crash
2007-03-21 15:29:18 -04:00
Behdad Esfahbod
9cea8a4bb2 [cairo.c] Don't access gstate members directly 2007-03-21 15:12:58 -04:00
Behdad Esfahbod
1469ea22ba [cairo-gstate] Move save/restore logic into gstate instead of cairo_t
by adding _cairo_gstate_save/restore().  This is in preparation for
adding copy-on-write behavior to gstate.
2007-03-21 11:22:33 -04:00
Behdad Esfahbod
d40126f5ab [cairo_t] Embed a gstate into cairo_t
So we don't have to malloc the first gstate.
2007-03-13 05:14:19 -04:00
Behdad Esfahbod
bc8987068d [cairo_t] Make path an array of size one
This is more natural since cr->path can be used as if it was a pointer.
This means, for example, if we move on to making it a pointer, most of
the code using it does not need any change.  So we get some level of
encapsulation of implementation details, if you prefer the terminology :).
2007-03-13 05:14:19 -04:00
Behdad Esfahbod
6bc543a0eb [cairo_t] Move gstate pointer before cairo_path_fixed_t for better cache behavior 2007-03-13 05:14:18 -04:00
Behdad Esfahbod
85aff353ca [cairo-path-fixed] Fine-tune size of buffer
such that cairo_path_fixed_t fits in 512 bytes.
2007-03-13 05:14:18 -04:00
Behdad Esfahbod
1bd073a1a2 [cairo-path-fixed] Merge op and arg bufs
This means, we have to malloc only one buffer, not two.  Worst case
is that one always draws curves, which fills the arg (point) buffer
six times faster than op buffer.  But that's not a big deal since
each op takes 1 byte, while each point takes 8 bytes.  So op space
is cheap to spare, so to speak (about 10% memory waste at worst).
2007-03-13 05:14:18 -04:00
Behdad Esfahbod
5750d669af [cairo-path-fixed] Avoid malloc for small paths
We do this by including an initial op and arg buf in cairo_path_fixed_t,
so for small paths we don't have to alloc those buffers.

The way this is done is a bit unusual.  Specifically, using an array of
length one instead of a normal member:

-    cairo_path_op_buf_t *op_buf_head;
+    cairo_path_op_buf_t  op_buf_head[1];

Has the advantage that read-only use of the buffers does not need any
change as arrays act like pointers syntactically.  All manipulation code
however needs to be updates, which the patch supposed does.  Still, there
seems to be bugs remaining as cairo-perf quits with a Bad X Request error
with this patch.
2007-03-13 05:14:18 -04:00
Behdad Esfahbod
3ab9ca54aa In cairo_text_path(), bail out if zero glyphs 2007-03-05 16:33:46 -05:00
Behdad Esfahbod
4f138e4af5 Uniform object handling in _reference(), _destroy(), and _get_reference_count()
All three now regard NULL and nil inputs the same.  This is new for
_get_reference_count().  It now returns 0 on NULL too, like it does on
nil objects.
2007-03-05 16:28:31 -05:00
Behdad Esfahbod
cc12c5acc4 Make cairo_text_path() set current point correctly
This fixes the bitmap-text test that I just made reveal a bug.
2007-03-05 16:19:28 -05:00
Behdad Esfahbod
1082fed692 [doc] Docuemnt all symbols but cairo_filter_t and cairo_operator_t
Lets see if this is enough to push Carl Worth document those two.
2007-03-02 22:42:17 -05:00
Behdad Esfahbod
9be961eb0c [doc] Some documentation love 2007-03-02 22:01:15 -05:00