diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2011-12-08 13:24:17 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-19 14:23:12 +0100 |
commit | 6efca58ab943bbd8c91c8f12ad47484677e2cf60 (patch) | |
tree | d1d5629d17451f36abaca975eed92d9132269e01 /tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp | |
parent | 8460eae44c241d5975b3041eedf6e08c9638fd41 (diff) |
Implement "headless mode" for hidden QQuickCanvases
When all views are hidden, we stop the rendering thread,
kill the OpenGL context and all scene graph content.
The entire scenegraph is recreated based on the QML scene
when a view is shown again.
Change-Id: I734619d9f29263a5cdecbcc9b88c3808d1d64a7f
Reviewed-by: Kim M. Kalland <kim.kalland@nokia.com>
Diffstat (limited to 'tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp')
-rw-r--r-- | tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp b/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp index f8e3596683..780f58cc37 100644 --- a/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp +++ b/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp @@ -196,6 +196,8 @@ private slots: void multipleWindows(); void animationsWhileHidden(); + + void headless(); }; tst_qquickcanvas::tst_qquickcanvas() @@ -541,6 +543,8 @@ void tst_qquickcanvas::qmlCreation() QQuickItem* item = canvas->findChild<QQuickItem*>("item"); QVERIFY(item); QCOMPARE(item->canvas(), canvas); + + delete canvas; } void tst_qquickcanvas::clearColor() @@ -616,6 +620,75 @@ void tst_qquickcanvas::animationsWhileHidden() // Running animaiton should cause it to become visible again shortly. QTRY_VERIFY(canvas->visible()); + + delete canvas; +} + + +class SceneGraphListener : public QObject +{ + Q_OBJECT + +public: + SceneGraphListener() + : wasInitialized(false) + , wasInvalidated(false) + { + } + + bool wasInitialized; + bool wasInvalidated; + +public slots: + void initialized() { wasInitialized = true; } + void invalidated() { wasInvalidated = true; } +}; + +void tst_qquickcanvas::headless() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine); + component.loadUrl(TESTDATA("Headless.qml")); + QObject* created = component.create(); + + QQuickCanvas* canvas = qobject_cast<QQuickCanvas*>(created); + QVERIFY(canvas); + + QTest::qWaitForWindowShown(canvas); + QVERIFY(canvas->visible()); + + SceneGraphListener listener; + connect(canvas, SIGNAL(sceneGraphInitialized()), &listener, SLOT(initialized()), Qt::DirectConnection); + connect(canvas, SIGNAL(sceneGraphInvalidated()), &listener, SLOT(invalidated()), Qt::DirectConnection); + + // Verify that the canvas is alive and kicking + QVERIFY(canvas->openglContext() != 0); + + // Store the visual result + QImage originalContent = canvas->grabFrameBuffer(); + + // Hide the canvas and verify signal emittion and GL context deletion + canvas->hide(); + QVERIFY(listener.wasInvalidated); + QVERIFY(canvas->openglContext() == 0); + + // Destroy the native windowing system buffers + canvas->destroy(); + QVERIFY(canvas->handle() == 0); + + // Show and verify that we are back and running + canvas->show(); + QTest::qWaitForWindowShown(canvas); + + QVERIFY(listener.wasInitialized); + QVERIFY(canvas->openglContext() != 0); + + // Verify that the visual output is the same + QImage newContent = canvas->grabFrameBuffer(); + + QCOMPARE(originalContent, newContent); + + } QTEST_MAIN(tst_qquickcanvas) |