From b5e041d48d49ad684dcc8c922d47cbaa4e53574a Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Fri, 1 Jun 2012 12:18:45 -0700 Subject: [PATCH] eglfs refactor: Query screen and format info from hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows boards to customize what they really work best for without having to set environment variables. Change-Id: Ib40c3a870ade568f66e37e621a8abc6b17e39411 Reviewed-by: Samuel Rødal --- src/plugins/platforms/eglfs/qeglfshooks.h | 5 +++ .../platforms/eglfs/qeglfshooks_stub.cpp | 33 ++++++++++++++ src/plugins/platforms/eglfs/qeglfsscreen.cpp | 43 ++----------------- src/plugins/platforms/eglfs/qeglfsscreen.h | 3 -- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/plugins/platforms/eglfs/qeglfshooks.h b/src/plugins/platforms/eglfs/qeglfshooks.h index 22ba77149d..baaa90aa91 100644 --- a/src/plugins/platforms/eglfs/qeglfshooks.h +++ b/src/plugins/platforms/eglfs/qeglfshooks.h @@ -43,6 +43,8 @@ #define QEGLFSHOOKS_H #include +#include +#include #include QT_BEGIN_NAMESPACE @@ -57,6 +59,9 @@ public: virtual void platformDestroy(); virtual EGLNativeDisplayType platformDisplay() const; virtual QSize screenSize() const; + virtual int screenDepth() const; + virtual QImage::Format screenFormat() const; + virtual QSurfaceFormat defaultSurfaceFormat() const; virtual EGLNativeWindowType createNativeWindow(const QSize &size); virtual void destroyNativeWindow(EGLNativeWindowType window); virtual bool hasCapability(QPlatformIntegration::Capability cap) const; diff --git a/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp b/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp index d0e3e4546d..fbc02d1a01 100644 --- a/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp +++ b/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp @@ -61,6 +61,39 @@ QSize QEglFSHooks::screenSize() const return QSize(); } +int QEglFSHooks::screenDepth() const +{ + static int depth = qgetenv("QT_QPA_EGLFS_DEPTH").toInt(); + return depth == 16 ? 16 : 32; +} + +QImage::Format QEglFSHooks::screenFormat() const +{ + return screenDepth() == 16 ? QImage::Format_RGB16 : QImage::Format_RGB32; +} + +QSurfaceFormat QEglFSHooks::defaultSurfaceFormat() 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; +} + EGLNativeWindowType QEglFSHooks::createNativeWindow(const QSize &size) { Q_UNUSED(size); diff --git a/src/plugins/platforms/eglfs/qeglfsscreen.cpp b/src/plugins/platforms/eglfs/qeglfsscreen.cpp index 8374ba5707..4f14efc0a7 100644 --- a/src/plugins/platforms/eglfs/qeglfsscreen.cpp +++ b/src/plugins/platforms/eglfs/qeglfsscreen.cpp @@ -80,8 +80,6 @@ public: QEglFSScreen::QEglFSScreen(EGLDisplay dpy) : m_dpy(dpy) - , m_depth(32) - , m_format(QImage::Format_Invalid) , m_platformContext(0) , m_surface(0) , m_window(0) @@ -116,28 +114,7 @@ void QEglFSScreen::createAndSetPlatformContext() const { void QEglFSScreen::createAndSetPlatformContext() { - QSurfaceFormat platformFormat; - - QByteArray depthString = qgetenv("QT_QPA_EGLFS_DEPTH"); - if (depthString.toInt() == 16) { - platformFormat.setDepthBufferSize(16); - platformFormat.setRedBufferSize(5); - platformFormat.setGreenBufferSize(6); - platformFormat.setBlueBufferSize(5); - m_depth = 16; - m_format = QImage::Format_RGB16; - } else { - platformFormat.setDepthBufferSize(24); - platformFormat.setStencilBufferSize(8); - platformFormat.setRedBufferSize(8); - platformFormat.setGreenBufferSize(8); - platformFormat.setBlueBufferSize(8); - m_depth = 32; - m_format = QImage::Format_RGB32; - } - - if (!qgetenv("QT_QPA_EGLFS_MULTISAMPLE").isEmpty()) - platformFormat.setSamples(4); + QSurfaceFormat platformFormat = hooks->defaultSurfaceFormat(); EGLConfig config = q_configFromGLFormat(m_dpy, platformFormat); @@ -157,33 +134,21 @@ void QEglFSScreen::createAndSetPlatformContext() QEGLPlatformContext *platformContext = new QEglFSContext(platformFormat, 0, m_dpy); m_platformContext = platformContext; - - EGLint w,h; // screen size detection - eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w); - eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h); - - m_geometry = QRect(0,0,w,h); - } QRect QEglFSScreen::geometry() const { - if (m_geometry.isNull()) { - createAndSetPlatformContext(); - } - return m_geometry; + return QRect(QPoint(0, 0), hooks->screenSize()); } int QEglFSScreen::depth() const { - return m_depth; + return hooks->screenDepth(); } QImage::Format QEglFSScreen::format() const { - if (m_format == QImage::Format_Invalid) - createAndSetPlatformContext(); - return m_format; + return hooks->screenFormat(); } QPlatformCursor *QEglFSScreen::cursor() const diff --git a/src/plugins/platforms/eglfs/qeglfsscreen.h b/src/plugins/platforms/eglfs/qeglfsscreen.h index 7b8860e9df..9b67e29763 100644 --- a/src/plugins/platforms/eglfs/qeglfsscreen.h +++ b/src/plugins/platforms/eglfs/qeglfsscreen.h @@ -75,9 +75,6 @@ private: void createAndSetPlatformContext(); EGLDisplay m_dpy; - QRect m_geometry; - int m_depth; - QImage::Format m_format; QPlatformOpenGLContext *m_platformContext; EGLSurface m_surface; EGLNativeWindowType m_window;