Commit graph

209 commits

Author SHA1 Message Date
Chris Wilson
8ad30ccdb0 [cairo-xlib] Introduce a workqueue for deferred destruction of X resources.
Due to the nature of the reference counting, an X resource may be
destroyed later than anticipated and possibly from a different thread
than the original context. This becomes an issue for applications that
carefully manage their single X connection from a single thread and do
not use locking and are then suprised when cairo triggers X traffic when
performing work for a different part of the application in another thread.
2007-05-04 14:06:01 +01:00
Chris Wilson
dd8681b76b [cairo-xlib] Split per-display attributes from per-screen.
Previously, we stored the per-display attributes inside a special
screen=NULL _cairo_xlib_screen_info_t. Now we keep track of known X
displays and store the screen information beneath the display structure
alongside the per-display hooks.
2007-05-04 14:02:28 +01:00
Chris Wilson
c412e42c72 [cairo-xlib-surface] Check that the acquire surfaces are xlib surfaces
_cairo_pattern_acquire_surfaces() may substitute an image surface for
either the source or the mask should the backend not support creation
of similar scratch surfaces or an error occurs during creation. For
composition we require xlib surfaces and so we must trigger the
fallback path if this happens.
2007-05-02 21:17:39 +01:00
Chris Wilson
7f7f4d4f35 [cairo-xlib-surface.c] Free the Pixmap on surface construction failure.
If we create the Pixmap whilst constructing a similar xlib surface, then
it our responsibility to free the Pixmap should we fail to allocate the
surface.
2007-05-01 12:37:38 +01: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
Behdad Esfahbod
cd72167ede [xlib] Get rid of _cairo_xlib_test_disable_render
in favor of cairo_boilerplate_xlib_surface_disable_render.
2007-04-21 02:08:38 -04:00
Behdad Esfahbod
1345552ac2 [xlib] Move cairo_xlib_surface_t definition into cairo-xlib-surface-private.h 2007-04-21 02:08:37 -04:00
Chris Wilson
55ea0466e2 Embed simple clip XRectangles in cairo_xlib_surface_t
Toolkits like GTK+ almost always set a simple rectangular clip mask before
any cairo operation, so avoid the allocation for this simple case by
embedding a small number of XRectangles into the surface structure.
2007-04-19 20:37:06 +01:00
Chris Wilson
ef60e7c651 cairo-xlib-surface - track picture properties.
By tracking picture properties we can dramatically reduce the amount of
X11 traffic by avoiding redundant changes.
2007-04-19 10:54:02 +01:00
Chris Wilson
8a4c108a4b Add a reference count to cairo_xlib_screen_info_t
Due to the interaction between multiple threads showing glyphs and
asynchronous CloseDisplays, it is possible for a font to maintain a
cairo_xlib_screen_info_t beyond the CloseDisplay. The simple solution
is to add a reference count in order to track the lifetime of the
cairo_xlib_screen_info_t correctly.
2007-04-12 23:31:37 +01:00
Chris Wilson
35bb2152c0 Hold the scaled_font->mutex whilst operating on the shared members.
Obey the locking rules whilst resetting the scaled_font after a
CloseDisplay.
2007-04-12 21:44:08 +01:00
Carl Worth
3d21037a8f Add assertion check to quiet warn_unused_result warning.
This is a somewhat useful internal consistency check.
2007-04-10 13:57:41 -07:00
Carl Worth
9a33dab969 Fix an incorrectly indented condition 2007-04-10 10:14:49 -07:00
Chris Wilson
b823e2f68f cairo-xlib-surface - propagate status returns.
These were found during a cairo_static pass on an alternative branch...

A critical one in particular was setting the have added glyph flag to
TRUE even if _cairo_xlib_surface_add_glyph() fails. This can cause an
application crash due to a RenderBadGlyph error later when the scaled
font is cleaned and we attempt to remove the glyph.
2007-04-09 16:22:48 -07:00
Chris Wilson
1cdb54f883 Reorder cleanup cairo_xlib_surface_show_glyphs()
_cairo_pattern_release_surface() asserts that it is passed a pattern
surface. This itself is bad as breaks the symmetry with
_cairo_pattern_acquire_surface under() error conditions, however reorder
the cleanup to avoid this assertion.
2007-04-09 16:18:29 -07:00
Chris Wilson
ea4945850a Avoid using substituted surfaces for xlib operations.
Detect when a substitute image surface is returned for a solid pattern,
and avoid mixed image/xlib composite operations. This can happen for example
if there is a resource allocation failure during creating a similar surface.
2007-04-09 16:12:41 -07:00
Chris Wilson
751976970b Handle failure to allocate a GC. 2007-04-09 16:11:22 -07:00
Carl Worth
eb472a9d9c xlib: Prefer surface->format over surface->visual for identifying masks
The original test for 'if (surface->visual)' dates back to a very old
assumption that if the xlib surface was created with an XRenderFormat
that the surface->visual field would be set to NULL. This assumption
was broken years ago with the following commit:

	0c05b23b31

This fixes the crash reported here:

	BadMatch when running gnome-terminal with the murrine-0.51 gtk engine
	https://bugs.freedesktop.org/show_bug.cgi?id=10250
2007-03-19 15:10:33 -07:00
Chris Wilson
96d8f58daf Clear the XRender data on display closure.
Use the new hook functions to register a callback for xlib to clear
the private glyph data when the display is closed. In order to do this
we need to reset the glyph cache inside the generic scaled font as well.
2007-03-14 17:20:13 -07:00
Behdad Esfahbod
d0fe666a6a Revert the solid-pattern cache
This reverts the following commits:

	2715f20981
	67e3b3c53b

See this thread for an analysis of the problems it caused:

	http://lists.freedesktop.org/archives/cairo/2007-February/009825.html

In short, a single cache for all backends doesn't work, as one thread
using any backend can cause an unused xlib pattern to be evicted from
the cache, and trigger an xlib call while the display is being used
from another thread.  Xlib is not prepared for this.
2007-02-28 14:58:57 -05:00
Behdad Esfahbod
67e3b3c53b [xlib/xcb] Check for same_screen in is_compatible
Two drawables can be used in an X and Render operation only if they share
the same screen.  Previously we were only checking for the same display
in is_compatible.  Check for the same screen now.
2007-02-23 11:15:04 -05:00
Jorn Baayen
2715f20981 [cairo-pattern] Cache surface for solid patterns
We use a small cache of size 16 for surfaces created for solid patterns.
This mainly helps with the X backends where we don't have to create a
pattern for every operation, so we save a lot on X traffic.  Xft uses a
similar cache, so cairo's text rendering traffic with the xlib backend
now completely matches that of Xft.

The cache uses an static index variable, which itself acts like a cache of
size 1, remembering the most recently used solid pattern.  So repeated
lookups for the same pattern hit immediately.  If that fails, the cache is
searched linearly, and if that fails too, a new surface is created and a
random member of the cache is evicted.

Only surfaces that are "compatible" are used.  The definition of compatible
is backend specific.  For the xlib backend, it means that the two surfaces
are allocated on the same display.  Implementations for compatibility are
provided for all backends that it makes sense.
2007-02-14 18:28:56 -08:00
Alp Toker
caa3c2e1e7 Fix various code/comment typos 2007-01-07 01:35:15 -05:00
Behdad Esfahbod
1781e6018c [Xlib] Rewrite an optimized cairo_xlib_show_glyphs()
The old implementation was a very naive one that used to generate one XRender
glyph element per glyph.  That is, position glyphs individually.  This was
raised here:

  http://lists.freedesktop.org/archives/cairo/2006-December/008835.html

The new implmentation is a free rewriting of the Xft logic, that is,
compressing glyphs with "natural" advance into elements, but with various
optimizations and improvements.

In short, it works like this: glyphs are looped over, skipping those that are
not desired, and computing offset from "current position".  Whenever a glyph
has non-zero offsets from the current position, a new element should be
started.  All these are used to compute the request size in the render
protocol.  Whenever the request size may exceed the max request size, or at
the end, glyphs are flushed.  For this to work, we now set non-zero glyph
advances when sending glyphs to the server.

Notable optimizations and improvements include:

  - Reusing the input glyph array (with double glyph positions) as a working
    array to compute glyph offsets.

  - Reusing the input glyph array as the output glyph-index array to be passed
    to XRender.

  - Marking glyphs to be skipped as so, avoiding a copy of the glyph array,
    which is what the old code was doing.

  - Skip glyphs with positions "out-of-range".  That is, those with positions
    that would cause an overflow in Xrender's glyph offset calculations.

On my Fedora desktop on Pentium 4, and on a Nokia 770, it shows a 6% speedup on
the timetext test.
2006-12-12 03:30:21 -05:00
Behdad Esfahbod
5a9642c574 Add/remove const to cairo_glyph_t* arguments consistently
The rule is: cairo_glyph_t* is always passed as const for measurement
purposes.  This was not reflected in our public api previously.  Fixed

Showing glyphs used to have cairo_glyph_t* always as const.  With this
changed, it is only const on cairo_t and cairo_gstate_t operations.
cairo_surface_t, cairo_scaled_font_t, and individual backends receive
cairo_glyph_t* as non-const.  The desired semantics is that they may modify
the contents of the array as long as they do not return
CAIRO_STATUS_UNSUPPORTED.  This makes it possible to avoid copying the glyph
array again and again, and edit it in-place.  Backends are in fact free to use
the array as a generic buffer as they see fit.
2006-12-11 01:39:51 -05:00
Daniel Amelang
57fba8d9b6 Replace existing rounding code with _cairo_lround 2006-11-22 16:25:53 -08:00
Christopher (Monty) Montgomery
8d7a02ed58 Add extents to clone_similar (fixing subimage_copy performance bug)
This fixes a huge performance bug (entire image was being pushed to X
server in order to copy a tiny piece of it). I see up to 50x improvement
from subimage_copy (which was designed to expose this problem) but also
a 5x improvement in some text performance cases.

 xlib-rgba              subimage_copy-512    3.93 2.46% ->   0.07 2.71%: 52.91x faster
███████████████████████████████████████████████████▉
 xlib-rgb               subimage_copy-512    4.03 1.97% ->   0.09 2.61%: 44.74x faster
███████████████████████████████████████████▊
 xlib-rgba              subimage_copy-256    1.02 2.25% ->   0.07 0.56%: 14.42x faster
█████████████▍
 xlib-rgba        text_image_rgb_over-256   63.21 1.53% ->  11.87 2.17%:  5.33x faster
████▍
 xlib-rgba       text_image_rgba_over-256   62.31 0.72% ->  11.87 2.82%:  5.25x faster
████▎
 xlib-rgba     text_image_rgba_source-256   67.97 0.85% ->  16.48 2.23%:  4.13x faster
███▏
 xlib-rgba      text_image_rgb_source-256   68.82 0.55% ->  16.93 2.10%:  4.07x faster
███▏
 xlib-rgba              subimage_copy-128    0.19 1.72% ->   0.06 0.85%:  3.10x faster
██▏
2006-10-18 17:06:23 -07:00
Carl Worth
79aed8c5fc Deprecated CAIRO_FORMAT_RGB16_565. Add cairo-deprecated.h . 2006-09-11 11:05:02 -07:00
Carl Worth
d7f08794ef Add many missing slim_hidden calls to bypass PLT entries for local use of public functions 2006-09-05 17:22:00 -07:00
Behdad Esfahbod
b6e5f2b0fe [xlib] Bug 7593: rewrite loop to be more readable, and fix warnings
Basically, it's evil to write a loop like:

    while ((c -= 4) > 0) {
        ...
    }

for one reason that doesn't work if c is unsigned.  And when c is signed, if
for some reason c is about -MAXINT, then it will overflow and not work as
expected.

It's much safer (and more gcc warning friendly) to rewrite it as:

    unsigned int c;

    while (c >= 4) {
        ...
        c -= 4;
    }
2006-08-28 22:30:38 -04:00
Behdad Esfahbod
1b7ced6614 Bug #7593: Avoid unsigned loop control variable to eliminate infinite, memory-scribbling loop.
Behdad chased this bug down when looking into bug #7593. This
bug is what finally motivated us to figure out how to get -Wextra
(for the "always true" comparisons of unsigned variables against
negative values).
2006-08-28 18:57:14 -07:00
Carl Worth
401f0ce3c4 Merge branch 'surface-font-options' into cairo 2006-08-08 00:19:51 -07:00
Carl Worth
959b85e98c Merge branch 'warnings-cleanup' into cairo
Conflicts:

	src/cairo-font-subset.c
2006-08-07 15:06:47 -07:00
Carl Worth
43b579d757 Add -Wswitch-enum compiler flag and fix all trivial warnings 2006-08-07 14:30:06 -07:00
Behdad Esfahbod
d1f9bef30e Add -Wunsafe-loop-optimizations compiler flag and fix all warnings 2006-08-07 14:24:32 -07:00
Behdad Esfahbod
0071102208 Add -Wwrite-strings compiler flag and fix all warnings 2006-08-07 13:13:33 -07:00
Carl Worth
9ae66174e7 Fix bug 7294 by adding pixman BGR formats and internal cairo BGR formats.
This approach to fixing the bug is valid since there is code in pixman
for rendering to BGR images, (which is why cairo 1.0 worked with BGR X
servers for example). But, since we don't want to advertise additional
image formats we implement this through a new cairo_internal_format_t.

This is rather fragile since we don't want to leak any internal formats
nor do we ever want an internal format to be used somewhere a real
format is expected, (and trigger a CAIRO_FORMAT_VALID assertion failure).
More comments than code are added here to help compensate for the
fragility and to give some guidance in fixing this mess in a better way
in the future.
2006-08-07 11:19:19 -07:00
Behdad Esfahbod
b3341b4eda Let backends return NULL in create_similar to take the fallback path.
Make xlib backend use it.
2006-07-31 14:45:54 -04:00
Carl Worth
eb9caf0833 Add -Wsign-compare compiler flag and fix all warnings 2006-07-28 22:50:06 -07:00
Carl Worth
456cdb3058 Elide size-zero glyphs from calls to XRender functions.
There appears to be a bug in some X servers which is triggered by
rendering 1-bit glyphs with zero size via the functions
XRenderAddGlyphs and XRenderCompositeText8 (and likely its variants).

We avoid this bug by making a copy of the glyphs array which does not
include any of the size-zero glyphs so that the X server never sees them.
2006-07-27 00:17:52 -07:00
Vladimir Vukicevic
b7191885c8 [xlib] Remove XSync implementation of surface_flush
Remove the xlib implementation of surface_flush which just called XSync
before.
2006-07-17 11:33:47 -07:00
Behdad Esfahbod
e0ad1aa995 Change version number of Sun's Xorg server with buggy repeat from 60800000 to
60900000. (#7483, pointed by Brian Cameron)
2006-07-10 13:45:51 -04:00
Behdad Esfahbod
45ebf2d1f3 Fix an oops. 2006-06-30 02:21:51 +02:00
Behdad Esfahbod
66436d1327 Update lots of docs. 2006-06-30 02:21:50 +02:00
Carl Worth
bd92eb7f3c Move device_transform of path to before floating->fixed conversion.
This is an attempt to fix the following bug:

	http://bugzilla.gnome.org/show_bug.cgi?id=332266

With the recent rewrite of the device-offset code, which pushed things
from the gstate to the surface layer, the 16-bit limitations on coordinates
which previously applied to device space only, have lately been applying to
user space. This commit moves the device_transform back up above the conversion
from floating-point to fixed-point values so that once again the limitation
only applies to device space.
2006-06-29 21:33:34 +02:00
Behdad Esfahbod
195b1142e7 Prefix "cairo_*_test_*" symbols with underscore. 2006-06-29 15:22:44 +02:00
Carl Worth
7e0e503fba xlib: Fix failure path to do cache thawing cleanup. 2006-06-25 11:32:36 +02:00
Robert O'Callahan
ddead8e061 Surface size getters for xlib
When accessing the underlying drawable etc of an xlib surface, it is
also helpful to be able to get the width and height without a server
round trip. This patch provides those functions.
2006-06-25 11:23:43 +02:00
Carl Worth
5488c3b462 xlib: Prefer BAIL over FAIL when the cleanup code is also used in succesful cases. 2006-06-22 22:38:17 -07:00
Carl Worth
7e457cb4c1 Bug 6955: Fix by adding freeze/thaw around scaled_font glyph cache in _cairo_xlib_surface_show_glyphs 2006-06-22 22:32:57 -07:00