2013-10-17 12:53:33 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-10-17 12:53:33 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2013-10-17 12:53:33 +00:00
|
|
|
** 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
|
2015-01-28 11:55:39 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-19 11:23:05 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2013-10-17 12:53:33 +00:00
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** 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.
|
2013-10-17 12:53:33 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <qtest.h>
|
|
|
|
|
2014-06-04 18:32:07 +00:00
|
|
|
#include <QOffscreenSurface>
|
|
|
|
#include <QOpenGLContext>
|
|
|
|
#include <QOpenGLFunctions>
|
|
|
|
|
2013-10-17 12:53:33 +00:00
|
|
|
#include <QtQuick>
|
2014-06-04 18:32:07 +00:00
|
|
|
#include <QtQml>
|
2013-10-17 12:53:33 +00:00
|
|
|
|
2014-06-04 16:59:58 +00:00
|
|
|
#include <private/qopenglcontext_p.h>
|
2014-06-04 18:32:07 +00:00
|
|
|
#include <private/qsgcontext_p.h>
|
|
|
|
#include <private/qsgrenderloop_p.h>
|
2013-10-17 12:53:33 +00:00
|
|
|
|
|
|
|
|
2014-08-04 08:10:10 +00:00
|
|
|
class PerPixelRect : public QQuickItem
|
|
|
|
{
|
|
|
|
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
PerPixelRect() {
|
|
|
|
setFlag(ItemHasContents);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setColor(const QColor &c) {
|
|
|
|
if (c == m_color)
|
|
|
|
return;
|
|
|
|
m_color = c;
|
|
|
|
emit colorChanged(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor color() const { return m_color; }
|
|
|
|
|
|
|
|
QSGNode *updatePaintNode(QSGNode *old, UpdatePaintNodeData *)
|
|
|
|
{
|
|
|
|
if (old)
|
|
|
|
delete old;
|
|
|
|
|
|
|
|
QSGNode *node = new QSGNode();
|
|
|
|
|
|
|
|
for (int y=0; y<height(); ++y) {
|
|
|
|
for (int x=0; x<width(); ++x) {
|
|
|
|
QSGSimpleRectNode *rn = new QSGSimpleRectNode();
|
|
|
|
rn->setRect(x, y, 1, 1);
|
|
|
|
rn->setColor(m_color);
|
|
|
|
node->appendChildNode(rn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void colorChanged(const QColor &c );
|
|
|
|
|
|
|
|
private:
|
|
|
|
QColor m_color;
|
|
|
|
};
|
|
|
|
|
2013-10-17 12:53:33 +00:00
|
|
|
class tst_SceneGraph : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
2014-08-04 08:10:10 +00:00
|
|
|
void initTestCase();
|
|
|
|
|
2013-10-17 12:53:33 +00:00
|
|
|
void manyWindows_data();
|
|
|
|
void manyWindows();
|
|
|
|
|
2013-10-31 21:22:54 +00:00
|
|
|
void render_data();
|
|
|
|
void render();
|
2013-11-18 07:53:13 +00:00
|
|
|
|
|
|
|
void hideWithOtherContext();
|
2015-03-27 10:32:27 +00:00
|
|
|
|
2015-06-11 08:17:45 +00:00
|
|
|
void createTextureFromImage_data();
|
|
|
|
void createTextureFromImage();
|
|
|
|
|
2015-03-27 10:32:27 +00:00
|
|
|
private:
|
|
|
|
bool m_brokenMipmapSupport;
|
2013-10-17 12:53:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T> class ScopedList : public QList<T> {
|
|
|
|
public:
|
|
|
|
~ScopedList() { qDeleteAll(*this); }
|
|
|
|
};
|
|
|
|
|
2014-08-04 08:10:10 +00:00
|
|
|
void tst_SceneGraph::initTestCase()
|
|
|
|
{
|
|
|
|
qmlRegisterType<PerPixelRect>("SceneGraphTest", 1, 0, "PerPixelRect");
|
2014-06-04 18:32:07 +00:00
|
|
|
|
|
|
|
QSGRenderLoop *loop = QSGRenderLoop::instance();
|
|
|
|
qDebug() << "RenderLoop: " << loop;
|
|
|
|
|
|
|
|
QOpenGLContext context;
|
|
|
|
context.setFormat(loop->sceneGraphContext()->defaultSurfaceFormat());
|
|
|
|
context.create();
|
|
|
|
QSurfaceFormat format = context.format();
|
|
|
|
|
|
|
|
QOffscreenSurface surface;
|
|
|
|
surface.setFormat(format);
|
|
|
|
surface.create();
|
|
|
|
if (!context.makeCurrent(&surface))
|
|
|
|
qFatal("Failed to create a GL context...");
|
|
|
|
|
|
|
|
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
|
|
|
|
qDebug() << "R/G/B/A Buffers: " << format.redBufferSize() << format.greenBufferSize() << format.blueBufferSize() << format.alphaBufferSize();
|
|
|
|
qDebug() << "Depth Buffer: " << format.depthBufferSize();
|
|
|
|
qDebug() << "Stencil Buffer: " << format.stencilBufferSize();
|
|
|
|
qDebug() << "Samples: " << format.samples();
|
|
|
|
int textureSize;
|
|
|
|
funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &textureSize);
|
|
|
|
qDebug() << "Max Texture Size: " << textureSize;
|
|
|
|
qDebug() << "GL_VENDOR: " << (const char *) funcs->glGetString(GL_VENDOR);
|
|
|
|
qDebug() << "GL_RENDERER: " << (const char *) funcs->glGetString(GL_RENDERER);
|
2015-03-27 10:32:27 +00:00
|
|
|
QByteArray version = (const char *) funcs->glGetString(GL_VERSION);
|
|
|
|
qDebug() << "GL_VERSION: " << version.constData();
|
2014-06-04 18:32:07 +00:00
|
|
|
QSet<QByteArray> exts = context.extensions();
|
|
|
|
QByteArray all;
|
|
|
|
foreach (const QByteArray &e, exts) all += ' ' + e;
|
|
|
|
qDebug() << "GL_EXTENSIONS: " << all.constData();
|
|
|
|
|
2015-03-27 10:32:27 +00:00
|
|
|
m_brokenMipmapSupport = version.contains("Mesa 10.1") || version.contains("Mesa 9.");
|
|
|
|
qDebug() << "Broken Mipmap: " << m_brokenMipmapSupport;
|
|
|
|
|
2014-06-04 18:32:07 +00:00
|
|
|
context.doneCurrent();
|
2014-08-04 08:10:10 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 12:53:33 +00:00
|
|
|
QQuickView *createView(const QString &file, QWindow *parent = 0, int x = -1, int y = -1, int w = -1, int h = -1)
|
|
|
|
{
|
|
|
|
QQuickView *view = new QQuickView(parent);
|
|
|
|
view->setSource(QUrl::fromLocalFile("data/" + file));
|
|
|
|
if (x >= 0 && y >= 0) view->setPosition(x, y);
|
|
|
|
if (w >= 0 && h >= 0) view->resize(w, h);
|
|
|
|
view->show();
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage showAndGrab(const QString &file, int w, int h)
|
|
|
|
{
|
|
|
|
QQuickView view;
|
|
|
|
view.setSource(QUrl::fromLocalFile(QStringLiteral("data/") + file));
|
|
|
|
if (w >= 0 && h >= 0)
|
|
|
|
view.resize(w, h);
|
|
|
|
view.create();
|
|
|
|
return view.grabWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assumes the images are opaque white...
|
|
|
|
bool containsSomethingOtherThanWhite(const QImage &image)
|
|
|
|
{
|
|
|
|
Q_ASSERT(image.format() == QImage::Format_ARGB32_Premultiplied
|
|
|
|
|| image.format() == QImage::Format_RGB32);
|
|
|
|
int w = image.width();
|
|
|
|
int h = image.height();
|
|
|
|
for (int y=0; y<h; ++y) {
|
|
|
|
const uint *pixels = (const uint *) image.constScanLine(y);
|
|
|
|
for (int x=0; x<w; ++x)
|
|
|
|
if (pixels[x] != 0xffffffff)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-30 13:32:54 +00:00
|
|
|
// When running on native Nvidia graphics cards on linux, the
|
|
|
|
// distance field glyph pixels have a measurable, but not visible
|
|
|
|
// pixel error. Use a custom compare function to avoid
|
|
|
|
//
|
|
|
|
// This was GT-216 with the ubuntu "nvidia-319" driver package.
|
|
|
|
// llvmpipe does not show the same issue.
|
|
|
|
//
|
2013-10-17 12:53:33 +00:00
|
|
|
bool compareImages(const QImage &ia, const QImage &ib)
|
|
|
|
{
|
|
|
|
if (ia.size() != ib.size())
|
|
|
|
qDebug() << "images are of different size" << ia.size() << ib.size();
|
|
|
|
Q_ASSERT(ia.size() == ib.size());
|
|
|
|
Q_ASSERT(ia.format() == ib.format());
|
|
|
|
|
|
|
|
int w = ia.width();
|
|
|
|
int h = ia.height();
|
2014-03-17 14:54:44 +00:00
|
|
|
const int tolerance = 5;
|
2013-10-17 12:53:33 +00:00
|
|
|
for (int y=0; y<h; ++y) {
|
|
|
|
const uint *as= (const uint *) ia.constScanLine(y);
|
|
|
|
const uint *bs= (const uint *) ib.constScanLine(y);
|
|
|
|
for (int x=0; x<w; ++x) {
|
|
|
|
uint a = as[x];
|
|
|
|
uint b = bs[x];
|
|
|
|
|
|
|
|
// No tolerance for error in the alpha.
|
|
|
|
if ((a & 0xff000000) != (b & 0xff000000))
|
|
|
|
return false;
|
|
|
|
if (qAbs(qRed(a) - qRed(b)) > tolerance)
|
|
|
|
return false;
|
|
|
|
if (qAbs(qRed(a) - qRed(b)) > tolerance)
|
|
|
|
return false;
|
|
|
|
if (qAbs(qRed(a) - qRed(b)) > tolerance)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_SceneGraph::manyWindows_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("file");
|
|
|
|
QTest::addColumn<bool>("toplevel");
|
2013-10-30 13:32:54 +00:00
|
|
|
QTest::addColumn<bool>("shared");
|
|
|
|
|
|
|
|
QTest::newRow("image,toplevel") << QStringLiteral("manyWindows_image.qml") << true << false;
|
|
|
|
QTest::newRow("image,subwindow") << QStringLiteral("manyWindows_image.qml") << false << false;
|
|
|
|
QTest::newRow("dftext,toplevel") << QStringLiteral("manyWindows_dftext.qml") << true << false;
|
|
|
|
QTest::newRow("dftext,subwindow") << QStringLiteral("manyWindows_dftext.qml") << false << false;
|
|
|
|
QTest::newRow("ntext,toplevel") << QStringLiteral("manyWindows_ntext.qml") << true << false;
|
|
|
|
QTest::newRow("ntext,subwindow") << QStringLiteral("manyWindows_ntext.qml") << false << false;
|
|
|
|
QTest::newRow("rects,toplevel") << QStringLiteral("manyWindows_rects.qml") << true << false;
|
|
|
|
QTest::newRow("rects,subwindow") << QStringLiteral("manyWindows_rects.qml") << false << false;
|
|
|
|
|
|
|
|
QTest::newRow("image,toplevel,sharing") << QStringLiteral("manyWindows_image.qml") << true << true;
|
|
|
|
QTest::newRow("image,subwindow,sharing") << QStringLiteral("manyWindows_image.qml") << false << true;
|
|
|
|
QTest::newRow("dftext,toplevel,sharing") << QStringLiteral("manyWindows_dftext.qml") << true << true;
|
|
|
|
QTest::newRow("dftext,subwindow,sharing") << QStringLiteral("manyWindows_dftext.qml") << false << true;
|
|
|
|
QTest::newRow("ntext,toplevel,sharing") << QStringLiteral("manyWindows_ntext.qml") << true << true;
|
|
|
|
QTest::newRow("ntext,subwindow,sharing") << QStringLiteral("manyWindows_ntext.qml") << false << true;
|
|
|
|
QTest::newRow("rects,toplevel,sharing") << QStringLiteral("manyWindows_rects.qml") << true << true;
|
|
|
|
QTest::newRow("rects,subwindow,sharing") << QStringLiteral("manyWindows_rects.qml") << false << true;
|
2013-10-17 12:53:33 +00:00
|
|
|
}
|
|
|
|
|
2013-10-30 13:32:54 +00:00
|
|
|
struct ShareContextResetter {
|
|
|
|
public:
|
2014-06-04 18:32:07 +00:00
|
|
|
~ShareContextResetter() { qt_gl_set_global_share_context(0); }
|
2013-10-30 13:32:54 +00:00
|
|
|
};
|
|
|
|
|
2013-10-17 12:53:33 +00:00
|
|
|
void tst_SceneGraph::manyWindows()
|
|
|
|
{
|
|
|
|
QFETCH(QString, file);
|
|
|
|
QFETCH(bool, toplevel);
|
2013-10-30 13:32:54 +00:00
|
|
|
QFETCH(bool, shared);
|
|
|
|
|
|
|
|
QOpenGLContext sharedGLContext;
|
|
|
|
ShareContextResetter cleanup; // To avoid dangling pointer in case of test-failure.
|
|
|
|
if (shared) {
|
2015-01-26 08:25:15 +00:00
|
|
|
QVERIFY(sharedGLContext.create());
|
2014-06-04 18:32:07 +00:00
|
|
|
qt_gl_set_global_share_context(&sharedGLContext);
|
2013-10-30 13:32:54 +00:00
|
|
|
}
|
2013-10-17 12:53:33 +00:00
|
|
|
|
|
|
|
QScopedPointer<QWindow> parent;
|
|
|
|
if (!toplevel) {
|
|
|
|
parent.reset(new QWindow());
|
|
|
|
parent->resize(200, 200);
|
|
|
|
parent->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedList <QQuickView *> views;
|
|
|
|
|
|
|
|
const int COUNT = 4;
|
|
|
|
|
|
|
|
QImage baseLine;
|
|
|
|
for (int i=0; i<COUNT; ++i) {
|
|
|
|
views << createView(file, parent.data(), (i % 2) * 100, (i / 2) * 100, 100, 100);
|
|
|
|
}
|
|
|
|
for (int i=0; i<COUNT; ++i) {
|
|
|
|
QQuickView *view = views.at(i);
|
|
|
|
QTest::qWaitForWindowExposed(view);
|
|
|
|
QImage content = view->grabWindow();
|
|
|
|
if (i == 0) {
|
|
|
|
baseLine = content;
|
|
|
|
QVERIFY(containsSomethingOtherThanWhite(baseLine));
|
|
|
|
} else {
|
|
|
|
QVERIFY(compareImages(content, baseLine));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wipe and recreate one (scope pointer delets it...)
|
|
|
|
delete views.takeLast();
|
|
|
|
QQuickView *last = createView(file, parent.data(), 100, 100, 100, 100);
|
|
|
|
QTest::qWaitForWindowExposed(last);
|
|
|
|
views << last;
|
|
|
|
QVERIFY(compareImages(baseLine, last->grabWindow()));
|
|
|
|
|
|
|
|
// Wipe and recreate all
|
|
|
|
qDeleteAll(views);
|
|
|
|
views.clear();
|
|
|
|
|
|
|
|
for (int i=0; i<COUNT; ++i) {
|
|
|
|
views << createView(file, parent.data(), (i % 2) * 100, (i / 2) * 100, 100, 100);
|
|
|
|
}
|
|
|
|
for (int i=0; i<COUNT; ++i) {
|
|
|
|
QQuickView *view = views.at(i);
|
|
|
|
QTest::qWaitForWindowExposed(view);
|
|
|
|
QImage content = view->grabWindow();
|
|
|
|
QVERIFY(compareImages(content, baseLine));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-31 21:22:54 +00:00
|
|
|
struct Sample {
|
|
|
|
Sample(int xx, int yy, qreal rr, qreal gg, qreal bb, qreal errorMargin = 0.05)
|
|
|
|
: x(xx)
|
|
|
|
, y(yy)
|
|
|
|
, r(rr)
|
|
|
|
, g(gg)
|
|
|
|
, b(bb)
|
|
|
|
, tolerance(errorMargin)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
Sample(const Sample &o) : x(o.x), y(o.y), r(o.r), g(o.g), b(o.b), tolerance(o.tolerance) { }
|
|
|
|
Sample() : x(0), y(0), r(0), g(0), b(0), tolerance(0) { }
|
|
|
|
|
|
|
|
QString toString(const QImage &image) const {
|
|
|
|
QColor color(image.pixel(x,y));
|
|
|
|
return QString::fromLatin1("pixel(%1,%2), rgb(%3,%4,%5), tolerance=%6 -- image(%7,%8,%9)")
|
|
|
|
.arg(x).arg(y)
|
|
|
|
.arg(r).arg(g).arg(b)
|
|
|
|
.arg(tolerance)
|
|
|
|
.arg(color.redF()).arg(color.greenF()).arg(color.blueF());
|
|
|
|
}
|
|
|
|
|
2014-06-04 18:32:07 +00:00
|
|
|
bool check(const QImage &image, qreal scale) {
|
|
|
|
QColor color(image.pixel(x * scale, y * scale));
|
2013-10-31 21:22:54 +00:00
|
|
|
return qAbs(color.redF() - r) <= tolerance
|
|
|
|
&& qAbs(color.greenF() - g) <= tolerance
|
|
|
|
&& qAbs(color.blueF() - b) <= tolerance;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int x, y;
|
|
|
|
qreal r, g, b;
|
|
|
|
qreal tolerance;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Sample sample_from_regexp(QRegExp *re) {
|
|
|
|
return Sample(re->cap(1).toInt(),
|
|
|
|
re->cap(2).toInt(),
|
|
|
|
re->cap(3).toFloat(),
|
|
|
|
re->cap(4).toFloat(),
|
|
|
|
re->cap(5).toFloat(),
|
|
|
|
re->cap(6).toFloat()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Sample);
|
|
|
|
|
|
|
|
/*
|
|
|
|
The render() test implements a small test framework for itself with
|
|
|
|
the purpose of testing odds and ends of the scene graph
|
|
|
|
rendering. Each .qml file can consist of one or two stages. The
|
|
|
|
first stage is when the file is first displayed. The content is
|
|
|
|
grabbed and matched against 'base' samples defined in the .qml file
|
|
|
|
itself. The samples contain a pixel position, and RGB value and a
|
|
|
|
margin of error. The samples are defined in the .qml file so it is
|
|
|
|
easy to make the connection between colors and positions on the screen.
|
|
|
|
|
|
|
|
If the base stage samples all succeed, the test emits
|
|
|
|
'enterFinalStage' on the root item and waits for the .qml file to
|
|
|
|
update the value of 'finalStageComplete' The test can set this
|
|
|
|
directly or run an animation and set it later. Once the
|
|
|
|
'finalStageComplete' variable is true, we grab and match against the
|
|
|
|
second set of samples 'final'
|
|
|
|
|
|
|
|
The samples in the .qml file are defined in comments on the format:
|
|
|
|
#base: x y r g b error-tolerance
|
|
|
|
#final: x y r g b error-tolerance
|
|
|
|
- x and y are integers
|
|
|
|
- r g b are floats in the range of 0.0-1.0
|
|
|
|
- error-tolerance is a float in the range of 0.0-1.0
|
|
|
|
|
|
|
|
We also include a
|
|
|
|
#samples: count
|
|
|
|
to sanity check that all base/final samples were matched correctly
|
|
|
|
as the matching regexp is a bit crude.
|
|
|
|
|
|
|
|
To add new tests, add them to the 'files' list and put #base,
|
|
|
|
#final, #samples tags into the .qml file
|
|
|
|
*/
|
|
|
|
|
|
|
|
void tst_SceneGraph::render_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("file");
|
|
|
|
QTest::addColumn<QList<Sample> >("baseStage");
|
|
|
|
QTest::addColumn<QList<Sample> >("finalStage");
|
|
|
|
|
|
|
|
QList<QString> files;
|
|
|
|
files << "data/render_DrawSets.qml"
|
|
|
|
<< "data/render_Overlap.qml"
|
|
|
|
<< "data/render_MovingOverlap.qml"
|
|
|
|
<< "data/render_BreakOpacityBatch.qml"
|
2013-11-06 09:06:27 +00:00
|
|
|
<< "data/render_OutOfFloatRange.qml"
|
2013-11-15 06:23:04 +00:00
|
|
|
<< "data/render_StackingOrder.qml"
|
2014-02-18 18:54:32 +00:00
|
|
|
<< "data/render_ImageFiltering.qml"
|
2014-06-04 16:59:58 +00:00
|
|
|
<< "data/render_bug37422.qml"
|
2015-03-27 10:32:27 +00:00
|
|
|
<< "data/render_OpacityThroughBatchRoot.qml";
|
|
|
|
if (!m_brokenMipmapSupport)
|
|
|
|
files << "data/render_Mipmap.qml";
|
2013-10-31 21:22:54 +00:00
|
|
|
|
|
|
|
QRegExp sampleCount("#samples: *(\\d+)");
|
|
|
|
// X:int Y:int R:float G:float B:float Error:float
|
|
|
|
QRegExp baseSamples("#base: *(\\d+) *(\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+)");
|
|
|
|
QRegExp finalSamples("#final: *(\\d+) *(\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+)");
|
|
|
|
|
|
|
|
foreach (QString fileName, files) {
|
|
|
|
QFile file(fileName);
|
|
|
|
if (!file.open(QFile::ReadOnly)) {
|
|
|
|
qFatal("render_data: QFile::open failed! file=%s, error=%s",
|
|
|
|
qPrintable(fileName), qPrintable(file.errorString()));
|
|
|
|
}
|
|
|
|
QStringList contents = QString::fromLatin1(file.readAll()).split(QLatin1Char('\n'));
|
|
|
|
|
|
|
|
int samples = -1;
|
|
|
|
foreach (QString line, contents) {
|
|
|
|
if (sampleCount.indexIn(line) >= 0) {
|
|
|
|
samples = sampleCount.cap(1).toInt();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (samples == -1)
|
|
|
|
qFatal("render_data: failed to find string '#samples: [count], file=%s", qPrintable(fileName));
|
|
|
|
|
|
|
|
QList<Sample> baseStage, finalStage;
|
|
|
|
foreach (QString line, contents) {
|
|
|
|
if (baseSamples.indexIn(line) >= 0)
|
|
|
|
baseStage << sample_from_regexp(&baseSamples);
|
|
|
|
else if (finalSamples.indexIn(line) >= 0)
|
|
|
|
finalStage << sample_from_regexp(&finalSamples);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (baseStage.size() + finalStage.size() != samples)
|
|
|
|
qFatal("render_data: #samples does not add up to number of counted samples, file=%s", qPrintable(fileName));
|
|
|
|
|
|
|
|
QTest::newRow(qPrintable(fileName)) << fileName << baseStage << finalStage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_SceneGraph::render()
|
|
|
|
{
|
|
|
|
QFETCH(QString, file);
|
|
|
|
QFETCH(QList<Sample>, baseStage);
|
|
|
|
QFETCH(QList<Sample>, finalStage);
|
|
|
|
|
|
|
|
QObject suite;
|
|
|
|
suite.setObjectName("The Suite");
|
|
|
|
|
|
|
|
QQuickView view;
|
|
|
|
view.rootContext()->setContextProperty("suite", &suite);
|
|
|
|
view.setSource(QUrl::fromLocalFile(file));
|
|
|
|
view.setResizeMode(QQuickView::SizeViewToRootObject);
|
|
|
|
view.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
|
|
|
|
2014-06-04 18:32:07 +00:00
|
|
|
// We're checking actual pixels, so scale up the sample point to the top-left of the
|
|
|
|
// 2x2 pixel block and hope that this is good enough. Ideally, view and content
|
|
|
|
// would be in identical coordinate space, meaning pixels, but we're not in an
|
|
|
|
// ideal world.
|
|
|
|
// Just keep this in mind when writing tests.
|
|
|
|
qreal scale = view.devicePixelRatio();
|
|
|
|
|
2013-10-31 21:22:54 +00:00
|
|
|
// Grab the window and check all our base stage samples
|
|
|
|
QImage content = view.grabWindow();
|
|
|
|
for (int i=0; i<baseStage.size(); ++i) {
|
|
|
|
Sample sample = baseStage.at(i);
|
2014-06-04 18:32:07 +00:00
|
|
|
QVERIFY2(sample.check(content, scale), qPrintable(sample.toString(content)));
|
2013-10-31 21:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put the qml file into the final stage and wait for it to
|
|
|
|
// complete it.
|
|
|
|
QQuickItem *rootItem = view.rootObject();
|
|
|
|
QMetaObject::invokeMethod(rootItem, "enterFinalStage");
|
|
|
|
QTRY_VERIFY(rootItem->property("finalStageComplete").toBool());
|
|
|
|
|
|
|
|
// The grab the results and verify the samples in the end state.
|
|
|
|
content = view.grabWindow();
|
|
|
|
for (int i=0; i<finalStage.size(); ++i) {
|
|
|
|
Sample sample = finalStage.at(i);
|
2014-06-04 18:32:07 +00:00
|
|
|
QVERIFY2(sample.check(content, scale), qPrintable(sample.toString(content)));
|
2013-10-31 21:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-17 12:53:33 +00:00
|
|
|
|
2013-11-18 07:53:13 +00:00
|
|
|
// Testcase for QTBUG-34898. We make another context current on another surface
|
|
|
|
// in the GUI thread and hide the QQuickWindow while the other context is
|
|
|
|
// current on the other window.
|
|
|
|
void tst_SceneGraph::hideWithOtherContext()
|
|
|
|
{
|
|
|
|
QWindow window;
|
|
|
|
window.setSurfaceType(QWindow::OpenGLSurface);
|
|
|
|
window.resize(100, 100);
|
|
|
|
window.create();
|
|
|
|
QOpenGLContext context;
|
2015-01-26 08:25:15 +00:00
|
|
|
QVERIFY(context.create());
|
2013-11-18 07:53:13 +00:00
|
|
|
bool renderingOnMainThread = false;
|
|
|
|
|
|
|
|
{
|
|
|
|
QQuickView view;
|
|
|
|
view.setSource(QUrl::fromLocalFile("data/simple.qml"));
|
|
|
|
view.setResizeMode(QQuickView::SizeViewToRootObject);
|
|
|
|
view.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
|
|
|
|
|
|
|
renderingOnMainThread = view.openglContext()->thread() == QGuiApplication::instance()->thread();
|
|
|
|
|
|
|
|
// Make the local context current on the local window...
|
|
|
|
context.makeCurrent(&window);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The local context should no longer be the current one. It is not
|
|
|
|
// rebound because all well behaving Qt/OpenGL applications are
|
|
|
|
// required to makeCurrent their context again before making any
|
|
|
|
// GL calls to a new frame (see QOpenGLContext docs).
|
|
|
|
QVERIFY(!renderingOnMainThread || QOpenGLContext::currentContext() != &context);
|
|
|
|
}
|
|
|
|
|
2015-06-11 08:17:45 +00:00
|
|
|
void tst_SceneGraph::createTextureFromImage_data()
|
|
|
|
{
|
|
|
|
QImage rgba(64, 64, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
QImage rgb(64, 64, QImage::Format_RGB32);
|
|
|
|
|
|
|
|
QTest::addColumn<QImage>("image");
|
|
|
|
QTest::addColumn<uint>("flags");
|
|
|
|
QTest::addColumn<bool>("expectedAlpha");
|
|
|
|
|
|
|
|
QTest::newRow("rgb") << rgb << uint(0) << false;
|
|
|
|
QTest::newRow("argb") << rgba << uint(0) << true;
|
|
|
|
QTest::newRow("rgb,alpha") << rgb << uint(QQuickWindow::TextureHasAlphaChannel) << false;
|
|
|
|
QTest::newRow("argb,alpha") << rgba << uint(QQuickWindow::TextureHasAlphaChannel) << true;
|
|
|
|
QTest::newRow("rgb,!alpha") << rgb << uint(QQuickWindow::TextureIsOpaque) << false;
|
|
|
|
QTest::newRow("argb,!alpha") << rgba << uint(QQuickWindow::TextureIsOpaque) << false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_SceneGraph::createTextureFromImage()
|
|
|
|
{
|
|
|
|
QFETCH(QImage, image);
|
|
|
|
QFETCH(uint, flags);
|
|
|
|
QFETCH(bool, expectedAlpha);
|
|
|
|
|
|
|
|
QQuickView view;
|
|
|
|
QScopedPointer<QSGTexture> texture(view.createTextureFromImage(image, (QQuickWindow::CreateTextureOptions) flags));
|
|
|
|
QCOMPARE(texture->hasAlphaChannel(), expectedAlpha);
|
|
|
|
}
|
|
|
|
|
2013-11-18 07:53:13 +00:00
|
|
|
|
2013-10-17 12:53:33 +00:00
|
|
|
#include "tst_scenegraph.moc"
|
|
|
|
|
|
|
|
QTEST_MAIN(tst_SceneGraph)
|
|
|
|
|