Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include <QByteArray> | - |
41 | #include <QOpenGLContext> | - |
42 | | - |
43 | #ifdef Q_OS_LINUX | - |
44 | #include <sys/ioctl.h> | - |
45 | #include <linux/fb.h> | - |
46 | #endif | - |
47 | #include <private/qmath_p.h> | - |
48 | | - |
49 | #include "qeglconvenience_p.h" | - |
50 | | - |
51 | #ifndef EGL_OPENGL_ES3_BIT_KHR | - |
52 | #define EGL_OPENGL_ES3_BIT_KHR 0x0040 | - |
53 | #endif | - |
54 | | - |
55 | QT_BEGIN_NAMESPACE | - |
56 | | - |
57 | QVector<EGLint> q_createConfigAttributesFromFormat(const QSurfaceFormat &format) | - |
58 | { | - |
59 | int redSize = format.redBufferSize(); | - |
60 | int greenSize = format.greenBufferSize(); | - |
61 | int blueSize = format.blueBufferSize(); | - |
62 | int alphaSize = format.alphaBufferSize(); | - |
63 | int depthSize = format.depthBufferSize(); | - |
64 | int stencilSize = format.stencilBufferSize(); | - |
65 | int sampleCount = format.samples(); | - |
66 | | - |
67 | QVector<EGLint> configAttributes; | - |
68 | | - |
69 | | - |
70 | | - |
71 | | - |
72 | | - |
73 | | - |
74 | | - |
75 | | - |
76 | | - |
77 | | - |
78 | | - |
79 | | - |
80 | | - |
81 | | - |
82 | | - |
83 | | - |
84 | | - |
85 | | - |
86 | | - |
87 | | - |
88 | | - |
89 | | - |
90 | | - |
91 | configAttributes.append(EGL_RED_SIZE); | - |
92 | configAttributes.append(redSize > 0 ? redSize : 0); | - |
93 | | - |
94 | configAttributes.append(EGL_GREEN_SIZE); | - |
95 | configAttributes.append(greenSize > 0 ? greenSize : 0); | - |
96 | | - |
97 | configAttributes.append(EGL_BLUE_SIZE); | - |
98 | configAttributes.append(blueSize > 0 ? blueSize : 0); | - |
99 | | - |
100 | configAttributes.append(EGL_ALPHA_SIZE); | - |
101 | configAttributes.append(alphaSize > 0 ? alphaSize : 0); | - |
102 | | - |
103 | configAttributes.append(EGL_DEPTH_SIZE); | - |
104 | configAttributes.append(depthSize > 0 ? depthSize : 0); | - |
105 | | - |
106 | configAttributes.append(EGL_STENCIL_SIZE); | - |
107 | configAttributes.append(stencilSize > 0 ? stencilSize : 0); | - |
108 | | - |
109 | configAttributes.append(EGL_SAMPLES); | - |
110 | configAttributes.append(sampleCount > 0 ? sampleCount : 0); | - |
111 | | - |
112 | configAttributes.append(EGL_SAMPLE_BUFFERS); | - |
113 | configAttributes.append(sampleCount > 0); | - |
114 | | - |
115 | return configAttributes; | - |
116 | } | - |
117 | | - |
118 | bool q_reduceConfigAttributes(QVector<EGLint> *configAttributes) | - |
119 | { | - |
120 | int i = -1; | - |
121 | | - |
122 | | - |
123 | | - |
124 | | - |
125 | | - |
126 | i = configAttributes->indexOf(EGL_SWAP_BEHAVIOR); | - |
127 | if (i >= 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
128 | configAttributes->remove(i,2); | - |
129 | } never executed: end of block | 0 |
130 | | - |
131 | #ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT | - |
132 | | - |
133 | | - |
134 | | - |
135 | i = configAttributes->indexOf(EGL_SURFACE_TYPE); | - |
136 | if (i >= 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
137 | EGLint surfaceType = configAttributes->at(i +1); | - |
138 | if (surfaceType & EGL_VG_ALPHA_FORMAT_PRE_BIT) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
139 | surfaceType ^= EGL_VG_ALPHA_FORMAT_PRE_BIT; | - |
140 | configAttributes->replace(i+1,surfaceType); | - |
141 | return true; never executed: return true; | 0 |
142 | } | - |
143 | } never executed: end of block | 0 |
144 | #endif | - |
145 | | - |
146 | | - |
147 | | - |
148 | | - |
149 | | - |
150 | | - |
151 | i = configAttributes->indexOf(EGL_BUFFER_SIZE); | - |
152 | if (i >= 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
153 | if (configAttributes->at(i+1) == 16) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
154 | configAttributes->remove(i,2); | - |
155 | return true; never executed: return true; | 0 |
156 | } | - |
157 | } never executed: end of block | 0 |
158 | | - |
159 | i = configAttributes->indexOf(EGL_SAMPLES); | - |
160 | if (i >= 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
161 | EGLint value = configAttributes->value(i+1, 0); | - |
162 | if (value > 1)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
163 | configAttributes->replace(i+1, qMin(EGLint(16), value / 2)); never executed: configAttributes->replace(i+1, qMin(EGLint(16), value / 2)); | 0 |
164 | else | - |
165 | configAttributes->remove(i, 2); never executed: configAttributes->remove(i, 2); | 0 |
166 | return true; never executed: return true; | 0 |
167 | } | - |
168 | | - |
169 | i = configAttributes->indexOf(EGL_SAMPLE_BUFFERS); | - |
170 | if (i >= 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
171 | configAttributes->remove(i,2); | - |
172 | return true; never executed: return true; | 0 |
173 | } | - |
174 | | - |
175 | i = configAttributes->indexOf(EGL_ALPHA_SIZEEGL_DEPTH_SIZE); | - |
176 | if (i >= 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
177 | if (configAttributes->removeat(i ,2);TRUE | never evaluated | FALSE | never evaluated |
| 0 |
| #if defined(EGL_BIND_TO_TEXTURE_RGBATRUE | never evaluated | FALSE | never evaluated |
+ 1) && defined(EGL_BIND_TO_TEXTURE_RGB>= 32)TRUE | never evaluated | FALSE | never evaluated |
| |
178 | i =configAttributes->indexOfreplace(EGL_BIND_TO_TEXTURE_RGBAi + 1, 24); never executed: configAttributes->replace(i + 1, 24); | 0 |
179 | else if (configAttributes->at(i >= 0+ 1) {> 1)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
180 | configAttributes->replace(i + 1, EGL_BIND_TO_TEXTURE_RGB1); never executed: configAttributes->replace(i + 1, 1); | 0 |
181 | else | - |
182 | configAttributes->replaceremove(i+1, true2); never executed: configAttributes->remove(i, 2); | 0 |
183 | } never executed: return true; | 0 |
| #endif never executed: return true; return true;never executed: return true; | |
184 | } | - |
185 | | - |
186 | i = configAttributes->indexOf(EGL_STENCIL_SIZEEGL_ALPHA_SIZE); | - |
187 | if (i >= 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
188 | if (configAttributes->atremove(i+ 1,2); | - |
189 | #if defined(EGL_BIND_TO_TEXTURE_RGBA) > 1&& defined(EGL_BIND_TO_TEXTURE_RGB) | - |
190 | i = configAttributes->indexOf(EGL_BIND_TO_TEXTURE_RGBA); | - |
191 | if (i >= 0TRUE | never evaluated | FALSE | never evaluated |
) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
192 | configAttributes->replace(i+ 1,1EGL_BIND_TO_TEXTURE_RGB); | - |
193 | elseconfigAttributes->removereplace(i+1,2true); | - |
194 | | - |
195 | } never executed: end of block | 0 |
196 | #endif | - |
197 | return true; never executed: return true; | 0 |
198 | } | - |
199 | | - |
200 | i = configAttributes->indexOf(EGL_DEPTH_SIZEEGL_STENCIL_SIZE); | - |
201 | if (i >= 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
202 | if (configAttributes->at(i + 1) > 1)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
203 | configAttributes->replace(i + 1, 1); never executed: configAttributes->replace(i + 1, 1); | 0 |
204 | else | - |
205 | configAttributes->remove(i, 2); never executed: configAttributes->remove(i, 2); | 0 |
206 | return true; never executed: return true; | 0 |
207 | } | - |
208 | | - |
209 | #ifdef EGL_BIND_TO_TEXTURE_RGB | - |
210 | i = configAttributes->indexOf(EGL_BIND_TO_TEXTURE_RGB); | - |
211 | if (i >= 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
212 | configAttributes->remove(i,2); | - |
213 | return true; never executed: return true; | 0 |
214 | } | - |
215 | #endif | - |
216 | | - |
217 | return false; never executed: return false; | 0 |
218 | } | - |
219 | | - |
220 | QEglConfigChooser::QEglConfigChooser(EGLDisplay display) | - |
221 | : m_display(display) | - |
222 | , m_surfaceType(EGL_WINDOW_BIT) | - |
223 | , m_ignore(false) | - |
224 | , m_confAttrRed(0) | - |
225 | , m_confAttrGreen(0) | - |
226 | , m_confAttrBlue(0) | - |
227 | , m_confAttrAlpha(0) | - |
228 | { | - |
229 | } | - |
230 | | - |
231 | QEglConfigChooser::~QEglConfigChooser() | - |
232 | { | - |
233 | } | - |
234 | | - |
235 | EGLConfig QEglConfigChooser::chooseConfig() | - |
236 | { | - |
237 | QVector<EGLint> configureAttributes = q_createConfigAttributesFromFormat(m_format); | - |
238 | configureAttributes.append(EGL_SURFACE_TYPE); | - |
239 | configureAttributes.append(surfaceType()); | - |
240 | | - |
241 | configureAttributes.append(EGL_RENDERABLE_TYPE); | - |
242 | bool needsES2Plus = false; | - |
243 | switch (m_format.renderableType()) { | - |
244 | case QSurfaceFormat::OpenVG: | - |
245 | configureAttributes.append(EGL_OPENVG_BIT); | - |
246 | break; | - |
247 | #ifdef EGL_VERSION_1_4 | - |
248 | case QSurfaceFormat::DefaultRenderableType: | - |
249 | #ifndef QT_NO_OPENGL | - |
250 | if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) | - |
251 | configureAttributes.append(EGL_OPENGL_BIT); | - |
252 | else | - |
253 | #endif // QT_NO_OPENGL | - |
254 | needsES2Plus = true; | - |
255 | break; | - |
256 | case QSurfaceFormat::OpenGL: | - |
257 | configureAttributes.append(EGL_OPENGL_BIT); | - |
258 | break; | - |
259 | #endif | - |
260 | case QSurfaceFormat::OpenGLES: | - |
261 | if (m_format.majorVersion() == 1) { | - |
262 | configureAttributes.append(EGL_OPENGL_ES_BIT); | - |
263 | break; | - |
264 | } | - |
265 | | - |
266 | default: | - |
267 | needsES2Plus = true; | - |
268 | break; | - |
269 | } | - |
270 | if (needsES2Plus) { | - |
271 | if (m_format.majorVersion() >= 3 && q_hasEglExtension(display(), "EGL_KHR_create_context")) | - |
272 | configureAttributes.append(EGL_OPENGL_ES3_BIT_KHR); | - |
273 | else | - |
274 | configureAttributes.append(EGL_OPENGL_ES2_BIT); | - |
275 | } | - |
276 | configureAttributes.append(EGL_NONE); | - |
277 | | - |
278 | EGLConfig cfg = 0; | - |
279 | do { | - |
280 | | - |
281 | EGLint matching = 0; | - |
282 | if (!eglChooseConfig(display(), configureAttributes.constData(), 0, 0, &matching) || !matching) | - |
283 | continue; | - |
284 | | - |
285 | | - |
286 | | - |
287 | int i = configureAttributes.indexOf(EGL_RED_SIZE); | - |
288 | m_confAttrRed = configureAttributes.at(i+1); | - |
289 | i = configureAttributes.indexOf(EGL_GREEN_SIZE); | - |
290 | m_confAttrGreen = configureAttributes.at(i+1); | - |
291 | i = configureAttributes.indexOf(EGL_BLUE_SIZE); | - |
292 | m_confAttrBlue = configureAttributes.at(i+1); | - |
293 | i = configureAttributes.indexOf(EGL_ALPHA_SIZE); | - |
294 | m_confAttrAlpha = i == -1 ? 0 : configureAttributes.at(i+1); | - |
295 | | - |
296 | QVector<EGLConfig> configs(matching); | - |
297 | eglChooseConfig(display(), configureAttributes.constData(), configs.data(), configs.size(), &matching); | - |
298 | if (!cfg && matching > 0) | - |
299 | cfg = configs.first(); | - |
300 | | - |
301 | | - |
302 | | - |
303 | | - |
304 | | - |
305 | | - |
306 | | - |
307 | | - |
308 | for (int i = 0; i < configs.size(); ++i) { | - |
309 | if (filterConfig(configs[i])) | - |
310 | return configs.at(i); | - |
311 | } | - |
312 | } while (q_reduceConfigAttributes(&configureAttributes)); | - |
313 | | - |
314 | if (!cfg) | - |
315 | qWarning("Cannot find EGLConfig, returning null config"); | - |
316 | return cfg; | - |
317 | } | - |
318 | | - |
319 | bool QEglConfigChooser::filterConfig(EGLConfig config) const | - |
320 | { | - |
321 | | - |
322 | | - |
323 | if (m_ignore) | - |
324 | return true; | - |
325 | | - |
326 | EGLint red = 0; | - |
327 | EGLint green = 0; | - |
328 | EGLint blue = 0; | - |
329 | EGLint alpha = 0; | - |
330 | | - |
331 | | - |
332 | if (m_confAttrRed) | - |
333 | eglGetConfigAttrib(display(), config, EGL_RED_SIZE, &red); | - |
334 | if (m_confAttrGreen) | - |
335 | eglGetConfigAttrib(display(), config, EGL_GREEN_SIZE, &green); | - |
336 | if (m_confAttrBlue) | - |
337 | eglGetConfigAttrib(display(), config, EGL_BLUE_SIZE, &blue); | - |
338 | if (m_confAttrAlpha) | - |
339 | eglGetConfigAttrib(display(), config, EGL_ALPHA_SIZE, &alpha); | - |
340 | | - |
341 | return red == m_confAttrRed && green == m_confAttrGreen | - |
342 | && blue == m_confAttrBlue && alpha == m_confAttrAlpha; | - |
343 | } | - |
344 | | - |
345 | EGLConfig q_configFromGLFormat(EGLDisplay display, const QSurfaceFormat &format, bool highestPixelFormat, int surfaceType) | - |
346 | { | - |
347 | QEglConfigChooser chooser(display); | - |
348 | chooser.setSurfaceFormat(format); | - |
349 | chooser.setSurfaceType(surfaceType); | - |
350 | chooser.setIgnoreColorChannels(highestPixelFormat); | - |
351 | | - |
352 | return chooser.chooseConfig(); | - |
353 | } | - |
354 | | - |
355 | QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config, const QSurfaceFormat &referenceFormat) | - |
356 | { | - |
357 | QSurfaceFormat format; | - |
358 | EGLint redSize = 0; | - |
359 | EGLint greenSize = 0; | - |
360 | EGLint blueSize = 0; | - |
361 | EGLint alphaSize = 0; | - |
362 | EGLint depthSize = 0; | - |
363 | EGLint stencilSize = 0; | - |
364 | EGLint sampleCount = 0; | - |
365 | EGLint renderableType = 0; | - |
366 | | - |
367 | eglGetConfigAttrib(display, config, EGL_RED_SIZE, &redSize); | - |
368 | eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &greenSize); | - |
369 | eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blueSize); | - |
370 | eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alphaSize); | - |
371 | eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &depthSize); | - |
372 | eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencilSize); | - |
373 | eglGetConfigAttrib(display, config, EGL_SAMPLES, &sampleCount); | - |
374 | eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType); | - |
375 | | - |
376 | if (referenceFormat.renderableType() == QSurfaceFormat::OpenVG && (renderableType & EGL_OPENVG_BIT)) | - |
377 | format.setRenderableType(QSurfaceFormat::OpenVG); | - |
378 | #ifdef EGL_VERSION_1_4 | - |
379 | else if (referenceFormat.renderableType() == QSurfaceFormat::OpenGL | - |
380 | && (renderableType & EGL_OPENGL_BIT)) | - |
381 | format.setRenderableType(QSurfaceFormat::OpenGL); | - |
382 | else if (referenceFormat.renderableType() == QSurfaceFormat::DefaultRenderableType | - |
383 | #ifndef QT_NO_OPENGL | - |
384 | && QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL | - |
385 | #endif | - |
386 | && (renderableType & EGL_OPENGL_BIT)) | - |
387 | format.setRenderableType(QSurfaceFormat::OpenGL); | - |
388 | #endif | - |
389 | else | - |
390 | format.setRenderableType(QSurfaceFormat::OpenGLES); | - |
391 | | - |
392 | format.setRedBufferSize(redSize); | - |
393 | format.setGreenBufferSize(greenSize); | - |
394 | format.setBlueBufferSize(blueSize); | - |
395 | format.setAlphaBufferSize(alphaSize); | - |
396 | format.setDepthBufferSize(depthSize); | - |
397 | format.setStencilBufferSize(stencilSize); | - |
398 | format.setSamples(sampleCount); | - |
399 | format.setStereo(false); | - |
400 | format.setSwapInterval(referenceFormat.swapInterval()); | - |
401 | | - |
402 | | - |
403 | | - |
404 | | - |
405 | eglGetError(); | - |
406 | | - |
407 | return format; | - |
408 | } | - |
409 | | - |
410 | bool q_hasEglExtension(EGLDisplay display, const char* extensionName) | - |
411 | { | - |
412 | QList<QByteArray> extensions = | - |
413 | QByteArray(reinterpret_cast<const char *> | - |
414 | (eglQueryString(display, EGL_EXTENSIONS))).split(' '); | - |
415 | return extensions.contains(extensionName); | - |
416 | } | - |
417 | | - |
418 | struct AttrInfo { EGLint attr; const char *name; }; | - |
419 | static struct AttrInfo attrs[] = { | - |
420 | {EGL_BUFFER_SIZE, "EGL_BUFFER_SIZE"}, | - |
421 | {EGL_ALPHA_SIZE, "EGL_ALPHA_SIZE"}, | - |
422 | {EGL_BLUE_SIZE, "EGL_BLUE_SIZE"}, | - |
423 | {EGL_GREEN_SIZE, "EGL_GREEN_SIZE"}, | - |
424 | {EGL_RED_SIZE, "EGL_RED_SIZE"}, | - |
425 | {EGL_DEPTH_SIZE, "EGL_DEPTH_SIZE"}, | - |
426 | {EGL_STENCIL_SIZE, "EGL_STENCIL_SIZE"}, | - |
427 | {EGL_CONFIG_CAVEAT, "EGL_CONFIG_CAVEAT"}, | - |
428 | {EGL_CONFIG_ID, "EGL_CONFIG_ID"}, | - |
429 | {EGL_LEVEL, "EGL_LEVEL"}, | - |
430 | {EGL_MAX_PBUFFER_HEIGHT, "EGL_MAX_PBUFFER_HEIGHT"}, | - |
431 | {EGL_MAX_PBUFFER_PIXELS, "EGL_MAX_PBUFFER_PIXELS"}, | - |
432 | {EGL_MAX_PBUFFER_WIDTH, "EGL_MAX_PBUFFER_WIDTH"}, | - |
433 | {EGL_NATIVE_RENDERABLE, "EGL_NATIVE_RENDERABLE"}, | - |
434 | {EGL_NATIVE_VISUAL_ID, "EGL_NATIVE_VISUAL_ID"}, | - |
435 | {EGL_NATIVE_VISUAL_TYPE, "EGL_NATIVE_VISUAL_TYPE"}, | - |
436 | {EGL_SAMPLES, "EGL_SAMPLES"}, | - |
437 | {EGL_SAMPLE_BUFFERS, "EGL_SAMPLE_BUFFERS"}, | - |
438 | {EGL_SURFACE_TYPE, "EGL_SURFACE_TYPE"}, | - |
439 | {EGL_TRANSPARENT_TYPE, "EGL_TRANSPARENT_TYPE"}, | - |
440 | {EGL_TRANSPARENT_BLUE_VALUE, "EGL_TRANSPARENT_BLUE_VALUE"}, | - |
441 | {EGL_TRANSPARENT_GREEN_VALUE, "EGL_TRANSPARENT_GREEN_VALUE"}, | - |
442 | {EGL_TRANSPARENT_RED_VALUE, "EGL_TRANSPARENT_RED_VALUE"}, | - |
443 | {EGL_BIND_TO_TEXTURE_RGB, "EGL_BIND_TO_TEXTURE_RGB"}, | - |
444 | {EGL_BIND_TO_TEXTURE_RGBA, "EGL_BIND_TO_TEXTURE_RGBA"}, | - |
445 | {EGL_MIN_SWAP_INTERVAL, "EGL_MIN_SWAP_INTERVAL"}, | - |
446 | {EGL_MAX_SWAP_INTERVAL, "EGL_MAX_SWAP_INTERVAL"}, | - |
447 | {-1, 0}}; | - |
448 | | - |
449 | void q_printEglConfig(EGLDisplay display, EGLConfig config) | - |
450 | { | - |
451 | EGLint index; | - |
452 | for (index = 0; attrs[index].attr != -1; ++index) { | - |
453 | EGLint value; | - |
454 | if (eglGetConfigAttrib(display, config, attrs[index].attr, &value)) { | - |
455 | qDebug("\t%s: %d", attrs[index].name, (int)value); | - |
456 | } | - |
457 | } | - |
458 | } | - |
459 | | - |
460 | #ifdef Q_OS_UNIX | - |
461 | | - |
462 | QSizeF q_physicalScreenSizeFromFb(int framebufferDevice, const QSize &screenSize) | - |
463 | { | - |
464 | #ifndef Q_OS_LINUX | - |
465 | Q_UNUSED(framebufferDevice) | - |
466 | #endif | - |
467 | const int defaultPhysicalDpi = 100; | - |
468 | static QSizeF size; | - |
469 | | - |
470 | if (size.isEmpty()) { | - |
471 | | - |
472 | int width = qEnvironmentVariableIntValue("QT_QPA_EGLFS_PHYSICAL_WIDTH"); | - |
473 | int height = qEnvironmentVariableIntValue("QT_QPA_EGLFS_PHYSICAL_HEIGHT"); | - |
474 | | - |
475 | if (width && height) { | - |
476 | size.setWidth(width); | - |
477 | size.setHeight(height); | - |
478 | return size; | - |
479 | } | - |
480 | | - |
481 | int w = -1; | - |
482 | int h = -1; | - |
483 | QSize screenResolution; | - |
484 | #ifdef Q_OS_LINUX | - |
485 | struct fb_var_screeninfo vinfo; | - |
486 | | - |
487 | if (framebufferDevice != -1) { | - |
488 | if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1) { | - |
489 | qWarning("eglconvenience: Could not query screen info"); | - |
490 | } else { | - |
491 | w = vinfo.width; | - |
492 | h = vinfo.height; | - |
493 | screenResolution = QSize(vinfo.xres, vinfo.yres); | - |
494 | } | - |
495 | } else | - |
496 | #endif | - |
497 | { | - |
498 | | - |
499 | | - |
500 | screenResolution = screenSize.isEmpty() ? q_screenSizeFromFb(framebufferDevice) : screenSize; | - |
501 | } | - |
502 | | - |
503 | size.setWidth(w <= 0 ? screenResolution.width() * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(w)); | - |
504 | size.setHeight(h <= 0 ? screenResolution.height() * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(h)); | - |
505 | | - |
506 | if (w <= 0 || h <= 0) | - |
507 | qWarning("Unable to query physical screen size, defaulting to %d dpi.\n" | - |
508 | "To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH " | - |
509 | "and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).", defaultPhysicalDpi); | - |
510 | } | - |
511 | | - |
512 | return size; | - |
513 | } | - |
514 | | - |
515 | QSize q_screenSizeFromFb(int framebufferDevice) | - |
516 | { | - |
517 | #ifndef Q_OS_LINUX | - |
518 | Q_UNUSED(framebufferDevice) | - |
519 | #endif | - |
520 | const int defaultWidth = 800; | - |
521 | const int defaultHeight = 600; | - |
522 | static QSize size; | - |
523 | | - |
524 | if (size.isEmpty()) { | - |
525 | int width = qEnvironmentVariableIntValue("QT_QPA_EGLFS_WIDTH"); | - |
526 | int height = qEnvironmentVariableIntValue("QT_QPA_EGLFS_HEIGHT"); | - |
527 | | - |
528 | if (width && height) { | - |
529 | size.setWidth(width); | - |
530 | size.setHeight(height); | - |
531 | return size; | - |
532 | } | - |
533 | | - |
534 | #ifdef Q_OS_LINUX | - |
535 | struct fb_var_screeninfo vinfo; | - |
536 | int xres = -1; | - |
537 | int yres = -1; | - |
538 | | - |
539 | if (framebufferDevice != -1) { | - |
540 | if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1) { | - |
541 | qWarning("eglconvenience: Could not read screen info"); | - |
542 | } else { | - |
543 | xres = vinfo.xres; | - |
544 | yres = vinfo.yres; | - |
545 | } | - |
546 | } | - |
547 | | - |
548 | size.setWidth(xres <= 0 ? defaultWidth : xres); | - |
549 | size.setHeight(yres <= 0 ? defaultHeight : yres); | - |
550 | #else | - |
551 | size.setWidth(defaultWidth); | - |
552 | size.setHeight(defaultHeight); | - |
553 | #endif | - |
554 | } | - |
555 | | - |
556 | return size; | - |
557 | } | - |
558 | | - |
559 | int q_screenDepthFromFb(int framebufferDevice) | - |
560 | { | - |
561 | #ifndef Q_OS_LINUX | - |
562 | Q_UNUSED(framebufferDevice) | - |
563 | #endif | - |
564 | const int defaultDepth = 32; | - |
565 | static int depth = qEnvironmentVariableIntValue("QT_QPA_EGLFS_DEPTH"); | - |
566 | | - |
567 | if (depth == 0) { | - |
568 | #ifdef Q_OS_LINUX | - |
569 | struct fb_var_screeninfo vinfo; | - |
570 | | - |
571 | if (framebufferDevice != -1) { | - |
572 | if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1) | - |
573 | qWarning("eglconvenience: Could not query screen info"); | - |
574 | else | - |
575 | depth = vinfo.bits_per_pixel; | - |
576 | } | - |
577 | | - |
578 | if (depth <= 0) | - |
579 | depth = defaultDepth; | - |
580 | #else | - |
581 | depth = defaultDepth; | - |
582 | #endif | - |
583 | } | - |
584 | | - |
585 | return depth; | - |
586 | } | - |
587 | | - |
588 | qreal q_refreshRateFromFb(int framebufferDevice) | - |
589 | { | - |
590 | #ifndef Q_OS_LINUX | - |
591 | Q_UNUSED(framebufferDevice) | - |
592 | #endif | - |
593 | | - |
594 | static qreal rate = 0; | - |
595 | | - |
596 | #ifdef Q_OS_LINUX | - |
597 | if (rate == 0) { | - |
598 | if (framebufferDevice != -1) { | - |
599 | struct fb_var_screeninfo vinfo; | - |
600 | if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) != -1) { | - |
601 | const quint64 quot = quint64(vinfo.left_margin + vinfo.right_margin + vinfo.xres + vinfo.hsync_len) | - |
602 | * quint64(vinfo.upper_margin + vinfo.lower_margin + vinfo.yres + vinfo.vsync_len) | - |
603 | * vinfo.pixclock; | - |
604 | if (quot) | - |
605 | rate = 1000000000000LLU / quot; | - |
606 | } else { | - |
607 | qWarning("eglconvenience: Could not query screen info"); | - |
608 | } | - |
609 | } | - |
610 | } | - |
611 | #endif | - |
612 | | - |
613 | if (rate == 0) | - |
614 | rate = 60; | - |
615 | | - |
616 | return rate; | - |
617 | } | - |
618 | | - |
619 | #endif // Q_OS_UNIX | - |
620 | | - |
621 | QT_END_NAMESPACE | - |
| | |