summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAndy Nichols <andy.nichols@qt.io>2018-04-19 17:19:38 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2018-04-27 07:33:27 +0000
commit3bd3d3c76e0212e6d205fe9696f082adfd8ba788 (patch)
tree2b5c6eaee4aec355b7f073ac596c86456c65c020 /tests/auto
parent74b36c043b1c0f6451b109baf5d8b2602812b183 (diff)
Add Optional scene grabber for Q3DS1
This makes it possible to generate lancelot results for Q3DS1.x. This will only be built if studio3d module is present. You can turn this test on by setting the environment variable QT_LANCELOT_Q3DS1 before running the lancelot test. Change-Id: I6042457d715aa0dae0525d9de5f26a3a64443998 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/q3dslancelot/oldscenegrabber/main.cpp190
-rw-r--r--tests/auto/q3dslancelot/oldscenegrabber/oldscenegrabber.pro9
-rw-r--r--tests/auto/q3dslancelot/q3ds/tst_q3ds.cpp12
-rw-r--r--tests/auto/q3dslancelot/q3dslancelot.pro5
-rw-r--r--tests/auto/q3dslancelot/scenegrabber/main.cpp12
5 files changed, 224 insertions, 4 deletions
diff --git a/tests/auto/q3dslancelot/oldscenegrabber/main.cpp b/tests/auto/q3dslancelot/oldscenegrabber/main.cpp
new file mode 100644
index 0000000..e942a9b
--- /dev/null
+++ b/tests/auto/q3dslancelot/oldscenegrabber/main.cpp
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QTimer>
+#include <QtCore/QDebug>
+#include <QtCore/QFileInfo>
+#include <QtCore/QHashFunctions>
+#include <QtGui/QGuiApplication>
+#include <QtGui/QImage>
+#include <QtGui/QWindow>
+#include <QtGui/QOpenGLContext>
+
+#include <QtStudio3D/Q3DSSurfaceViewer>
+#include <QtStudio3D/Q3DSViewerSettings>
+#include <QtStudio3D/Q3DSPresentation>
+
+// Timeout values:
+
+// A valid screen grab requires the scene to not change
+// for SCENE_STABLE_TIME ms
+#define SCENE_STABLE_TIME 200
+
+// Give up after SCENE_TIMEOUT ms
+#define SCENE_TIMEOUT 6000
+
+class Grabber : public QObject
+{
+ Q_OBJECT
+
+public:
+ Grabber(Q3DSSurfaceViewer *viewer, const QString &outputFile)
+ : ofile(outputFile)
+ , grabNo(0)
+ , isGrabbing(false)
+ , surfaceViewer(viewer)
+ {
+ grabTimer = new QTimer(this);
+ grabTimer->setSingleShot(true);
+ grabTimer->setInterval(SCENE_STABLE_TIME);
+ connect(grabTimer, SIGNAL(timeout()), this, SLOT(grab()));
+
+ grabTimer->start();
+ QTimer::singleShot(SCENE_TIMEOUT, this, SLOT(timedOut()));
+ }
+
+private slots:
+ void grab()
+ {
+ if (isGrabbing)
+ return;
+ isGrabbing = true;
+ grabNo++;
+
+ auto image = surfaceViewer->grab();
+
+ if (!image.isNull() && image == lastGrab) {
+ sceneStabilized();
+ } else {
+ lastGrab = image;
+ grabTimer->start();
+ }
+
+ isGrabbing = false;
+ }
+
+ void sceneStabilized()
+ {
+ if (ofile == "-") { // Write to stdout
+ QFile of;
+ if (!of.open(1, QIODevice::WriteOnly) || !lastGrab.save(&of, "ppm")) {
+ qWarning() << "Error: failed to write grabbed image to stdout.";
+ QGuiApplication::exit(2);
+ return;
+ }
+ } else {
+ if (!lastGrab.save(ofile)) {
+ qWarning() << "Error: failed to store grabbed image to" << ofile;
+ QGuiApplication::exit(2);
+ return;
+ }
+ }
+ QGuiApplication::exit(0);
+ }
+
+ void timedOut()
+ {
+ qWarning() << "Error: timed out waiting for scene to stabilize." << grabNo << "grab(s) done. Last grab was" << (lastGrab.isNull() ? "invalid." : "valid.");
+ QGuiApplication::exit(3);
+ }
+
+private:
+ QImage lastGrab;
+ QTimer *grabTimer;
+ QString ofile;
+ int grabNo;
+ bool isGrabbing;
+ Q3DSSurfaceViewer *surfaceViewer;
+};
+
+int main(int argc, char *argv[])
+{
+ qSetGlobalQHashSeed(0);
+
+ QGuiApplication a(argc, argv);
+
+ // Parse command line
+ QString ifile, ofile;
+ QStringList args = a.arguments();
+ int i = 0;
+ bool argError = false;
+ while (++i < args.size()) {
+ QString arg = args.at(i);
+ if ((arg == "-o") && (i < args.size()-1)) {
+ ofile = args.at(++i);
+ } else if (ifile.isEmpty()) {
+ ifile = arg;
+ } else {
+ argError = true;
+ break;
+ }
+ }
+ if (argError || ifile.isEmpty() || ofile.isEmpty()) {
+ qWarning() << "Usage:" << args.at(0).toLatin1().constData() << "<uip-infile> -o <outfile or - for ppm on stdout>";
+ return 1;
+ }
+
+ QFileInfo ifi(ifile);
+ if (!ifi.exists() || !ifi.isReadable() || !ifi.isFile()) {
+ qWarning() << args.at(0).toLatin1().constData() << " error: unreadable input file" << ifile;
+ return 1;
+ }
+ // End parsing
+
+
+ QWindow window;
+
+ QSize size(1280, 720);
+ window.resize(size);
+ window.setSurfaceType(QSurface::OpenGLSurface);
+ window.setTitle(QStringLiteral("Qt 3D Studio 1.x Scene Grabber"));
+ window.create();
+
+ QOpenGLContext context;
+ context.setFormat(window.format());
+ context.create();
+
+ Q3DSSurfaceViewer viewer;
+ viewer.presentation()->setSource(QUrl::fromLocalFile(ifile));
+ viewer.setUpdateInterval(0);
+ viewer.settings()->setScaleMode(Q3DSViewerSettings::ScaleModeFill);
+ viewer.settings()->setShowRenderStats(false);
+
+ viewer.initialize(&window, &context);
+
+ window.show();
+
+ Grabber grabber(&viewer, ofile);
+
+ int retVal = a.exec();
+ return retVal;
+}
+
+#include "main.moc"
+
diff --git a/tests/auto/q3dslancelot/oldscenegrabber/oldscenegrabber.pro b/tests/auto/q3dslancelot/oldscenegrabber/oldscenegrabber.pro
new file mode 100644
index 0000000..73e2e0f
--- /dev/null
+++ b/tests/auto/q3dslancelot/oldscenegrabber/oldscenegrabber.pro
@@ -0,0 +1,9 @@
+TARGET = q3ds1scenegrabber
+DESTDIR=..
+macos:CONFIG -= app_bundle
+CONFIG += console
+
+QT += studio3d
+
+SOURCES += \
+ main.cpp
diff --git a/tests/auto/q3dslancelot/q3ds/tst_q3ds.cpp b/tests/auto/q3dslancelot/q3ds/tst_q3ds.cpp
index 94b39cc..56d3902 100644
--- a/tests/auto/q3dslancelot/q3ds/tst_q3ds.cpp
+++ b/tests/auto/q3dslancelot/q3ds/tst_q3ds.cpp
@@ -170,10 +170,18 @@ void tst_Q3DS::runTest(const QStringList &extraArgs)
bool tst_Q3DS::renderAndGrab(const QString &uipFile, const QStringList &extraArgs, QImage *screenshot, QString *errMsg)
{
bool usePipe = true; // Whether to transport the grabbed image using temp. file or pipe. TBD: cmdline option
- QString cmd = QCoreApplication::applicationDirPath() + "/q3dsscenegrabber";
+ bool q3ds1 = qEnvironmentVariableIsSet("QT_LANCELOT_Q3DS1");
+ QString cmd;
+ if (!q3ds1)
+ cmd = QCoreApplication::applicationDirPath() + "/q3dsscenegrabber";
+ else
+ cmd = QCoreApplication::applicationDirPath() + "/q3ds1scenegrabber";
#ifdef Q_OS_WIN
usePipe = false;
- cmd = QCoreApplication::applicationDirPath() + "/q3dsscenegrabber.exe";
+ if (!q3ds1)
+ cmd = QCoreApplication::applicationDirPath() + "/q3dsscenegrabber.exe";
+ else
+ cmd = QCoreApplication::applicationDirPath() + "/q3ds1scenegrabber.exe";
#endif
QProcess grabber;
QStringList args = extraArgs;
diff --git a/tests/auto/q3dslancelot/q3dslancelot.pro b/tests/auto/q3dslancelot/q3dslancelot.pro
index 81802a6..6f1a172 100644
--- a/tests/auto/q3dslancelot/q3dslancelot.pro
+++ b/tests/auto/q3dslancelot/q3dslancelot.pro
@@ -1,2 +1,7 @@
TEMPLATE = subdirs
SUBDIRS = q3ds scenegrabber
+
+qtHaveModule(studio3d) {
+ SUBDIRS += oldscenegrabber
+}
+
diff --git a/tests/auto/q3dslancelot/scenegrabber/main.cpp b/tests/auto/q3dslancelot/scenegrabber/main.cpp
index 3195088..357b257 100644
--- a/tests/auto/q3dslancelot/scenegrabber/main.cpp
+++ b/tests/auto/q3dslancelot/scenegrabber/main.cpp
@@ -48,7 +48,7 @@
#define SCENE_STABLE_TIME 200
// Give up after SCENE_TIMEOUT ms
-#define SCENE_TIMEOUT 6000
+#define SCENE_TIMEOUT 10000
class GrabbingView : public Q3DSWindow
{
@@ -86,6 +86,13 @@ private slots:
}
}
+ bool isJustClear(const QImage &image) {
+ QColor color = image.pixel(0, 0);
+ QImage imageCopy = image;
+ imageCopy.fill(color);
+ return image == imageCopy;
+ }
+
void grab(QImage image)
{
if (isGrabbing)
@@ -93,7 +100,7 @@ private slots:
isGrabbing = true;
grabNo++;
- if (!image.isNull() && image == lastGrab) {
+ if (!image.isNull() && !isJustClear(image) && image == lastGrab) {
sceneStabilized();
} else {
lastGrab = image;
@@ -177,6 +184,7 @@ int main(int argc, char *argv[])
GrabbingView v(ofile);
v.engine()->setSource(ifile);
+ v.forceResize(1280, 720);
v.show();
int retVal = a.exec();