Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/platformsupport/eglconvenience/qeglconvenience.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the plugins of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include <QByteArray> | - | ||||||||||||
35 | #include <QOpenGLContext> | - | ||||||||||||
36 | - | |||||||||||||
37 | #ifdef Q_OS_LINUX | - | ||||||||||||
38 | #include <sys/ioctl.h> | - | ||||||||||||
39 | #include <linux/fb.h> | - | ||||||||||||
40 | #endif | - | ||||||||||||
41 | #include <private/qmath_p.h> | - | ||||||||||||
42 | - | |||||||||||||
43 | #include "qeglconvenience_p.h" | - | ||||||||||||
44 | - | |||||||||||||
45 | #ifndef EGL_OPENGL_ES3_BIT_KHR | - | ||||||||||||
46 | #define EGL_OPENGL_ES3_BIT_KHR 0x0040 | - | ||||||||||||
47 | #endif | - | ||||||||||||
48 | - | |||||||||||||
49 | QT_BEGIN_NAMESPACE | - | ||||||||||||
50 | - | |||||||||||||
51 | QVector<EGLint> q_createConfigAttributesFromFormat(const QSurfaceFormat &format) | - | ||||||||||||
52 | { | - | ||||||||||||
53 | int redSize = format.redBufferSize(); | - | ||||||||||||
54 | int greenSize = format.greenBufferSize(); | - | ||||||||||||
55 | int blueSize = format.blueBufferSize(); | - | ||||||||||||
56 | int alphaSize = format.alphaBufferSize(); | - | ||||||||||||
57 | int depthSize = format.depthBufferSize(); | - | ||||||||||||
58 | int stencilSize = format.stencilBufferSize(); | - | ||||||||||||
59 | int sampleCount = format.samples(); | - | ||||||||||||
60 | - | |||||||||||||
61 | QVector<EGLint> configAttributes; | - | ||||||||||||
62 | - | |||||||||||||
63 | // Map default, unspecified values (-1) to 0. This is important due to sorting rule #3 | - | ||||||||||||
64 | // in section 3.4.1 of the spec and allows picking a potentially faster 16-bit config | - | ||||||||||||
65 | // over 32-bit ones when there is no explicit request for the color channel sizes: | - | ||||||||||||
66 | // | - | ||||||||||||
67 | // The red/green/blue sizes have a sort priority of 3, so they are sorted by | - | ||||||||||||
68 | // first. (unless a caveat like SLOW or NON_CONFORMANT is present) The sort order is | - | ||||||||||||
69 | // Special and described as "by larger _total_ number of color bits.". So EGL will put | - | ||||||||||||
70 | // 32-bit configs in the list before the 16-bit configs. However, the spec also goes | - | ||||||||||||
71 | // on to say "If the requested number of bits in attrib_list for a particular | - | ||||||||||||
72 | // component is 0, then the number of bits for that component is not considered". This | - | ||||||||||||
73 | // part of the spec also seems to imply that setting the red/green/blue bits to zero | - | ||||||||||||
74 | // means none of the components are considered and EGL disregards the entire sorting | - | ||||||||||||
75 | // rule. It then looks to the next highest priority rule, which is | - | ||||||||||||
76 | // EGL_BUFFER_SIZE. Despite the selection criteria being "AtLeast" for | - | ||||||||||||
77 | // EGL_BUFFER_SIZE, it's sort order is "smaller" meaning 16-bit configs are put in the | - | ||||||||||||
78 | // list before 32-bit configs. | - | ||||||||||||
79 | // | - | ||||||||||||
80 | // This also means that explicitly specifying a size like 565 will still result in | - | ||||||||||||
81 | // having larger (888) configs first in the returned list. We need to handle this | - | ||||||||||||
82 | // ourselves later by manually filtering the list, instead of just blindly taking the | - | ||||||||||||
83 | // first config from it. | - | ||||||||||||
84 | - | |||||||||||||
85 | configAttributes.append(EGL_RED_SIZE); | - | ||||||||||||
86 | configAttributes.append(redSize > 0 ? redSize : 0); | - | ||||||||||||
87 | - | |||||||||||||
88 | configAttributes.append(EGL_GREEN_SIZE); | - | ||||||||||||
89 | configAttributes.append(greenSize > 0 ? greenSize : 0); | - | ||||||||||||
90 | - | |||||||||||||
91 | configAttributes.append(EGL_BLUE_SIZE); | - | ||||||||||||
92 | configAttributes.append(blueSize > 0 ? blueSize : 0); | - | ||||||||||||
93 | - | |||||||||||||
94 | configAttributes.append(EGL_ALPHA_SIZE); | - | ||||||||||||
95 | configAttributes.append(alphaSize > 0 ? alphaSize : 0); | - | ||||||||||||
96 | - | |||||||||||||
97 | configAttributes.append(EGL_DEPTH_SIZE); | - | ||||||||||||
98 | configAttributes.append(depthSize > 0 ? depthSize : 0); | - | ||||||||||||
99 | - | |||||||||||||
100 | configAttributes.append(EGL_STENCIL_SIZE); | - | ||||||||||||
101 | configAttributes.append(stencilSize > 0 ? stencilSize : 0); | - | ||||||||||||
102 | - | |||||||||||||
103 | configAttributes.append(EGL_SAMPLES); | - | ||||||||||||
104 | configAttributes.append(sampleCount > 0 ? sampleCount : 0); | - | ||||||||||||
105 | - | |||||||||||||
106 | configAttributes.append(EGL_SAMPLE_BUFFERS); | - | ||||||||||||
107 | configAttributes.append(sampleCount > 0); | - | ||||||||||||
108 | - | |||||||||||||
109 | return configAttributes; never executed: return configAttributes; | 0 | ||||||||||||
110 | } | - | ||||||||||||
111 | - | |||||||||||||
112 | bool q_reduceConfigAttributes(QVector<EGLint> *configAttributes) | - | ||||||||||||
113 | { | - | ||||||||||||
114 | int i = -1; | - | ||||||||||||
115 | // Reduce the complexity of a configuration request to ask for less | - | ||||||||||||
116 | // because the previous request did not result in success. Returns | - | ||||||||||||
117 | // true if the complexity was reduced, or false if no further | - | ||||||||||||
118 | // reductions in complexity are possible. | - | ||||||||||||
119 | - | |||||||||||||
120 | i = configAttributes->indexOf(EGL_SWAP_BEHAVIOR); | - | ||||||||||||
121 | if (i >= 0) {
| 0 | ||||||||||||
122 | configAttributes->remove(i,2); | - | ||||||||||||
123 | } never executed: end of block | 0 | ||||||||||||
124 | - | |||||||||||||
125 | #ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT | - | ||||||||||||
126 | // For OpenVG, we sometimes try to create a surface using a pre-multiplied format. If we can't | - | ||||||||||||
127 | // find a config which supports pre-multiplied formats, remove the flag on the surface type: | - | ||||||||||||
128 | - | |||||||||||||
129 | i = configAttributes->indexOf(EGL_SURFACE_TYPE); | - | ||||||||||||
130 | if (i >= 0) {
| 0 | ||||||||||||
131 | EGLint surfaceType = configAttributes->at(i +1); | - | ||||||||||||
132 | if (surfaceType & EGL_VG_ALPHA_FORMAT_PRE_BIT) {
| 0 | ||||||||||||
133 | surfaceType ^= EGL_VG_ALPHA_FORMAT_PRE_BIT; | - | ||||||||||||
134 | configAttributes->replace(i+1,surfaceType); | - | ||||||||||||
135 | return true; never executed: return true; | 0 | ||||||||||||
136 | } | - | ||||||||||||
137 | } never executed: end of block | 0 | ||||||||||||
138 | #endif | - | ||||||||||||
139 | - | |||||||||||||
140 | // EGL chooses configs with the highest color depth over | - | ||||||||||||
141 | // those with smaller (but faster) lower color depths. One | - | ||||||||||||
142 | // way around this is to set EGL_BUFFER_SIZE to 16, which | - | ||||||||||||
143 | // trumps the others. Of course, there may not be a 16-bit | - | ||||||||||||
144 | // config available, so it's the first restraint we remove. | - | ||||||||||||
145 | i = configAttributes->indexOf(EGL_BUFFER_SIZE); | - | ||||||||||||
146 | if (i >= 0) {
| 0 | ||||||||||||
147 | if (configAttributes->at(i+1) == 16) {
| 0 | ||||||||||||
148 | configAttributes->remove(i,2); | - | ||||||||||||
149 | return true; never executed: return true; | 0 | ||||||||||||
150 | } | - | ||||||||||||
151 | } never executed: end of block | 0 | ||||||||||||
152 | - | |||||||||||||
153 | i = configAttributes->indexOf(EGL_SAMPLES); | - | ||||||||||||
154 | if (i >= 0) {
| 0 | ||||||||||||
155 | EGLint value = configAttributes->value(i+1, 0); | - | ||||||||||||
156 | if (value > 1)
| 0 | ||||||||||||
157 | configAttributes->replace(i+1, qMin(EGLint(16), value / 2)); never executed: configAttributes->replace(i+1, qMin(EGLint(16), value / 2)); | 0 | ||||||||||||
158 | else | - | ||||||||||||
159 | configAttributes->remove(i, 2); never executed: configAttributes->remove(i, 2); | 0 | ||||||||||||
160 | return true; never executed: return true; | 0 | ||||||||||||
161 | } | - | ||||||||||||
162 | - | |||||||||||||
163 | i = configAttributes->indexOf(EGL_SAMPLE_BUFFERS); | - | ||||||||||||
164 | if (i >= 0) {
| 0 | ||||||||||||
165 | configAttributes->remove(i,2); | - | ||||||||||||
166 | return true; never executed: return true; | 0 | ||||||||||||
167 | } | - | ||||||||||||
168 | - | |||||||||||||
169 | i = configAttributes->indexOf(EGL_ALPHA_SIZE); | - | ||||||||||||
170 | if (i >= 0) {
| 0 | ||||||||||||
171 | configAttributes->remove(i,2); | - | ||||||||||||
172 | #if defined(EGL_BIND_TO_TEXTURE_RGBA) && defined(EGL_BIND_TO_TEXTURE_RGB) | - | ||||||||||||
173 | i = configAttributes->indexOf(EGL_BIND_TO_TEXTURE_RGBA); | - | ||||||||||||
174 | if (i >= 0) {
| 0 | ||||||||||||
175 | configAttributes->replace(i,EGL_BIND_TO_TEXTURE_RGB); | - | ||||||||||||
176 | configAttributes->replace(i+1,true); | - | ||||||||||||
177 | - | |||||||||||||
178 | } never executed: end of block | 0 | ||||||||||||
179 | #endif | - | ||||||||||||
180 | return true; never executed: return true; | 0 | ||||||||||||
181 | } | - | ||||||||||||
182 | - | |||||||||||||
183 | i = configAttributes->indexOf(EGL_STENCIL_SIZE); | - | ||||||||||||
184 | if (i >= 0) {
| 0 | ||||||||||||
185 | if (configAttributes->at(i + 1) > 1)
| 0 | ||||||||||||
186 | configAttributes->replace(i + 1, 1); never executed: configAttributes->replace(i + 1, 1); | 0 | ||||||||||||
187 | else | - | ||||||||||||
188 | configAttributes->remove(i, 2); never executed: configAttributes->remove(i, 2); | 0 | ||||||||||||
189 | return true; never executed: return true; | 0 | ||||||||||||
190 | } | - | ||||||||||||
191 | - | |||||||||||||
192 | i = configAttributes->indexOf(EGL_DEPTH_SIZE); | - | ||||||||||||
193 | if (i >= 0) {
| 0 | ||||||||||||
194 | if (configAttributes->at(i + 1) > 1)
| 0 | ||||||||||||
195 | configAttributes->replace(i + 1, 1); never executed: configAttributes->replace(i + 1, 1); | 0 | ||||||||||||
196 | else | - | ||||||||||||
197 | configAttributes->remove(i, 2); never executed: configAttributes->remove(i, 2); | 0 | ||||||||||||
198 | return true; never executed: return true; | 0 | ||||||||||||
199 | } | - | ||||||||||||
200 | #ifdef EGL_BIND_TO_TEXTURE_RGB | - | ||||||||||||
201 | i = configAttributes->indexOf(EGL_BIND_TO_TEXTURE_RGB); | - | ||||||||||||
202 | if (i >= 0) {
| 0 | ||||||||||||
203 | configAttributes->remove(i,2); | - | ||||||||||||
204 | return true; never executed: return true; | 0 | ||||||||||||
205 | } | - | ||||||||||||
206 | #endif | - | ||||||||||||
207 | - | |||||||||||||
208 | return false; never executed: return false; | 0 | ||||||||||||
209 | } | - | ||||||||||||
210 | - | |||||||||||||
211 | QEglConfigChooser::QEglConfigChooser(EGLDisplay display) | - | ||||||||||||
212 | : m_display(display) | - | ||||||||||||
213 | , m_surfaceType(EGL_WINDOW_BIT) | - | ||||||||||||
214 | , m_ignore(false) | - | ||||||||||||
215 | , m_confAttrRed(0) | - | ||||||||||||
216 | , m_confAttrGreen(0) | - | ||||||||||||
217 | , m_confAttrBlue(0) | - | ||||||||||||
218 | , m_confAttrAlpha(0) | - | ||||||||||||
219 | { | - | ||||||||||||
220 | } never executed: end of block | 0 | ||||||||||||
221 | - | |||||||||||||
222 | QEglConfigChooser::~QEglConfigChooser() | - | ||||||||||||
223 | { | - | ||||||||||||
224 | } | - | ||||||||||||
225 | - | |||||||||||||
226 | EGLConfig QEglConfigChooser::chooseConfig() | - | ||||||||||||
227 | { | - | ||||||||||||
228 | QVector<EGLint> configureAttributes = q_createConfigAttributesFromFormat(m_format); | - | ||||||||||||
229 | configureAttributes.append(EGL_SURFACE_TYPE); | - | ||||||||||||
230 | configureAttributes.append(surfaceType()); | - | ||||||||||||
231 | - | |||||||||||||
232 | configureAttributes.append(EGL_RENDERABLE_TYPE); | - | ||||||||||||
233 | bool needsES2Plus = false; | - | ||||||||||||
234 | switch (m_format.renderableType()) { | - | ||||||||||||
235 | case QSurfaceFormat::OpenVG: never executed: case QSurfaceFormat::OpenVG: | 0 | ||||||||||||
236 | configureAttributes.append(EGL_OPENVG_BIT); | - | ||||||||||||
237 | break; never executed: break; | 0 | ||||||||||||
238 | #ifdef EGL_VERSION_1_4 | - | ||||||||||||
239 | case QSurfaceFormat::DefaultRenderableType: never executed: case QSurfaceFormat::DefaultRenderableType: | 0 | ||||||||||||
240 | #ifndef QT_NO_OPENGL | - | ||||||||||||
241 | if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL)
| 0 | ||||||||||||
242 | configureAttributes.append(EGL_OPENGL_BIT); never executed: configureAttributes.append(0x0008); | 0 | ||||||||||||
243 | else | - | ||||||||||||
244 | #endif // QT_NO_OPENGL | - | ||||||||||||
245 | needsES2Plus = true; never executed: needsES2Plus = true; | 0 | ||||||||||||
246 | break; never executed: break; | 0 | ||||||||||||
247 | case QSurfaceFormat::OpenGL: never executed: case QSurfaceFormat::OpenGL: | 0 | ||||||||||||
248 | configureAttributes.append(EGL_OPENGL_BIT); | - | ||||||||||||
249 | break; never executed: break; | 0 | ||||||||||||
250 | #endif | - | ||||||||||||
251 | case QSurfaceFormat::OpenGLES: never executed: case QSurfaceFormat::OpenGLES: | 0 | ||||||||||||
252 | if (m_format.majorVersion() == 1) {
| 0 | ||||||||||||
253 | configureAttributes.append(EGL_OPENGL_ES_BIT); | - | ||||||||||||
254 | break; never executed: break; | 0 | ||||||||||||
255 | } | - | ||||||||||||
256 | // fall through | - | ||||||||||||
257 | default: code before this statement never executed: default: never executed: default: | 0 | ||||||||||||
258 | needsES2Plus = true; | - | ||||||||||||
259 | break; never executed: break; | 0 | ||||||||||||
260 | } | - | ||||||||||||
261 | if (needsES2Plus) {
| 0 | ||||||||||||
262 | if (m_format.majorVersion() >= 3 && q_hasEglExtension(display(), "EGL_KHR_create_context"))
| 0 | ||||||||||||
263 | configureAttributes.append(EGL_OPENGL_ES3_BIT_KHR); never executed: configureAttributes.append(0x0040); | 0 | ||||||||||||
264 | else | - | ||||||||||||
265 | configureAttributes.append(EGL_OPENGL_ES2_BIT); never executed: configureAttributes.append(0x0004); | 0 | ||||||||||||
266 | } | - | ||||||||||||
267 | configureAttributes.append(EGL_NONE); | - | ||||||||||||
268 | - | |||||||||||||
269 | EGLConfig cfg = 0; | - | ||||||||||||
270 | do { | - | ||||||||||||
271 | // Get the number of matching configurations for this set of properties. | - | ||||||||||||
272 | EGLint matching = 0; | - | ||||||||||||
273 | if (!eglChooseConfig(display(), configureAttributes.constData(), 0, 0, &matching) || !matching)
| 0 | ||||||||||||
274 | continue; never executed: continue; | 0 | ||||||||||||
275 | - | |||||||||||||
276 | // Fetch all of the matching configurations and find the | - | ||||||||||||
277 | // first that matches the pixel format we wanted. | - | ||||||||||||
278 | int i = configureAttributes.indexOf(EGL_RED_SIZE); | - | ||||||||||||
279 | m_confAttrRed = configureAttributes.at(i+1); | - | ||||||||||||
280 | i = configureAttributes.indexOf(EGL_GREEN_SIZE); | - | ||||||||||||
281 | m_confAttrGreen = configureAttributes.at(i+1); | - | ||||||||||||
282 | i = configureAttributes.indexOf(EGL_BLUE_SIZE); | - | ||||||||||||
283 | m_confAttrBlue = configureAttributes.at(i+1); | - | ||||||||||||
284 | i = configureAttributes.indexOf(EGL_ALPHA_SIZE); | - | ||||||||||||
285 | m_confAttrAlpha = i == -1 ? 0 : configureAttributes.at(i+1);
| 0 | ||||||||||||
286 | - | |||||||||||||
287 | QVector<EGLConfig> configs(matching); | - | ||||||||||||
288 | eglChooseConfig(display(), configureAttributes.constData(), configs.data(), configs.size(), &matching); | - | ||||||||||||
289 | if (!cfg && matching > 0)
| 0 | ||||||||||||
290 | cfg = configs.first(); never executed: cfg = configs.first(); | 0 | ||||||||||||
291 | - | |||||||||||||
292 | // Filter the list. Due to the EGL sorting rules configs with higher depth are | - | ||||||||||||
293 | // placed first when the minimum color channel sizes have been specified (i.e. the | - | ||||||||||||
294 | // QSurfaceFormat contains color sizes > 0). To prevent returning a 888 config | - | ||||||||||||
295 | // when the QSurfaceFormat explicitly asked for 565, go through the returned | - | ||||||||||||
296 | // configs and look for one that exactly matches the requested sizes. When no | - | ||||||||||||
297 | // sizes have been given, take the first, which will be a config with the smaller | - | ||||||||||||
298 | // (e.g. 16-bit) depth. | - | ||||||||||||
299 | for (int i = 0; i < configs.size(); ++i) {
| 0 | ||||||||||||
300 | if (filterConfig(configs[i]))
| 0 | ||||||||||||
301 | return configs.at(i); never executed: return configs.at(i); | 0 | ||||||||||||
302 | } never executed: end of block | 0 | ||||||||||||
303 | } while (q_reduceConfigAttributes(&configureAttributes)); never executed: end of block
| 0 | ||||||||||||
304 | - | |||||||||||||
305 | if (!cfg)
| 0 | ||||||||||||
306 | qWarning("Cannot find EGLConfig, returning null config"); never executed: QMessageLogger(__FILE__, 306, __PRETTY_FUNCTION__).warning("Cannot find EGLConfig, returning null config"); | 0 | ||||||||||||
307 | return cfg; never executed: return cfg; | 0 | ||||||||||||
308 | } | - | ||||||||||||
309 | - | |||||||||||||
310 | bool QEglConfigChooser::filterConfig(EGLConfig config) const | - | ||||||||||||
311 | { | - | ||||||||||||
312 | // If we are fine with the highest depth (e.g. RGB888 configs) even when something | - | ||||||||||||
313 | // smaller (565) was explicitly requested, do nothing. | - | ||||||||||||
314 | if (m_ignore)
| 0 | ||||||||||||
315 | return true; never executed: return true; | 0 | ||||||||||||
316 | - | |||||||||||||
317 | EGLint red = 0; | - | ||||||||||||
318 | EGLint green = 0; | - | ||||||||||||
319 | EGLint blue = 0; | - | ||||||||||||
320 | EGLint alpha = 0; | - | ||||||||||||
321 | - | |||||||||||||
322 | // Compare only if a size was given. Otherwise just accept. | - | ||||||||||||
323 | if (m_confAttrRed)
| 0 | ||||||||||||
324 | eglGetConfigAttrib(display(), config, EGL_RED_SIZE, &red); never executed: eglGetConfigAttrib(display(), config, 0x3024, &red); | 0 | ||||||||||||
325 | if (m_confAttrGreen)
| 0 | ||||||||||||
326 | eglGetConfigAttrib(display(), config, EGL_GREEN_SIZE, &green); never executed: eglGetConfigAttrib(display(), config, 0x3023, &green); | 0 | ||||||||||||
327 | if (m_confAttrBlue)
| 0 | ||||||||||||
328 | eglGetConfigAttrib(display(), config, EGL_BLUE_SIZE, &blue); never executed: eglGetConfigAttrib(display(), config, 0x3022, &blue); | 0 | ||||||||||||
329 | if (m_confAttrAlpha)
| 0 | ||||||||||||
330 | eglGetConfigAttrib(display(), config, EGL_ALPHA_SIZE, &alpha); never executed: eglGetConfigAttrib(display(), config, 0x3021, &alpha); | 0 | ||||||||||||
331 | - | |||||||||||||
332 | return red == m_confAttrRed && green == m_confAttrGreen never executed: return red == m_confAttrRed && green == m_confAttrGreen && blue == m_confAttrBlue && alpha == m_confAttrAlpha;
| 0 | ||||||||||||
333 | && blue == m_confAttrBlue && alpha == m_confAttrAlpha; never executed: return red == m_confAttrRed && green == m_confAttrGreen && blue == m_confAttrBlue && alpha == m_confAttrAlpha;
| 0 | ||||||||||||
334 | } | - | ||||||||||||
335 | - | |||||||||||||
336 | EGLConfig q_configFromGLFormat(EGLDisplay display, const QSurfaceFormat &format, bool highestPixelFormat, int surfaceType) | - | ||||||||||||
337 | { | - | ||||||||||||
338 | QEglConfigChooser chooser(display); | - | ||||||||||||
339 | chooser.setSurfaceFormat(format); | - | ||||||||||||
340 | chooser.setSurfaceType(surfaceType); | - | ||||||||||||
341 | chooser.setIgnoreColorChannels(highestPixelFormat); | - | ||||||||||||
342 | - | |||||||||||||
343 | return chooser.chooseConfig(); never executed: return chooser.chooseConfig(); | 0 | ||||||||||||
344 | } | - | ||||||||||||
345 | - | |||||||||||||
346 | QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config, const QSurfaceFormat &referenceFormat) | - | ||||||||||||
347 | { | - | ||||||||||||
348 | QSurfaceFormat format; | - | ||||||||||||
349 | EGLint redSize = 0; | - | ||||||||||||
350 | EGLint greenSize = 0; | - | ||||||||||||
351 | EGLint blueSize = 0; | - | ||||||||||||
352 | EGLint alphaSize = 0; | - | ||||||||||||
353 | EGLint depthSize = 0; | - | ||||||||||||
354 | EGLint stencilSize = 0; | - | ||||||||||||
355 | EGLint sampleCount = 0; | - | ||||||||||||
356 | EGLint renderableType = 0; | - | ||||||||||||
357 | - | |||||||||||||
358 | eglGetConfigAttrib(display, config, EGL_RED_SIZE, &redSize); | - | ||||||||||||
359 | eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &greenSize); | - | ||||||||||||
360 | eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blueSize); | - | ||||||||||||
361 | eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alphaSize); | - | ||||||||||||
362 | eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &depthSize); | - | ||||||||||||
363 | eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencilSize); | - | ||||||||||||
364 | eglGetConfigAttrib(display, config, EGL_SAMPLES, &sampleCount); | - | ||||||||||||
365 | eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType); | - | ||||||||||||
366 | - | |||||||||||||
367 | if (referenceFormat.renderableType() == QSurfaceFormat::OpenVG && (renderableType & EGL_OPENVG_BIT))
| 0 | ||||||||||||
368 | format.setRenderableType(QSurfaceFormat::OpenVG); never executed: format.setRenderableType(QSurfaceFormat::OpenVG); | 0 | ||||||||||||
369 | #ifdef EGL_VERSION_1_4 | - | ||||||||||||
370 | else if (referenceFormat.renderableType() == QSurfaceFormat::OpenGL
| 0 | ||||||||||||
371 | && (renderableType & EGL_OPENGL_BIT))
| 0 | ||||||||||||
372 | format.setRenderableType(QSurfaceFormat::OpenGL); never executed: format.setRenderableType(QSurfaceFormat::OpenGL); | 0 | ||||||||||||
373 | else if (referenceFormat.renderableType() == QSurfaceFormat::DefaultRenderableType
| 0 | ||||||||||||
374 | #ifndef QT_NO_OPENGL | - | ||||||||||||
375 | && QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL
| 0 | ||||||||||||
376 | #endif | - | ||||||||||||
377 | && (renderableType & EGL_OPENGL_BIT))
| 0 | ||||||||||||
378 | format.setRenderableType(QSurfaceFormat::OpenGL); never executed: format.setRenderableType(QSurfaceFormat::OpenGL); | 0 | ||||||||||||
379 | #endif | - | ||||||||||||
380 | else | - | ||||||||||||
381 | format.setRenderableType(QSurfaceFormat::OpenGLES); never executed: format.setRenderableType(QSurfaceFormat::OpenGLES); | 0 | ||||||||||||
382 | - | |||||||||||||
383 | format.setRedBufferSize(redSize); | - | ||||||||||||
384 | format.setGreenBufferSize(greenSize); | - | ||||||||||||
385 | format.setBlueBufferSize(blueSize); | - | ||||||||||||
386 | format.setAlphaBufferSize(alphaSize); | - | ||||||||||||
387 | format.setDepthBufferSize(depthSize); | - | ||||||||||||
388 | format.setStencilBufferSize(stencilSize); | - | ||||||||||||
389 | format.setSamples(sampleCount); | - | ||||||||||||
390 | format.setStereo(false); // EGL doesn't support stereo buffers | - | ||||||||||||
391 | format.setSwapInterval(referenceFormat.swapInterval()); | - | ||||||||||||
392 | - | |||||||||||||
393 | // Clear the EGL error state because some of the above may | - | ||||||||||||
394 | // have errored out because the attribute is not applicable | - | ||||||||||||
395 | // to the surface type. Such errors don't matter. | - | ||||||||||||
396 | eglGetError(); | - | ||||||||||||
397 | - | |||||||||||||
398 | return format; never executed: return format; | 0 | ||||||||||||
399 | } | - | ||||||||||||
400 | - | |||||||||||||
401 | bool q_hasEglExtension(EGLDisplay display, const char* extensionName) | - | ||||||||||||
402 | { | - | ||||||||||||
403 | QList<QByteArray> extensions = | - | ||||||||||||
404 | QByteArray(reinterpret_cast<const char *> | - | ||||||||||||
405 | (eglQueryString(display, EGL_EXTENSIONS))).split(' '); | - | ||||||||||||
406 | return extensions.contains(extensionName); never executed: return extensions.contains(extensionName); | 0 | ||||||||||||
407 | } | - | ||||||||||||
408 | - | |||||||||||||
409 | struct AttrInfo { EGLint attr; const char *name; }; | - | ||||||||||||
410 | static struct AttrInfo attrs[] = { | - | ||||||||||||
411 | {EGL_BUFFER_SIZE, "EGL_BUFFER_SIZE"}, | - | ||||||||||||
412 | {EGL_ALPHA_SIZE, "EGL_ALPHA_SIZE"}, | - | ||||||||||||
413 | {EGL_BLUE_SIZE, "EGL_BLUE_SIZE"}, | - | ||||||||||||
414 | {EGL_GREEN_SIZE, "EGL_GREEN_SIZE"}, | - | ||||||||||||
415 | {EGL_RED_SIZE, "EGL_RED_SIZE"}, | - | ||||||||||||
416 | {EGL_DEPTH_SIZE, "EGL_DEPTH_SIZE"}, | - | ||||||||||||
417 | {EGL_STENCIL_SIZE, "EGL_STENCIL_SIZE"}, | - | ||||||||||||
418 | {EGL_CONFIG_CAVEAT, "EGL_CONFIG_CAVEAT"}, | - | ||||||||||||
419 | {EGL_CONFIG_ID, "EGL_CONFIG_ID"}, | - | ||||||||||||
420 | {EGL_LEVEL, "EGL_LEVEL"}, | - | ||||||||||||
421 | {EGL_MAX_PBUFFER_HEIGHT, "EGL_MAX_PBUFFER_HEIGHT"}, | - | ||||||||||||
422 | {EGL_MAX_PBUFFER_PIXELS, "EGL_MAX_PBUFFER_PIXELS"}, | - | ||||||||||||
423 | {EGL_MAX_PBUFFER_WIDTH, "EGL_MAX_PBUFFER_WIDTH"}, | - | ||||||||||||
424 | {EGL_NATIVE_RENDERABLE, "EGL_NATIVE_RENDERABLE"}, | - | ||||||||||||
425 | {EGL_NATIVE_VISUAL_ID, "EGL_NATIVE_VISUAL_ID"}, | - | ||||||||||||
426 | {EGL_NATIVE_VISUAL_TYPE, "EGL_NATIVE_VISUAL_TYPE"}, | - | ||||||||||||
427 | {EGL_SAMPLES, "EGL_SAMPLES"}, | - | ||||||||||||
428 | {EGL_SAMPLE_BUFFERS, "EGL_SAMPLE_BUFFERS"}, | - | ||||||||||||
429 | {EGL_SURFACE_TYPE, "EGL_SURFACE_TYPE"}, | - | ||||||||||||
430 | {EGL_TRANSPARENT_TYPE, "EGL_TRANSPARENT_TYPE"}, | - | ||||||||||||
431 | {EGL_TRANSPARENT_BLUE_VALUE, "EGL_TRANSPARENT_BLUE_VALUE"}, | - | ||||||||||||
432 | {EGL_TRANSPARENT_GREEN_VALUE, "EGL_TRANSPARENT_GREEN_VALUE"}, | - | ||||||||||||
433 | {EGL_TRANSPARENT_RED_VALUE, "EGL_TRANSPARENT_RED_VALUE"}, | - | ||||||||||||
434 | {EGL_BIND_TO_TEXTURE_RGB, "EGL_BIND_TO_TEXTURE_RGB"}, | - | ||||||||||||
435 | {EGL_BIND_TO_TEXTURE_RGBA, "EGL_BIND_TO_TEXTURE_RGBA"}, | - | ||||||||||||
436 | {EGL_MIN_SWAP_INTERVAL, "EGL_MIN_SWAP_INTERVAL"}, | - | ||||||||||||
437 | {EGL_MAX_SWAP_INTERVAL, "EGL_MAX_SWAP_INTERVAL"}, | - | ||||||||||||
438 | {-1, 0}}; | - | ||||||||||||
439 | - | |||||||||||||
440 | void q_printEglConfig(EGLDisplay display, EGLConfig config) | - | ||||||||||||
441 | { | - | ||||||||||||
442 | EGLint index; | - | ||||||||||||
443 | for (index = 0; attrs[index].attr != -1; ++index) {
| 0 | ||||||||||||
444 | EGLint value; | - | ||||||||||||
445 | if (eglGetConfigAttrib(display, config, attrs[index].attr, &value)) {
| 0 | ||||||||||||
446 | qDebug("\t%s: %d", attrs[index].name, (int)value); | - | ||||||||||||
447 | } never executed: end of block | 0 | ||||||||||||
448 | } never executed: end of block | 0 | ||||||||||||
449 | } never executed: end of block | 0 | ||||||||||||
450 | - | |||||||||||||
451 | #ifdef Q_OS_UNIX | - | ||||||||||||
452 | - | |||||||||||||
453 | QSizeF q_physicalScreenSizeFromFb(int framebufferDevice, const QSize &screenSize) | - | ||||||||||||
454 | { | - | ||||||||||||
455 | #ifndef Q_OS_LINUX | - | ||||||||||||
456 | Q_UNUSED(framebufferDevice) | - | ||||||||||||
457 | #endif | - | ||||||||||||
458 | const int defaultPhysicalDpi = 100; | - | ||||||||||||
459 | static QSizeF size; | - | ||||||||||||
460 | - | |||||||||||||
461 | if (size.isEmpty()) {
| 0 | ||||||||||||
462 | // Note: in millimeters | - | ||||||||||||
463 | int width = qEnvironmentVariableIntValue("QT_QPA_EGLFS_PHYSICAL_WIDTH"); | - | ||||||||||||
464 | int height = qEnvironmentVariableIntValue("QT_QPA_EGLFS_PHYSICAL_HEIGHT"); | - | ||||||||||||
465 | - | |||||||||||||
466 | if (width && height) {
| 0 | ||||||||||||
467 | size.setWidth(width); | - | ||||||||||||
468 | size.setHeight(height); | - | ||||||||||||
469 | return size; never executed: return size; | 0 | ||||||||||||
470 | } | - | ||||||||||||
471 | - | |||||||||||||
472 | int w = -1; | - | ||||||||||||
473 | int h = -1; | - | ||||||||||||
474 | QSize screenResolution; | - | ||||||||||||
475 | #ifdef Q_OS_LINUX | - | ||||||||||||
476 | struct fb_var_screeninfo vinfo; | - | ||||||||||||
477 | - | |||||||||||||
478 | if (framebufferDevice != -1) {
| 0 | ||||||||||||
479 | if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1) {
| 0 | ||||||||||||
480 | qWarning("eglconvenience: Could not query screen info"); | - | ||||||||||||
481 | } else { never executed: end of block | 0 | ||||||||||||
482 | w = vinfo.width; | - | ||||||||||||
483 | h = vinfo.height; | - | ||||||||||||
484 | screenResolution = QSize(vinfo.xres, vinfo.yres); | - | ||||||||||||
485 | } never executed: end of block | 0 | ||||||||||||
486 | } else | - | ||||||||||||
487 | #endif | - | ||||||||||||
488 | { | - | ||||||||||||
489 | // Use the provided screen size, when available, since some platforms may have their own | - | ||||||||||||
490 | // specific way to query it. Otherwise try querying it from the framebuffer. | - | ||||||||||||
491 | screenResolution = screenSize.isEmpty() ? q_screenSizeFromFb(framebufferDevice) : screenSize;
| 0 | ||||||||||||
492 | } never executed: end of block | 0 | ||||||||||||
493 | - | |||||||||||||
494 | size.setWidth(w <= 0 ? screenResolution.width() * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(w)); | - | ||||||||||||
495 | size.setHeight(h <= 0 ? screenResolution.height() * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(h)); | - | ||||||||||||
496 | - | |||||||||||||
497 | if (w <= 0 || h <= 0)
| 0 | ||||||||||||
498 | qWarning("Unable to query physical screen size, defaulting to %d dpi.\n" never executed: QMessageLogger(__FILE__, 498, __PRETTY_FUNCTION__).warning("Unable to query physical screen size, defaulting to %d dpi.\n" "To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH " "and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).", defaultPhysicalDpi); | 0 | ||||||||||||
499 | "To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH " never executed: QMessageLogger(__FILE__, 498, __PRETTY_FUNCTION__).warning("Unable to query physical screen size, defaulting to %d dpi.\n" "To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH " "and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).", defaultPhysicalDpi); | 0 | ||||||||||||
500 | "and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).", defaultPhysicalDpi); never executed: QMessageLogger(__FILE__, 498, __PRETTY_FUNCTION__).warning("Unable to query physical screen size, defaulting to %d dpi.\n" "To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH " "and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).", defaultPhysicalDpi); | 0 | ||||||||||||
501 | } never executed: end of block | 0 | ||||||||||||
502 | - | |||||||||||||
503 | return size; never executed: return size; | 0 | ||||||||||||
504 | } | - | ||||||||||||
505 | - | |||||||||||||
506 | QSize q_screenSizeFromFb(int framebufferDevice) | - | ||||||||||||
507 | { | - | ||||||||||||
508 | #ifndef Q_OS_LINUX | - | ||||||||||||
509 | Q_UNUSED(framebufferDevice) | - | ||||||||||||
510 | #endif | - | ||||||||||||
511 | const int defaultWidth = 800; | - | ||||||||||||
512 | const int defaultHeight = 600; | - | ||||||||||||
513 | static QSize size; | - | ||||||||||||
514 | - | |||||||||||||
515 | if (size.isEmpty()) {
| 0 | ||||||||||||
516 | int width = qEnvironmentVariableIntValue("QT_QPA_EGLFS_WIDTH"); | - | ||||||||||||
517 | int height = qEnvironmentVariableIntValue("QT_QPA_EGLFS_HEIGHT"); | - | ||||||||||||
518 | - | |||||||||||||
519 | if (width && height) {
| 0 | ||||||||||||
520 | size.setWidth(width); | - | ||||||||||||
521 | size.setHeight(height); | - | ||||||||||||
522 | return size; never executed: return size; | 0 | ||||||||||||
523 | } | - | ||||||||||||
524 | - | |||||||||||||
525 | #ifdef Q_OS_LINUX | - | ||||||||||||
526 | struct fb_var_screeninfo vinfo; | - | ||||||||||||
527 | int xres = -1; | - | ||||||||||||
528 | int yres = -1; | - | ||||||||||||
529 | - | |||||||||||||
530 | if (framebufferDevice != -1) {
| 0 | ||||||||||||
531 | if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1) {
| 0 | ||||||||||||
532 | qWarning("eglconvenience: Could not read screen info"); | - | ||||||||||||
533 | } else { never executed: end of block | 0 | ||||||||||||
534 | xres = vinfo.xres; | - | ||||||||||||
535 | yres = vinfo.yres; | - | ||||||||||||
536 | } never executed: end of block | 0 | ||||||||||||
537 | } | - | ||||||||||||
538 | - | |||||||||||||
539 | size.setWidth(xres <= 0 ? defaultWidth : xres); | - | ||||||||||||
540 | size.setHeight(yres <= 0 ? defaultHeight : yres); | - | ||||||||||||
541 | #else | - | ||||||||||||
542 | size.setWidth(defaultWidth); | - | ||||||||||||
543 | size.setHeight(defaultHeight); | - | ||||||||||||
544 | #endif | - | ||||||||||||
545 | } never executed: end of block | 0 | ||||||||||||
546 | - | |||||||||||||
547 | return size; never executed: return size; | 0 | ||||||||||||
548 | } | - | ||||||||||||
549 | - | |||||||||||||
550 | int q_screenDepthFromFb(int framebufferDevice) | - | ||||||||||||
551 | { | - | ||||||||||||
552 | #ifndef Q_OS_LINUX | - | ||||||||||||
553 | Q_UNUSED(framebufferDevice) | - | ||||||||||||
554 | #endif | - | ||||||||||||
555 | const int defaultDepth = 32; | - | ||||||||||||
556 | static int depth = qEnvironmentVariableIntValue("QT_QPA_EGLFS_DEPTH"); | - | ||||||||||||
557 | - | |||||||||||||
558 | if (depth == 0) {
| 0 | ||||||||||||
559 | #ifdef Q_OS_LINUX | - | ||||||||||||
560 | struct fb_var_screeninfo vinfo; | - | ||||||||||||
561 | - | |||||||||||||
562 | if (framebufferDevice != -1) {
| 0 | ||||||||||||
563 | if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1)
| 0 | ||||||||||||
564 | qWarning("eglconvenience: Could not query screen info"); never executed: QMessageLogger(__FILE__, 564, __PRETTY_FUNCTION__).warning("eglconvenience: Could not query screen info"); | 0 | ||||||||||||
565 | else | - | ||||||||||||
566 | depth = vinfo.bits_per_pixel; never executed: depth = vinfo.bits_per_pixel; | 0 | ||||||||||||
567 | } | - | ||||||||||||
568 | - | |||||||||||||
569 | if (depth <= 0)
| 0 | ||||||||||||
570 | depth = defaultDepth; never executed: depth = defaultDepth; | 0 | ||||||||||||
571 | #else | - | ||||||||||||
572 | depth = defaultDepth; | - | ||||||||||||
573 | #endif | - | ||||||||||||
574 | } never executed: end of block | 0 | ||||||||||||
575 | - | |||||||||||||
576 | return depth; never executed: return depth; | 0 | ||||||||||||
577 | } | - | ||||||||||||
578 | - | |||||||||||||
579 | qreal q_refreshRateFromFb(int framebufferDevice) | - | ||||||||||||
580 | { | - | ||||||||||||
581 | #ifndef Q_OS_LINUX | - | ||||||||||||
582 | Q_UNUSED(framebufferDevice) | - | ||||||||||||
583 | #endif | - | ||||||||||||
584 | - | |||||||||||||
585 | static qreal rate = 0; | - | ||||||||||||
586 | - | |||||||||||||
587 | #ifdef Q_OS_LINUX | - | ||||||||||||
588 | if (rate == 0) {
| 0 | ||||||||||||
589 | if (framebufferDevice != -1) {
| 0 | ||||||||||||
590 | struct fb_var_screeninfo vinfo; | - | ||||||||||||
591 | if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) != -1) {
| 0 | ||||||||||||
592 | const quint64 quot = quint64(vinfo.left_margin + vinfo.right_margin + vinfo.xres + vinfo.hsync_len) | - | ||||||||||||
593 | * quint64(vinfo.upper_margin + vinfo.lower_margin + vinfo.yres + vinfo.vsync_len) | - | ||||||||||||
594 | * vinfo.pixclock; | - | ||||||||||||
595 | if (quot)
| 0 | ||||||||||||
596 | rate = 1000000000000LLU / quot; never executed: rate = 1000000000000LLU / quot; | 0 | ||||||||||||
597 | } else { never executed: end of block | 0 | ||||||||||||
598 | qWarning("eglconvenience: Could not query screen info"); | - | ||||||||||||
599 | } never executed: end of block | 0 | ||||||||||||
600 | } | - | ||||||||||||
601 | } never executed: end of block | 0 | ||||||||||||
602 | #endif | - | ||||||||||||
603 | - | |||||||||||||
604 | if (rate == 0)
| 0 | ||||||||||||
605 | rate = 60; never executed: rate = 60; | 0 | ||||||||||||
606 | - | |||||||||||||
607 | return rate; never executed: return rate; | 0 | ||||||||||||
608 | } | - | ||||||||||||
609 | - | |||||||||||||
610 | #endif // Q_OS_UNIX | - | ||||||||||||
611 | - | |||||||||||||
612 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |