eglfs: Make QEglFSWindow respect the window format
authorGirish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
Wed, 13 Jun 2012 23:38:27 +0000 (16:38 -0700)
committerQt by Nokia <qt-info@nokia.com>
Thu, 14 Jun 2012 14:12:19 +0000 (16:12 +0200)
Prior to this change, eglfs code used to override the window format
with it's own format. With this change, eglfs will respect the window
format. This is useful when the application requires a surface with
alpha (for example, so that the video layer below is visible)

QEglFSHooks::surfaceFormatFor() allows the hook author to override
the context and window surface format.

Change-Id: I97f03a8b0871dfebfca73004fa0188b33d0d0367
Reviewed-by: Johannes Zellner <johannes.zellner@nokia.com>
Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
src/plugins/platforms/eglfs/qeglfscontext.cpp
src/plugins/platforms/eglfs/qeglfshooks.h
src/plugins/platforms/eglfs/qeglfshooks_stub.cpp
src/plugins/platforms/eglfs/qeglfswindow.cpp
src/plugins/platforms/eglfs/qeglfswindow.h

index 7e874be..1a16b36 100644 (file)
@@ -50,15 +50,12 @@ QT_BEGIN_NAMESPACE
 
 QEglFSContext::QEglFSContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share,
                              EGLDisplay display, EGLenum eglApi)
-    : QEGLPlatformContext(format, share, display, eglApi)
+    : QEGLPlatformContext(hooks->surfaceFormatFor(format), share, display, eglApi)
 {
 }
 
 bool QEglFSContext::makeCurrent(QPlatformSurface *surface)
 {
-    // create the native window surface. this makes sure that
-    // we create surfaces only for painted widgets (unlike QDesktopWidget)
-    (static_cast<QEglFSWindow *>(surface))->create();
     return QEGLPlatformContext::makeCurrent(surface);
 }
 
index baaa90a..3e40d16 100644 (file)
@@ -61,7 +61,7 @@ public:
     virtual QSize screenSize() const;
     virtual int screenDepth() const;
     virtual QImage::Format screenFormat() const;
-    virtual QSurfaceFormat defaultSurfaceFormat() const;
+    virtual QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &inputFormat) const;
     virtual EGLNativeWindowType createNativeWindow(const QSize &size);
     virtual void destroyNativeWindow(EGLNativeWindowType window);
     virtual bool hasCapability(QPlatformIntegration::Capability cap) const;
index fbc02d1..fe622e1 100644 (file)
@@ -72,26 +72,9 @@ QImage::Format QEglFSHooks::screenFormat() const
     return screenDepth() == 16 ? QImage::Format_RGB16 : QImage::Format_RGB32;
 }
 
-QSurfaceFormat QEglFSHooks::defaultSurfaceFormat() const
+QSurfaceFormat QEglFSHooks::surfaceFormatFor(const QSurfaceFormat &inputFormat) const
 {
-    QSurfaceFormat format;
-    if (screenDepth() == 16) {
-        format.setDepthBufferSize(16);
-        format.setRedBufferSize(5);
-        format.setGreenBufferSize(6);
-        format.setBlueBufferSize(5);
-    } else {
-        format.setDepthBufferSize(24);
-        format.setStencilBufferSize(8);
-        format.setRedBufferSize(8);
-        format.setGreenBufferSize(8);
-        format.setBlueBufferSize(8);
-    }
-
-    static int samples = qgetenv("QT_QPA_EGLFS_MULTISAMPLE").toInt();
-    format.setSamples(samples);
-
-    return format;
+    return inputFormat;
 }
 
 EGLNativeWindowType QEglFSHooks::createNativeWindow(const QSize &size)
index 5e6d09a..6cb9fc6 100644 (file)
@@ -61,6 +61,8 @@ QEglFSWindow::QEglFSWindow(QWindow *w)
 #endif
 
     setWindowState(Qt::WindowFullScreen);
+
+    create();
 }
 
 QEglFSWindow::~QEglFSWindow()
@@ -70,19 +72,17 @@ QEglFSWindow::~QEglFSWindow()
 
 void QEglFSWindow::create()
 {
-    if (m_window) {
-        return;
-    }
+    Q_ASSERT(!m_window);
 
     EGLDisplay display = (static_cast<QEglFSScreen *>(window()->screen()->handle()))->display();
-    QSurfaceFormat platformFormat = hooks->defaultSurfaceFormat();
+    QSurfaceFormat platformFormat = hooks->surfaceFormatFor(window()->requestedFormat());
     EGLConfig config = q_configFromGLFormat(display, platformFormat);
+    m_format = q_glFormatFromConfig(display, config);
     m_window = hooks->createNativeWindow(hooks->screenSize());
     m_surface = eglCreateWindowSurface(display, config, m_window, NULL);
     if (m_surface == EGL_NO_SURFACE) {
-        qWarning("Could not create the egl surface: error = 0x%x\n", eglGetError());
         eglTerminate(display);
-        qFatal("EGL error");
+        qFatal("EGL Error : Could not create the egl surface: error = 0x%x\n", eglGetError());
     }
 }
 
@@ -122,7 +122,7 @@ WId QEglFSWindow::winId() const
 
 QSurfaceFormat QEglFSWindow::format() const
 {
-    return hooks->defaultSurfaceFormat();
+    return m_format;
 }
 
 QT_END_NAMESPACE
index f8c594b..85866e4 100644 (file)
@@ -69,6 +69,7 @@ private:
     WId m_winid;
     EGLSurface m_surface;
     EGLNativeWindowType m_window;
+    QSurfaceFormat m_format;
 };
 QT_END_NAMESPACE
 #endif // QEGLFSWINDOW_H