KWin
Loading...
Searching...
No Matches
x11_standalone_glxconvenience.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
3 SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
4 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
5
6 SPDX-License-Identifier: GPL-2.0-or-later
7*/
8
10
11#include <algorithm>
12#include <deque>
13
14namespace KWin
15{
16
17GLXFBConfig chooseGlxFbConfig(::Display *display, const int attributes[])
18{
19 int configCount = 0;
20 GLXFBConfig *configs = glXChooseFBConfig(display, DefaultScreen(display),
21 attributes, &configCount);
22
23 struct FBConfig
24 {
25 GLXFBConfig config;
26 int depth;
27 int stencil;
28 };
29
30 std::deque<FBConfig> candidates;
31
32 for (int i = 0; i < configCount; i++) {
33 int depth, stencil;
34 glXGetFBConfigAttrib(display, configs[i], GLX_DEPTH_SIZE, &depth);
35 glXGetFBConfigAttrib(display, configs[i], GLX_STENCIL_SIZE, &stencil);
36
37 candidates.emplace_back(FBConfig{configs[i], depth, stencil});
38 }
39
40 if (configCount > 0) {
41 XFree(configs);
42 }
43
44 std::stable_sort(candidates.begin(), candidates.end(), [](const FBConfig &left, const FBConfig &right) {
45 if (left.depth < right.depth) {
46 return true;
47 }
48
49 if (left.stencil < right.stencil) {
50 return true;
51 }
52
53 return false;
54 });
55
56 return candidates.empty() ? nullptr : candidates.front().config;
57}
58
59} // namespace KWin
GLXFBConfig chooseGlxFbConfig(::Display *display, const int attributes[])
struct _XDisplay Display