Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for XCB surfaces via xcffib [updated] #39

Merged
merged 6 commits into from
Sep 23, 2014

Conversation

flacjacket
Copy link
Contributor

Adaptation of #37 addressing the concerns raised there. This adds cairocffi.xcb which allows for interfacing with XCB surfaces through cairo with the cairocffi.xcb.XCBSurface objects. There are also tests and docs for the new module. I couldn't think of a good way to verify the images that are rendered, but just left them to be if the tests run successfully.

I know the tests won't pass now, as the version of xcffib currently tagged on pypi isn't up to date. Once @tych0 takes care of that, the tests can be re-run and should pass (fingers crossed).

EDIT: all tests should pass now https://travis-ci.org/flacjacket/cairocffi/builds/31476403

@flacjacket
Copy link
Contributor Author

Ping @SimonSapin
Tests are all passing, let me know if you'll be able to look at this

flacjacket and others added 6 commits September 10, 2014 20:47
Add cairo-xcb.h functions to constants as
cairocffi.constants._CAIRO_XCB_HEADERS
Create cairocffi.xcb module, which uses xcffib as a library to create
XCBSurface objects
Add test cases for the new cairocffi.xcb module. Two test cases are for
creating XCB surfaces on pixmap and window.
Add documentation for cairocffi.xcb module to sphinx docs
Installs xcffib for xcb support when running:

    pip install cairocffi[xcb]
When using XCB extensions you need to query the extension before making
requests to it. (This is referred to in the XCB documentation as the
"extension cache".) Older versions of cairo sometimes don't do this, so the
first test will pass, but the second test will fail because cairo is caching
request ids from the old connection (an example wth an xtrace is [1]). To work
around this, we run each test in a separate process via --boxed, which forces
cairo to ask XCB about the extensions for each test.

[1]: http://paste.ubuntu.com/8320590/
@flacjacket
Copy link
Contributor Author

@SimonSapin I've just updated this, between some work on this and on xcffib, this is now passing and robust, and we think is ready to merge. Let me know what you think about these changes as they stand, thanks.

@SimonSapin SimonSapin merged commit 132098d into Kozea:master Sep 23, 2014
@SimonSapin
Copy link
Member

Released on PyPI in version 0.6, thanks!

@flacjacket
Copy link
Contributor Author

I haven't taken an extensive look at testing against different cairo versions, I know it works fine on my machine with 1.12, but running in Ubuntu 12.04 with 1.10, I've seen the same problem as seen on Travis.

Thanks for getting this up!

@SimonSapin
Copy link
Member

Yeah, all the XCB-related functions in cairo were added in 1.12.

@tych0
Copy link
Contributor

tych0 commented Sep 23, 2014

They've been around since at least 1.8 (that was the earliest I ever encountered them): http://cgit.freedesktop.org/cairo/tree/src/cairo-xcb-surface.c?h=1.8

I have no idea why the docs say 1.12, that seems wrong :). In any case, I haven't seen this bug on anything >= 1.13, although I haven't actually looked through the cairo source to see when they patched their implementation.

@SimonSapin
Copy link
Member

Well, the error message seems pretty clear to me, the function is not in my build of 1.10.0: (And same with 1.8.2.)

$ tox -e py26-cairo-1.10.0
[...]
AttributeError: cairo_xcb_surface_create: "function 'cairo_xcb_surface_create' not found in library 'libcairo.so.2': ../cairo-1.10.0/lib/libcairo.so.2: undefined symbol: cairo_xcb_surface_create"

I built this cairo from cairo-1.10.0.tar.gz with ./configure && make on Archlinux x86_64

I do see these functions in the git tree as you point out, but for some reason the files are not included in the release tarballs.

@SimonSapin
Copy link
Member

the files are not included in the release tarballs.

Now I’m confused. I’m not sure how I came to that conclusion 10 minutes ago. The files are there, but the ./configure script has an --enable-xcb option. Maybe it’s off by default before 1.12?

@tych0
Copy link
Contributor

tych0 commented Sep 24, 2014

I guess it depends on distro configuration, too. The debian/ubuntu packages
have had it on since 1.8 (viz. the tests pass on travis-ci with 1.10).

On Wed, Sep 24, 2014 at 3:27 AM, Simon Sapin notifications@github.com
wrote:

the files are not included in the release tarballs.

Now I’m confused. I’m not sure how I came to that conclusion 10 minutes
ago. The files are there, but the ./configure script has an --enable-xcb
option. Maybe it’s off by default before 1.12?


Reply to this email directly or view it on GitHub
#39 (comment).

jsonn referenced this pull request in jsonn/pkgsrc Oct 6, 2014
...........

Released on 2014-09-23.

* `#39 <https://github.com/SimonSapin/cairocffi/pull/39>`_:
  Add :class:`xcb.XCBSurface`.
* `#42 <https://github.com/SimonSapin/cairocffi/pull/42>`_:
  Add :class:`Win32PrintingSurface`.
jsonn referenced this pull request in jsonn/pkgsrc Oct 11, 2014
...........

Released on 2014-09-23.

* `#39 <https://github.com/SimonSapin/cairocffi/pull/39>`_:
  Add :class:`xcb.XCBSurface`.
* `#42 <https://github.com/SimonSapin/cairocffi/pull/42>`_:
  Add :class:`Win32PrintingSurface`.
@whitelynx
Copy link

I'm seeing a very similar issue on Arch Linux, with cairo 1.14.8-1 and cairocffi==0.8.0:

Traceback (most recent call last):
  File "xcffibaer", line 129, in <module>
    run()
  File "xcffibaer", line 104, in run
    surface = createWindow(conn, screens[screenIndex], visualType)
  File "xcffibaer", line 50, in createWindow
    surface = XCBSurface(conn, window, visualType, width, height)
  File "/home/whitelynx/Development/Personal/xcffibär/env/lib/python3.6/site-packages/cairocffi/xcb.py", line 37, in __init__
    p = cairo.cairo_xcb_surface_create(
AttributeError: cffi library 'libcairo.so.2' has no function, constant or global variable named 'cairo_xcb_surface_create'

The really weird thing is, according to /usr/include/cairo/cairo-features.h (from cairo 1.14.8-1), XCB support is enabled, which means that function should be there:

$ grep -r CAIRO_HAS_XCB_SURFACE /usr/include/cairo/
/usr/include/cairo/cairo-features.h:#define CAIRO_HAS_XCB_SURFACE 1
/usr/include/cairo/cairo-xcb.h:#if CAIRO_HAS_XCB_SURFACE
/usr/include/cairo/cairo-xcb.h:#else  /* CAIRO_HAS_XCB_SURFACE */
/usr/include/cairo/cairo-xcb.h:#endif /* CAIRO_HAS_XCB_SURFACE */
$ grep '#if CAIRO_HAS_XCB_SURFACE' /usr/include/cairo/cairo-xcb.h -A15
#if CAIRO_HAS_XCB_SURFACE

#include <xcb/xcb.h>
#include <xcb/render.h>

CAIRO_BEGIN_DECLS

cairo_public cairo_surface_t *
cairo_xcb_surface_create (xcb_connection_t	*connection,
			  xcb_drawable_t	 drawable,
			  xcb_visualtype_t	*visual,
			  int			 width,
			  int			 height);

cairo_public cairo_surface_t *
cairo_xcb_surface_create_for_bitmap (xcb_connection_t	*connection,

and the string even shows up in the .so:

$ strings /usr/lib/libcairo.so.2 | grep cairo_xcb_surface_create
cairo_xcb_surface_create
cairo_xcb_surface_create_for_bitmap
cairo_xcb_surface_create_with_xrender_format
_cairo_xcb_surface_create_similar

It seems like there's a mismatch between what cairocffi is trying to call, and what libcairo.so.2 is actually exporting, but I'm not sure how to debug that further... Should I open a new issue for this?

@whitelynx
Copy link

Also, just to clarify, I did install cairocffi with pip install cairocffi[xcb] as mentioned in the docs.

@whitelynx
Copy link

I managed to get it working using pip install cairocffi[xcb] -U --force-reinstall --no-binary cairocffi. Sadly, I don't think I can provide --no-binary cairocffi in a requirements.txt.

@flacjacket
Copy link
Contributor Author

@whitelynx The way the XCB stuff works here currently, xcffib has to be installed before installing cairocffi in order for the XCB stuff to come in correctly. We have seen similar issues in qtile and have had to put in install-time checks that this AttributeError isn't being thrown.

@whitelynx
Copy link

Even separating cairocffi out into a separate requirements-2.txt and running pip install -r requirements-2.txt after installing everything else (including xcffib) doesn't solve this; the only way I've found to make it work so far is using --no-binary.

@tych0
Copy link
Contributor

tych0 commented Apr 21, 2017

I was just looking at this. I wonder if we can get away with copying and pasting the whole types definition from xcffib into cairocffi? We'd have to change it in both places when new structures were added, but given where XCB is at in its software life, perhaps that won't ever happen.

At least this way it wouldn't depend on what order things were installed in, which seems like it bites a lot of people today. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants