/* SPDX-FileCopyrightText: 2006 Lubos Lunak SPDX-FileCopyrightText: 2012 Martin Gräßlin SPDX-FileCopyrightText: 2021 Vlad Zahorodnii SPDX-License-Identifier: GPL-2.0-or-later */ #include "glxconvenience.h" #include 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 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