gdk: Create our egl surface with srgb colorspace

For GDK_MEMORY_U8_SRGB depth, try to create an SRGB surface.

This requires the EXT_KHR_gl_colorspace extension, which
isn't super-common in the wild (37%), so we fall back to regular U8 if
that fails.

But if we have the extension, create our egl surface with the
srgb colorspace, and report that fact in gdk_surface_gl_is_srgb().
This commit is contained in:
Matthias Clasen 2024-06-17 07:56:06 -04:00 committed by Benjamin Otte
parent db3b3c62bb
commit ad6fd451fb
3 changed files with 26 additions and 1 deletions

View File

@ -1870,6 +1870,8 @@ gdk_display_init_egl (GdkDisplay *self,
epoxy_has_egl_extension (priv->egl_display, "EGL_EXT_image_dma_buf_import_modifiers");
self->have_egl_dma_buf_export =
epoxy_has_egl_extension (priv->egl_display, "EGL_MESA_image_dma_buf_export");
self->have_egl_gl_colorspace =
epoxy_has_egl_extension (priv->egl_display, "EGL_KHR_gl_colorspace");
if (self->have_egl_no_config_context)
priv->egl_config_high_depth = gdk_display_create_egl_config (self,

View File

@ -131,6 +131,7 @@ struct _GdkDisplay
guint have_egl_pixel_format_float : 1;
guint have_egl_dma_buf_import : 1;
guint have_egl_dma_buf_export : 1;
guint have_egl_gl_colorspace : 1;
GdkDmabufFormats *dmabuf_formats;
GdkDmabufDownloader *dmabuf_downloaders[4];

View File

@ -1159,10 +1159,32 @@ gdk_surface_ensure_egl_surface (GdkSurface *self,
if (priv->egl_surface == NULL)
{
EGLint attribs[4];
int i;
i = 0;
if (depth == GDK_MEMORY_U8_SRGB && display->have_egl_gl_colorspace)
{
attribs[i++] = EGL_GL_COLORSPACE_KHR;
attribs[i++] = EGL_GL_COLORSPACE_SRGB_KHR;
self->is_srgb = TRUE;
}
g_assert (i < G_N_ELEMENTS (attribs));
attribs[i++] = EGL_NONE;
priv->egl_surface = eglCreateWindowSurface (gdk_display_get_egl_display (display),
gdk_display_get_egl_config (display, depth),
(EGLNativeWindowType) priv->egl_native_window,
NULL);
attribs);
if (priv->egl_surface == EGL_NO_SURFACE)
{
/* just assume the error is no srgb support and try again without */
self->is_srgb = FALSE;
priv->egl_surface = eglCreateWindowSurface (gdk_display_get_egl_display (display),
gdk_display_get_egl_config (display, depth),
(EGLNativeWindowType) priv->egl_native_window,
NULL);
}
priv->egl_surface_depth = depth;
}
#endif