summaryrefslogtreecommitdiffstats
path: root/src/gui/egl
diff options
context:
space:
mode:
authorTrond Kjernåsen <trond.kjernasen@nokia.com>2010-05-21 11:24:54 (GMT)
committerTrond Kjernåsen <trond.kjernasen@nokia.com>2010-05-21 11:24:54 (GMT)
commit17555ab77041d5b68972eab608fe98799e0789e9 (patch)
treeae1c6911feb362c7245180c939355dc874e381bd /src/gui/egl
parent803c7c3ff783ca74bc75fe574a98db51e2de9f22 (diff)
downloadQt-17555ab77041d5b68972eab608fe98799e0789e9.zip
Qt-17555ab77041d5b68972eab608fe98799e0789e9.tar.gz
Qt-17555ab77041d5b68972eab608fe98799e0789e9.tar.bz2
Call eglTerminate() when the last QEglContext is destroyed to free mem.
We never called eglTerminate() to free memory allocated by eglInitialize() since it was a fixed allocation that would be used for the lifetime of an application. The new behavior is to call eglTerminate() when the last EGL context in the app is destroyed. Task-number: QT-3383 Reviewed-by: Rhys Weatherley
Diffstat (limited to 'src/gui/egl')
-rw-r--r--src/gui/egl/qegl.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/gui/egl/qegl.cpp b/src/gui/egl/qegl.cpp
index ee19216..c16aeb1 100644
--- a/src/gui/egl/qegl.cpp
+++ b/src/gui/egl/qegl.cpp
@@ -42,11 +42,40 @@
#include <QtGui/qpaintdevice.h>
#include <QtGui/qpixmap.h>
#include <QtGui/qwidget.h>
+#include <QtCore/qatomic.h>
#include <QtCore/qdebug.h>
#include "qegl_p.h"
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
@@ -65,6 +94,7 @@ QEglContext::QEglContext()
, ownsContext(true)
, sharing(false)
{
+ QEglContextTracker::ref();
}
QEglContext::~QEglContext()
@@ -75,6 +105,7 @@ QEglContext::~QEglContext()
currentGLContext = 0;
if (currentVGContext == this)
currentVGContext = 0;
+ QEglContextTracker::deref();
}
bool QEglContext::isValid() const
@@ -361,11 +392,9 @@ QEglProperties QEglContext::configProperties(EGLConfig cfg) const
EGLDisplay QEglContext::display()
{
- static bool openedDisplay = false;
-
- if (!openedDisplay) {
+ if (!QEglContextTracker::displayOpened()) {
dpy = eglGetDisplay(nativeDisplay());
- openedDisplay = true;
+ QEglContextTracker::setDisplayOpened();
if (dpy == EGL_NO_DISPLAY) {
qWarning("QEglContext::display(): Falling back to EGL_DEFAULT_DISPLAY");
dpy = eglGetDisplay(EGLNativeDisplayType(EGL_DEFAULT_DISPLAY));