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
This commit is contained in:
Jonas Ådahl 2019-09-18 16:38:20 +02:00 committed by Robert Mader
parent 2d6040e2a3
commit 115de303b0

View File

@ -217,6 +217,18 @@ shm_format_to_cogl_pixel_format (enum wl_shm_format shm_format,
format = COGL_PIXEL_FORMAT_BGRA_8888; format = COGL_PIXEL_FORMAT_BGRA_8888;
components = COGL_TEXTURE_COMPONENTS_RGB; components = COGL_TEXTURE_COMPONENTS_RGB;
break; 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 #endif
default: default:
return FALSE; return FALSE;
@ -235,6 +247,10 @@ shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer,
CoglPixelFormat *format_out, CoglPixelFormat *format_out,
CoglTextureComponents *components_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; CoglPixelFormat cogl_format;
CoglTextureComponents cogl_components; CoglTextureComponents cogl_components;
@ -243,6 +259,9 @@ shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer,
&cogl_components)) &cogl_components))
return FALSE; return FALSE;
if (!cogl_context_format_supports_upload (cogl_context, cogl_format))
return FALSE;
if (format_out) if (format_out)
*format_out = cogl_format; *format_out = cogl_format;
if (components_out) if (components_out)
@ -745,9 +764,18 @@ meta_wayland_buffer_class_init (MetaWaylandBufferClass *klass)
void void
meta_wayland_init_shm (MetaWaylandCompositor *compositor) 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[] = { static const enum wl_shm_format shm_formats[] = {
#if G_BYTE_ORDER == G_LITTLE_ENDIAN #if G_BYTE_ORDER == G_LITTLE_ENDIAN
WL_SHM_FORMAT_RGB565, WL_SHM_FORMAT_RGB565,
WL_SHM_FORMAT_ARGB2101010,
WL_SHM_FORMAT_XRGB2101010,
WL_SHM_FORMAT_ABGR2101010,
WL_SHM_FORMAT_XBGR2101010,
#endif #endif
}; };
int i; int i;
@ -755,5 +783,17 @@ meta_wayland_init_shm (MetaWaylandCompositor *compositor)
wl_display_init_shm (compositor->wayland_display); wl_display_init_shm (compositor->wayland_display);
for (i = 0; i < G_N_ELEMENTS (shm_formats); i++) 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]);
}
} }