aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickwindow
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>2015-03-18 14:13:10 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-15 17:53:01 +0000
commite036a0d80cd78474a6bfe4a78c9ee108c1552f80 (patch)
tree156773f30f1e5406a8a54847ce1f1ce80a85f05f /tests/auto/quick/qquickwindow
parent327ddb7488805241fb48c20ec8628c630224f4ce (diff)
Added a new render job stage: NoStage
NoStage allows scheduling jobs for immediate execution on the renderer thread. [ChangeLog][QtQuick][QQuickWindow] Added a render job stage: NoStage Task-number: QTBUG-44953 Change-Id: I918c79f1d095bc27d911a88d81376d146a04313c Reviewed-by: Gunnar Sletta <gunnar@sletta.org> Reviewed-by: Venugopal Shivashankar <venugopal.shivashankar@digia.com> Reviewed-by: Pasi Keränen <pasi.keranen@digia.com>
Diffstat (limited to 'tests/auto/quick/qquickwindow')
-rw-r--r--tests/auto/quick/qquickwindow/tst_qquickwindow.cpp90
1 files changed, 77 insertions, 13 deletions
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
index 070d6636b0..09ee431422 100644
--- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
+++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
@@ -2008,43 +2008,107 @@ public:
static int deleted;
};
+class GlRenderJob : public QRunnable
+{
+public:
+ GlRenderJob(GLubyte *buf) : readPixel(buf), mutex(0), condition(0) {}
+ ~GlRenderJob() {}
+ void run() {
+ QOpenGLContext::currentContext()->functions()->glClearColor(1.0f, 0, 0, 1.0f);
+ QOpenGLContext::currentContext()->functions()->glClear(GL_COLOR_BUFFER_BIT);
+ QOpenGLContext::currentContext()->functions()->glReadPixels(0, 0, 1, 1, GL_RGBA,
+ GL_UNSIGNED_BYTE,
+ (void *)readPixel);
+ if (mutex) {
+ mutex->lock();
+ condition->wakeOne();
+ mutex->unlock();
+ }
+ }
+ GLubyte *readPixel;
+ QMutex *mutex;
+ QWaitCondition *condition;
+};
+
int RenderJob::deleted = 0;
void tst_qquickwindow::testRenderJob()
{
QList<QQuickWindow::RenderStage> completedJobs;
- QQuickWindow window;
-
QQuickWindow::RenderStage stages[] = {
QQuickWindow::BeforeSynchronizingStage,
QQuickWindow::AfterSynchronizingStage,
QQuickWindow::BeforeRenderingStage,
QQuickWindow::AfterRenderingStage,
- QQuickWindow::AfterSwapStage
+ QQuickWindow::AfterSwapStage,
+ QQuickWindow::NoStage
};
- // Schedule the jobs
- for (int i=0; i<5; ++i)
- window.scheduleRenderJob(new RenderJob(stages[i], &completedJobs), stages[i]);
- window.show();
- QTRY_COMPARE(completedJobs.size(), 5);
+ const int numJobs = 6;
- for (int i=0; i<5; ++i) {
- QCOMPARE(completedJobs.at(i), stages[i]);
+ {
+ QQuickWindow window;
+ RenderJob::deleted = 0;
+
+ // Schedule the jobs
+ for (int i = 0; i < numJobs; ++i)
+ window.scheduleRenderJob(new RenderJob(stages[i], &completedJobs), stages[i]);
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+
+ // All jobs should be deleted
+ QTRY_COMPARE(RenderJob::deleted, numJobs);
+
+ // The NoStage job is not completed, if it is issued when there is no context,
+ // but the rest will be queued and completed once relevant render stage is hit.
+ QCOMPARE(completedJobs.size(), numJobs - 1);
+
+ // Verify jobs were completed in correct order
+ for (int i = 0; i < numJobs - 1; ++i)
+ QCOMPARE(completedJobs.at(i), stages[i]);
+
+
+ // Check that NoStage job gets executed if it is scheduled when window is exposed
+ completedJobs.clear();
+ RenderJob::deleted = 0;
+ window.scheduleRenderJob(new RenderJob(QQuickWindow::NoStage, &completedJobs),
+ QQuickWindow::NoStage);
+ QTRY_COMPARE(RenderJob::deleted, 1);
+ QCOMPARE(completedJobs.size(), 1);
+
+ // Do a synchronized GL job.
+ GLubyte readPixel[4] = {0, 0, 0, 0};
+ GlRenderJob *glJob = new GlRenderJob(readPixel);
+ if (window.openglContext()->thread() != QThread::currentThread()) {
+ QMutex mutex;
+ QWaitCondition condition;
+ glJob->mutex = &mutex;
+ glJob->condition = &condition;
+ mutex.lock();
+ window.scheduleRenderJob(glJob, QQuickWindow::NoStage);
+ condition.wait(&mutex);
+ mutex.unlock();
+ } else {
+ window.scheduleRenderJob(glJob, QQuickWindow::NoStage);
+ }
+ QCOMPARE(int(readPixel[0]), 255);
+ QCOMPARE(int(readPixel[1]), 0);
+ QCOMPARE(int(readPixel[2]), 0);
+ QCOMPARE(int(readPixel[3]), 255);
}
- // Verify that jobs are deleted when window has not been rendered at all...
+ // Verify that jobs are deleted when window is not rendered at all
completedJobs.clear();
RenderJob::deleted = 0;
{
QQuickWindow window2;
- for (int i=0; i<5; ++i) {
+ for (int i = 0; i < numJobs; ++i) {
window2.scheduleRenderJob(new RenderJob(stages[i], &completedJobs), stages[i]);
}
}
+ QTRY_COMPARE(RenderJob::deleted, numJobs);
QCOMPARE(completedJobs.size(), 0);
- QCOMPARE(RenderJob::deleted, 5);
}
class EventCounter : public QQuickRectangle