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