qeglplatformcontext.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/eglconvenience/qeglplatformcontext.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9QEGLPlatformContext::QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,-
10 EGLConfig *config, const QVariant &nativeHandle, Flags flags)-
11 : m_eglDisplay(display)-
12 , m_swapInterval(-1)-
13 , m_swapIntervalEnvChecked(false)-
14 , m_swapIntervalFromEnv(-1)-
15 , m_flags(flags)-
16{-
17 if (nativeHandle.isNull()
nativeHandle.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
18 m_eglConfig = config
configDescription
TRUEnever evaluated
FALSEnever evaluated
? *config : q_configFromGLFormat(display, format);
0
19 m_ownsContext = true;-
20 init(format, share);-
21 }
never executed: end of block
else {
0
22 m_ownsContext = false;-
23 adopt(nativeHandle, share);-
24 }
never executed: end of block
0
25}-
26-
27void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLContext *share)-
28{-
29 m_format = q_glFormatFromConfig(m_eglDisplay, m_eglConfig);-
30-
31-
32 m_shareContext = share
shareDescription
TRUEnever evaluated
FALSEnever evaluated
? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 0;
0
33-
34 QVector<EGLint> contextAttrs;-
35 contextAttrs.append(0x3098);-
36 contextAttrs.append(format.majorVersion());-
37 const bool hasKHRCreateContext = q_hasEglExtension(m_eglDisplay, "EGL_KHR_create_context");-
38 if (hasKHRCreateContext
hasKHRCreateContextDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
39 contextAttrs.append(0x30FB);-
40 contextAttrs.append(format.minorVersion());-
41 int flags = 0;-
42-
43 if (format.testOption(QSurfaceFormat::DebugContext)
format.testOpt...:DebugContext)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
44 flags |= 0x00000001;
never executed: flags |= 0x00000001;
0
45-
46 if (m_format.renderableType() == QSurfaceFormat::OpenGL
m_format.rende...Format::OpenGLDescription
TRUEnever evaluated
FALSEnever evaluated
0
47 && format.majorVersion() >= 3
format.majorVersion() >= 3Description
TRUEnever evaluated
FALSEnever evaluated
0
48 && !format.testOption(QSurfaceFormat::DeprecatedFunctions)
!format.testOp...atedFunctions)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
49 flags |= 0x00000002;
never executed: flags |= 0x00000002;
0
50 if (flags
flagsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
51 contextAttrs.append(0x30FC);-
52 contextAttrs.append(flags);-
53 }
never executed: end of block
0
54-
55 if (m_format.renderableType() == QSurfaceFormat::OpenGL
m_format.rende...Format::OpenGLDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
56 contextAttrs.append(0x30FD);-
57 contextAttrs.append(format.profile() == QSurfaceFormat::CoreProfile-
58 ? 0x00000001-
59 : 0x00000002);-
60 }
never executed: end of block
0
61 }
never executed: end of block
0
62 contextAttrs.append(0x3038);-
63 m_contextAttrs = contextAttrs;-
64-
65 switch (m_format.renderableType()) {-
66 case
never executed: case QSurfaceFormat::OpenVG:
QSurfaceFormat::OpenVG:
never executed: case QSurfaceFormat::OpenVG:
0
67 m_api = 0x30A1;-
68 break;
never executed: break;
0
69-
70 case
never executed: case QSurfaceFormat::OpenGL:
QSurfaceFormat::OpenGL:
never executed: case QSurfaceFormat::OpenGL:
0
71 m_api = 0x30A2;-
72 break;
never executed: break;
0
73-
74 default
never executed: default:
:
never executed: default:
0
75 m_api = 0x30A0;-
76 break;
never executed: break;
0
77 }-
78-
79 eglBindAPI(m_api);-
80 m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, m_shareContext, contextAttrs.constData());-
81 if (m_eglContext == ((EGLContext)0)
m_eglContext =...(EGLContext)0)Description
TRUEnever evaluated
FALSEnever evaluated
&& m_shareContext != ((EGLContext)0)
m_shareContext...(EGLContext)0)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
82 m_shareContext = 0;-
83 m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, 0, contextAttrs.constData());-
84 }
never executed: end of block
0
85-
86 if (m_eglContext == ((EGLContext)0)
m_eglContext =...(EGLContext)0)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
87 QMessageLogger(__FILE__, 195, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: Failed to create context: %x", eglGetError());-
88 return;
never executed: return;
0
89 }-
90-
91 static const bool printConfig = qEnvironmentVariableIntValue("QT_QPA_EGLFS_DEBUG");-
92 if (printConfig
printConfigDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
93 QMessageLogger(__FILE__, 201, __PRETTY_FUNCTION__).debug() << "Created context for format" << format << "with config:";-
94 q_printEglConfig(m_eglDisplay, m_eglConfig);-
95 }
never executed: end of block
0
96-
97-
98}
never executed: end of block
0
99-
100void QEGLPlatformContext::adopt(const QVariant &nativeHandle, QPlatformOpenGLContext *share)-
101{-
102 if (!nativeHandle.canConvert<QEGLNativeContext>()
!nativeHandle....tiveContext>()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
103 QMessageLogger(__FILE__, 211, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: Requires a QEGLNativeContext");-
104 return;
never executed: return;
0
105 }-
106 QEGLNativeContext handle = nativeHandle.value<QEGLNativeContext>();-
107 EGLContext context = handle.context();-
108 if (!context
!contextDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
109 QMessageLogger(__FILE__, 217, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: No EGLContext given");-
110 return;
never executed: return;
0
111 }-
112-
113-
114 if (handle.display() != m_eglDisplay
handle.display...= m_eglDisplayDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
115 QMessageLogger(__FILE__, 223, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: Cannot adopt context from different display");-
116 return;
never executed: return;
0
117 }-
118-
119-
120 EGLint value = 0;-
121 eglQueryContext(m_eglDisplay, context, 0x3028, &value);-
122 EGLint n = 0;-
123 EGLConfig cfg;-
124 const EGLint attribs[] = { 0x3028, value, 0x3038 };-
125 if (eglChooseConfig(m_eglDisplay, attribs, &cfg, 1, &n)
eglChooseConfi..., &cfg, 1, &n)Description
TRUEnever evaluated
FALSEnever evaluated
&& n == 1
n == 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
126 m_eglConfig = cfg;-
127 m_format = q_glFormatFromConfig(m_eglDisplay, m_eglConfig);-
128 }
never executed: end of block
else {
0
129 QMessageLogger(__FILE__, 237, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: Failed to get framebuffer configuration for context");-
130 }
never executed: end of block
0
131-
132-
133 value = 0;-
134 eglQueryContext(m_eglDisplay, context, 0x3097, &value);-
135 if (value == 0x30A2
value == 0x30A2Description
TRUEnever evaluated
FALSEnever evaluated
|| value == 0x30A0
value == 0x30A0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
136 m_api = value;-
137 eglBindAPI(m_api);-
138 }
never executed: end of block
else {
0
139 QMessageLogger(__FILE__, 247, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: Failed to get client API type");-
140 m_api = 0x30A0;-
141 }
never executed: end of block
0
142-
143 m_eglContext = context;-
144 m_shareContext = share
shareDescription
TRUEnever evaluated
FALSEnever evaluated
? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 0;
0
145 updateFormatFromGL();-
146}
never executed: end of block
0
147-
148void QEGLPlatformContext::initialize()-
149{-
150 if (m_eglContext != ((EGLContext)0)
m_eglContext !...(EGLContext)0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
151 updateFormatFromGL();
never executed: updateFormatFromGL();
0
152}
never executed: end of block
0
153-
154-
155-
156EGLSurface QEGLPlatformContext::createTemporaryOffscreenSurface()-
157{-
158-
159 const EGLint pbufferAttributes[] = {-
160 0x3057, 1,-
161 0x3056, 1,-
162 0x3058, 0,-
163 0x3038-
164 };-
165-
166-
167-
168-
169 EGLConfig config = q_configFromGLFormat(m_eglDisplay, m_format, false, 0x0001);-
170-
171 return
never executed: return eglCreatePbufferSurface(m_eglDisplay, config, pbufferAttributes);
eglCreatePbufferSurface(m_eglDisplay, config, pbufferAttributes);
never executed: return eglCreatePbufferSurface(m_eglDisplay, config, pbufferAttributes);
0
172}-
173-
174void QEGLPlatformContext::destroyTemporaryOffscreenSurface(EGLSurface surface)-
175{-
176 eglDestroySurface(m_eglDisplay, surface);-
177}
never executed: end of block
0
178-
179void QEGLPlatformContext::runGLChecks()-
180{-
181-
182-
183}-
184-
185void QEGLPlatformContext::updateFormatFromGL()-
186{-
187-
188-
189-
190 EGLDisplay prevDisplay = eglGetCurrentDisplay();-
191 if (prevDisplay == ((EGLDisplay)0)
prevDisplay == ((EGLDisplay)0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
192 prevDisplay = m_eglDisplay;
never executed: prevDisplay = m_eglDisplay;
0
193 EGLContext prevContext = eglGetCurrentContext();-
194 EGLSurface prevSurfaceDraw = eglGetCurrentSurface(0x3059);-
195 EGLSurface prevSurfaceRead = eglGetCurrentSurface(0x305A);-
196-
197-
198-
199-
200 EGLSurface tempSurface = ((EGLSurface)0);-
201 EGLContext tempContext = ((EGLContext)0);-
202 if (m_flags.testFlag(NoSurfaceless)
m_flags.testFl...NoSurfaceless)Description
TRUEnever evaluated
FALSEnever evaluated
|| !q_hasEglExtension(m_eglDisplay, "EGL_KHR_surfaceless_context")
!q_hasEglExten...less_context")Description
TRUEnever evaluated
FALSEnever evaluated
)
0
203 tempSurface = createTemporaryOffscreenSurface();
never executed: tempSurface = createTemporaryOffscreenSurface();
0
204-
205 EGLBoolean ok = eglMakeCurrent(m_eglDisplay, tempSurface, tempSurface, m_eglContext);-
206 if (!ok
!okDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
207 EGLConfig config = q_configFromGLFormat(m_eglDisplay, m_format, false, 0x0001);-
208 tempContext = eglCreateContext(m_eglDisplay, config, 0, m_contextAttrs.constData());-
209 if (tempContext != ((EGLContext)0)
tempContext != ((EGLContext)0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
210 ok = eglMakeCurrent(m_eglDisplay, tempSurface, tempSurface, tempContext);
never executed: ok = eglMakeCurrent(m_eglDisplay, tempSurface, tempSurface, tempContext);
0
211 }
never executed: end of block
0
212 if (ok
okDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
213 if (m_format.renderableType() == QSurfaceFormat::OpenGL
m_format.rende...Format::OpenGLDescription
TRUEnever evaluated
FALSEnever evaluated
0
214 || m_format.renderableType() == QSurfaceFormat::OpenGLES
m_format.rende...rmat::OpenGLESDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
215 const GLubyte *s = glGetString(0x1F02);-
216 if (s
sDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
217 QByteArray version = QByteArray(reinterpret_cast<const char *>(s));-
218 int major, minor;-
219 if (QPlatformOpenGLContext::parseOpenGLVersion(version, major, minor)
QPlatformOpenG... major, minor)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
220 m_format.setMajorVersion(major);-
221 m_format.setMinorVersion(minor);-
222 }
never executed: end of block
0
223 }
never executed: end of block
0
224 m_format.setProfile(QSurfaceFormat::NoProfile);-
225 m_format.setOptions(QSurfaceFormat::FormatOptions());-
226 if (m_format.renderableType() == QSurfaceFormat::OpenGL
m_format.rende...Format::OpenGLDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
227-
228 if (m_format.majorVersion() < 3
m_format.majorVersion() < 3Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
229 m_format.setOption(QSurfaceFormat::DeprecatedFunctions);-
230 }
never executed: end of block
else {
0
231 GLint value = 0;-
232 glGetIntegerv(0x821E, &value);-
233 if (!(value & 0x00000001)
!(value & 0x00000001)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
234 m_format.setOption(QSurfaceFormat::DeprecatedFunctions);
never executed: m_format.setOption(QSurfaceFormat::DeprecatedFunctions);
0
235 if (value & 0x00000002
value & 0x00000002Description
TRUEnever evaluated
FALSEnever evaluated
)
0
236 m_format.setOption(QSurfaceFormat::DebugContext);
never executed: m_format.setOption(QSurfaceFormat::DebugContext);
0
237 if (m_format.version() >= qMakePair(3, 2)
m_format.versi...MakePair(3, 2)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
238 value = 0;-
239 glGetIntegerv(0x9126, &value);-
240 if (value & 0x00000001
value & 0x00000001Description
TRUEnever evaluated
FALSEnever evaluated
)
0
241 m_format.setProfile(QSurfaceFormat::CoreProfile);
never executed: m_format.setProfile(QSurfaceFormat::CoreProfile);
0
242 else if (value & 0x00000002
value & 0x00000002Description
TRUEnever evaluated
FALSEnever evaluated
)
0
243 m_format.setProfile(QSurfaceFormat::CompatibilityProfile);
never executed: m_format.setProfile(QSurfaceFormat::CompatibilityProfile);
0
244 }
never executed: end of block
0
245 }
never executed: end of block
0
246 }-
247 }
never executed: end of block
0
248 runGLChecks();-
249 eglMakeCurrent(prevDisplay, prevSurfaceDraw, prevSurfaceRead, prevContext);-
250 }
never executed: end of block
else {
0
251 QMessageLogger(__FILE__, 367, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: Failed to make temporary surface current, format not updated (%x)", eglGetError());-
252 }
never executed: end of block
0
253 if (tempSurface != ((EGLSurface)0)
tempSurface != ((EGLSurface)0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
254 destroyTemporaryOffscreenSurface(tempSurface);
never executed: destroyTemporaryOffscreenSurface(tempSurface);
0
255 if (tempContext != ((EGLContext)0)
tempContext != ((EGLContext)0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
256 eglDestroyContext(m_eglDisplay, tempContext);
never executed: eglDestroyContext(m_eglDisplay, tempContext);
0
257-
258}
never executed: end of block
0
259-
260bool QEGLPlatformContext::makeCurrent(QPlatformSurface *surface)-
261{-
262 ((!(surface->surface()->supportsOpenGL())) ? qt_assert("surface->surface()->supportsOpenGL()",__FILE__,378) : qt_noop());-
263-
264 eglBindAPI(m_api);-
265-
266 EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface);-
267-
268-
269 if (eglGetCurrentContext() == m_eglContext
eglGetCurrentC...= m_eglContextDescription
TRUEnever evaluated
FALSEnever evaluated
&&
0
270 eglGetCurrentDisplay() == m_eglDisplay
eglGetCurrentD...= m_eglDisplayDescription
TRUEnever evaluated
FALSEnever evaluated
&&
0
271 eglGetCurrentSurface(0x305A) == eglSurface
eglGetCurrentS... == eglSurfaceDescription
TRUEnever evaluated
FALSEnever evaluated
&&
0
272 eglGetCurrentSurface(0x3059) == eglSurface
eglGetCurrentS... == eglSurfaceDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
273 return
never executed: return true;
true;
never executed: return true;
0
274 }-
275-
276 const bool ok = eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_eglContext);-
277 if (ok
okDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
278 if (!m_swapIntervalEnvChecked
!m_swapIntervalEnvCheckedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
279 m_swapIntervalEnvChecked = true;-
280 if (qEnvironmentVariableIsSet("QT_QPA_EGLFS_SWAPINTERVAL")
qEnvironmentVa...SWAPINTERVAL")Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
281 QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL");-
282 bool intervalOk;-
283 const int swapInterval = swapIntervalString.toInt(&intervalOk);-
284 if (intervalOk
intervalOkDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
285 m_swapIntervalFromEnv = swapInterval;
never executed: m_swapIntervalFromEnv = swapInterval;
0
286 }
never executed: end of block
0
287 }
never executed: end of block
0
288 const int requestedSwapInterval = m_swapIntervalFromEnv >= 0
m_swapIntervalFromEnv >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
289 ? m_swapIntervalFromEnv-
290 : surface->format().swapInterval();-
291 if (requestedSwapInterval >= 0
requestedSwapInterval >= 0Description
TRUEnever evaluated
FALSEnever evaluated
&& m_swapInterval != requestedSwapInterval
m_swapInterval...edSwapIntervalDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
292 m_swapInterval = requestedSwapInterval;-
293 if (eglSurface != ((EGLSurface)0)
eglSurface != ((EGLSurface)0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
294 eglSwapInterval(eglDisplay(), m_swapInterval);
never executed: eglSwapInterval(eglDisplay(), m_swapInterval);
0
295 }
never executed: end of block
0
296 }
never executed: end of block
else {
0
297 QMessageLogger(__FILE__, 413, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError());-
298 }
never executed: end of block
0
299-
300 return
never executed: return ok;
ok;
never executed: return ok;
0
301}-
302-
303QEGLPlatformContext::~QEGLPlatformContext()-
304{-
305 if (m_ownsContext
m_ownsContextDescription
TRUEnever evaluated
FALSEnever evaluated
&& m_eglContext != ((EGLContext)0)
m_eglContext !...(EGLContext)0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
306 eglDestroyContext(m_eglDisplay, m_eglContext);
never executed: eglDestroyContext(m_eglDisplay, m_eglContext);
0
307-
308 m_eglContext = ((EGLContext)0);-
309}
never executed: end of block
0
310-
311void QEGLPlatformContext::doneCurrent()-
312{-
313 eglBindAPI(m_api);-
314 bool ok = eglMakeCurrent(m_eglDisplay, ((EGLSurface)0), ((EGLSurface)0), ((EGLContext)0));-
315 if (!ok
!okDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
316 QMessageLogger(__FILE__, 432, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError());
never executed: QMessageLogger(__FILE__, 432, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError());
0
317}
never executed: end of block
0
318-
319void QEGLPlatformContext::swapBuffers(QPlatformSurface *surface)-
320{-
321 eglBindAPI(m_api);-
322 EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface);-
323 if (eglSurface != ((EGLSurface)0)
eglSurface != ((EGLSurface)0)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
324 bool ok = eglSwapBuffers(m_eglDisplay, eglSurface);-
325 if (!ok
!okDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
326 QMessageLogger(__FILE__, 442, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: eglSwapBuffers failed: %x", eglGetError());
never executed: QMessageLogger(__FILE__, 442, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: eglSwapBuffers failed: %x", eglGetError());
0
327 }
never executed: end of block
0
328}
never executed: end of block
0
329-
330QFunctionPointer QEGLPlatformContext::getProcAddress(const char *procName)-
331{-
332 eglBindAPI(m_api);-
333 QFunctionPointer proc = (QFunctionPointer) eglGetProcAddress(procName);-
334-
335 if (!proc
!procDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
336 proc = (QFunctionPointer) dlsym(((void *) 0), procName);
never executed: proc = (QFunctionPointer) dlsym(((void *) 0), procName);
0
337-
338 return
never executed: return proc;
proc;
never executed: return proc;
0
339}-
340-
341QSurfaceFormat QEGLPlatformContext::format() const-
342{-
343 return
never executed: return m_format;
m_format;
never executed: return m_format;
0
344}-
345-
346EGLContext QEGLPlatformContext::eglContext() const-
347{-
348 return
never executed: return m_eglContext;
m_eglContext;
never executed: return m_eglContext;
0
349}-
350-
351EGLDisplay QEGLPlatformContext::eglDisplay() const-
352{-
353 return
never executed: return m_eglDisplay;
m_eglDisplay;
never executed: return m_eglDisplay;
0
354}-
355-
356EGLConfig QEGLPlatformContext::eglConfig() const-
357{-
358 return
never executed: return m_eglConfig;
m_eglConfig;
never executed: return m_eglConfig;
0
359}-
360-
361-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9