diff options
Diffstat (limited to 'tests/auto/quick/scenegraph')
-rw-r--r-- | tests/auto/quick/scenegraph/scenegraph.pro | 1 | ||||
-rw-r--r-- | tests/auto/quick/scenegraph/tst_scenegraph.cpp | 89 |
2 files changed, 43 insertions, 47 deletions
diff --git a/tests/auto/quick/scenegraph/scenegraph.pro b/tests/auto/quick/scenegraph/scenegraph.pro index 320228bd08..40ff7750cc 100644 --- a/tests/auto/quick/scenegraph/scenegraph.pro +++ b/tests/auto/quick/scenegraph/scenegraph.pro @@ -3,6 +3,7 @@ TARGET = tst_scenegraph SOURCES += tst_scenegraph.cpp include (../../shared/util.pri) +include (../shared/util.pri) macx:CONFIG -= app_bundle diff --git a/tests/auto/quick/scenegraph/tst_scenegraph.cpp b/tests/auto/quick/scenegraph/tst_scenegraph.cpp index 1e46727526..f6d624d871 100644 --- a/tests/auto/quick/scenegraph/tst_scenegraph.cpp +++ b/tests/auto/quick/scenegraph/tst_scenegraph.cpp @@ -28,18 +28,26 @@ #include <qtest.h> +#ifndef QT_NO_OPENGL #include <QOffscreenSurface> #include <QOpenGLContext> #include <QOpenGLFunctions> +#endif #include <QtQuick> #include <QtQml> +#ifndef QT_NO_OPENGL #include <private/qopenglcontext_p.h> +#endif + #include <private/qsgcontext_p.h> #include <private/qsgrenderloop_p.h> #include "../../shared/util.h" +#include "../shared/visualtestutil.h" + +using namespace QQuickVisualTestUtil; class PerPixelRect : public QQuickItem { @@ -97,9 +105,9 @@ private slots: void render_data(); void render(); - +#ifndef QT_NO_OPENGL void hideWithOtherContext(); - +#endif void createTextureFromImage_data(); void createTextureFromImage(); @@ -122,6 +130,7 @@ void tst_SceneGraph::initTestCase() QSGRenderLoop *loop = QSGRenderLoop::instance(); qDebug() << "RenderLoop: " << loop; +#ifndef QT_NO_OPENGL QOpenGLContext context; context.setFormat(loop->sceneGraphContext()->defaultSurfaceFormat()); context.create(); @@ -154,6 +163,7 @@ void tst_SceneGraph::initTestCase() qDebug() << "Broken Mipmap: " << m_brokenMipmapSupport; context.doneCurrent(); +#endif } QQuickView *tst_SceneGraph::createView(const QString &file, QWindow *parent, int x, int y, int w, int h) @@ -169,12 +179,17 @@ QQuickView *tst_SceneGraph::createView(const QString &file, QWindow *parent, int // 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(); + QImage img; + if (image.format() != QImage::Format_ARGB32_Premultiplied + || image.format() != QImage::Format_RGB32) + img = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); + else + img = image; + + int w = img.width(); + int h = img.height(); for (int y=0; y<h; ++y) { - const uint *pixels = (const uint *) image.constScanLine(y); + const uint *pixels = (const uint *) img.constScanLine(y); for (int x=0; x<w; ++x) if (pixels[x] != 0xffffffff) return true; @@ -182,44 +197,6 @@ bool containsSomethingOtherThanWhite(const QImage &image) return false; } -// 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. -// -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(); - const int tolerance = 5; - 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"); @@ -245,24 +222,26 @@ void tst_SceneGraph::manyWindows_data() QTest::newRow("rects,subwindow,sharing") << QStringLiteral("manyWindows_rects.qml") << false << true; } +#ifndef QT_NO_OPENGL struct ShareContextResetter { public: ~ShareContextResetter() { qt_gl_set_global_share_context(0); } }; +#endif void tst_SceneGraph::manyWindows() { QFETCH(QString, file); QFETCH(bool, toplevel); QFETCH(bool, shared); - +#ifndef QT_NO_OPENGL QOpenGLContext sharedGLContext; ShareContextResetter cleanup; // To avoid dangling pointer in case of test-failure. if (shared) { QVERIFY(sharedGLContext.create()); qt_gl_set_global_share_context(&sharedGLContext); } - +#endif QScopedPointer<QWindow> parent; if (!toplevel) { parent.reset(new QWindow()); @@ -451,6 +430,13 @@ void tst_SceneGraph::render_data() void tst_SceneGraph::render() { + QQuickView dummy; + dummy.show(); + QTest::qWaitForWindowExposed(&dummy); + if (dummy.rendererInterface()->graphicsApi() != QSGRendererInterface::OpenGL) + QSKIP("Skipping complex rendering tests due to not running with OpenGL"); + dummy.hide(); + QFETCH(QString, file); QFETCH(QList<Sample>, baseStage); QFETCH(QList<Sample>, finalStage); @@ -493,6 +479,7 @@ void tst_SceneGraph::render() } } +#ifndef QT_NO_OPENGL // 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. @@ -513,6 +500,9 @@ void tst_SceneGraph::hideWithOtherContext() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); + if (view.rendererInterface()->graphicsApi() != QSGRendererInterface::OpenGL) + QSKIP("Skipping OpenGL context test due to not running with OpenGL"); + renderingOnMainThread = view.openglContext()->thread() == QGuiApplication::instance()->thread(); // Make the local context current on the local window... @@ -525,6 +515,7 @@ void tst_SceneGraph::hideWithOtherContext() // GL calls to a new frame (see QOpenGLContext docs). QVERIFY(!renderingOnMainThread || QOpenGLContext::currentContext() != &context); } +#endif void tst_SceneGraph::createTextureFromImage_data() { @@ -550,6 +541,10 @@ void tst_SceneGraph::createTextureFromImage() QFETCH(bool, expectedAlpha); QQuickView view; + view.show(); + QTest::qWaitForWindowExposed(&view); + QTRY_VERIFY(view.isSceneGraphInitialized()); + QScopedPointer<QSGTexture> texture(view.createTextureFromImage(image, (QQuickWindow::CreateTextureOptions) flags)); QCOMPARE(texture->hasAlphaChannel(), expectedAlpha); } |