Changeset View
Changeset View
Standalone View
Standalone View
greeter/kwinglplatform.h
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2010 Fredrik Höglund <fredrik@kde.org> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | | ||||
21 | #ifndef KWIN_GLPLATFORM_H | ||||
22 | #define KWIN_GLPLATFORM_H | ||||
23 | | ||||
24 | #include <QByteArray> | ||||
25 | #include <QSet> | ||||
26 | | ||||
27 | namespace KWin | ||||
28 | { | ||||
29 | // forward declare method | ||||
30 | void cleanupGL(); | ||||
31 | | ||||
32 | inline qint64 kVersionNumber(qint64 major, qint64 minor, qint64 patch = 0) | ||||
33 | { | ||||
34 | return ((major & 0xffff) << 32) | ((minor & 0xffff) << 16) | (patch & 0xffff); | ||||
35 | } | ||||
36 | | ||||
37 | enum GLFeature { | ||||
38 | /** | ||||
39 | * Set when a texture bound to a pixmap uses the same storage as the pixmap, | ||||
40 | * and thus doesn't need to be rebound when the contents of the pixmap | ||||
41 | * has changed. | ||||
42 | */ | ||||
43 | LooseBinding, | ||||
44 | | ||||
45 | /** | ||||
46 | * Set if the driver supports the following extensions: | ||||
47 | * - GL_ARB_shader_objects | ||||
48 | * - GL_ARB_fragment_shader | ||||
49 | * - GL_ARB_vertex_shader | ||||
50 | * - GL_ARB_shading_language_100 | ||||
51 | */ | ||||
52 | GLSL, | ||||
53 | | ||||
54 | /** | ||||
55 | * If set, assume the following: | ||||
56 | * - No flow control or branches | ||||
57 | * - No loops, unless the loops have a fixed iteration count and can be unrolled | ||||
58 | * - No functions, unless they can be inlined | ||||
59 | * - No indirect indexing of arrays | ||||
60 | * - No support for gl_ClipVertex or gl_FrontFacing | ||||
61 | * - No texture fetches in vertex shaders | ||||
62 | * - Max 32 texture fetches in fragment shaders | ||||
63 | * - Max 4 texture indirections | ||||
64 | */ | ||||
65 | LimitedGLSL, | ||||
66 | | ||||
67 | /** | ||||
68 | * Set when the driver supports GL_ARB_texture_non_power_of_two. | ||||
69 | */ | ||||
70 | TextureNPOT, | ||||
71 | | ||||
72 | /** | ||||
73 | * If set, the driver supports GL_ARB_texture_non_power_of_two with the | ||||
74 | * GL_ARB_texture_rectangle limitations. | ||||
75 | * | ||||
76 | * This means no support for mipmap filters, and that only the following | ||||
77 | * wrap modes are supported: | ||||
78 | * - GL_CLAMP | ||||
79 | * - GL_CLAMP_TO_EDGE | ||||
80 | * - GL_CLAMP_TO_BORDER | ||||
81 | */ | ||||
82 | LimitedNPOT | ||||
83 | }; | ||||
84 | | ||||
85 | enum Driver { | ||||
86 | Driver_R100, // Technically "Radeon" | ||||
87 | Driver_R200, | ||||
88 | Driver_R300C, | ||||
89 | Driver_R300G, | ||||
90 | Driver_R600C, | ||||
91 | Driver_R600G, | ||||
92 | Driver_Nouveau, | ||||
93 | Driver_Intel, | ||||
94 | Driver_NVidia, | ||||
95 | Driver_Catalyst, | ||||
96 | Driver_Swrast, | ||||
97 | Driver_Softpipe, | ||||
98 | Driver_Llvmpipe, | ||||
99 | Driver_VirtualBox, | ||||
100 | Driver_VMware, | ||||
101 | Driver_Qualcomm, | ||||
102 | Driver_Unknown | ||||
103 | }; | ||||
104 | | ||||
105 | enum ChipClass { | ||||
106 | // Radeon | ||||
107 | R100 = 0, // GL1.3 DX7 2000 | ||||
108 | R200, // GL1.4 DX8.1 SM 1.4 2001 | ||||
109 | R300, // GL2.0 DX9 SM 2.0 2002 | ||||
110 | R400, // GL2.0 DX9b SM 2.0b 2004 | ||||
111 | R500, // GL2.0 DX9c SM 3.0 2005 | ||||
112 | R600, // GL3.3 DX10 SM 4.0 2006 | ||||
113 | R700, // GL3.3 DX10.1 SM 4.1 2008 | ||||
114 | Evergreen, // GL4.0 CL1.0 DX11 SM 5.0 2009 | ||||
115 | NorthernIslands, // GL4.0 CL1.1 DX11 SM 5.0 2010 | ||||
116 | UnknownRadeon = 999, | ||||
117 | | ||||
118 | // NVIDIA | ||||
119 | NV10 = 1000, // GL1.2 DX7 1999 | ||||
120 | NV20, // GL1.3 DX8 SM 1.1 2001 | ||||
121 | NV30, // GL1.5 DX9a SM 2.0 2003 | ||||
122 | NV40, // GL2.1 DX9c SM 3.0 2004 | ||||
123 | G80, // GL3.3 DX10 SM 4.0 2006 | ||||
124 | GF100, // GL4.1 CL1.1 DX11 SM 5.0 2010 | ||||
125 | UnknownNVidia = 1999, | ||||
126 | | ||||
127 | // Intel | ||||
128 | I8XX = 2000, // GL1.3 DX7 2001 | ||||
129 | I915, // GL1.4/1.5 DX9/DX9c SM 2.0 2004 | ||||
130 | I965, // GL2.0/2.1 DX9/DX10 SM 3.0/4.0 2006 | ||||
131 | SandyBridge, // GL3.1 CL1.1 DX10.1 SM 4.0 2010 | ||||
132 | IvyBridge, // GL4.0 CL1.1 DX11 SM 5.0 2012 | ||||
133 | Haswell, // GL4.0 CL1.2 DX11.1 SM 5.0 2013 | ||||
134 | UnknownIntel = 2999, | ||||
135 | | ||||
136 | // Qualcomm Adreno | ||||
137 | // from https://en.wikipedia.org/wiki/Adreno | ||||
138 | Adreno1XX = 3000, // GLES1.1 | ||||
139 | Adreno2XX, // GLES2.0 DX9c | ||||
140 | Adreno3XX, // GLES3.0 CL1.1 DX11.1 | ||||
141 | Adreno4XX, // GLES3.1 CL1.2 DX11.2 | ||||
142 | Adreno5XX, // GLES3.1 CL2.0 DX11.2 | ||||
143 | UnknownAdreno = 3999, | ||||
144 | | ||||
145 | UnknownChipClass = 99999 | ||||
146 | }; | ||||
147 | | ||||
148 | | ||||
149 | class GLPlatform | ||||
150 | { | ||||
151 | public: | ||||
152 | ~GLPlatform(); | ||||
153 | | ||||
154 | /** | ||||
155 | * Runs the detection code using the current OpenGL context. | ||||
156 | */ | ||||
157 | void detect(); | ||||
158 | | ||||
159 | /** | ||||
160 | * Prints the results of the detection code. | ||||
161 | */ | ||||
162 | void printResults() const; | ||||
163 | | ||||
164 | /** | ||||
165 | * Returns a pointer to the GLPlatform instance. | ||||
166 | */ | ||||
167 | static GLPlatform *instance(); | ||||
168 | | ||||
169 | /** | ||||
170 | * Returns true if the driver support the given feature, and false otherwise. | ||||
171 | */ | ||||
172 | bool supports(GLFeature feature) const; | ||||
173 | | ||||
174 | /** | ||||
175 | * Returns the OpenGL version. | ||||
176 | */ | ||||
177 | qint64 glVersion() const; | ||||
178 | | ||||
179 | /** | ||||
180 | * Returns the GLSL version if the driver supports GLSL, and 0 otherwise. | ||||
181 | */ | ||||
182 | qint64 glslVersion() const; | ||||
183 | | ||||
184 | /** | ||||
185 | * Returns the Mesa version if the driver is a Mesa driver, and 0 otherwise. | ||||
186 | */ | ||||
187 | qint64 mesaVersion() const; | ||||
188 | | ||||
189 | /** | ||||
190 | * Returns the Gallium version if the driver is a Gallium driver, and 0 otherwise. | ||||
191 | */ | ||||
192 | qint64 galliumVersion() const; | ||||
193 | | ||||
194 | /** | ||||
195 | * Returns the X server version. | ||||
196 | * | ||||
197 | * Note that the version number changed from 7.2 to 1.3 in the first release | ||||
198 | * following the doupling of the X server from the katamari. | ||||
199 | * | ||||
200 | * For non X.org servers, this method returns 0. | ||||
201 | */ | ||||
202 | qint64 serverVersion() const; | ||||
203 | | ||||
204 | /** | ||||
205 | * Returns the Linux kernel version. | ||||
206 | * | ||||
207 | * If the kernel is not a Linux kernel, this method returns 0. | ||||
208 | */ | ||||
209 | qint64 kernelVersion() const; | ||||
210 | | ||||
211 | /** | ||||
212 | * Returns the driver version. | ||||
213 | * | ||||
214 | * For Mesa drivers, this is the same as the Mesa version number. | ||||
215 | */ | ||||
216 | qint64 driverVersion() const; | ||||
217 | | ||||
218 | /** | ||||
219 | * Returns the driver. | ||||
220 | */ | ||||
221 | Driver driver() const; | ||||
222 | | ||||
223 | /** | ||||
224 | * Returns the chip class. | ||||
225 | */ | ||||
226 | ChipClass chipClass() const; | ||||
227 | | ||||
228 | /** | ||||
229 | * Returns true if the driver is a Mesa driver, and false otherwise. | ||||
230 | */ | ||||
231 | bool isMesaDriver() const; | ||||
232 | | ||||
233 | /** | ||||
234 | * Returns true if the driver is a Gallium driver, and false otherwise. | ||||
235 | */ | ||||
236 | bool isGalliumDriver() const; | ||||
237 | | ||||
238 | /** | ||||
239 | * Returns true if the GPU is a Radeon GPU, and false otherwise. | ||||
240 | */ | ||||
241 | bool isRadeon() const; | ||||
242 | | ||||
243 | /** | ||||
244 | * Returns true if the GPU is an NVIDIA GPU, and false otherwise. | ||||
245 | */ | ||||
246 | bool isNvidia() const; | ||||
247 | | ||||
248 | /** | ||||
249 | * Returns true if the GPU is an Intel GPU, and false otherwise. | ||||
250 | */ | ||||
251 | bool isIntel() const; | ||||
252 | | ||||
253 | /** | ||||
254 | * @returns @c true if the "GPU" is a VirtualBox GPU, and @c false otherwise. | ||||
255 | * @since 4.10 | ||||
256 | **/ | ||||
257 | bool isVirtualBox() const; | ||||
258 | | ||||
259 | /** | ||||
260 | * @returns @c true if the "GPU" is a VMWare GPU, and @c false otherwise. | ||||
261 | * @since 4.10 | ||||
262 | **/ | ||||
263 | bool isVMware() const; | ||||
264 | | ||||
265 | /** | ||||
266 | * @returns @c true if OpenGL is emulated in software. | ||||
267 | * @since 4.7 | ||||
268 | **/ | ||||
269 | bool isSoftwareEmulation() const; | ||||
270 | | ||||
271 | /** | ||||
272 | * @returns @c true if the driver is known to be from a virtual machine. | ||||
273 | * @since 4.10 | ||||
274 | **/ | ||||
275 | bool isVirtualMachine() const; | ||||
276 | | ||||
277 | /** | ||||
278 | * @returns @c true if the GPU is a Qualcomm Adreno GPU, and false otherwise | ||||
279 | * @since 5.8 | ||||
280 | **/ | ||||
281 | bool isAdreno() const; | ||||
282 | | ||||
283 | /** | ||||
284 | * @returns the GL_VERSION string as provided by the driver. | ||||
285 | * @since 4.9 | ||||
286 | **/ | ||||
287 | const QByteArray &glVersionString() const; | ||||
288 | /** | ||||
289 | * @returns the GL_RENDERER string as provided by the driver. | ||||
290 | * @since 4.9 | ||||
291 | **/ | ||||
292 | const QByteArray &glRendererString() const; | ||||
293 | /** | ||||
294 | * @returns the GL_VENDOR string as provided by the driver. | ||||
295 | * @since 4.9 | ||||
296 | **/ | ||||
297 | const QByteArray &glVendorString() const; | ||||
298 | /** | ||||
299 | * @returns the GL_SHADING_LANGUAGE_VERSION string as provided by the driver. | ||||
300 | * If the driver does not support the OpenGL Shading Language a null bytearray is returned. | ||||
301 | * @since 4.9 | ||||
302 | **/ | ||||
303 | const QByteArray &glShadingLanguageVersionString() const; | ||||
304 | /** | ||||
305 | * @returns Whether the driver supports loose texture binding. | ||||
306 | * @since 4.9 | ||||
307 | **/ | ||||
308 | bool isLooseBinding() const; | ||||
309 | /** | ||||
310 | * @returns Whether OpenGL ES is used | ||||
311 | */ | ||||
312 | bool isGLES() const; | ||||
313 | | ||||
314 | /** | ||||
315 | * Returns true if glMapBufferRange() is likely to perform worse than glBufferSubData() | ||||
316 | * when updating an unused range of a buffer object, and false otherwise. | ||||
317 | * | ||||
318 | * @since 4.11 | ||||
319 | */ | ||||
320 | bool preferBufferSubData() const; | ||||
321 | | ||||
322 | /** | ||||
323 | * @returns a human readable form of the @p version as a QString. | ||||
324 | * @since 4.9 | ||||
325 | * @see glVersion | ||||
326 | * @see glslVersion | ||||
327 | * @see driverVersion | ||||
328 | * @see mesaVersion | ||||
329 | * @see galliumVersion | ||||
330 | * @see kernelVersion | ||||
331 | * @see serverVersion | ||||
332 | **/ | ||||
333 | static QString versionToString(qint64 version); | ||||
334 | /** | ||||
335 | * @returns a human readable form of the @p version as a QByteArray. | ||||
336 | * @since 5.5 | ||||
337 | * @see glVersion | ||||
338 | * @see glslVersion | ||||
339 | * @see driverVersion | ||||
340 | * @see mesaVersion | ||||
341 | * @see galliumVersion | ||||
342 | * @see kernelVersion | ||||
343 | * @see serverVersion | ||||
344 | **/ | ||||
345 | static QByteArray versionToString8(qint64 version); | ||||
346 | | ||||
347 | /** | ||||
348 | * @returns a human readable form for the @p driver as a QString. | ||||
349 | * @since 4.9 | ||||
350 | * @see driver | ||||
351 | **/ | ||||
352 | static QString driverToString(Driver driver); | ||||
353 | /** | ||||
354 | * @returns a human readable form for the @p driver as a QByteArray. | ||||
355 | * @since 5.5 | ||||
356 | * @see driver | ||||
357 | **/ | ||||
358 | static QByteArray driverToString8(Driver driver); | ||||
359 | | ||||
360 | /** | ||||
361 | * @returns a human readable form for the @p chipClass as a QString. | ||||
362 | * @since 4.9 | ||||
363 | * @see chipClass | ||||
364 | **/ | ||||
365 | static QString chipClassToString(ChipClass chipClass); | ||||
366 | /** | ||||
367 | * @returns a human readable form for the @p chipClass as a QByteArray. | ||||
368 | * @since 5.5 | ||||
369 | * @see chipClass | ||||
370 | **/ | ||||
371 | static QByteArray chipClassToString8(ChipClass chipClass); | ||||
372 | | ||||
373 | private: | ||||
374 | GLPlatform(); | ||||
375 | friend void KWin::cleanupGL(); | ||||
376 | static void cleanup(); | ||||
377 | | ||||
378 | private: | ||||
379 | QByteArray m_renderer; | ||||
380 | QByteArray m_vendor; | ||||
381 | QByteArray m_version; | ||||
382 | QByteArray m_glsl_version; | ||||
383 | QByteArray m_chipset; | ||||
384 | QSet<QByteArray> m_extensions; | ||||
385 | Driver m_driver; | ||||
386 | ChipClass m_chipClass; | ||||
387 | qint64 m_glVersion; | ||||
388 | qint64 m_glslVersion; | ||||
389 | qint64 m_mesaVersion; | ||||
390 | qint64 m_driverVersion; | ||||
391 | qint64 m_galliumVersion; | ||||
392 | qint64 m_serverVersion; | ||||
393 | qint64 m_kernelVersion; | ||||
394 | bool m_looseBinding: 1; | ||||
395 | bool m_supportsGLSL: 1; | ||||
396 | bool m_limitedGLSL: 1; | ||||
397 | bool m_textureNPOT: 1; | ||||
398 | bool m_limitedNPOT: 1; | ||||
399 | bool m_virtualMachine: 1; | ||||
400 | bool m_preferBufferSubData: 1; | ||||
401 | bool m_gles: 1; | ||||
402 | static GLPlatform *s_platform; | ||||
403 | }; | ||||
404 | | ||||
405 | inline GLPlatform *GLPlatform::instance() | ||||
406 | { | ||||
407 | if (!s_platform) | ||||
408 | s_platform = new GLPlatform; | ||||
409 | | ||||
410 | return s_platform; | ||||
411 | } | ||||
412 | | ||||
413 | } // namespace KWin | ||||
414 | | ||||
415 | #endif // KWIN_GLPLATFORM_H | ||||
416 | |