[cairo] Having trouble using Cairo, EGL, and Wayland together

Philip White philipwhite at cedarville.edu
Mon May 4 02:03:40 UTC 2020

I have been having a lot of trouble getting a valid Cairo context for
EGL on Wayland. I have a piece of software that I initially built
using an image surface that was built on top of the wl_shm interface.
Thus, all of the rendering for the application was happening on the
CPU. I'd like to make it faster by using both Wayland and Cairo's EGL
APIs instead of the software rendering ones.

I am at a point where I have an egl_context that I can call
eglMakeCurrent with, and I can bare OpenGL ES calls to draw things. I
also have a function that renders directly to a cairo_surface_t. Thus,
all I really need to do is create a cairo_surface_t from the EGL
context. I have attempted to do that through the following.

eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context);

egl_device = cairo_egl_device_create(egl_device, egl_context);
surface = cairo_gl_surface_create_for_egl(egl_device, egl_surface,
width, height);

eglSwapInterval(egl_display, 0);
eglSwapBuffers(egl_display, egl_surface);

This is of course stripped down, but these are the important bits. If
I replace the middle three lines with a call to glClear, then there
are no errors. However, as it stands, I receive an EGL_BAD_CONTEXT
error at eglSwapInterval, and EGL_BAD_DISPLAY at eglSwapBuffers. Thus,
something about the cairo function calls has ruined the state of
things. What am I doing wrong, and how can I fix it?

In my internet searching, I actually found a similar question to this
in the archive of this mailing list, but it was never answered.


More information about the cairo mailing list