From 79f20d08b6397e480391c2ef3282ddb47671eb82 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Thu, 1 Dec 2011 22:52:59 +0000 Subject: [PATCH] wayland: Updates the wayland compositor side support The compositor side wayland support enabling us to create textures from wayland buffers needed updating since visuals were removed from the wayland protocol. This also fixes the #ifdef guards for the bind_wayland_display extension in cogl-winsys-egl-feature-functions.h since it was mistakenly checking that client-side wayland support had been enabled which won't be the case. Reviewed-by: Neil Roberts --- cogl/cogl-texture-2d.c | 68 +++++++++++-------- .../cogl-winsys-egl-feature-functions.h | 2 +- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c index 823729325..216c566eb 100644 --- a/cogl/cogl-texture-2d.c +++ b/cogl/cogl-texture-2d.c @@ -493,45 +493,52 @@ _cogl_egl_texture_2d_new_from_image (CoglContext *ctx, #endif /* defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base) */ #ifdef COGL_HAS_WAYLAND_EGL_SERVER_SUPPORT -static CoglPixelFormat -get_buffer_format (struct wl_buffer *buffer) -{ - struct wl_compositor *compositor = buffer->compositor; - struct wl_visual *visual = buffer->visual; -#if G_BYTE_ORDER == G_BIG_ENDIAN - if (visual == &compositor->premultiplied_argb_visual) - return COGL_PIXEL_FORMAT_ARGB_8888_PRE; - else if (visual == &compositor->argb_visual) - return COGL_PIXEL_FORMAT_ARGB_8888; - else if (visual == &compositor->rgb_visual) - return COGL_PIXEL_FORMAT_RGB_888; -#elif G_BYTE_ORDER == G_LITTLE_ENDIAN - if (visual == &compositor->premultiplied_argb_visual) - return COGL_PIXEL_FORMAT_BGRA_8888_PRE; - else if (visual == &compositor->argb_visual) - return COGL_PIXEL_FORMAT_BGRA_8888; - else if (visual == &compositor->rgb_visual) - return COGL_PIXEL_FORMAT_BGR_888; -#endif - else - g_return_val_if_reached (COGL_PIXEL_FORMAT_ANY); -} - CoglTexture2D * cogl_wayland_texture_2d_new_from_buffer (CoglContext *ctx, struct wl_buffer *buffer, GError **error) { - CoglPixelFormat format = get_buffer_format (buffer); - if (wl_buffer_is_shm (buffer)) { int stride = wl_shm_buffer_get_stride (buffer); + CoglPixelFormat format; + CoglPixelFormat internal_format = COGL_PIXEL_FORMAT_ANY; + + switch (wl_shm_buffer_get_format (buffer)) + { +#if G_BYTE_ORDER == G_BIG_ENDIAN + case WL_SHM_FORMAT_PREMULTIPLIED_ARGB32: + format = COGL_PIXEL_FORMAT_ARGB_8888_PRE; + break; + case WL_SHM_FORMAT_ARGB32: + format = COGL_PIXEL_FORMAT_ARGB_8888; + break; + case WL_SHM_FORMAT_XRGB32: + format = COGL_PIXEL_FORMAT_ARGB_8888; + internal_format = COGL_PIXEL_FORMAT_RGB_888; + break; +#elif G_BYTE_ORDER == G_LITTLE_ENDIAN + case WL_SHM_FORMAT_PREMULTIPLIED_ARGB32: + format = COGL_PIXEL_FORMAT_BGRA_8888_PRE; + break; + case WL_SHM_FORMAT_ARGB32: + format = COGL_PIXEL_FORMAT_BGRA_8888; + break; + case WL_SHM_FORMAT_XRGB32: + format = COGL_PIXEL_FORMAT_BGRA_8888; + internal_format = COGL_PIXEL_FORMAT_BGR_888; + break; +#endif + default: + g_warn_if_reached (); + format = COGL_PIXEL_FORMAT_ARGB_8888; + } + return cogl_texture_2d_new_from_data (ctx, buffer->width, buffer->height, format, - COGL_PIXEL_FORMAT_ANY, + internal_format, stride, wl_shm_buffer_get_data (buffer), error); @@ -541,16 +548,17 @@ cogl_wayland_texture_2d_new_from_buffer (CoglContext *ctx, EGLImageKHR image; _COGL_RETURN_VAL_IF_FAIL (_cogl_context_get_winsys (ctx) == - _cogl_winsys_egl_get_vtable (), - NULL); + _cogl_winsys_egl_get_vtable (), + NULL); image = _cogl_egl_create_image (ctx, EGL_WAYLAND_BUFFER_WL, buffer, NULL); +#warning "XXX: without a way to query the format of a wayland buffer we have to guess!" return _cogl_egl_texture_2d_new_from_image (ctx, buffer->width, buffer->height, - format, + COGL_PIXEL_FORMAT_ARGB_8888_PRE, image, error); } diff --git a/cogl/winsys/cogl-winsys-egl-feature-functions.h b/cogl/winsys/cogl-winsys-egl-feature-functions.h index 2d5301f5f..c043020bd 100644 --- a/cogl/winsys/cogl-winsys-egl-feature-functions.h +++ b/cogl/winsys/cogl-winsys-egl-feature-functions.h @@ -75,7 +75,7 @@ COGL_WINSYS_FEATURE_BEGIN (image_pixmap, "image_pixmap\0", COGL_EGL_WINSYS_FEATURE_EGL_IMAGE_FROM_X11_PIXMAP) COGL_WINSYS_FEATURE_END () -#ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT +#ifdef EGL_WL_bind_wayland_display COGL_WINSYS_FEATURE_BEGIN (bind_wayland_display, "WL\0", "bind_wayland_display\0",