From 8d5325b8163e6fb793613102f19d3251d70afc26 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 18 Jun 2024 19:52:41 -0400 Subject: [PATCH] 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. --- gdk/x11/gdkglcontext-glx.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/gdk/x11/gdkglcontext-glx.c b/gdk/x11/gdkglcontext-glx.c index e70ec692dd..2001251ef6 100644 --- a/gdk/x11/gdkglcontext-glx.c +++ b/gdk/x11/gdkglcontext-glx.c @@ -24,6 +24,7 @@ #include "gdkprofilerprivate.h" #include +#include "gdksurfaceprivate.h" #include @@ -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;