Commit be65b841 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

platforms/x11: Move GLXFBConfig selection code in a separate file

This allows reusing the GLXFBConfig selection code.


(cherry picked from commit b338c4cb)
parent 9679beac
......@@ -27,7 +27,11 @@ if (X11_Xi_FOUND)
endif()
if (HAVE_EPOXY_GLX)
target_sources(KWinX11Platform PRIVATE glxbackend glx_context_attribute_builder.cpp)
target_sources(KWinX11Platform PRIVATE
glx_context_attribute_builder.cpp
glxbackend.cpp
glxconvenience.cpp
)
endif()
if (KWIN_BUILD_XRENDER_COMPOSITING)
......
......@@ -13,6 +13,7 @@
// own
#include "glxbackend.h"
#include "glxconvenience.h"
#include "logging.h"
#include "glx_context_attribute_builder.h"
#include "omlsynccontrolvsyncmonitor.h"
......@@ -440,65 +441,12 @@ bool GlxBackend::initFbConfig()
}
}
// Try to find a double buffered sRGB capable configuration
int count = 0;
GLXFBConfig *configs = nullptr;
// Don't request an sRGB configuration with LLVMpipe when the default depth is 16. See bug #408594.
if (!llvmpipe || Xcb::defaultDepth() > 16) {
configs = glXChooseFBConfig(display(), DefaultScreen(display()), attribs_srgb, &count);
}
if (count == 0) {
// Try to find a double buffered non-sRGB capable configuration
configs = glXChooseFBConfig(display(), DefaultScreen(display()), attribs, &count);
}
struct FBConfig {
GLXFBConfig config;
int depth;
int stencil;
};
std::deque<FBConfig> candidates;
for (int i = 0; i < count; i++) {
int depth, stencil;
glXGetFBConfigAttrib(display(), configs[i], GLX_DEPTH_SIZE, &depth);
glXGetFBConfigAttrib(display(), configs[i], GLX_STENCIL_SIZE, &stencil);
candidates.emplace_back(FBConfig{configs[i], depth, stencil});
fbconfig = chooseGlxFbConfig(display(), attribs_srgb);
}
if (count > 0)
XFree(configs);
std::stable_sort(candidates.begin(), candidates.end(), [](const FBConfig &left, const FBConfig &right) {
if (left.depth < right.depth)
return true;
if (left.stencil < right.stencil)
return true;
return false;
});
if (candidates.size() > 0) {
fbconfig = candidates.front().config;
int fbconfig_id, visual_id, red, green, blue, alpha, depth, stencil, srgb;
glXGetFBConfigAttrib(display(), fbconfig, GLX_FBCONFIG_ID, &fbconfig_id);
glXGetFBConfigAttrib(display(), fbconfig, GLX_VISUAL_ID, &visual_id);
glXGetFBConfigAttrib(display(), fbconfig, GLX_RED_SIZE, &red);
glXGetFBConfigAttrib(display(), fbconfig, GLX_GREEN_SIZE, &green);
glXGetFBConfigAttrib(display(), fbconfig, GLX_BLUE_SIZE, &blue);
glXGetFBConfigAttrib(display(), fbconfig, GLX_ALPHA_SIZE, &alpha);
glXGetFBConfigAttrib(display(), fbconfig, GLX_DEPTH_SIZE, &depth);
glXGetFBConfigAttrib(display(), fbconfig, GLX_STENCIL_SIZE, &stencil);
glXGetFBConfigAttrib(display(), fbconfig, GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, &srgb);
qCDebug(KWIN_X11STANDALONE, "Choosing GLXFBConfig %#x X visual %#x depth %d RGBA %d:%d:%d:%d ZS %d:%d sRGB: %d",
fbconfig_id, visual_id, visualDepth(visual_id), red, green, blue, alpha, depth, stencil, srgb);
if (!fbconfig) {
fbconfig = chooseGlxFbConfig(display(), attribs);
}
if (fbconfig == nullptr) {
......@@ -506,6 +454,20 @@ bool GlxBackend::initFbConfig()
return false;
}
int fbconfig_id, visual_id, red, green, blue, alpha, depth, stencil, srgb;
glXGetFBConfigAttrib(display(), fbconfig, GLX_FBCONFIG_ID, &fbconfig_id);
glXGetFBConfigAttrib(display(), fbconfig, GLX_VISUAL_ID, &visual_id);
glXGetFBConfigAttrib(display(), fbconfig, GLX_RED_SIZE, &red);
glXGetFBConfigAttrib(display(), fbconfig, GLX_GREEN_SIZE, &green);
glXGetFBConfigAttrib(display(), fbconfig, GLX_BLUE_SIZE, &blue);
glXGetFBConfigAttrib(display(), fbconfig, GLX_ALPHA_SIZE, &alpha);
glXGetFBConfigAttrib(display(), fbconfig, GLX_DEPTH_SIZE, &depth);
glXGetFBConfigAttrib(display(), fbconfig, GLX_STENCIL_SIZE, &stencil);
glXGetFBConfigAttrib(display(), fbconfig, GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, &srgb);
qCDebug(KWIN_X11STANDALONE, "Choosing GLXFBConfig %#x X visual %#x depth %d RGBA %d:%d:%d:%d ZS %d:%d sRGB: %d",
fbconfig_id, visual_id, visualDepth(visual_id), red, green, blue, alpha, depth, stencil, srgb);
return true;
}
......
/*
SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "glxconvenience.h"
#include <deque>
namespace KWin
{
GLXFBConfig chooseGlxFbConfig(Display *display, const int attributes[])
{
int configCount = 0;
GLXFBConfig *configs = glXChooseFBConfig(display, DefaultScreen(display),
attributes, &configCount);
struct FBConfig {
GLXFBConfig config;
int depth;
int stencil;
};
std::deque<FBConfig> candidates;
for (int i = 0; i < configCount; i++) {
int depth, stencil;
glXGetFBConfigAttrib(display, configs[i], GLX_DEPTH_SIZE, &depth);
glXGetFBConfigAttrib(display, configs[i], GLX_STENCIL_SIZE, &stencil);
candidates.emplace_back(FBConfig{configs[i], depth, stencil});
}
if (configCount > 0) {
XFree(configs);
}
std::stable_sort(candidates.begin(), candidates.end(), [](const FBConfig &left, const FBConfig &right) {
if (left.depth < right.depth) {
return true;
}
if (left.stencil < right.stencil) {
return true;
}
return false;
});
return candidates.empty() ? nullptr : candidates.front().config;
}
} // namespace KWin
/*
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <epoxy/glx.h>
#include <fixx11h.h>
namespace KWin
{
GLXFBConfig chooseGlxFbConfig(Display *display, const int attributes[]);
} // namespace KWin
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment