glx: Create srgb drawables if possible

Make our visual selection code prefer fbconfigs that are
'srgb framebuffer capable', and mark the surface as 'is srgb'
in this case.

This arranges things so that GSK knows not to use an offscreen
for converting contents back to srgb in the end.
This commit is contained in:
Matthias Clasen 2024-06-18 19:52:41 -04:00 committed by Benjamin Otte
parent ad6fd451fb
commit 8d5325b816

View File

@ -24,6 +24,7 @@
#include "gdkprofilerprivate.h"
#include <glib/gi18n-lib.h>
#include "gdksurfaceprivate.h"
#include <cairo-xlib.h>
@ -47,12 +48,25 @@ typedef struct _GdkX11GLContextClass GdkX11GLContextGLXClass;
G_DEFINE_TYPE (GdkX11GLContextGLX, gdk_x11_gl_context_glx, GDK_TYPE_X11_GL_CONTEXT)
static gboolean
glxconfig_is_srgb (Display *dpy,
GLXFBConfig config)
{
int is_srgb;
if (glXGetFBConfigAttrib (dpy, config, GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, &is_srgb) != Success)
return FALSE;
return is_srgb != 0;
}
static GLXDrawable
gdk_x11_surface_get_glx_drawable (GdkSurface *surface)
{
GdkX11Surface *self = GDK_X11_SURFACE (surface);
GdkDisplay *display = gdk_surface_get_display (GDK_SURFACE (self));
GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
Display *dpy = gdk_x11_display_get_xdisplay (display);
if (self->glx_drawable)
return self->glx_drawable;
@ -62,6 +76,8 @@ gdk_x11_surface_get_glx_drawable (GdkSurface *surface)
gdk_x11_surface_get_xid (surface),
NULL);
surface->is_srgb = glxconfig_is_srgb (dpy, display_x11->glx_config);
return self->glx_drawable;
}
@ -777,6 +793,7 @@ gdk_x11_display_create_glx_config (GdkX11Display *self,
WITH_STENCIL_AND_DEPTH_BUFFER,
NO_ALPHA,
NO_ALPHA_VISUAL,
NO_SRGB,
PERFECT
} best_features;
int i = 0;
@ -865,6 +882,20 @@ gdk_x11_display_create_glx_config (GdkX11Display *self,
continue;
}
if (!glxconfig_is_srgb (dpy, configs[i]))
{
if (best_features < NO_SRGB)
{
GDK_DISPLAY_DEBUG (display, OPENGL, "Best GLX config is %u for visual 0x%lX with no SRGB", i, visinfo->visualid);
best_features = NO_SRGB;
*out_visual = visinfo->visual;
*out_depth = visinfo->depth;
self->glx_config = configs[i];
}
XFree (visinfo);
continue;
}
GDK_DISPLAY_DEBUG (display, OPENGL, "GLX config %u for visual 0x%lX is the perfect choice", i, visinfo->visualid);
best_features = PERFECT;
*out_visual = visinfo->visual;