diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-05-25 08:23:01 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2010-05-25 08:23:01 (GMT) |
commit | 7c471bde498c07f03acc612d5f132b904bc3870e (patch) | |
tree | 136805e93f9b781c6900f5efaa0bd6ce2301b68d /src/gui/egl/qegl.cpp | |
parent | 55664a0ef4b88b67c9931c7d2f6853e5fa0a9716 (diff) | |
parent | 6f6909ac6681ed614f00998a0d43b7b195dbb90b (diff) | |
download | Qt-7c471bde498c07f03acc612d5f132b904bc3870e.zip Qt-7c471bde498c07f03acc612d5f132b904bc3870e.tar.gz Qt-7c471bde498c07f03acc612d5f132b904bc3870e.tar.bz2 |
Merge remote branch 'origin/4.6' into qt-4.7-from-4.6
Conflicts:
demos/spectrum/app/app.pro
src/gui/egl/qegl.cpp
tests/auto/qhttpnetworkconnection/qhttpnetworkconnection.pro
tests/auto/qmenu/tst_qmenu.cpp
Diffstat (limited to 'src/gui/egl/qegl.cpp')
-rw-r--r-- | src/gui/egl/qegl.cpp | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/gui/egl/qegl.cpp b/src/gui/egl/qegl.cpp index bf9f530..8b20a9e 100644 --- a/src/gui/egl/qegl.cpp +++ b/src/gui/egl/qegl.cpp @@ -42,6 +42,7 @@ #include <QtGui/qpaintdevice.h> #include <QtGui/qpixmap.h> #include <QtGui/qwidget.h> +#include <QtCore/qatomic.h> #include <QtCore/qdebug.h> #include "qegl_p.h" @@ -50,6 +51,34 @@ QT_BEGIN_NAMESPACE + +/* + QEglContextTracker is used to track the EGL contexts that we + create internally in Qt, so that we can call eglTerminate() to + free additional EGL resources when the last context is destroyed. +*/ + +class QEglContextTracker +{ +public: + static void ref() { contexts.ref(); } + static void deref() { + if (!contexts.deref()) { + eglTerminate(QEglContext::display()); + displayOpen = 0; + } + } + static void setDisplayOpened() { displayOpen = 1; } + static bool displayOpened() { return displayOpen; } + +private: + static QAtomicInt contexts; + static QAtomicInt displayOpen; +}; + +QAtomicInt QEglContextTracker::contexts = 0; +QAtomicInt QEglContextTracker::displayOpen = 0; + // Current GL and VG contexts. These are used to determine if // we can avoid an eglMakeCurrent() after a call to lazyDoneCurrent(). // If a background thread modifies the value, the worst that will @@ -66,6 +95,7 @@ QEglContext::QEglContext() , ownsContext(true) , sharing(false) { + QEglContextTracker::ref(); } QEglContext::~QEglContext() @@ -76,6 +106,7 @@ QEglContext::~QEglContext() currentGLContext = 0; if (currentVGContext == this) currentVGContext = 0; + QEglContextTracker::deref(); } bool QEglContext::isValid() const @@ -504,12 +535,9 @@ static _eglDestroyImageKHR qt_eglDestroyImageKHR = 0; EGLDisplay QEgl::display() { - static EGLDisplay dpy = EGL_NO_DISPLAY; - static bool openedDisplay = false; - - if (!openedDisplay) { + if (!QEglContextTracker::displayOpened()) { dpy = eglGetDisplay(nativeDisplay()); - openedDisplay = true; + QEglContextTracker::setDisplayOpened(); if (dpy == EGL_NO_DISPLAY) { qWarning("QEgl::display(): Falling back to EGL_DEFAULT_DISPLAY"); dpy = eglGetDisplay(EGLNativeDisplayType(EGL_DEFAULT_DISPLAY)); |