diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2011-12-07 10:16:20 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-08 10:10:27 +0100 |
commit | fdd14a1a10a0a2f42015b30071771bd95215cc1a (patch) | |
tree | 1e79b74017df70e7f4b034dd4460406041507636 /tests/auto/qtquick2/qquickcanvas | |
parent | 9128eb13040c57872e226222c9a45cad9946ed1a (diff) |
Implemented multiple windows and GL context sharing
What was traditionally the QQuickRenderLoop which was used
to support one QQuickCanvas instance has now grown to support
multiple QQuickCanvas instances and is now called
QQuickWindowManager, of which there are two implementations.
QQuickRenderThreadSingleContextWindowManager:
One QSGContext and one OpenGL context is being used to draw
all the windows and we alternate between which surface the gl
context is bound to. This implementation relies on that
swap does not block, but that the graphics pipeline is
vsynced and will eventually block as the buffer queue is
filled up. This is the behavior we get on Mac OS X and
Wayland. The benefit of this implementation is that we have
vsync'ed animations, and the synchronizaiton between GUI and
render thread is simple. (well, simple relative to the
alternative, that is).
QQuickTrivialWindowManager:
One QSGContext and one OpenGL context is being used on the GUI
thread. Animations are ticked from a timer. Performance of this
implementation will deteriorate if the driver is using blocking
swap.
Task-number: QTBUG-19455
Change-Id: Ib961ac7d71eb49c70a057872b7cac020c4d19f3d
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'tests/auto/qtquick2/qquickcanvas')
3 files changed, 91 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qquickcanvas/data/AnimationsWhileHidden.qml b/tests/auto/qtquick2/qquickcanvas/data/AnimationsWhileHidden.qml new file mode 100644 index 0000000000..e95b029210 --- /dev/null +++ b/tests/auto/qtquick2/qquickcanvas/data/AnimationsWhileHidden.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 +import QtQuick.Window 2.0 as Window + +Window.Window +{ + id: win + visible: true + width: 250 + height: 250 + + SequentialAnimation { + PauseAnimation { duration: 500 } + PropertyAction { target: win; property: "visible"; value: true } + loops: Animation.Infinite + running: true + } +} diff --git a/tests/auto/qtquick2/qquickcanvas/qquickcanvas.pro b/tests/auto/qtquick2/qquickcanvas/qquickcanvas.pro index c95d474a21..b4a4bc5d9c 100644 --- a/tests/auto/qtquick2/qquickcanvas/qquickcanvas.pro +++ b/tests/auto/qtquick2/qquickcanvas/qquickcanvas.pro @@ -6,3 +6,7 @@ macx:CONFIG -= app_bundle CONFIG += parallel_test QT += core-private gui-private declarative-private quick-private testlib + +OTHER_FILES += \ + data/AnimationsWhileHidden.qml + diff --git a/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp b/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp index f894ff3d39..60522b7d44 100644 --- a/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp +++ b/tests/auto/qtquick2/qquickcanvas/tst_qquickcanvas.cpp @@ -203,6 +203,11 @@ private slots: void qmlCreation(); void clearColor(); + + void grab(); + void multipleWindows(); + + void animationsWhileHidden(); }; tst_qquickcanvas::tst_qquickcanvas() @@ -221,6 +226,7 @@ void tst_qquickcanvas::cleanupTestCase() void tst_qquickcanvas::constantUpdates() { QQuickCanvas canvas; + canvas.resize(250, 250); ConstantUpdateItem item(canvas.rootItem()); canvas.show(); QTRY_VERIFY(item.iterations > 60); @@ -520,6 +526,8 @@ void tst_qquickcanvas::mouseFiltering() QCOMPARE(middleItem->mousePressId, 1); QCOMPARE(bottomItem->mousePressId, 2); QCOMPARE(topItem->mousePressId, 3); + + delete canvas; } void tst_qquickcanvas::qmlCreation() @@ -552,6 +560,68 @@ void tst_qquickcanvas::clearColor() delete canvas; } +void tst_qquickcanvas::grab() +{ + QQuickCanvas canvas; + canvas.setClearColor(Qt::red); + + canvas.resize(250, 250); + canvas.show(); + + QImage content = canvas.grabFrameBuffer(); + QCOMPARE(content.width(), canvas.width()); + QCOMPARE(content.height(), canvas.height()); + QCOMPARE((uint) content.convertToFormat(QImage::Format_RGB32).pixel(0, 0), (uint) 0xffff0000); +} + +void tst_qquickcanvas::multipleWindows() +{ + QList<QQuickCanvas *> windows; + for (int i=0; i<6; ++i) { + QQuickCanvas *c = new QQuickCanvas(); + c->setClearColor(Qt::GlobalColor(Qt::red + i)); + c->resize(300, 200); + c->setPos(100 + i * 30, 100 + i * 20); + c->show(); + windows << c; + QVERIFY(c->visible()); + } + + // move them + for (int i=0; i<windows.size(); ++i) { + QQuickCanvas *c = windows.at(i); + c->setPos(c->x() - 10, c->y() - 10); + } + + // resize them + for (int i=0; i<windows.size(); ++i) { + QQuickCanvas *c = windows.at(i); + c->resize(200, 150); + } + + qDeleteAll(windows); +} + +void tst_qquickcanvas::animationsWhileHidden() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine); + component.loadUrl(TESTDATA("AnimationsWhileHidden.qml")); + QObject* created = component.create(); + + QQuickCanvas* canvas = qobject_cast<QQuickCanvas*>(created); + QVERIFY(canvas); + QVERIFY(canvas->visible()); + + // Now hide the window and verify that it went off screen + canvas->hide(); + QTest::qWait(10); + QVERIFY(!canvas->visible()); + + // Running animaiton should cause it to become visible again shortly. + QTRY_VERIFY(canvas->visible()); +} + QTEST_MAIN(tst_qquickcanvas) #include "tst_qquickcanvas.moc" |