diff options
Diffstat (limited to 'src/plugins/platforms/eglfs')
-rw-r--r-- | src/plugins/platforms/eglfs/eglfs.pri | 44 | ||||
-rw-r--r-- | src/plugins/platforms/eglfs/eglfs.pro | 46 | ||||
-rw-r--r-- | src/plugins/platforms/eglfs/qeglfscontext.cpp | 22 | ||||
-rw-r--r-- | src/plugins/platforms/eglfs/qeglfscursor.cpp | 7 | ||||
-rw-r--r-- | src/plugins/platforms/eglfs/qeglfshooks.h | 20 | ||||
-rw-r--r-- | src/plugins/platforms/eglfs/qeglfshooks_stub.cpp | 134 | ||||
-rw-r--r-- | src/plugins/platforms/eglfs/qeglfsintegration.cpp | 48 | ||||
-rw-r--r-- | src/plugins/platforms/eglfs/qeglfsintegration.h | 9 | ||||
-rw-r--r-- | src/plugins/platforms/eglfs/qeglfsscreen.cpp | 13 | ||||
-rw-r--r-- | src/plugins/platforms/eglfs/qeglfsscreen.h | 2 | ||||
-rw-r--r-- | src/plugins/platforms/eglfs/qeglfswindow.cpp | 37 | ||||
-rw-r--r-- | src/plugins/platforms/eglfs/qeglfswindow.h | 4 |
12 files changed, 284 insertions, 102 deletions
diff --git a/src/plugins/platforms/eglfs/eglfs.pri b/src/plugins/platforms/eglfs/eglfs.pri new file mode 100644 index 0000000000..eb66e17479 --- /dev/null +++ b/src/plugins/platforms/eglfs/eglfs.pri @@ -0,0 +1,44 @@ +QT += core-private gui-private platformsupport-private + +#DEFINES += QEGL_EXTRA_DEBUG + +#Avoid X11 header collision +DEFINES += MESA_EGL_NO_X11_HEADERS + +#To test the hooks on x11 (xlib), comment the above define too +#EGLFS_PLATFORM_HOOKS_SOURCES += qeglfshooks_x11.cpp +#LIBS += -lX11 + +SOURCES += $$PWD/qeglfsintegration.cpp \ + $$PWD/qeglfswindow.cpp \ + $$PWD/qeglfsbackingstore.cpp \ + $$PWD/qeglfsscreen.cpp \ + $$PWD/qeglfshooks_stub.cpp \ + $$PWD/qeglfscursor.cpp \ + $$PWD/qeglfscontext.cpp + +HEADERS += $$PWD/qeglfsintegration.h \ + $$PWD/qeglfswindow.h \ + $$PWD/qeglfsbackingstore.h \ + $$PWD/qeglfsscreen.h \ + $$PWD/qeglfscursor.h \ + $$PWD/qeglfshooks.h \ + $$PWD/qeglfscontext.h + +QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF + +INCLUDEPATH += $$PWD + +!isEmpty(EGLFS_PLATFORM_HOOKS_SOURCES) { + HEADERS += $$EGLFS_PLATFORM_HOOKS_HEADERS + SOURCES += $$EGLFS_PLATFORM_HOOKS_SOURCES + LIBS += $$EGLFS_PLATFORM_HOOKS_LIBS + DEFINES += EGLFS_PLATFORM_HOOKS +} + +CONFIG += egl qpa/genericunixfontdatabase + +RESOURCES += $$PWD/cursor.qrc + +OTHER_FILES += \ + $$PWD/eglfs.json diff --git a/src/plugins/platforms/eglfs/eglfs.pro b/src/plugins/platforms/eglfs/eglfs.pro index 45059a9cb9..8827f7680c 100644 --- a/src/plugins/platforms/eglfs/eglfs.pro +++ b/src/plugins/platforms/eglfs/eglfs.pro @@ -4,48 +4,6 @@ PLUGIN_TYPE = platforms PLUGIN_CLASS_NAME = QEglFSIntegrationPlugin load(qt_plugin) -QT += core-private gui-private platformsupport-private +SOURCES += $$PWD/main.cpp -#DEFINES += QEGL_EXTRA_DEBUG - -#Avoid X11 header collision -DEFINES += MESA_EGL_NO_X11_HEADERS - -#To test the hooks on x11 (xlib), comment the above define too -#EGLFS_PLATFORM_HOOKS_SOURCES += qeglfshooks_x11.cpp -#LIBS += -lX11 - -SOURCES = main.cpp \ - qeglfsintegration.cpp \ - qeglfswindow.cpp \ - qeglfsbackingstore.cpp \ - qeglfsscreen.cpp \ - qeglfshooks_stub.cpp \ - qeglfscursor.cpp \ - qeglfscontext.cpp - -HEADERS = qeglfsintegration.h \ - qeglfswindow.h \ - qeglfsbackingstore.h \ - qeglfsscreen.h \ - qeglfscursor.h \ - qeglfshooks.h \ - qeglfscontext.h - -QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF - -INCLUDEPATH += $$PWD - -!isEmpty(EGLFS_PLATFORM_HOOKS_SOURCES) { - HEADERS += $$EGLFS_PLATFORM_HOOKS_HEADERS - SOURCES += $$EGLFS_PLATFORM_HOOKS_SOURCES - LIBS += $$EGLFS_PLATFORM_HOOKS_LIBS - DEFINES += EGLFS_PLATFORM_HOOKS -} - -CONFIG += egl qpa/genericunixfontdatabase - -RESOURCES += cursor.qrc - -OTHER_FILES += \ - eglfs.json +include(eglfs.pri) diff --git a/src/plugins/platforms/eglfs/qeglfscontext.cpp b/src/plugins/platforms/eglfs/qeglfscontext.cpp index 66b42d64e7..51439646c6 100644 --- a/src/plugins/platforms/eglfs/qeglfscontext.cpp +++ b/src/plugins/platforms/eglfs/qeglfscontext.cpp @@ -43,14 +43,17 @@ #include "qeglfswindow.h" #include "qeglfscursor.h" #include "qeglfshooks.h" +#include "qeglfsintegration.h" +#include <QtPlatformSupport/private/qeglpbuffer_p.h> +#include <QtGui/QSurface> #include <QtDebug> QT_BEGIN_NAMESPACE QEglFSContext::QEglFSContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display, EGLenum eglApi) - : QEGLPlatformContext(hooks->surfaceFormatFor(format), share, display, eglApi) + : QEGLPlatformContext(QEglFSHooks::hooks()->surfaceFormatFor(format), share, display, QEglFSIntegration::chooseConfig(display, QEglFSHooks::hooks()->surfaceFormatFor(format)), eglApi) { } @@ -61,17 +64,22 @@ bool QEglFSContext::makeCurrent(QPlatformSurface *surface) EGLSurface QEglFSContext::eglSurfaceForPlatformSurface(QPlatformSurface *surface) { - QEglFSWindow *window = static_cast<QEglFSWindow *>(surface); - return window->surface(); + if (surface->surface()->surfaceClass() == QSurface::Window) + return static_cast<QEglFSWindow *>(surface)->surface(); + else + return static_cast<QEGLPbuffer *>(surface)->pbuffer(); } void QEglFSContext::swapBuffers(QPlatformSurface *surface) { - QEglFSWindow *window = static_cast<QEglFSWindow *>(surface); - // draw the cursor - if (QEglFSCursor *cursor = static_cast<QEglFSCursor *>(window->screen()->cursor())) - cursor->paintOnScreen(); + if (surface->surface()->surfaceClass() == QSurface::Window) { + QEglFSWindow *window = static_cast<QEglFSWindow *>(surface); + // draw the cursor + if (QEglFSCursor *cursor = static_cast<QEglFSCursor *>(window->screen()->cursor())) + cursor->paintOnScreen(); + } + QEglFSHooks::hooks()->waitForVSync(); QEGLPlatformContext::swapBuffers(surface); } diff --git a/src/plugins/platforms/eglfs/qeglfscursor.cpp b/src/plugins/platforms/eglfs/qeglfscursor.cpp index c245b1b5bb..9dc836b8b1 100644 --- a/src/plugins/platforms/eglfs/qeglfscursor.cpp +++ b/src/plugins/platforms/eglfs/qeglfscursor.cpp @@ -196,15 +196,16 @@ void QEglFSCursor::changeCursor(QCursor *cursor, QWindow *window) bool QEglFSCursor::setCurrentCursor(QCursor *cursor) { - if (m_cursor.shape == cursor->shape() && cursor->shape() != Qt::BitmapCursor) + const Qt::CursorShape newShape = cursor ? cursor->shape() : Qt::ArrowCursor; + if (m_cursor.shape == newShape && newShape != Qt::BitmapCursor) return false; if (m_cursor.shape == Qt::BitmapCursor) { m_cursor.customCursorImage = QImage(); // in case render() never uploaded it } - m_cursor.shape = cursor->shape(); - if (cursor->shape() != Qt::BitmapCursor) { // standard cursor + m_cursor.shape = newShape; + if (newShape != Qt::BitmapCursor) { // standard cursor const float ws = (float)m_cursorAtlas.cursorWidth / m_cursorAtlas.width, hs = (float)m_cursorAtlas.cursorHeight / m_cursorAtlas.height; m_cursor.textureRect = QRectF(ws * (m_cursor.shape % m_cursorAtlas.cursorsPerRow), diff --git a/src/plugins/platforms/eglfs/qeglfshooks.h b/src/plugins/platforms/eglfs/qeglfshooks.h index 2d095ba934..c4ac7185fb 100644 --- a/src/plugins/platforms/eglfs/qeglfshooks.h +++ b/src/plugins/platforms/eglfs/qeglfshooks.h @@ -55,10 +55,11 @@ class QEglFSScreen; class QEglFSHooks { public: - virtual ~QEglFSHooks() {}; + virtual ~QEglFSHooks() {} virtual void platformInit(); virtual void platformDestroy(); virtual EGLNativeDisplayType platformDisplay() const; + virtual QSizeF physicalScreenSize() const; virtual QSize screenSize() const; virtual int screenDepth() const; virtual QImage::Format screenFormat() const; @@ -67,15 +68,22 @@ public: virtual void destroyNativeWindow(EGLNativeWindowType window); virtual bool hasCapability(QPlatformIntegration::Capability cap) const; virtual QEglFSCursor *createCursor(QEglFSScreen *screen) const; -}; + virtual bool filterConfig(EGLDisplay display, EGLConfig config) const; + virtual void waitForVSync() const; + + virtual const char *fbDeviceName() const; + static QEglFSHooks *hooks() + { #ifdef EGLFS_PLATFORM_HOOKS -extern QEglFSHooks *platformHooks; -static QEglFSHooks *hooks = platformHooks; + extern QEglFSHooks *platformHooks; + return platformHooks; #else -extern QEglFSHooks stubHooks; -static QEglFSHooks *hooks = &stubHooks; + extern QEglFSHooks stubHooks; + return &stubHooks; #endif + } +}; QT_END_NAMESPACE diff --git a/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp b/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp index e9a22ea605..8200fa70b2 100644 --- a/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp +++ b/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp @@ -46,15 +46,32 @@ #include <linux/fb.h> #include <sys/ioctl.h> +#include <private/qmath_p.h> +#include <private/qcore_unix_p.h> + QT_BEGIN_NAMESPACE +// file descriptor for the frame buffer +// this is a global static to keep the QEglFSHooks interface as clean as possible +static int framebuffer = -1; + +const char *QEglFSHooks::fbDeviceName() const +{ + return "/dev/fb0"; +} + void QEglFSHooks::platformInit() { - Q_UNUSED(hooks); + framebuffer = qt_safe_open(fbDeviceName(), O_RDONLY); + + if (framebuffer == -1) + qWarning("EGLFS: Failed to open %s", fbDeviceName()); } void QEglFSHooks::platformDestroy() { + if (framebuffer != -1) + close(framebuffer); } EGLNativeDisplayType QEglFSHooks::platformDisplay() const @@ -62,6 +79,55 @@ EGLNativeDisplayType QEglFSHooks::platformDisplay() const return EGL_DEFAULT_DISPLAY; } +QSizeF QEglFSHooks::physicalScreenSize() const +{ + static QSizeF size; + if (size.isEmpty()) { + + // Note: in millimeters + int width = qgetenv("QT_QPA_EGLFS_PHYSICAL_WIDTH").toInt(); + int height = qgetenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT").toInt(); + + if (width && height) { + // no need to read fb0 + size.setWidth(width); + size.setHeight(height); + return size; + } + + struct fb_var_screeninfo vinfo; + int w = -1; + int h = -1; + + if (framebuffer != -1) { + if (ioctl(framebuffer, FBIOGET_VSCREENINFO, &vinfo) == -1) { + qWarning("EGLFS: Could not query variable screen info."); + } else { + w = vinfo.width; + h = vinfo.height; + } + } + + const int defaultPhysicalDpi = 100; + size.setWidth(w <= 0 ? vinfo.xres * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(w)); + size.setHeight(h <= 0 ? vinfo.yres * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(h)); + + if (w <= 0 || h <= 0) { + qWarning("EGLFS: Unable to query physical screen size, defaulting to %d dpi.\n" + "EGLFS: To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH " + "and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).", + defaultPhysicalDpi); + } + + // override fb0 from environment var setting + if (width) + size.setWidth(width); + if (height) + size.setWidth(height); + } + return size; +} + QSize QEglFSHooks::screenSize() const { static QSize size; @@ -78,17 +144,28 @@ QSize QEglFSHooks::screenSize() const } struct fb_var_screeninfo vinfo; - int fd = open("/dev/fb0", O_RDONLY); - if (fd != -1) { - if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1) - qWarning("Could not query variable screen info."); - else - size = QSize(vinfo.xres, vinfo.yres); + int xres = -1; + int yres = -1; + + if (framebuffer != -1) { + if (ioctl(framebuffer, FBIOGET_VSCREENINFO, &vinfo) == -1) { + qWarning("EGLFS: Could not query variable screen info."); + } else { + xres = vinfo.xres; + yres = vinfo.yres; + } + } + + const int defaultWidth = 800; + const int defaultHeight = 600; + size.setWidth(xres <= 0 ? defaultWidth : xres); + size.setHeight(yres <= 0 ? defaultHeight : yres); - close(fd); - } else { - qWarning("Failed to open /dev/fb0 to detect screen resolution."); + if (xres <= 0 || yres <= 0) { + qWarning("EGLFS: Unable to query screen resolution, defaulting to %dx%d.\n" + "EGLFS: To override, set QT_QPA_EGLFS_WIDTH and QT_QPA_EGLFS_HEIGHT.", + defaultWidth, defaultHeight); } // override fb0 from environment var setting @@ -107,21 +184,25 @@ int QEglFSHooks::screenDepth() const if (depth == 0) { struct fb_var_screeninfo vinfo; - int fd = open("/dev/fb0", O_RDONLY); - if (fd != -1) { - if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1) - qWarning("Could not query variable screen info."); + if (framebuffer != -1) { + if (ioctl(framebuffer, FBIOGET_VSCREENINFO, &vinfo) == -1) + qWarning("EGLFS: Could not query variable screen info."); else depth = vinfo.bits_per_pixel; + } + + const int defaultDepth = 32; + + if (depth <= 0) { + depth = defaultDepth; - close(fd); - } else { - qWarning("Failed to open /dev/fb0 to detect screen depth."); + qWarning("EGLFS: Unable to query screen depth, defaulting to %d.\n" + "EGLFS: To override, set QT_QPA_EGLFS_DEPTH.", defaultDepth); } } - return depth == 0 ? 32 : depth; + return depth; } QImage::Format QEglFSHooks::screenFormat() const @@ -134,6 +215,11 @@ QSurfaceFormat QEglFSHooks::surfaceFormatFor(const QSurfaceFormat &inputFormat) return inputFormat; } +bool QEglFSHooks::filterConfig(EGLDisplay, EGLConfig) const +{ + return true; +} + EGLNativeWindowType QEglFSHooks::createNativeWindow(const QSize &size, const QSurfaceFormat &format) { Q_UNUSED(size); @@ -158,6 +244,18 @@ QEglFSCursor *QEglFSHooks::createCursor(QEglFSScreen *screen) const return 0; } +void QEglFSHooks::waitForVSync() const +{ +#if defined(FBIO_WAITFORVSYNC) + static const bool forceSync = qgetenv("QT_QPA_EGLFS_FORCEVSYNC").toInt(); + if (forceSync && framebuffer != -1) { + int arg = 0; + if (ioctl(framebuffer, FBIO_WAITFORVSYNC, &arg) == -1) + qWarning("Could not wait for vsync."); + } +#endif +} + #ifndef EGLFS_PLATFORM_HOOKS QEglFSHooks stubHooks; #endif diff --git a/src/plugins/platforms/eglfs/qeglfsintegration.cpp b/src/plugins/platforms/eglfs/qeglfsintegration.cpp index 0dcde9ca36..8cebe16775 100644 --- a/src/plugins/platforms/eglfs/qeglfsintegration.cpp +++ b/src/plugins/platforms/eglfs/qeglfsintegration.cpp @@ -49,9 +49,11 @@ #include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h> #include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h> +#include <QtPlatformSupport/private/qeglconvenience_p.h> #include <QtPlatformSupport/private/qeglplatformcontext_p.h> +#include <QtPlatformSupport/private/qeglpbuffer_p.h> -#if !defined(QT_NO_EVDEV) +#if !defined(QT_NO_EVDEV) && !defined(Q_OS_ANDROID) #include <QtPlatformSupport/private/qevdevmousemanager_p.h> #include <QtPlatformSupport/private/qevdevkeyboardmanager_p.h> #include <QtPlatformSupport/private/qevdevtouch_p.h> @@ -61,6 +63,7 @@ #include <QtGui/QSurfaceFormat> #include <QtGui/QOpenGLContext> #include <QtGui/QScreen> +#include <QtGui/QOffscreenSurface> #include <qpa/qplatformcursor.h> #include "qeglfscontext.h" @@ -74,13 +77,13 @@ QEglFSIntegration::QEglFSIntegration() { QGuiApplicationPrivate::instance()->setEventDispatcher(mEventDispatcher); -#if !defined(QT_NO_EVDEV) +#if !defined(QT_NO_EVDEV) && !defined(Q_OS_ANDROID) new QEvdevKeyboardManager(QLatin1String("EvdevKeyboard"), QString() /* spec */, this); new QEvdevMouseManager(QLatin1String("EvdevMouse"), QString() /* spec */, this); new QEvdevTouchScreenHandlerThread(QString() /* spec */, this); #endif - hooks->platformInit(); + QEglFSHooks::hooks()->platformInit(); EGLint major, minor; @@ -89,7 +92,7 @@ QEglFSIntegration::QEglFSIntegration() qFatal("EGL error"); } - mDisplay = eglGetDisplay(hooks ? hooks->platformDisplay() : EGL_DEFAULT_DISPLAY); + mDisplay = eglGetDisplay(QEglFSHooks::hooks() ? QEglFSHooks::hooks()->platformDisplay() : EGL_DEFAULT_DISPLAY); if (mDisplay == EGL_NO_DISPLAY) { qWarning("Could not open egl display\n"); qFatal("EGL error"); @@ -119,13 +122,13 @@ QEglFSIntegration::~QEglFSIntegration() delete mScreen; eglTerminate(mDisplay); - hooks->platformDestroy(); + QEglFSHooks::hooks()->platformDestroy(); } bool QEglFSIntegration::hasCapability(QPlatformIntegration::Capability cap) const { // We assume that devices will have more and not less capabilities - if (hooks && hooks->hasCapability(cap)) + if (QEglFSHooks::hooks() && QEglFSHooks::hooks()->hasCapability(cap)) return true; switch (cap) { @@ -150,7 +153,13 @@ QPlatformBackingStore *QEglFSIntegration::createPlatformBackingStore(QWindow *wi QPlatformOpenGLContext *QEglFSIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const { - return new QEglFSContext(context->format(), 0 /*share*/, mDisplay); + return new QEglFSContext(QEglFSHooks::hooks()->surfaceFormatFor(context->format()), context->shareHandle(), mDisplay); +} + +QPlatformOffscreenSurface *QEglFSIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const +{ + QEglFSScreen *screen = static_cast<QEglFSScreen *>(surface->screen()->handle()); + return new QEGLPbuffer(screen->display(), QEglFSHooks::hooks()->surfaceFormatFor(surface->requestedFormat()), surface); } QPlatformFontDatabase *QEglFSIntegration::fontDatabase() const @@ -201,4 +210,29 @@ void *QEglFSIntegration::nativeResourceForContext(const QByteArray &resource, QO return 0; } +EGLConfig QEglFSIntegration::chooseConfig(EGLDisplay display, const QSurfaceFormat &format) +{ + class Chooser : public QEglConfigChooser { + public: + Chooser(EGLDisplay display, QEglFSHooks *hooks) + : QEglConfigChooser(display) + , m_hooks(hooks) + { + } + + protected: + bool filterConfig(EGLConfig config) const + { + return m_hooks->filterConfig(display(), config) && QEglConfigChooser::filterConfig(config); + } + + private: + QEglFSHooks *m_hooks; + }; + + Chooser chooser(display, QEglFSHooks::hooks()); + chooser.setSurfaceFormat(format); + return chooser.chooseConfig(); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/eglfs/qeglfsintegration.h b/src/plugins/platforms/eglfs/qeglfsintegration.h index 42b132b73a..5427137463 100644 --- a/src/plugins/platforms/eglfs/qeglfsintegration.h +++ b/src/plugins/platforms/eglfs/qeglfsintegration.h @@ -48,8 +48,6 @@ #include <qpa/qplatformnativeinterface.h> #include <qpa/qplatformscreen.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE class QEglFSIntegration : public QPlatformIntegration, public QPlatformNativeInterface @@ -63,6 +61,7 @@ public: QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; + QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const; QPlatformNativeInterface *nativeInterface() const; QPlatformFontDatabase *fontDatabase() const; @@ -75,6 +74,11 @@ public: void *nativeResourceForIntegration(const QByteArray &resource); void *nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context); + QPlatformScreen *screen() const { return mScreen; } + static EGLConfig chooseConfig(EGLDisplay display, const QSurfaceFormat &format); + + EGLDisplay display() const { return mDisplay; } + private: EGLDisplay mDisplay; QAbstractEventDispatcher *mEventDispatcher; @@ -83,6 +87,5 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif // QEGLFSINTEGRATION_H diff --git a/src/plugins/platforms/eglfs/qeglfsscreen.cpp b/src/plugins/platforms/eglfs/qeglfsscreen.cpp index 1bc1e944de..83f50dd382 100644 --- a/src/plugins/platforms/eglfs/qeglfsscreen.cpp +++ b/src/plugins/platforms/eglfs/qeglfsscreen.cpp @@ -56,7 +56,7 @@ QEglFSScreen::QEglFSScreen(EGLDisplay dpy) static int hideCursor = qgetenv("QT_QPA_EGLFS_HIDECURSOR").toInt(); if (!hideCursor) { - if (QEglFSCursor *customCursor = hooks->createCursor(this)) + if (QEglFSCursor *customCursor = QEglFSHooks::hooks()->createCursor(this)) m_cursor = customCursor; else m_cursor = new QEglFSCursor(this); @@ -70,17 +70,22 @@ QEglFSScreen::~QEglFSScreen() QRect QEglFSScreen::geometry() const { - return QRect(QPoint(0, 0), hooks->screenSize()); + return QRect(QPoint(0, 0), QEglFSHooks::hooks()->screenSize()); } int QEglFSScreen::depth() const { - return hooks->screenDepth(); + return QEglFSHooks::hooks()->screenDepth(); } QImage::Format QEglFSScreen::format() const { - return hooks->screenFormat(); + return QEglFSHooks::hooks()->screenFormat(); +} + +QSizeF QEglFSScreen::physicalSize() const +{ + return QEglFSHooks::hooks()->physicalScreenSize(); } QPlatformCursor *QEglFSScreen::cursor() const diff --git a/src/plugins/platforms/eglfs/qeglfsscreen.h b/src/plugins/platforms/eglfs/qeglfsscreen.h index 309791d6c2..8d3c5dbaec 100644 --- a/src/plugins/platforms/eglfs/qeglfsscreen.h +++ b/src/plugins/platforms/eglfs/qeglfsscreen.h @@ -63,6 +63,8 @@ public: int depth() const; QImage::Format format() const; + QSizeF physicalSize() const; + QPlatformCursor *cursor() const; EGLDisplay display() const { return m_dpy; } diff --git a/src/plugins/platforms/eglfs/qeglfswindow.cpp b/src/plugins/platforms/eglfs/qeglfswindow.cpp index ceb04901c4..68cef6253e 100644 --- a/src/plugins/platforms/eglfs/qeglfswindow.cpp +++ b/src/plugins/platforms/eglfs/qeglfswindow.cpp @@ -76,18 +76,36 @@ void QEglFSWindow::create() return; if (window()->type() == Qt::Desktop) { - QRect rect(QPoint(), hooks->screenSize()); + QRect rect(QPoint(), QEglFSHooks::hooks()->screenSize()); QPlatformWindow::setGeometry(rect); QWindowSystemInterface::handleGeometryChange(window(), rect); return; } EGLDisplay display = (static_cast<QEglFSScreen *>(window()->screen()->handle()))->display(); - 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_format); - m_surface = eglCreateWindowSurface(display, config, m_window, NULL); + QSurfaceFormat platformFormat = QEglFSHooks::hooks()->surfaceFormatFor(window()->requestedFormat()); + m_config = QEglFSIntegration::chooseConfig(display, platformFormat); + m_format = q_glFormatFromConfig(display, m_config); + resetSurface(); +} + +void QEglFSWindow::invalidateSurface() +{ + // Native surface has been deleted behind our backs + m_window = 0; + if (m_surface != 0) { + EGLDisplay display = (static_cast<QEglFSScreen *>(window()->screen()->handle()))->display(); + eglDestroySurface(display, m_surface); + m_surface = 0; + } +} + +void QEglFSWindow::resetSurface() +{ + EGLDisplay display = static_cast<QEglFSScreen *>(screen())->display(); + + m_window = QEglFSHooks::hooks()->createNativeWindow(QEglFSHooks::hooks()->screenSize(), m_format); + m_surface = eglCreateWindowSurface(display, m_config, m_window, NULL); if (m_surface == EGL_NO_SURFACE) { EGLint error = eglGetError(); eglTerminate(display); @@ -98,13 +116,13 @@ void QEglFSWindow::create() void QEglFSWindow::destroy() { if (m_surface) { - EGLDisplay display = (static_cast<QEglFSScreen *>(window()->screen()->handle()))->display(); + EGLDisplay display = static_cast<QEglFSScreen *>(screen())->display(); eglDestroySurface(display, m_surface); m_surface = 0; } if (m_window) { - hooks->destroyNativeWindow(m_window); + QEglFSHooks::hooks()->destroyNativeWindow(m_window); m_window = 0; } } @@ -113,9 +131,8 @@ void QEglFSWindow::setGeometry(const QRect &) { // We only support full-screen windows QRect rect(screen()->availableGeometry()); - QWindowSystemInterface::handleGeometryChange(window(), rect); - QPlatformWindow::setGeometry(rect); + QWindowSystemInterface::handleGeometryChange(window(), rect); } void QEglFSWindow::setWindowState(Qt::WindowState) diff --git a/src/plugins/platforms/eglfs/qeglfswindow.h b/src/plugins/platforms/eglfs/qeglfswindow.h index 706bbddd22..a351b4a6f4 100644 --- a/src/plugins/platforms/eglfs/qeglfswindow.h +++ b/src/plugins/platforms/eglfs/qeglfswindow.h @@ -65,10 +65,14 @@ public: void create(); void destroy(); + virtual void invalidateSurface(); + virtual void resetSurface(); + private: WId m_winid; EGLSurface m_surface; EGLNativeWindowType m_window; + EGLConfig m_config; QSurfaceFormat m_format; }; QT_END_NAMESPACE |