diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2014-11-15 11:40:51 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2014-11-17 10:38:22 +0100 |
commit | c5ecabb70c0f0cb25a22bf3742f39648a34d1c3c (patch) | |
tree | e0c788b152d0cb7ec51d0d3e880aa0e286c9fd14 /tests/auto/gui/kernel | |
parent | 3d575d4845926bd141ff0c14e57427bba79644d0 (diff) |
Send events when platform surfaces are created/about to be destroyed
These synchronously delivered events allow applications to correctly
and conveniently handle native platform surfaces being destroyed. This
is particularly useful when doing rendering on a non-gui thread as it
allows to shutdown rendering before the native surface gets destroyed
from under us.
Task-number: QTBUG-42476
Task-number: QTBUG-42483
Change-Id: I63f41bbdb32f281d0f3b8ec2537eb2b0361f3bb3
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r-- | tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index fac16ff8a3..7a0683c3bf 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -63,6 +63,7 @@ private slots: void positioning_data(); void positioning(); void positioningDuringMinimized(); + void platformSurface(); void isExposed(); void isActive(); void testInputEvents(); @@ -160,8 +161,18 @@ public: { m_received[event->type()]++; m_order << event->type(); - if (event->type() == QEvent::Expose) + switch (event->type()) { + case QEvent::Expose: m_exposeRegion = static_cast<QExposeEvent *>(event)->region(); + break; + + case QEvent::PlatformSurface: + m_surfaceventType = static_cast<QPlatformSurfaceEvent *>(event)->surfaceEventType(); + break; + + default: + break; + } return QWindow::event(event); } @@ -181,10 +192,16 @@ public: return m_exposeRegion; } + QPlatformSurfaceEvent::SurfaceEventType surfaceEventType() const + { + return m_surfaceventType; + } + private: QHash<QEvent::Type, int> m_received; QVector<QEvent::Type> m_order; QRegion m_exposeRegion; + QPlatformSurfaceEvent::SurfaceEventType m_surfaceventType; }; void tst_QWindow::eventOrderOnShow() @@ -352,6 +369,63 @@ void tst_QWindow::positioningDuringMinimized() QTRY_COMPARE(window.geometry(), newGeometry); } +class PlatformWindowFilter : public QObject +{ + Q_OBJECT +public: + PlatformWindowFilter(QObject *parent = 0) + : QObject(parent) + , m_window(Q_NULLPTR) + , m_alwaysExisted(true) + {} + + void setWindow(Window *window) { m_window = window; } + + bool eventFilter(QObject *o, QEvent *e) + { + // Check that the platform surface events are delivered synchronously. + // If they are, the native platform surface should always exist when we + // receive a QPlatformSurfaceEvent + if (e->type() == QEvent::PlatformSurface && o == m_window) { + m_alwaysExisted &= (m_window->handle() != Q_NULLPTR); + } + return false; + } + + bool surfaceExisted() const { return m_alwaysExisted; } + +private: + Window *m_window; + bool m_alwaysExisted; +}; + +void tst_QWindow::platformSurface() +{ + QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); + + Window window; + PlatformWindowFilter filter; + filter.setWindow(&window); + window.installEventFilter(&filter); + + window.setGeometry(geometry); + QCOMPARE(window.geometry(), geometry); + window.create(); + + QTRY_VERIFY(window.received(QEvent::PlatformSurface) == 1); + QTRY_VERIFY(window.surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated); + QTRY_VERIFY(window.handle() != Q_NULLPTR); + + window.destroy(); + QTRY_VERIFY(window.received(QEvent::PlatformSurface) == 2); + QTRY_VERIFY(window.surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed); + QTRY_VERIFY(window.handle() == Q_NULLPTR); + + // Check for synchronous delivery of platform surface events and that the platform + // surface always existed upon event delivery + QTRY_VERIFY(filter.surfaceExisted()); +} + void tst_QWindow::isExposed() { QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); |