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()) {-
18 m_eglConfig = config ? *config : q_configFromGLFormat(display, format);-
19 m_ownsContext = true;-
20 init(format, share);-
21 } else {-
22 m_ownsContext = false;-
23 adopt(nativeHandle, share);-
24 }-
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 ? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 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) {-
39 contextAttrs.append(0x30FB);-
40 contextAttrs.append(format.minorVersion());-
41 int flags = 0;-
42-
43 if (format.testOption(QSurfaceFormat::DebugContext))-
44 flags |= 0x00000001;-
45-
46 if (m_format.renderableType() == QSurfaceFormat::OpenGL-
47 && format.majorVersion() >= 3-
48 && !format.testOption(QSurfaceFormat::DeprecatedFunctions))-
49 flags |= 0x00000002;-
50 if (flags) {-
51 contextAttrs.append(0x30FC);-
52 contextAttrs.append(flags);-
53 }-
54-
55 if (m_format.renderableType() == QSurfaceFormat::OpenGL) {-
56 contextAttrs.append(0x30FD);-
57 contextAttrs.append(format.profile() == QSurfaceFormat::CoreProfile-
58 ? 0x00000001-
59 : 0x00000002);-
60 }-
61 }-
62 contextAttrs.append(0x3038);-
63 m_contextAttrs = contextAttrs;-
64-
65 switch (m_format.renderableType()) {-
66 case QSurfaceFormat::OpenVG:-
67 m_api = 0x30A1;-
68 break;-
69-
70 case QSurfaceFormat::OpenGL:-
71 m_api = 0x30A2;-
72 break;-
73-
74 default:-
75 m_api = 0x30A0;-
76 break;-
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_shareContext != ((EGLContext)0)) {-
82 m_shareContext = 0;-
83 m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, 0, contextAttrs.constData());-
84 }-
85-
86 if (m_eglContext == ((EGLContext)0)) {-
87 QMessageLogger(__FILE__, 186195, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: Failed to create context: %x", eglGetError());-
88 return;-
89 }-
90-
91 static const bool printConfig = qEnvironmentVariableIntValue("QT_QPA_EGLFS_DEBUG");-
92 if (printConfig) {-
93 QMessageLogger(__FILE__, 192201, __PRETTY_FUNCTION__).debug() << "Created context for format" << format << "with config:";-
94 q_printEglConfig(m_eglDisplay, m_eglConfig);-
95 }-
96-
97-
98}-
99-
100void QEGLPlatformContext::adopt(const QVariant &nativeHandle, QPlatformOpenGLContext *share)-
101{-
102 if (!nativeHandle.canConvert<QEGLNativeContext>()) {-
103 QMessageLogger(__FILE__, 202211, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: Requires a QEGLNativeContext");-
104 return;-
105 }-
106 QEGLNativeContext handle = nativeHandle.value<QEGLNativeContext>();-
107 EGLContext context = handle.context();-
108 if (!context) {-
109 QMessageLogger(__FILE__, 208217, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: No EGLContext given");-
110 return;-
111 }-
112-
113-
114 if (handle.display() != m_eglDisplay) {-
115 QMessageLogger(__FILE__, 214223, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: Cannot adopt context from different display");-
116 return;-
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) && n == 1) {-
126 m_eglConfig = cfg;-
127 m_format = q_glFormatFromConfig(m_eglDisplay, m_eglConfig);-
128 } else {-
129 QMessageLogger(__FILE__, 228237, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: Failed to get framebuffer configuration for context");-
130 }-
131-
132-
133 value = 0;-
134 eglQueryContext(m_eglDisplay, context, 0x3097, &value);-
135 if (value == 0x30A2 || value == 0x30A0) {-
136 m_api = value;-
137 eglBindAPI(m_api);-
138 } else {-
139 QMessageLogger(__FILE__, 238247, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: Failed to get client API type");-
140 m_api = 0x30A0;-
141 }-
142-
143 m_eglContext = context;-
144 m_shareContext = share ? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 0;-
145 updateFormatFromGL();-
146}-
147-
148void QEGLPlatformContext::initialize()-
149{-
150 if (m_eglContext != ((EGLContext)0))-
151 updateFormatFromGL();-
152}-
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 eglCreatePbufferSurface(m_eglDisplay, config, pbufferAttributes);-
172}-
173-
174void QEGLPlatformContext::destroyTemporaryOffscreenSurface(EGLSurface surface)-
175{-
176 eglDestroySurface(m_eglDisplay, surface);-
177}-
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))-
192 prevDisplay = m_eglDisplay;-
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) || !q_hasEglExtension(m_eglDisplay, "EGL_KHR_surfaceless_context"))-
203 tempSurface = createTemporaryOffscreenSurface();-
204-
205 EGLBoolean ok = eglMakeCurrent(m_eglDisplay, tempSurface, tempSurface, m_eglContext);-
206 if (!ok) {-
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))-
210 ok = eglMakeCurrent(m_eglDisplay, tempSurface, tempSurface, tempContext);-
211 }-
212 if (ok) {-
213 if (m_format.renderableType() == QSurfaceFormat::OpenGL-
214 || m_format.renderableType() == QSurfaceFormat::OpenGLES) {-
215 const GLubyte *s = glGetString(0x1F02);-
216 if (s) {-
217 QByteArray version = QByteArray(reinterpret_cast<const char *>(s));-
218 int major, minor;-
219 if (QPlatformOpenGLContext::parseOpenGLVersion(version, major, minor)) {-
220 m_format.setMajorVersion(major);-
221 m_format.setMinorVersion(minor);-
222 }-
223 }-
224 m_format.setProfile(QSurfaceFormat::NoProfile);-
225 m_format.setOptions(QSurfaceFormat::FormatOptions());-
226 if (m_format.renderableType() == QSurfaceFormat::OpenGL) {-
227-
228 if (m_format.majorVersion() < 3) {-
229 m_format.setOption(QSurfaceFormat::DeprecatedFunctions);-
230 } else {-
231 GLint value = 0;-
232 glGetIntegerv(0x821E, &value);-
233 if (!(value & 0x00000001))-
234 m_format.setOption(QSurfaceFormat::DeprecatedFunctions);-
235 if (value & 0x00000002)-
236 m_format.setOption(QSurfaceFormat::DebugContext);-
237 if (m_format.version() >= qMakePair(3, 2)) {-
238 value = 0;-
239 glGetIntegerv(0x9126, &value);-
240 if (value & 0x00000001)-
241 m_format.setProfile(QSurfaceFormat::CoreProfile);-
242 else if (value & 0x00000002)-
243 m_format.setProfile(QSurfaceFormat::CompatibilityProfile);-
244 }-
245 }-
246 }-
247 }-
248 runGLChecks();-
249 eglMakeCurrent(prevDisplay, prevSurfaceDraw, prevSurfaceRead, prevContext);-
250 } else {-
251 QMessageLogger(__FILE__, 358367, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: Failed to make temporary surface current, format not updated (%x)", eglGetError());-
252 }-
253 if (tempSurface != ((EGLSurface)0))-
254 destroyTemporaryOffscreenSurface(tempSurface);-
255 if (tempContext != ((EGLContext)0))-
256 eglDestroyContext(m_eglDisplay, tempContext);-
257-
258}-
259-
260bool QEGLPlatformContext::makeCurrent(QPlatformSurface *surface)-
261{-
262 ((!(surface->surface()->supportsOpenGL())) ? qt_assert("surface->surface()->supportsOpenGL()",__FILE__,369378) : qt_noop());-
263-
264 eglBindAPI(m_api);-
265-
266 EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface);-
267-
268-
269 if (eglGetCurrentContext() == m_eglContext &&-
270 eglGetCurrentDisplay() == m_eglDisplay &&-
271 eglGetCurrentSurface(0x305A) == eglSurface &&-
272 eglGetCurrentSurface(0x3059) == eglSurface) {-
273 return true;-
274 }-
275-
276 const bool ok = eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_eglContext);-
277 if (ok) {-
278 if (!m_swapIntervalEnvChecked) {-
279 m_swapIntervalEnvChecked = true;-
280 if (qEnvironmentVariableIsSet("QT_QPA_EGLFS_SWAPINTERVAL")) {-
281 QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL");-
282 bool intervalOk;-
283 const int swapInterval = swapIntervalString.toInt(&intervalOk);-
284 if (intervalOk)-
285 m_swapIntervalFromEnv = swapInterval;-
286 }-
287 }-
288 const int requestedSwapInterval = m_swapIntervalFromEnv >= 0-
289 ? m_swapIntervalFromEnv-
290 : surface->format().swapInterval();-
291 if (requestedSwapInterval >= 0 && m_swapInterval != requestedSwapInterval) {-
292 m_swapInterval = requestedSwapInterval;-
293 if (eglSurface != ((EGLSurface)0))-
294 eglSwapInterval(eglDisplay(), m_swapInterval);-
295 }-
296 } else {-
297 QMessageLogger(__FILE__, 404413, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError());-
298 }-
299-
300 return ok;-
301}-
302-
303QEGLPlatformContext::~QEGLPlatformContext()-
304{-
305 if (m_ownsContext && m_eglContext != ((EGLContext)0))-
306 eglDestroyContext(m_eglDisplay, m_eglContext);-
307-
308 m_eglContext = ((EGLContext)0);-
309}-
310-
311void QEGLPlatformContext::doneCurrent()-
312{-
313 eglBindAPI(m_api);-
314 bool ok = eglMakeCurrent(m_eglDisplay, ((EGLSurface)0), ((EGLSurface)0), ((EGLContext)0));-
315 if (!ok)-
316 QMessageLogger(__FILE__, 423432, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError());-
317}-
318-
319void QEGLPlatformContext::swapBuffers(QPlatformSurface *surface)-
320{-
321 eglBindAPI(m_api);-
322 EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface);-
323 if (eglSurface != ((EGLSurface)0)) {-
324 bool ok = eglSwapBuffers(m_eglDisplay, eglSurface);-
325 if (!ok)-
326 QMessageLogger(__FILE__, 433442, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: eglSwapBuffers failed: %x", eglGetError());-
327 }-
328}-
329-
void (*QFunctionPointer QEGLPlatformContext::getProcAddress(const QByteArray &procName)) ()char *procName)
331{-
332 eglBindAPI(m_api);-
333 returnQFunctionPointer proc = (QFunctionPointer) eglGetProcAddress(procName.constData()););-
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 m_format;-
344}-
345-
346EGLContext QEGLPlatformContext::eglContext() const-
347{-
348 return m_eglContext;-
349}-
350-
351EGLDisplay QEGLPlatformContext::eglDisplay() const-
352{-
353 return m_eglDisplay;-
354}-
355-
356EGLConfig QEGLPlatformContext::eglConfig() const-
357{-
358 return m_eglConfig;-
359}-
360-
361-
Switch to Source codePreprocessed file

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