From 115de303b0675efc2e8b0dcc96ae9444a7f114ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 18 Sep 2019 16:38:20 +0200 Subject: [PATCH] wayland/shm: Add ARGB2101010 formats and friends In order to get higher color pixel precision when the alpha channel is less important. Only advertise these formats if it is supported by the used cogl renderer. https://gitlab.gnome.org/GNOME/mutter/merge_requests/804 --- src/wayland/meta-wayland-buffer.c | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c index 60ef78cd1..312fc26f9 100644 --- a/src/wayland/meta-wayland-buffer.c +++ b/src/wayland/meta-wayland-buffer.c @@ -217,6 +217,18 @@ shm_format_to_cogl_pixel_format (enum wl_shm_format shm_format, format = COGL_PIXEL_FORMAT_BGRA_8888; components = COGL_TEXTURE_COMPONENTS_RGB; break; + case WL_SHM_FORMAT_XRGB2101010: + components = COGL_TEXTURE_COMPONENTS_RGB; + G_GNUC_FALLTHROUGH; + case WL_SHM_FORMAT_ARGB2101010: + format = COGL_PIXEL_FORMAT_ARGB_2101010_PRE; + break; + case WL_SHM_FORMAT_XBGR2101010: + components = COGL_TEXTURE_COMPONENTS_RGB; + G_GNUC_FALLTHROUGH; + case WL_SHM_FORMAT_ABGR2101010: + format = COGL_PIXEL_FORMAT_ABGR_2101010_PRE; + break; #endif default: return FALSE; @@ -235,6 +247,10 @@ shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer, CoglPixelFormat *format_out, CoglTextureComponents *components_out) { + MetaBackend *backend = meta_get_backend (); + ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); + CoglContext *cogl_context = + clutter_backend_get_cogl_context (clutter_backend); CoglPixelFormat cogl_format; CoglTextureComponents cogl_components; @@ -243,6 +259,9 @@ shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer, &cogl_components)) return FALSE; + if (!cogl_context_format_supports_upload (cogl_context, cogl_format)) + return FALSE; + if (format_out) *format_out = cogl_format; if (components_out) @@ -745,9 +764,18 @@ meta_wayland_buffer_class_init (MetaWaylandBufferClass *klass) void meta_wayland_init_shm (MetaWaylandCompositor *compositor) { + MetaBackend *backend = meta_get_backend (); + ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); + CoglContext *cogl_context = + clutter_backend_get_cogl_context (clutter_backend); + static const enum wl_shm_format shm_formats[] = { #if G_BYTE_ORDER == G_LITTLE_ENDIAN WL_SHM_FORMAT_RGB565, + WL_SHM_FORMAT_ARGB2101010, + WL_SHM_FORMAT_XRGB2101010, + WL_SHM_FORMAT_ABGR2101010, + WL_SHM_FORMAT_XBGR2101010, #endif }; int i; @@ -755,5 +783,17 @@ meta_wayland_init_shm (MetaWaylandCompositor *compositor) wl_display_init_shm (compositor->wayland_display); for (i = 0; i < G_N_ELEMENTS (shm_formats); i++) - wl_display_add_shm_format (compositor->wayland_display, shm_formats[i]); + { + CoglPixelFormat cogl_format; + + if (!shm_format_to_cogl_pixel_format (shm_formats[i], + &cogl_format, + NULL)) + continue; + + if (!cogl_context_format_supports_upload (cogl_context, cogl_format)) + continue; + + wl_display_add_shm_format (compositor->wayland_display, shm_formats[i]); + } }