Discussion:
[cairo] Concerns regarding cairo-xcb backend
Alexandre Bique
2017-12-12 13:47:37 UTC
Permalink
Hi,

I'm improving the Linux port of the u-he plugins (www.u-he.com) and I was
using Xlib before but I've switched to xcb now, and I'm using cairo-xcb
instead of cairo-xlib for the painting.

While using the cairo-xcb backend I've come across the following assertion:

cairo-xcb-screen.c:219: _get_screen_index: Assertion `!"reached"' failed.

I've looked at the source code and I was surprised to see that the
cairo-xcb backend has global variables (mutex, list of
cairo_xcb_connection, ...), and I wonder if this is the issue in my case.

The application I'm working on is a software synthesizer plugin (VST2/VST3)
which a Digital Audio Workstation like Bitwig Studio (www.bitwig.com) can
use and display.

The DAW loads the plugins, can show the plugin window (using XEmbed), hide
or close the plugin window. In case the plugin window is closed I close my
xcb connection, free my FT library handle and destroy my cairo xcb surface.

So if the window is shown/closed/shown/closed/... it will initialize and
destroy xcb+FT+cairo_xcb_surface for each of them.

And I wonder if this is the issue: cairo_xcb seems to not work properly in
such scenario.

Do you have any experience or ideas to share?

I've been testing on Archlinux, with cairo-1.15.8-2

Regards,
--
Alexandre Bique
Uli Schlachter
2017-12-16 09:46:06 UTC
Permalink
Hi,
Post by Alexandre Bique
I'm improving the Linux port of the u-he plugins (www.u-he.com) and I was
using Xlib before but I've switched to xcb now, and I'm using cairo-xcb
instead of cairo-xlib for the painting.
cairo-xcb-screen.c:219: _get_screen_index: Assertion `!"reached"' failed.
I've looked at the source code and I was surprised to see that the
cairo-xcb backend has global variables (mutex, list of
cairo_xcb_connection, ...), and I wonder if this is the issue in my case.
cairo-xlib has such global data as well. When you create two cairo
surfaces for the same XCB connection, you want cairo to initialise
"everything" just once.
Post by Alexandre Bique
The application I'm working on is a software synthesizer plugin (VST2/VST3)
which a Digital Audio Workstation like Bitwig Studio (www.bitwig.com) can
use and display.
The DAW loads the plugins, can show the plugin window (using XEmbed), hide
or close the plugin window. In case the plugin window is closed I close my
xcb connection, free my FT library handle and destroy my cairo xcb surface.
So if the window is shown/closed/shown/closed/... it will initialize and
destroy xcb+FT+cairo_xcb_surface for each of them.
And I wonder if this is the issue: cairo_xcb seems to not work properly in
such scenario.
Do you have any experience or ideas to share?
When you have a cairo surface using your xcb_connection*, do the following:

cairo_device_t *device = cairo_device_reference(
cairo_surface_get_device(surface));

Then, *before* you do xcb_disconnect(connection), do:

cairo_device_finish(device);
cairo_device_destroy(device);

The above should happen automatically when the last cairo-xcb surface is
finished. Thus, it might be that you have a leak somewhere? (Not
necessarily, there are non-leak cases where the above can happen)

cairo-xlib does some (IMO) bad hacks so that the above is not necessary:
It registers itself as an X11 extension with libX11. That way it gets a
callback when you do XCloseDisplay(), but since unregistering an X11
extension is not possible, this has some other downsides (e.g. the above
"dance" is still necessary if cairo ends up being unloaded before the
X11 connection is closed).

Cheers,
Uli
--
- Captain, I think I should tell you I've never
actually landed a starship before.
- That's all right, Lieutenant, neither have I.
--
cairo mailing list
***@cairographics.org
https://lists.cairographics.org/mail
Alexandre Bique
2017-12-16 21:39:56 UTC
Permalink
Hi Uli,

Many thanks for the response.

As of today I'm using cairo-image + xcb-shm and the bug seems to be gone.

Regards,
Alexandre
Post by Uli Schlachter
Hi,
Post by Alexandre Bique
I'm improving the Linux port of the u-he plugins (www.u-he.com) and I
was
Post by Alexandre Bique
using Xlib before but I've switched to xcb now, and I'm using cairo-xcb
instead of cairo-xlib for the painting.
While using the cairo-xcb backend I've come across the following
cairo-xcb-screen.c:219: _get_screen_index: Assertion `!"reached"' failed.
I've looked at the source code and I was surprised to see that the
cairo-xcb backend has global variables (mutex, list of
cairo_xcb_connection, ...), and I wonder if this is the issue in my case.
cairo-xlib has such global data as well. When you create two cairo
surfaces for the same XCB connection, you want cairo to initialise
"everything" just once.
Post by Alexandre Bique
The application I'm working on is a software synthesizer plugin
(VST2/VST3)
Post by Alexandre Bique
which a Digital Audio Workstation like Bitwig Studio (www.bitwig.com)
can
Post by Alexandre Bique
use and display.
The DAW loads the plugins, can show the plugin window (using XEmbed),
hide
Post by Alexandre Bique
or close the plugin window. In case the plugin window is closed I close
my
Post by Alexandre Bique
xcb connection, free my FT library handle and destroy my cairo xcb
surface.
Post by Alexandre Bique
So if the window is shown/closed/shown/closed/... it will initialize and
destroy xcb+FT+cairo_xcb_surface for each of them.
And I wonder if this is the issue: cairo_xcb seems to not work properly
in
Post by Alexandre Bique
such scenario.
Do you have any experience or ideas to share?
cairo_device_t *device = cairo_device_reference(
cairo_surface_get_device(surface));
cairo_device_finish(device);
cairo_device_destroy(device);
The above should happen automatically when the last cairo-xcb surface is
finished. Thus, it might be that you have a leak somewhere? (Not
necessarily, there are non-leak cases where the above can happen)
It registers itself as an X11 extension with libX11. That way it gets a
callback when you do XCloseDisplay(), but since unregistering an X11
extension is not possible, this has some other downsides (e.g. the above
"dance" is still necessary if cairo ends up being unloaded before the
X11 connection is closed).
Cheers,
Uli
--
- Captain, I think I should tell you I've never
actually landed a starship before.
- That's all right, Lieutenant, neither have I.
--
Alexandre Bique
Loading...