Commit graph

350 commits

Author SHA1 Message Date
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
Adrian Johnson
d682d275b9 Add an extents argument to the high level surface backend functions
Add a "cairo_rectangle_int_t *extents" argument to to the following
backend functions:
  paint
  mask,
  stroke
  fill
  show_glyphs
  show_text_glyphs

This will be used to pass the extents of each operation computed by
the analysis surface to the backend. This is required for implementing
EXTEND_PAD.
2008-11-02 20:12:22 +10:30
Chris Wilson
08f4d49a94 [xlib] Intialise clip_dirty.
Eeek, forgot to set the clip_dirty to 0 on construction.
2008-10-31 02:25:22 +00:00
Chris Wilson
7d546bba21 [xlib] Eliminate shadowed variable.
Cleanup a minor -Wshadow warning.
2008-10-30 17:52:15 +00:00
Chris Wilson
6429e3f394 [xlib] Only set Picture clip as necessary.
Only set ClipRectangles on a new Picture, avoiding redundant calls to
clear the non-existent ClipMask otherwise.
2008-10-30 17:52:14 +00:00
Chris Wilson
cd45258c5b [xlib] Only clear the GC clip mask as necessary.
Avoid redundant calls to XSetClipMask() for clean GCs.
2008-10-30 17:52:14 +00:00
Chris Wilson
d384f86499 [xlib] Propagate real status from get_screen_info().
Return the real error from _cairo_xlib_screen_info_get() in order to avoid
having to create a fake NO_MEMORY error.
2008-10-30 17:52:14 +00:00
Chris Wilson
e25b106e9c [xlib] Propagate real status from get_display()
Avoid throwing away the error and inventing a new NO_MEMORY error for
_cairo_xlib_display_get().
2008-10-30 17:52:14 +00:00
Chris Wilson
2555f83b11 [xlib] Avoid repeated calls to XRenderQueryVersion
Use the value determined during display initialisation in order to avoid
redundant XRenderQueryFormats requests.
2008-10-30 17:52:13 +00:00
Chris Wilson
74876b00cd [xlib] Exploit compaction of XRenderFillRectangle()
libXrender amalgamates sequences of XRenderFillRectangle() into a single
XRenderFillRectangles request (when permissible). Since it is common for a
cairo application to draw rectangles individually in order to exploit fast
paths within cairo [rectilinear fills], it is a reasonably common pattern.
2008-10-30 17:52:13 +00:00
Chris Wilson
a002375810 [xlib] Defer querying of font options until first use
Constructing the font options cause the initialisation of Xlc and invoke
several round-trips to the X server, significantly delaying the creation
of the first surface. By deferring that operation until the first use of
fonts then we avoid that overhead for very simple applications (like the
test suite) and should improve start-up latency for larger application.
2008-10-30 17:52:13 +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
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
42711a5586 [xlib] Fix _draw_image_surface() with opaque images.
If the image was opaque with no alpha channel, we filled the output alpha
with 0. Typically, the destination surface for dithering is an RGB window,
so this bug went unnoticed. However, test/xlib-expose-event is an example
where we generate an intermediate alpha-only pixmap for use as a stencil
and this was failing as the mask was left completely transparent. The
simple solution is to ensure that for opaque images, the output alpha is
set to the maximum permissible value.
2008-10-30 10:00:30 +00:00
Chris Wilson
c3940d342a [xlib] whitespace
Tweak the whitespace to lose some unnecessary line wrapping, casts and
blanks.
2008-10-30 10:00:30 +00:00
Chris Wilson
1db8949f2b Ensure that the scaled font is frozen for the lifetime of the scaled glyph.
After discussing the scaled font locking with Behdad, it transpired that it
is not sufficient for a font to be locked for the lifetime of a scaled glyph,
but that the scaled font's glyph cache must be frozen for the glyph'
lifetime.  If the cache is not frozen, then there is a possibility that the
glyph may be evicted before the reference goes out of scope i.e. the glyph
becomes invalid whilst we are trying to use it.

Since the freezing of the cache is the stronger barrier, we remove the
locking/unlocking of the mutex from the backends and instead move the
mutex acquisition into the freeze/thaw routines. Then update the rule on
acquiring glyphs to enforce that the cache is frozen and review the usage
of freeze/thaw by all the backends to ensure that the cache is frozen for
the lifetime of the glyph.
2008-10-22 00:53:55 +01:00
Chris Wilson
d3a6651237 [xlib] Set return code after failing to allocate glyph surface.
Although we checked for an allocation error, we missed propagating the
status to the return error code.
2008-10-19 09:36:50 +01:00
Chris Wilson
bf3202fcfd [xlib] Fix double free of Pixmap along error path.
If the paint fails then we attempt to free the Pixmap ourselves and via
the cairo_surface_destroy (as it also believes that it owns the Pixmap).
2008-10-19 09:36:49 +01:00
Chris Wilson
bc872a5f5f [xlib] Handle 4,20,24,28 depth XImages
Bug 9102 cairo doesn't support 24 bits per pixel mode on X11
(https://bugs.freedesktop.org/show_bug.cgi?id=9102)
is a reminder that that we need to support many obscure XImage formats.
With Carl's and Behdad's work to support psuedocolor we have a mechanism
in place to handle any format that is not natively handled by pixman. The
only piece we were missing was extending the swapper to handle all-known
formats and putting in defensive checks that pixels were correctly aligned
in accordance with pixman's requirements.
2008-10-15 10:21:05 +01:00
Chris Wilson
ab1d106cba [xlib] Use the cached xrender formats.
Use the cached formats for consistency and simplify several double pointer
dereferences.
2008-10-11 19:52:28 +01:00
Chris Wilson
ac3e4b4bea [xlib] Disable XRender support if the surface has no xrender_format
Bug 11734:
  XRender crashes due to NULL pointer from Cairo on SGI O2
  (https://bugs.freedesktop.org/show_bug.cgi?id=1173)
is an example of a case where we try to perform an XRender operation on a
surface with a format that was not supported by the XRender extension. By
marking the extension version as -1 on those surfaces, the current checks
for SURFACE_RENDER_HAS_* always correctly return false and prevent us try
to create a Picture with a NULL xrender_format.
2008-10-10 15:42:09 +01:00
Chris Wilson
552cc09e6b [xlib] Check integer translation for XCopyArea.
A precondition for using the core XCopyArea protocol is that the source
attributes contain only integer translations. However, we failed to apply
any integer translations from the source matrix to the XCopyArea offsets.
This worked prior to 5b97ee6525 as
_cairo_pattern_acquire_surface_for_surface() was careful to only generate
an identity matrix if the pattern matrix only contained an integer
translation (and thus we would use XCopyArea in the xlib backend).
2008-10-07 21:05:57 +01:00
Chris Wilson
8ec24a443d [xlib] Share the common conditions for starting a new xGlyphElt using a macro.
Move the predicate for starting a new glyph elt into a macro so that it
can be shared between _cairo_xlib_surface_emit_glyphs() and
_emit_glyph_chunks() without code duplication.
2008-10-04 10:10:52 +01:00
Carl Worth
8ea9cb187a Use symbolic constants for Render repeat modes.
Names like RepeatNone and RepeatNormal are much easier to
read and understand than bare 0 and 1.
2008-10-01 14:12:18 -07:00
Behdad Esfahbod
2c58a2c385 [xlib] Start a new glyph element every 128 glyphs
Xrender has limits at 252 glyphs.  We play safe and fast and limit
elements to 128 glyphs.  That's plenty, no measurable performance
hit expected.
2008-09-30 17:55:01 -04:00
Behdad Esfahbod
fd7e09c7e6 [xlib] Allow room for glyph element padding
Xrender pads glyph elements to 4byte boundaries.  We didn't consider
that in our request size calculations.  We do now.
2008-09-30 17:46:06 -04:00
Behdad Esfahbod
c01fb77abb [xlib] s/_cairo_xlib_surface_emit_glyphs_chunk/_emit_glyphs_chunk/
For readability's sake.
2008-09-30 17:41:51 -04:00
Behdad Esfahbod
c2ba25df1a [xlib] Add comment about glyph chunk invariant 2008-09-30 17:40:56 -04:00
Behdad Esfahbod
e983458e1f Revert "[xlib] Correct calculation of XRenderComposite* request size."
This reverts commit 0eb0c26474.
The change was too drastic and overlooked some subleties of the old
code, but the main reason for the revert is that it introduced an
ugly duplicated glyph flush block.  I'm working on a more incremental
fix.
2008-09-30 17:26:46 -04:00
Chris Wilson
0eb0c26474 [xlib] Correct calculation of XRenderComposite* request size.
show-glyphs-many is triggering an assertion failure within xlib. The cause
appears to be that we are submitting an overlong request.

Reviewing the code and comparing with libXrender/src/Glyph.c I found two
points to address.

1. When encountering the first 2-byte, or 4-byte glyph and thus triggering
the recalculation of the current request_size, we did not check that there
was enough room for the expanded request. In case there is not, we need to
emit the current request (before expansion) and reset.

2. Subtleties in how XRenderCompositeText* constructs the binary protocol
buffer require that xGlyphElts are aligned to 32-bit boundaries and that
it inserts an additional xGlyphElt every 252 glyphs when width==1 or
every 254 glyphs for width==2 || width==4.  Thus we need to explicitly
compute how many bytes would be required to add this glyph in accordance
with the above.

Considering the complexity (and apparent fragility since we require tight
coupling to XRender) of the code, I'm sure there are more bugs to be
found.
2008-09-30 15:29:30 +01:00
Karl Tomlinson
d52b55cb1b [xlib] _surfaces_compatible() can return true for different picture formats
_surfaces_compatible in cairo-xlib-surface returns true for surfaces with
different xrender_format when each has the same depth and no (NULL)
visual.

Common picture formats will not have the same depth, but
it is possible to create a surface with a non-standard xrender_format
having the same depth as another xrender_format with
cairo_xlib_surface_create_with_xrender_format.

Both cairo_xlib_surface_create_with_xrender_format and
_cairo_xlib_surface_create_similar_with_format create surfaces with no
visual.

The same issue exists in the xcb backend.

Fixes bug https://bugs.freedesktop.org/show_bug.cgi?id=16564.
2008-09-28 17:51:23 +01:00
Chris Wilson
871f683367 clone_similar(): s/device_offset/clone_offset/
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.
2008-09-27 17:27:21 +01:00
Chris Wilson
5b97ee6525 Allow cloning sub-regions of similar surfaces.
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...
2008-09-27 02:20:42 +01:00
Søren Sandmann Pedersen
86485e76b7 [xlib] Use _cairo_matrix_to_pixman_matrix() to compute the XTransform
The adjustments done to the pixman matrix also need to be done for
XTransform. Since an XTransform is just a pixman_transform_t with
another name, we can reuse the conversion function.
2008-09-17 15:18:55 -04:00
Chris Wilson
a5d33bcbb4 [xlib] Keep a pointer to the cairo_xlib_display_t on the surface.
Cleanup the code somewhat by passing cairo_xlib_display_t around
internally as opposed to a Display and then having to lookup the
corresponding cairo_xlib_display_t each time.

[To get a cairo_xlib_display_t from a Display is a list traversal under
mutex (though the element we're looking for is most likely at the start),
but to get the Display is just a lockless pointer dereference.]
2008-09-02 10:49:12 +01:00
Chris Wilson
939b836bfa [xlib] Use an embedded doubly-linked list for the close display hooks.
Kill the allocation and linear search of the close display list on remove,
by embedding a list node into the parent structure.

Original patch by Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation.
https://bugzilla.mozilla.org/show_bug.cgi?id=453199#c5
2008-09-02 10:08:04 +01:00
Vladimir Vukicevic
d756a4d632 [xlib] check for too-large surface size in create similar to avoid UNSUPPORTED loop 2008-08-28 16:58:52 -07:00
Vladimir Vukicevic
2cf82eaf0d [xlib] Check CreatePixmap dimensions before calling, to avoid unnecessary size errors 2008-08-27 14:16:52 -07:00
Chris Wilson
63befc6ab1 [xlib] Remove the key parameter from the close display hook.
By inspecting all the users of the close display hooks, we can see that
(a) the key is redundant and (b) the data is unique to the hook. This
means we can trim the interface and stop the linear searches as soon as
we've found the correct element.
2008-08-14 09:14:51 +01:00
Chris Wilson
84a541a041 [cairo-xlib-surface] Remove status return for SUCCESS only function.
Convert _cairo_xlib_surface_set_repeat() to a void return type, and
update caller, as the function can only return CAIRO_STATUS_SUCCESS.
2008-08-14 09:06:24 +01:00
Chris Wilson
8552e76ee5 [xlib] Fix leak of pending_free_glyphs on CloseDisplay.
Missing free of the pending_free_glyphs array in
_cairo_xlib_surface_remove_scaled_font.
2008-08-14 08:25:58 +01:00
Chris Wilson
fef03ef98a [xlib] Check for depth == 0 in create_surface_internal().
Validate that we find an appropriate depth for the Xlib surface, before
attempting to create the surface. This was manifesting itself with
XInitImage() failures during _draw_image_surface() (actually detected as
a segmentation fault in XPutPixel() due to an incomplete XImage).  So we
also add a couple of asserts to ensure that XInitImage() is successful -
which to the best of our knowledge, they should always be.
2008-08-10 08:44:45 +01:00
Chris Wilson
5bac12252c [xlib] Free regions on failure.
Fix leak of regions along error path.
2008-08-08 01:48:43 +01:00
Behdad Esfahbod
787fb13566 [xlib] Use _cairo_xlib_surface_create_internal() directly 2008-06-26 16:20:58 -04:00
Behdad Esfahbod
d9784c8c37 [cairo-xlib] Don't undither pseudocolor, doesn't look good 2008-06-19 22:24:13 -04:00
Behdad Esfahbod
fe41d100aa [cairo-xlib-surface] Fix core solid_fill_rectangles to do dithering
Do this by tiling the surface form the solid pattern.  The pattern in
turn calls into xlib's create_solid_surface which returns a dithered
pattern.

This can get into infinite loop right now, because of the way solid
surface cache tries to repaint cached surfaces.
2008-06-19 22:00:52 -04:00
Behdad Esfahbod
abac0f96cb [cairo-xlib-surface] Implement create_solid_pattern_surface
If render is disabled, this will create a surface the size of the
dither pattern and paint it with dithering.
2008-06-19 22:00:50 -04:00
Behdad Esfahbod
fb8f2b3854 [cairo-xlib-surface] Make _draw_image_surface handle arbitrary image formats
This is not a useful change.  Just committing because I already did it.
2008-06-19 21:55:41 -04:00
Behdad Esfahbod
bc4b788ec1 [cairo-xlib-surface] In _get_image_surface only use pixman formats >= 24bpp
Otherwise we can't do dithering.  This drastically improves gradient rendering
on 16bit displays, essentially making them indistinguishable from 32bit ones
with a naked eye.
2008-06-19 21:55:27 -04:00
Behdad Esfahbod
5faf8663b2 [cairo-xlib-surface] Force buggy_repeat to TRUE if Render is not available
So we use more core protocol paths.
2008-06-19 21:54:29 -04:00