author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtGui/qpaintdevice.h> |
|
43 |
#include <QtGui/qpixmap.h> |
|
44 |
#include <QtGui/qwidget.h> |
|
45 |
#include <QtCore/qdebug.h> |
|
46 |
#include "qegl_p.h" |
|
47 |
||
48 |
QT_BEGIN_NAMESPACE |
|
49 |
||
50 |
// Current GL and VG contexts. These are used to determine if |
|
51 |
// we can avoid an eglMakeCurrent() after a call to lazyDoneCurrent(). |
|
52 |
// If a background thread modifies the value, the worst that will |
|
53 |
// happen is a redundant eglMakeCurrent() in the foreground thread. |
|
54 |
static QEglContext * volatile currentGLContext = 0; |
|
55 |
static QEglContext * volatile currentVGContext = 0; |
|
56 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
57 |
EGLDisplay QEglContext::dpy = EGL_NO_DISPLAY; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
58 |
|
0 | 59 |
QEglContext::QEglContext() |
60 |
: apiType(QEgl::OpenGL) |
|
61 |
, ctx(EGL_NO_CONTEXT) |
|
62 |
, cfg(0) |
|
63 |
, currentSurface(EGL_NO_SURFACE) |
|
64 |
, current(false) |
|
65 |
, ownsContext(true) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
66 |
, sharing(false) |
0 | 67 |
{ |
68 |
} |
|
69 |
||
70 |
QEglContext::~QEglContext() |
|
71 |
{ |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
72 |
destroyContext(); |
0 | 73 |
|
74 |
if (currentGLContext == this) |
|
75 |
currentGLContext = 0; |
|
76 |
if (currentVGContext == this) |
|
77 |
currentVGContext = 0; |
|
78 |
} |
|
79 |
||
80 |
bool QEglContext::isValid() const |
|
81 |
{ |
|
82 |
return (ctx != EGL_NO_CONTEXT); |
|
83 |
} |
|
84 |
||
85 |
bool QEglContext::isCurrent() const |
|
86 |
{ |
|
87 |
return current; |
|
88 |
} |
|
89 |
||
90 |
// Choose a configuration that matches "properties". |
|
91 |
bool QEglContext::chooseConfig |
|
92 |
(const QEglProperties& properties, QEgl::PixelFormatMatch match) |
|
93 |
{ |
|
94 |
QEglProperties props(properties); |
|
95 |
do { |
|
96 |
// Get the number of matching configurations for this set of properties. |
|
97 |
EGLint matching = 0; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
98 |
if (!eglChooseConfig(display(), props.properties(), 0, 0, &matching) || !matching) |
0 | 99 |
continue; |
100 |
||
101 |
// If we want the best pixel format, then return the first |
|
102 |
// matching configuration. |
|
103 |
if (match == QEgl::BestPixelFormat) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
104 |
eglChooseConfig(display(), props.properties(), &cfg, 1, &matching); |
0 | 105 |
if (matching < 1) |
106 |
continue; |
|
107 |
return true; |
|
108 |
} |
|
109 |
||
110 |
// Fetch all of the matching configurations and find the |
|
111 |
// first that matches the pixel format we wanted. |
|
112 |
EGLint size = matching; |
|
113 |
EGLConfig *configs = new EGLConfig [size]; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
114 |
eglChooseConfig(display(), props.properties(), configs, size, &matching); |
0 | 115 |
for (EGLint index = 0; index < size; ++index) { |
116 |
EGLint red, green, blue, alpha; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
117 |
eglGetConfigAttrib(display(), configs[index], EGL_RED_SIZE, &red); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
118 |
eglGetConfigAttrib(display(), configs[index], EGL_GREEN_SIZE, &green); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
119 |
eglGetConfigAttrib(display(), configs[index], EGL_BLUE_SIZE, &blue); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
120 |
eglGetConfigAttrib(display(), configs[index], EGL_ALPHA_SIZE, &alpha); |
0 | 121 |
if (red == props.value(EGL_RED_SIZE) && |
122 |
green == props.value(EGL_GREEN_SIZE) && |
|
123 |
blue == props.value(EGL_BLUE_SIZE) && |
|
124 |
(props.value(EGL_ALPHA_SIZE) == 0 || |
|
125 |
alpha == props.value(EGL_ALPHA_SIZE))) { |
|
126 |
cfg = configs[index]; |
|
127 |
delete [] configs; |
|
128 |
return true; |
|
129 |
} |
|
130 |
} |
|
131 |
delete [] configs; |
|
132 |
} while (props.reduceConfiguration()); |
|
133 |
||
134 |
#ifdef EGL_BIND_TO_TEXTURE_RGBA |
|
135 |
// Don't report an error just yet if we failed to get a pbuffer |
|
136 |
// configuration with texture rendering. Only report failure if |
|
137 |
// we cannot get any pbuffer configurations at all. |
|
138 |
if (props.value(EGL_BIND_TO_TEXTURE_RGBA) == EGL_DONT_CARE && |
|
139 |
props.value(EGL_BIND_TO_TEXTURE_RGB) == EGL_DONT_CARE) |
|
140 |
#endif |
|
141 |
{ |
|
142 |
qWarning() << "QEglContext::chooseConfig(): Could not find a suitable EGL configuration"; |
|
143 |
qWarning() << "Requested:" << props.toString(); |
|
144 |
qWarning() << "Available:"; |
|
145 |
dumpAllConfigs(); |
|
146 |
} |
|
147 |
return false; |
|
148 |
} |
|
149 |
||
150 |
// Create the EGLContext. |
|
151 |
bool QEglContext::createContext(QEglContext *shareContext, const QEglProperties *properties) |
|
152 |
{ |
|
153 |
// We need to select the correct API before calling eglCreateContext(). |
|
154 |
#ifdef EGL_OPENGL_ES_API |
|
155 |
if (apiType == QEgl::OpenGL) |
|
156 |
eglBindAPI(EGL_OPENGL_ES_API); |
|
157 |
#endif |
|
158 |
#ifdef EGL_OPENVG_API |
|
159 |
if (apiType == QEgl::OpenVG) |
|
160 |
eglBindAPI(EGL_OPENVG_API); |
|
161 |
#endif |
|
162 |
||
163 |
// Create a new context for the configuration. |
|
164 |
QEglProperties contextProps; |
|
165 |
if (properties) |
|
166 |
contextProps = *properties; |
|
167 |
#if defined(QT_OPENGL_ES_2) |
|
168 |
if (apiType == QEgl::OpenGL) |
|
169 |
contextProps.setValue(EGL_CONTEXT_CLIENT_VERSION, 2); |
|
170 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
sharing = false; |
0 | 172 |
if (shareContext && shareContext->ctx == EGL_NO_CONTEXT) |
173 |
shareContext = 0; |
|
174 |
if (shareContext) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
175 |
ctx = eglCreateContext(display(), cfg, shareContext->ctx, contextProps.properties()); |
0 | 176 |
if (ctx == EGL_NO_CONTEXT) { |
177 |
qWarning() << "QEglContext::createContext(): Could not share context:" << errorString(eglGetError()); |
|
178 |
shareContext = 0; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
sharing = true; |
0 | 181 |
} |
182 |
} |
|
183 |
if (ctx == EGL_NO_CONTEXT) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
184 |
ctx = eglCreateContext(display(), cfg, 0, contextProps.properties()); |
0 | 185 |
if (ctx == EGL_NO_CONTEXT) { |
186 |
qWarning() << "QEglContext::createContext(): Unable to create EGL context:" << errorString(eglGetError()); |
|
187 |
return false; |
|
188 |
} |
|
189 |
} |
|
190 |
return true; |
|
191 |
} |
|
192 |
||
193 |
// Destroy an EGL surface object. If it was current on this context |
|
194 |
// then call doneCurrent() for it first. |
|
195 |
void QEglContext::destroySurface(EGLSurface surface) |
|
196 |
{ |
|
197 |
if (surface != EGL_NO_SURFACE) { |
|
198 |
if (surface == currentSurface) |
|
199 |
doneCurrent(); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
200 |
eglDestroySurface(display(), surface); |
0 | 201 |
} |
202 |
} |
|
203 |
||
204 |
// Destroy the context. Note: this does not destroy the surface. |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
205 |
void QEglContext::destroyContext() |
0 | 206 |
{ |
207 |
if (ctx != EGL_NO_CONTEXT && ownsContext) |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
208 |
eglDestroyContext(display(), ctx); |
0 | 209 |
ctx = EGL_NO_CONTEXT; |
210 |
cfg = 0; |
|
211 |
} |
|
212 |
||
213 |
bool QEglContext::makeCurrent(EGLSurface surface) |
|
214 |
{ |
|
215 |
if (ctx == EGL_NO_CONTEXT) { |
|
216 |
qWarning() << "QEglContext::makeCurrent(): Cannot make invalid context current"; |
|
217 |
return false; |
|
218 |
} |
|
219 |
||
220 |
// If lazyDoneCurrent() was called on the surface, then we may be able |
|
221 |
// to assume that it is still current within the thread. |
|
222 |
if (surface == currentSurface && currentContext(apiType) == this) { |
|
223 |
current = true; |
|
224 |
return true; |
|
225 |
} |
|
226 |
||
227 |
current = true; |
|
228 |
currentSurface = surface; |
|
229 |
setCurrentContext(apiType, this); |
|
230 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
231 |
// Force the right API to be bound before making the context current. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
232 |
// The EGL implementation should be able to figure this out from ctx, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
233 |
// but some systems require the API to be explicitly set anyway. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
234 |
#ifdef EGL_OPENGL_ES_API |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
235 |
if (apiType == QEgl::OpenGL) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
eglBindAPI(EGL_OPENGL_ES_API); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
237 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
238 |
#ifdef EGL_OPENVG_API |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
239 |
if (apiType == QEgl::OpenVG) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
eglBindAPI(EGL_OPENVG_API); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
243 |
bool ok = eglMakeCurrent(display(), surface, surface, ctx); |
0 | 244 |
if (!ok) |
245 |
qWarning() << "QEglContext::makeCurrent():" << errorString(eglGetError()); |
|
246 |
return ok; |
|
247 |
} |
|
248 |
||
249 |
bool QEglContext::doneCurrent() |
|
250 |
{ |
|
251 |
// If the context is invalid, we assume that an error was reported |
|
252 |
// when makeCurrent() was called. |
|
253 |
if (ctx == EGL_NO_CONTEXT) |
|
254 |
return false; |
|
255 |
||
256 |
current = false; |
|
257 |
currentSurface = EGL_NO_SURFACE; |
|
258 |
setCurrentContext(apiType, 0); |
|
259 |
||
260 |
// We need to select the correct API before calling eglMakeCurrent() |
|
261 |
// with EGL_NO_CONTEXT because threads can have both OpenGL and OpenVG |
|
262 |
// contexts active at the same time. |
|
263 |
#ifdef EGL_OPENGL_ES_API |
|
264 |
if (apiType == QEgl::OpenGL) |
|
265 |
eglBindAPI(EGL_OPENGL_ES_API); |
|
266 |
#endif |
|
267 |
#ifdef EGL_OPENVG_API |
|
268 |
if (apiType == QEgl::OpenVG) |
|
269 |
eglBindAPI(EGL_OPENVG_API); |
|
270 |
#endif |
|
271 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
272 |
bool ok = eglMakeCurrent(display(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
0 | 273 |
if (!ok) |
274 |
qWarning() << "QEglContext::doneCurrent():" << errorString(eglGetError()); |
|
275 |
return ok; |
|
276 |
} |
|
277 |
||
278 |
// Act as though doneCurrent() was called, but keep the context |
|
279 |
// and the surface active for the moment. This allows makeCurrent() |
|
280 |
// to skip a call to eglMakeCurrent() if we are using the same |
|
281 |
// surface as the last set of painting operations. We leave the |
|
282 |
// currentContext() pointer as-is for now. |
|
283 |
bool QEglContext::lazyDoneCurrent() |
|
284 |
{ |
|
285 |
current = false; |
|
286 |
return true; |
|
287 |
} |
|
288 |
||
289 |
bool QEglContext::swapBuffers(EGLSurface surface) |
|
290 |
{ |
|
291 |
if(ctx == EGL_NO_CONTEXT) |
|
292 |
return false; |
|
293 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
294 |
bool ok = eglSwapBuffers(display(), surface); |
0 | 295 |
if (!ok) |
296 |
qWarning() << "QEglContext::swapBuffers():" << errorString(eglGetError()); |
|
297 |
return ok; |
|
298 |
} |
|
299 |
||
300 |
// Wait for native rendering operations to complete before starting |
|
301 |
// to use OpenGL/OpenVG operations. |
|
302 |
void QEglContext::waitNative() |
|
303 |
{ |
|
304 |
#ifdef EGL_CORE_NATIVE_ENGINE |
|
305 |
eglWaitNative(EGL_CORE_NATIVE_ENGINE); |
|
306 |
#endif |
|
307 |
} |
|
308 |
||
309 |
// Wait for client OpenGL/OpenVG operations to complete before |
|
310 |
// using native rendering operations. |
|
311 |
void QEglContext::waitClient() |
|
312 |
{ |
|
313 |
#ifdef EGL_OPENGL_ES_API |
|
314 |
if (apiType == QEgl::OpenGL) { |
|
315 |
eglBindAPI(EGL_OPENGL_ES_API); |
|
316 |
eglWaitClient(); |
|
317 |
} |
|
318 |
#else |
|
319 |
if (apiType == QEgl::OpenGL) |
|
320 |
eglWaitGL(); |
|
321 |
#endif |
|
322 |
#ifdef EGL_OPENVG_API |
|
323 |
if (apiType == QEgl::OpenVG) { |
|
324 |
eglBindAPI(EGL_OPENVG_API); |
|
325 |
eglWaitClient(); |
|
326 |
} |
|
327 |
#endif |
|
328 |
} |
|
329 |
||
330 |
// Query the value of a configuration attribute. |
|
331 |
bool QEglContext::configAttrib(int name, EGLint *value) const |
|
332 |
{ |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
333 |
return eglGetConfigAttrib(display(), cfg, name, value); |
0 | 334 |
} |
335 |
||
336 |
// Retrieve all of the properties on "cfg". If zero, return |
|
337 |
// the context's configuration. |
|
338 |
QEglProperties QEglContext::configProperties(EGLConfig cfg) const |
|
339 |
{ |
|
340 |
if (!cfg) |
|
341 |
cfg = config(); |
|
342 |
QEglProperties props; |
|
343 |
for (int name = 0x3020; name <= 0x304F; ++name) { |
|
344 |
EGLint value; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
345 |
if (name != EGL_NONE && eglGetConfigAttrib(display(), cfg, name, &value)) |
0 | 346 |
props.setValue(name, value); |
347 |
} |
|
348 |
eglGetError(); // Clear the error state. |
|
349 |
return props; |
|
350 |
} |
|
351 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
352 |
EGLDisplay QEglContext::display() |
0 | 353 |
{ |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
354 |
static bool openedDisplay = false; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
355 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
356 |
if (!openedDisplay) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
357 |
dpy = eglGetDisplay(nativeDisplay()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
358 |
openedDisplay = true; |
0 | 359 |
if (dpy == EGL_NO_DISPLAY) { |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
360 |
qWarning("QEglContext::display(): Falling back to EGL_DEFAULT_DISPLAY"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
361 |
dpy = eglGetDisplay(EGLNativeDisplayType(EGL_DEFAULT_DISPLAY)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
362 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
363 |
if (dpy == EGL_NO_DISPLAY) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
364 |
qWarning("QEglContext::display(): Can't even open the default display"); |
0 | 365 |
return EGL_NO_DISPLAY; |
366 |
} |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
367 |
|
0 | 368 |
if (!eglInitialize(dpy, NULL, NULL)) { |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
369 |
qWarning() << "QEglContext::display(): Cannot initialize EGL display:" << errorString(eglGetError()); |
0 | 370 |
return EGL_NO_DISPLAY; |
371 |
} |
|
372 |
} |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
373 |
|
0 | 374 |
return dpy; |
375 |
} |
|
376 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
377 |
#if !defined(Q_WS_X11) && !defined(Q_WS_WINCE) // WinCE & X11 implement this properly |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
378 |
EGLNativeDisplayType QEglContext::nativeDisplay() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
379 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
380 |
return EGL_DEFAULT_DISPLAY; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
381 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
382 |
#endif |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
383 |
|
0 | 384 |
// Return the error string associated with a specific code. |
385 |
QString QEglContext::errorString(EGLint code) |
|
386 |
{ |
|
387 |
static const char * const errors[] = { |
|
388 |
"Success (0x3000)", // No tr |
|
389 |
"Not initialized (0x3001)", // No tr |
|
390 |
"Bad access (0x3002)", // No tr |
|
391 |
"Bad alloc (0x3003)", // No tr |
|
392 |
"Bad attribute (0x3004)", // No tr |
|
393 |
"Bad config (0x3005)", // No tr |
|
394 |
"Bad context (0x3006)", // No tr |
|
395 |
"Bad current surface (0x3007)", // No tr |
|
396 |
"Bad display (0x3008)", // No tr |
|
397 |
"Bad match (0x3009)", // No tr |
|
398 |
"Bad native pixmap (0x300A)", // No tr |
|
399 |
"Bad native window (0x300B)", // No tr |
|
400 |
"Bad parameter (0x300C)", // No tr |
|
401 |
"Bad surface (0x300D)", // No tr |
|
402 |
"Context lost (0x300E)" // No tr |
|
403 |
}; |
|
404 |
if (code >= 0x3000 && code <= 0x300E) { |
|
405 |
return QString::fromLatin1(errors[code - 0x3000]); |
|
406 |
} else { |
|
407 |
return QLatin1String("0x") + QString::number(int(code), 16); |
|
408 |
} |
|
409 |
} |
|
410 |
||
411 |
// Dump all of the EGL configurations supported by the system. |
|
412 |
void QEglContext::dumpAllConfigs() |
|
413 |
{ |
|
414 |
QEglProperties props; |
|
415 |
EGLint count = 0; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
416 |
if (!eglGetConfigs(display(), 0, 0, &count) || count < 1) |
0 | 417 |
return; |
418 |
EGLConfig *configs = new EGLConfig [count]; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
419 |
eglGetConfigs(display(), configs, count, &count); |
0 | 420 |
for (EGLint index = 0; index < count; ++index) { |
421 |
props = configProperties(configs[index]); |
|
422 |
qWarning() << props.toString(); |
|
423 |
} |
|
424 |
delete [] configs; |
|
425 |
} |
|
426 |
||
427 |
QString QEglContext::extensions() |
|
428 |
{ |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
429 |
const char* exts = eglQueryString(QEglContext::display(), EGL_EXTENSIONS); |
0 | 430 |
return QString(QLatin1String(exts)); |
431 |
} |
|
432 |
||
433 |
bool QEglContext::hasExtension(const char* extensionName) |
|
434 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
435 |
QList<QByteArray> extensions = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
436 |
QByteArray(reinterpret_cast<const char *> |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
437 |
(eglQueryString(QEglContext::display(), EGL_EXTENSIONS))).split(' '); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
438 |
return extensions.contains(extensionName); |
0 | 439 |
} |
440 |
||
441 |
QEglContext *QEglContext::currentContext(QEgl::API api) |
|
442 |
{ |
|
443 |
if (api == QEgl::OpenGL) |
|
444 |
return currentGLContext; |
|
445 |
else |
|
446 |
return currentVGContext; |
|
447 |
} |
|
448 |
||
449 |
void QEglContext::setCurrentContext(QEgl::API api, QEglContext *context) |
|
450 |
{ |
|
451 |
if (api == QEgl::OpenGL) |
|
452 |
currentGLContext = context; |
|
453 |
else |
|
454 |
currentVGContext = context; |
|
455 |
} |
|
456 |
||
457 |
QT_END_NAMESPACE |