eglfs refactor: Move egl initialization to the integration
authorGirish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
Fri, 1 Jun 2012 19:04:35 +0000 (12:04 -0700)
committerQt by Nokia <qt-info@nokia.com>
Tue, 5 Jun 2012 16:48:16 +0000 (18:48 +0200)
Change-Id: If2c870538c742fd034fb9e5c115e4ac0bd8e2e03
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/plugins/platforms/eglfs/qeglfsintegration.cpp
src/plugins/platforms/eglfs/qeglfsintegration.h
src/plugins/platforms/eglfs/qeglfsscreen.cpp
src/plugins/platforms/eglfs/qeglfsscreen.h

index a42f685..94bf0d9 100644 (file)
@@ -66,7 +66,7 @@
 QT_BEGIN_NAMESPACE
 
 QEglFSIntegration::QEglFSIntegration()
-    : mEventDispatcher(createUnixEventDispatcher()), mFontDb(new QGenericUnixFontDatabase()), mScreen(new QEglFSScreen)
+    : mEventDispatcher(createUnixEventDispatcher()), mFontDb(new QGenericUnixFontDatabase())
 {
     QGuiApplicationPrivate::instance()->setEventDispatcher(mEventDispatcher);
 
@@ -74,6 +74,40 @@ QEglFSIntegration::QEglFSIntegration()
     new QEvdevMouseManager(QLatin1String("EvdevMouse"), QString() /* spec */, this);
     new QEvdevTouchScreenHandlerThread(QString() /* spec */, this);
 
+    hooks->platformInit();
+
+    EGLint major, minor;
+
+    if (!eglBindAPI(EGL_OPENGL_ES_API)) {
+        qWarning("Could not bind GL_ES API\n");
+        qFatal("EGL error");
+    }
+
+    mDisplay = eglGetDisplay(hooks ? hooks->platformDisplay() : EGL_DEFAULT_DISPLAY);
+    if (mDisplay == EGL_NO_DISPLAY) {
+        qWarning("Could not open egl display\n");
+        qFatal("EGL error");
+    }
+    qWarning("Opened display %p\n", mDisplay);
+
+    if (!eglInitialize(mDisplay, &major, &minor)) {
+        qWarning("Could not initialize egl display\n");
+        qFatal("EGL error");
+    }
+
+    qWarning("Initialized display %d %d\n", major, minor);
+
+    int swapInterval = 1;
+    QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL");
+    if (!swapIntervalString.isEmpty()) {
+        bool ok;
+        swapInterval = swapIntervalString.toInt(&ok);
+        if (!ok)
+            swapInterval = 1;
+    }
+    eglSwapInterval(mDisplay, swapInterval);
+
+    mScreen = new QEglFSScreen(mDisplay);
     screenAdded(mScreen);
 
 #ifdef QEGL_EXTRA_DEBUG
@@ -84,6 +118,9 @@ QEglFSIntegration::QEglFSIntegration()
 QEglFSIntegration::~QEglFSIntegration()
 {
     delete mScreen;
+
+    eglTerminate(mDisplay);
+    hooks->platformDestroy();
 }
 
 bool QEglFSIntegration::hasCapability(QPlatformIntegration::Capability cap) const
index 14cec21..341b553 100644 (file)
@@ -76,6 +76,7 @@ public:
     void *nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context);
 
 private:
+    EGLDisplay mDisplay;
     QAbstractEventDispatcher *mEventDispatcher;
     QPlatformFontDatabase *mFontDb;
     QPlatformScreen *mScreen;
index 007829b..8374ba5 100644 (file)
@@ -78,8 +78,9 @@ public:
     }
 };
 
-QEglFSScreen::QEglFSScreen()
-    : m_depth(32)
+QEglFSScreen::QEglFSScreen(EGLDisplay dpy)
+    : m_dpy(dpy)
+    , m_depth(32)
     , m_format(QImage::Format_Invalid)
     , m_platformContext(0)
     , m_surface(0)
@@ -90,39 +91,6 @@ QEglFSScreen::QEglFSScreen()
     qWarning("QEglScreen %p\n", this);
 #endif
 
-    hooks->platformInit();
-
-    EGLint major, minor;
-
-    if (!eglBindAPI(EGL_OPENGL_ES_API)) {
-        qWarning("Could not bind GL_ES API\n");
-        qFatal("EGL error");
-    }
-
-    m_dpy = eglGetDisplay(hooks ? hooks->platformDisplay() : EGL_DEFAULT_DISPLAY);
-    if (m_dpy == EGL_NO_DISPLAY) {
-        qWarning("Could not open egl display\n");
-        qFatal("EGL error");
-    }
-    qWarning("Opened display %p\n", m_dpy);
-
-    if (!eglInitialize(m_dpy, &major, &minor)) {
-        qWarning("Could not initialize egl display\n");
-        qFatal("EGL error");
-    }
-
-    qWarning("Initialized display %d %d\n", major, minor);
-
-    int swapInterval = 1;
-    QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL");
-    if (!swapIntervalString.isEmpty()) {
-        bool ok;
-        swapInterval = swapIntervalString.toInt(&ok);
-        if (!ok)
-            swapInterval = 1;
-    }
-    eglSwapInterval(m_dpy, swapInterval);
-
     static int hideCursor = qgetenv("QT_QPA_EGLFS_HIDECURSOR").toInt();
     if (!hideCursor) {
         if (QEglFSCursor *customCursor = hooks->createCursor(this))
@@ -140,10 +108,6 @@ QEglFSScreen::~QEglFSScreen()
         eglDestroySurface(m_dpy, m_surface);
 
     hooks->destroyNativeWindow(m_window);
-
-    eglTerminate(m_dpy);
-
-    hooks->platformDestroy();
 }
 
 void QEglFSScreen::createAndSetPlatformContext() const {
index ba5db65..7b8860e 100644 (file)
@@ -56,7 +56,7 @@ class QEglFSCursor;
 class QEglFSScreen : public QPlatformScreen //huh: FullScreenScreen ;) just to follow namespace
 {
 public:
-    QEglFSScreen();
+    QEglFSScreen(EGLDisplay display);
     ~QEglFSScreen();
 
     QRect geometry() const;
@@ -74,11 +74,11 @@ private:
     void createAndSetPlatformContext() const;
     void createAndSetPlatformContext();
 
+    EGLDisplay m_dpy;
     QRect m_geometry;
     int m_depth;
     QImage::Format m_format;
     QPlatformOpenGLContext *m_platformContext;
-    EGLDisplay m_dpy;
     EGLSurface m_surface;
     EGLNativeWindowType m_window;
     QEglFSCursor *m_cursor;