File indexing completed on 2024-11-10 04:56:35
0001 /* 0002 SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org> 0003 SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org> 0004 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "x11_standalone_glxconvenience.h" 0010 0011 #include <algorithm> 0012 #include <deque> 0013 0014 namespace KWin 0015 { 0016 0017 GLXFBConfig chooseGlxFbConfig(::Display *display, const int attributes[]) 0018 { 0019 int configCount = 0; 0020 GLXFBConfig *configs = glXChooseFBConfig(display, DefaultScreen(display), 0021 attributes, &configCount); 0022 0023 struct FBConfig 0024 { 0025 GLXFBConfig config; 0026 int depth; 0027 int stencil; 0028 }; 0029 0030 std::deque<FBConfig> candidates; 0031 0032 for (int i = 0; i < configCount; i++) { 0033 int depth, stencil; 0034 glXGetFBConfigAttrib(display, configs[i], GLX_DEPTH_SIZE, &depth); 0035 glXGetFBConfigAttrib(display, configs[i], GLX_STENCIL_SIZE, &stencil); 0036 0037 candidates.emplace_back(FBConfig{configs[i], depth, stencil}); 0038 } 0039 0040 if (configCount > 0) { 0041 XFree(configs); 0042 } 0043 0044 std::stable_sort(candidates.begin(), candidates.end(), [](const FBConfig &left, const FBConfig &right) { 0045 if (left.depth < right.depth) { 0046 return true; 0047 } 0048 0049 if (left.stencil < right.stencil) { 0050 return true; 0051 } 0052 0053 return false; 0054 }); 0055 0056 return candidates.empty() ? nullptr : candidates.front().config; 0057 } 0058 0059 } // namespace KWin