[cairo] Cairo to Wayland

Tarnyko tarnyko at tarnyko.net
Sun Jun 25 19:00:50 UTC 2017


Hi Mike, 

Cairo supports Wayland directly, mast notably via its EGL backend, by using 
the Wayland "wl_egl_window" abstraction.
Creation order is like this : wl_egl_window -> EGLSurface -> cairo_surface_t 
. 

Here is simplified C sample code : 

EGLDisplay edpy;
EGLConfig ecfg;
EGLContext ectx;
EGLSurface esrf;
/* - Wayland - */
struct wl_surface *wlsurface;
struct wl_egl_window *wlwindow;
/* - Cairo - */
cairo_device_t *device;
cairo_surface_t *surface;
cairo_t *cr; 

wlsurface =  wl_compositor_create_surface (wlcompositor);
wlwindow = wl_egl_window_create (wlsurface, 320, 240); 

 /* create egl display context (edpy, ecfg, ectx) here ... */
esrf = eglCreateWindowSurface (edpy, ecfg, wlwindow, NULL); 

device = cairo_egl_device_create (edpy, ectx);
surface = cairo_gl_surface_create_for_egl (device, esrf, 320, 240);
cr = cairo_create (surface);
cairo_rectangle (cr, 0, 0, 320, 240);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgba (cr, 0, 0, 0, 1);
cairo_paint (cr); 


I hope it helps.
Regards, Tarnyko 

Mike Gran writes: 

> Hi all, 
> 
> This might be more of a Wayland question than a Cairo question, but... 
> 
> If I wanted to use Cairo to draw a raw Wayland client window,
> what is the most efficient pathway?  For a CPU solution,
> I could have Cairo draw to an in-memory RGB array and then
> send the damaged part of that array to Wayland. 
> 
> But if there to directly interoperate between Wayland and
> Cairo?  Can I have both of them looking at the same EGL surface
> or the same location in RAM or VRAM? 
> 
> Regards,
> Mike Gran
> -- 
> cairo mailing list
> cairo at cairographics.org
> https://lists.cairographics.org/mailman/listinfo/cairo


More information about the cairo mailing list