Changeset 769 for trunk/src/gui/egl/qegl.cpp
- Timestamp:
- Aug 2, 2010, 9:27:30 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.3 (added) merged: 768 /branches/vendor/nokia/qt/current merged: 767 /branches/vendor/nokia/qt/4.6.2 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/egl/qegl.cpp
r651 r769 43 43 #include <QtGui/qpixmap.h> 44 44 #include <QtGui/qwidget.h> 45 #include <QtCore/qatomic.h> 45 46 #include <QtCore/qdebug.h> 46 47 #include "qegl_p.h" 47 48 48 49 QT_BEGIN_NAMESPACE 50 51 52 /* 53 QEglContextTracker is used to track the EGL contexts that we 54 create internally in Qt, so that we can call eglTerminate() to 55 free additional EGL resources when the last context is destroyed. 56 */ 57 58 class QEglContextTracker 59 { 60 public: 61 static void ref() { contexts.ref(); } 62 static void deref() { 63 if (!contexts.deref()) { 64 eglTerminate(QEglContext::display()); 65 displayOpen = 0; 66 } 67 } 68 static void setDisplayOpened() { displayOpen = 1; } 69 static bool displayOpened() { return displayOpen; } 70 71 private: 72 static QBasicAtomicInt contexts; 73 static QBasicAtomicInt displayOpen; 74 }; 75 76 QBasicAtomicInt QEglContextTracker::contexts = Q_BASIC_ATOMIC_INITIALIZER(0); 77 QBasicAtomicInt QEglContextTracker::displayOpen = Q_BASIC_ATOMIC_INITIALIZER(0); 49 78 50 79 // Current GL and VG contexts. These are used to determine if … … 55 84 static QEglContext * volatile currentVGContext = 0; 56 85 86 EGLDisplay QEglContext::dpy = EGL_NO_DISPLAY; 87 57 88 QEglContext::QEglContext() 58 89 : apiType(QEgl::OpenGL) 59 , dpy(EGL_NO_DISPLAY)60 90 , ctx(EGL_NO_CONTEXT) 61 91 , cfg(0) … … 65 95 , sharing(false) 66 96 { 97 QEglContextTracker::ref(); 67 98 } 68 99 69 100 QEglContext::~QEglContext() 70 101 { 71 destroy ();102 destroyContext(); 72 103 73 104 if (currentGLContext == this) … … 75 106 if (currentVGContext == this) 76 107 currentVGContext = 0; 108 QEglContextTracker::deref(); 77 109 } 78 110 … … 85 117 { 86 118 return current; 87 }88 89 // Open the EGL display associated with "device".90 bool QEglContext::openDisplay(QPaintDevice *device)91 {92 if (dpy == EGL_NO_DISPLAY)93 dpy = defaultDisplay(device);94 return (dpy != EGL_NO_DISPLAY);95 119 } 96 120 … … 103 127 // Get the number of matching configurations for this set of properties. 104 128 EGLint matching = 0; 105 if (!eglChooseConfig(d py, props.properties(), 0, 0, &matching) || !matching)129 if (!eglChooseConfig(display(), props.properties(), 0, 0, &matching) || !matching) 106 130 continue; 107 131 … … 109 133 // matching configuration. 110 134 if (match == QEgl::BestPixelFormat) { 111 eglChooseConfig(d py, props.properties(), &cfg, 1, &matching);135 eglChooseConfig(display(), props.properties(), &cfg, 1, &matching); 112 136 if (matching < 1) 113 137 continue; … … 119 143 EGLint size = matching; 120 144 EGLConfig *configs = new EGLConfig [size]; 121 eglChooseConfig(d py, props.properties(), configs, size, &matching);145 eglChooseConfig(display(), props.properties(), configs, size, &matching); 122 146 for (EGLint index = 0; index < size; ++index) { 123 147 EGLint red, green, blue, alpha; 124 eglGetConfigAttrib(d py, configs[index], EGL_RED_SIZE, &red);125 eglGetConfigAttrib(d py, configs[index], EGL_GREEN_SIZE, &green);126 eglGetConfigAttrib(d py, configs[index], EGL_BLUE_SIZE, &blue);127 eglGetConfigAttrib(d py, configs[index], EGL_ALPHA_SIZE, &alpha);148 eglGetConfigAttrib(display(), configs[index], EGL_RED_SIZE, &red); 149 eglGetConfigAttrib(display(), configs[index], EGL_GREEN_SIZE, &green); 150 eglGetConfigAttrib(display(), configs[index], EGL_BLUE_SIZE, &blue); 151 eglGetConfigAttrib(display(), configs[index], EGL_ALPHA_SIZE, &alpha); 128 152 if (red == props.value(EGL_RED_SIZE) && 129 153 green == props.value(EGL_GREEN_SIZE) && … … 180 204 shareContext = 0; 181 205 if (shareContext) { 182 ctx = eglCreateContext(d py, cfg, shareContext->ctx, contextProps.properties());206 ctx = eglCreateContext(display(), cfg, shareContext->ctx, contextProps.properties()); 183 207 if (ctx == EGL_NO_CONTEXT) { 184 208 qWarning() << "QEglContext::createContext(): Could not share context:" << errorString(eglGetError()); … … 189 213 } 190 214 if (ctx == EGL_NO_CONTEXT) { 191 ctx = eglCreateContext(d py, cfg, 0, contextProps.properties());215 ctx = eglCreateContext(display(), cfg, 0, contextProps.properties()); 192 216 if (ctx == EGL_NO_CONTEXT) { 193 217 qWarning() << "QEglContext::createContext(): Unable to create EGL context:" << errorString(eglGetError()); … … 205 229 if (surface == currentSurface) 206 230 doneCurrent(); 207 eglDestroySurface(d py, surface);231 eglDestroySurface(display(), surface); 208 232 } 209 233 } 210 234 211 235 // Destroy the context. Note: this does not destroy the surface. 212 void QEglContext::destroy ()236 void QEglContext::destroyContext() 213 237 { 214 238 if (ctx != EGL_NO_CONTEXT && ownsContext) 215 eglDestroyContext(dpy, ctx); 216 dpy = EGL_NO_DISPLAY; 239 eglDestroyContext(display(), ctx); 217 240 ctx = EGL_NO_CONTEXT; 218 241 cfg = 0; … … 249 272 #endif 250 273 251 bool ok = eglMakeCurrent(d py, surface, surface, ctx);274 bool ok = eglMakeCurrent(display(), surface, surface, ctx); 252 275 if (!ok) 253 276 qWarning() << "QEglContext::makeCurrent():" << errorString(eglGetError()); … … 278 301 #endif 279 302 280 bool ok = eglMakeCurrent(d py, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);303 bool ok = eglMakeCurrent(display(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); 281 304 if (!ok) 282 305 qWarning() << "QEglContext::doneCurrent():" << errorString(eglGetError()); … … 300 323 return false; 301 324 302 bool ok = eglSwapBuffers(d py, surface);325 bool ok = eglSwapBuffers(display(), surface); 303 326 if (!ok) 304 327 qWarning() << "QEglContext::swapBuffers():" << errorString(eglGetError()); … … 339 362 bool QEglContext::configAttrib(int name, EGLint *value) const 340 363 { 341 return eglGetConfigAttrib(dpy, cfg, name, value); 364 return eglGetConfigAttrib(display(), cfg, name, value); 365 } 366 367 void QEglContext::clearError() 368 { 369 eglGetError(); 370 } 371 372 EGLint QEglContext::error() 373 { 374 return eglGetError(); 342 375 } 343 376 … … 351 384 for (int name = 0x3020; name <= 0x304F; ++name) { 352 385 EGLint value; 353 if (name != EGL_NONE && eglGetConfigAttrib(d py, cfg, name, &value))386 if (name != EGL_NONE && eglGetConfigAttrib(display(), cfg, name, &value)) 354 387 props.setValue(name, value); 355 388 } … … 358 391 } 359 392 360 // Initialize and return the default display. 361 EGLDisplay QEglContext::defaultDisplay(QPaintDevice *device) 362 { 363 static EGLDisplay dpy = EGL_NO_DISPLAY; 364 if (dpy == EGL_NO_DISPLAY) { 365 dpy = getDisplay(device); 393 EGLDisplay QEglContext::display() 394 { 395 if (!QEglContextTracker::displayOpened()) { 396 dpy = eglGetDisplay(nativeDisplay()); 397 QEglContextTracker::setDisplayOpened(); 366 398 if (dpy == EGL_NO_DISPLAY) { 367 qWarning() << "QEglContext::defaultDisplay(): Cannot open EGL display"; 399 qWarning("QEglContext::display(): Falling back to EGL_DEFAULT_DISPLAY"); 400 dpy = eglGetDisplay(EGLNativeDisplayType(EGL_DEFAULT_DISPLAY)); 401 } 402 if (dpy == EGL_NO_DISPLAY) { 403 qWarning("QEglContext::display(): Can't even open the default display"); 368 404 return EGL_NO_DISPLAY; 369 405 } 406 370 407 if (!eglInitialize(dpy, NULL, NULL)) { 371 qWarning() << "QEglContext::d efaultDisplay(): Cannot initialize EGL display:" << errorString(eglGetError());408 qWarning() << "QEglContext::display(): Cannot initialize EGL display:" << errorString(eglGetError()); 372 409 return EGL_NO_DISPLAY; 373 410 } 374 #ifdef EGL_OPENGL_ES_API 375 eglBindAPI(EGL_OPENGL_ES_API); 376 #endif 377 } 411 } 412 378 413 return dpy; 379 414 } 415 416 #if !defined(Q_WS_X11) && !defined(Q_WS_WINCE) // WinCE & X11 implement this properly 417 EGLNativeDisplayType QEglContext::nativeDisplay() 418 { 419 return EGL_DEFAULT_DISPLAY; 420 } 421 #endif 380 422 381 423 // Return the error string associated with a specific code. … … 411 453 QEglProperties props; 412 454 EGLint count = 0; 413 if (!eglGetConfigs(d py, 0, 0, &count) || count < 1)455 if (!eglGetConfigs(display(), 0, 0, &count) || count < 1) 414 456 return; 415 457 EGLConfig *configs = new EGLConfig [count]; 416 eglGetConfigs(d py, configs, count, &count);458 eglGetConfigs(display(), configs, count, &count); 417 459 for (EGLint index = 0; index < count; ++index) { 418 460 props = configProperties(configs[index]); … … 424 466 QString QEglContext::extensions() 425 467 { 426 const char* exts = eglQueryString(QEglContext::d efaultDisplay(0), EGL_EXTENSIONS);468 const char* exts = eglQueryString(QEglContext::display(), EGL_EXTENSIONS); 427 469 return QString(QLatin1String(exts)); 428 470 } … … 432 474 QList<QByteArray> extensions = 433 475 QByteArray(reinterpret_cast<const char *> 434 (eglQueryString(QEglContext::d efaultDisplay(0), EGL_EXTENSIONS))).split(' ');476 (eglQueryString(QEglContext::display(), EGL_EXTENSIONS))).split(' '); 435 477 return extensions.contains(extensionName); 436 478 }
Note:
See TracChangeset
for help on using the changeset viewer.