2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-04-27 10:05:43 +00:00
|
|
|
|
Mark all of Qt as free of Q_FOREACH, except where it isn't
The density of Q_FOREACH uses in this and some other modules is still
extremely high, too high for anyone to tackle in a short amount of
time. Even if they're not concentrated in just a few TUs, we need to
make progress on a global QT_NO_FOREACH default, so grab the nettle
and stick to our strategy:
Mark the whole of Qt with QT_NO_FOREACH, to prevent new uses from
creeping in, and whitelist the affected TUs by #undef'ing
QT_NO_FOREACH locally, at the top of each file. For TUs that are part
of a larger executable, this requires these files to be compiled
separately, so add them to NO_PCH_SOURCES (which implies
NO_UNITY_BUILD_SOURCES, too).
In tst_qglobal.cpp and tst_qcollections.cpp change the comment on the
#undef QT_NO_FOREACH to indicate that these actually test the macro.
Task-number: QTBUG-115839
Change-Id: Iecc444eb7d43d7e4d037f6e155abe0e14a00a5d6
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-08-07 15:59:46 +00:00
|
|
|
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
|
|
|
|
|
2011-08-31 11:24:37 +00:00
|
|
|
#include "paintcommands.h"
|
2012-10-29 09:34:20 +00:00
|
|
|
#include <qbaselinetest.h>
|
|
|
|
#include <QDir>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QPainter>
|
2021-09-23 08:00:22 +00:00
|
|
|
#include <QPdfWriter>
|
|
|
|
#include <QTemporaryFile>
|
2021-10-01 08:02:36 +00:00
|
|
|
#if QT_CONFIG(process)
|
2021-09-23 08:00:22 +00:00
|
|
|
#include <QProcess>
|
2021-10-01 08:02:36 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#ifndef QT_NO_OPENGL
|
2012-10-29 09:34:20 +00:00
|
|
|
#include <QOpenGLFramebufferObjectFormat>
|
|
|
|
#include <QOpenGLContext>
|
|
|
|
#include <QOpenGLPaintDevice>
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-18 08:33:36 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2018-05-30 13:51:32 +00:00
|
|
|
#ifndef GL_RGB10
|
|
|
|
#define GL_RGB10 0x8052
|
|
|
|
#endif
|
2021-01-11 10:21:05 +00:00
|
|
|
#ifndef GL_RGB10_A2
|
|
|
|
#define GL_RGB10_A2 0x8059
|
|
|
|
#endif
|
2018-05-30 13:51:32 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
class tst_Lancelot : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
tst_Lancelot();
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum GraphicsEngine {
|
|
|
|
Raster = 0,
|
2021-09-23 08:00:22 +00:00
|
|
|
OpenGL = 1,
|
|
|
|
Pdf = 2
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
void setupTestSuite(const QStringList& blacklist = QStringList());
|
2022-04-05 07:40:55 +00:00
|
|
|
void runTestSuite(GraphicsEngine engine, QImage::Format format,
|
|
|
|
const QSurfaceFormat &contextFormat = QSurfaceFormat::defaultFormat());
|
2017-05-23 11:57:20 +00:00
|
|
|
void paint(QPaintDevice *device, GraphicsEngine engine, QImage::Format format, const QStringList &script, const QString &filePath);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
QStringList qpsFiles;
|
2011-04-27 10:05:43 +00:00
|
|
|
QHash<QString, QStringList> scripts;
|
2012-10-29 09:34:20 +00:00
|
|
|
QHash<QString, quint16> scriptChecksums;
|
2011-04-27 10:05:43 +00:00
|
|
|
QString scriptsDir;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initTestCase();
|
|
|
|
void cleanupTestCase() {}
|
|
|
|
|
|
|
|
void testRasterARGB32PM_data();
|
|
|
|
void testRasterARGB32PM();
|
|
|
|
void testRasterRGB32_data();
|
|
|
|
void testRasterRGB32();
|
2016-12-01 11:33:29 +00:00
|
|
|
void testRasterARGB32_data();
|
|
|
|
void testRasterARGB32();
|
2011-04-27 10:05:43 +00:00
|
|
|
void testRasterRGB16_data();
|
|
|
|
void testRasterRGB16();
|
2016-08-03 11:27:38 +00:00
|
|
|
void testRasterA2RGB30PM_data();
|
|
|
|
void testRasterA2RGB30PM();
|
|
|
|
void testRasterBGR30_data();
|
|
|
|
void testRasterBGR30();
|
2016-09-19 08:41:57 +00:00
|
|
|
void testRasterARGB8565PM_data();
|
|
|
|
void testRasterARGB8565PM();
|
|
|
|
void testRasterGrayscale8_data();
|
|
|
|
void testRasterGrayscale8();
|
2019-08-14 08:29:21 +00:00
|
|
|
void testRasterRGBA64PM_data();
|
|
|
|
void testRasterRGBA64PM();
|
2018-05-18 15:03:58 +00:00
|
|
|
void testRasterRGBA16F_data();
|
|
|
|
void testRasterRGBA16F();
|
|
|
|
void testRasterRGBA32FPM_data();
|
|
|
|
void testRasterRGBA32FPM();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2021-09-23 08:00:22 +00:00
|
|
|
void testPdf_data();
|
|
|
|
void testPdf();
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
|
|
|
void testOpenGL_data();
|
|
|
|
void testOpenGL();
|
2018-05-30 13:51:32 +00:00
|
|
|
void testOpenGLBGR30_data();
|
|
|
|
void testOpenGLBGR30();
|
2016-07-27 13:45:31 +00:00
|
|
|
void testCoreOpenGL_data();
|
|
|
|
void testCoreOpenGL();
|
2012-10-29 09:34:20 +00:00
|
|
|
private:
|
2022-04-05 07:40:55 +00:00
|
|
|
void initOpenGL();
|
2012-10-29 09:34:20 +00:00
|
|
|
bool checkSystemGLSupport();
|
2016-07-27 13:45:31 +00:00
|
|
|
bool checkSystemCoreGLSupport();
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
tst_Lancelot::tst_Lancelot()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::initTestCase()
|
|
|
|
{
|
|
|
|
// Check and setup the environment. We treat failures because of test environment
|
|
|
|
// (e.g. script files not found) as just warnings, and not QFAILs, to avoid false negatives
|
|
|
|
// caused by environment or server instability
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
QByteArray msg;
|
|
|
|
if (!QBaselineTest::connectToBaselineServer(&msg))
|
|
|
|
QSKIP(msg);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-01-04 02:28:20 +00:00
|
|
|
QString baseDir = QFINDTESTDATA("scripts/text.qps");
|
|
|
|
scriptsDir = baseDir.left(baseDir.lastIndexOf('/')) + '/';
|
2011-04-27 10:05:43 +00:00
|
|
|
QDir qpsDir(scriptsDir);
|
2012-10-29 09:34:20 +00:00
|
|
|
qpsFiles = qpsDir.entryList(QStringList() << QLatin1String("*.qps"), QDir::Files | QDir::Readable);
|
|
|
|
if (qpsFiles.isEmpty()) {
|
2021-07-31 16:25:42 +00:00
|
|
|
qWarning() << "No qps script files found in" << qpsDir.path();
|
2011-10-19 02:53:13 +00:00
|
|
|
QSKIP("Aborted due to errors.");
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 08:33:36 +00:00
|
|
|
std::sort(qpsFiles.begin(), qpsFiles.end());
|
2012-10-29 09:34:20 +00:00
|
|
|
foreach (const QString& fileName, qpsFiles) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QFile file(scriptsDir + fileName);
|
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
QByteArray cont = file.readAll();
|
2020-02-25 16:22:09 +00:00
|
|
|
scripts.insert(fileName, QString::fromUtf8(cont).split(QLatin1Char('\n'), Qt::SkipEmptyParts));
|
2020-09-11 11:50:48 +00:00
|
|
|
scriptChecksums.insert(fileName, qChecksum(cont));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2022-04-05 07:40:55 +00:00
|
|
|
|
|
|
|
#ifndef QT_NO_OPENGL
|
|
|
|
initOpenGL();
|
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterARGB32PM_data()
|
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
setupTestSuite();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterARGB32PM()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-01 11:33:29 +00:00
|
|
|
void tst_Lancelot::testRasterARGB32_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterARGB32()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_ARGB32);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_Lancelot::testRasterRGB32_data()
|
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
setupTestSuite();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterRGB32()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_RGB32);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterRGB16_data()
|
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
setupTestSuite();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterRGB16()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_RGB16);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 11:27:38 +00:00
|
|
|
void tst_Lancelot::testRasterA2RGB30PM_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterA2RGB30PM()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_A2RGB30_Premultiplied);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterBGR30_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterBGR30()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_BGR30);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-19 08:41:57 +00:00
|
|
|
void tst_Lancelot::testRasterARGB8565PM_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterARGB8565PM()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_ARGB8565_Premultiplied);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterGrayscale8_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterGrayscale8()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_Grayscale8);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-14 08:29:21 +00:00
|
|
|
void tst_Lancelot::testRasterRGBA64PM_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterRGBA64PM()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_RGBA64_Premultiplied);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-18 15:03:58 +00:00
|
|
|
void tst_Lancelot::testRasterRGBA16F_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterRGBA16F()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_RGBA16FPx4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterRGBA32FPM_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterRGBA32FPM()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_RGBA32FPx4_Premultiplied);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-23 08:00:22 +00:00
|
|
|
void tst_Lancelot::testPdf_data()
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
setupTestSuite();
|
|
|
|
#else
|
|
|
|
QSKIP("Pdf testing only implemented for macOS");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testPdf()
|
|
|
|
{
|
|
|
|
runTestSuite(Pdf, QImage::Format_RGB32);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
2022-04-05 07:40:55 +00:00
|
|
|
void tst_Lancelot::initOpenGL()
|
|
|
|
{
|
|
|
|
// Stencil buffer is needed for clipping
|
|
|
|
QSurfaceFormat glFormat;
|
|
|
|
glFormat.setStencilBufferSize(8);
|
|
|
|
QSurfaceFormat::setDefaultFormat(glFormat);
|
|
|
|
}
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
bool tst_Lancelot::checkSystemGLSupport()
|
|
|
|
{
|
|
|
|
QWindow win;
|
|
|
|
win.setSurfaceType(QSurface::OpenGLSurface);
|
|
|
|
win.create();
|
|
|
|
QOpenGLFramebufferObjectFormat fmt;
|
|
|
|
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
|
|
|
fmt.setSamples(4);
|
|
|
|
QOpenGLContext ctx;
|
|
|
|
if (!ctx.create() || !ctx.makeCurrent(&win))
|
|
|
|
return false;
|
|
|
|
QOpenGLFramebufferObject fbo(800, 800, fmt);
|
|
|
|
if (!fbo.isValid() || !fbo.bind())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-27 13:45:31 +00:00
|
|
|
bool tst_Lancelot::checkSystemCoreGLSupport()
|
|
|
|
{
|
|
|
|
if (QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGL)
|
|
|
|
return false;
|
|
|
|
|
2022-04-05 07:40:55 +00:00
|
|
|
QSurfaceFormat coreFormat(QSurfaceFormat::defaultFormat());
|
2016-07-27 13:45:31 +00:00
|
|
|
coreFormat.setVersion(3, 2);
|
|
|
|
coreFormat.setProfile(QSurfaceFormat::CoreProfile);
|
|
|
|
QWindow win;
|
|
|
|
win.setSurfaceType(QSurface::OpenGLSurface);
|
|
|
|
win.setFormat(coreFormat);
|
|
|
|
win.create();
|
|
|
|
QOpenGLFramebufferObjectFormat fmt;
|
|
|
|
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
|
|
|
fmt.setSamples(4);
|
|
|
|
QOpenGLContext ctx;
|
|
|
|
ctx.setFormat(coreFormat);
|
|
|
|
if (!ctx.create() || !ctx.makeCurrent(&win))
|
|
|
|
return false;
|
|
|
|
QOpenGLFramebufferObject fbo(800, 800, fmt);
|
|
|
|
if (!fbo.isValid() || !fbo.bind())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_Lancelot::testOpenGL_data()
|
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
if (!checkSystemGLSupport())
|
|
|
|
QSKIP("System under test does not meet preconditions for GL testing. Skipping.");
|
2011-04-27 10:05:43 +00:00
|
|
|
QStringList localBlacklist = QStringList() << QLatin1String("rasterops.qps");
|
2012-10-29 09:34:20 +00:00
|
|
|
setupTestSuite(localBlacklist);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testOpenGL()
|
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
runTestSuite(OpenGL, QImage::Format_RGB32);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2016-07-27 13:45:31 +00:00
|
|
|
|
2018-05-30 13:51:32 +00:00
|
|
|
void tst_Lancelot::testOpenGLBGR30_data()
|
|
|
|
{
|
|
|
|
tst_Lancelot::testOpenGL_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testOpenGLBGR30()
|
|
|
|
{
|
|
|
|
runTestSuite(OpenGL, QImage::Format_BGR30);
|
|
|
|
}
|
|
|
|
|
2016-07-27 13:45:31 +00:00
|
|
|
void tst_Lancelot::testCoreOpenGL_data()
|
|
|
|
{
|
|
|
|
if (!checkSystemCoreGLSupport())
|
|
|
|
QSKIP("System under test does not meet preconditions for Core Profile GL testing. Skipping.");
|
|
|
|
QStringList localBlacklist = QStringList() << QLatin1String("rasterops.qps");
|
|
|
|
setupTestSuite(localBlacklist);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testCoreOpenGL()
|
|
|
|
{
|
2022-04-05 07:40:55 +00:00
|
|
|
QSurfaceFormat coreFormat(QSurfaceFormat::defaultFormat());
|
2016-07-27 13:45:31 +00:00
|
|
|
coreFormat.setVersion(3, 2);
|
|
|
|
coreFormat.setProfile(QSurfaceFormat::CoreProfile);
|
|
|
|
runTestSuite(OpenGL, QImage::Format_RGB32, coreFormat);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
void tst_Lancelot::setupTestSuite(const QStringList& blacklist)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
QTest::addColumn<QString>("qpsFile");
|
|
|
|
foreach (const QString &fileName, qpsFiles) {
|
|
|
|
if (blacklist.contains(fileName))
|
|
|
|
continue;
|
|
|
|
QBaselineTest::newRow(fileName.toLatin1(), scriptChecksums.value(fileName)) << fileName;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-27 13:45:31 +00:00
|
|
|
void tst_Lancelot::runTestSuite(GraphicsEngine engine, QImage::Format format, const QSurfaceFormat &contextFormat)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
QFETCH(QString, qpsFile);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
QString filePath = scriptsDir + qpsFile;
|
|
|
|
QStringList script = scripts.value(qpsFile);
|
|
|
|
QImage rendered;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if (engine == Raster) {
|
|
|
|
QImage img(800, 800, format);
|
2017-05-23 11:57:20 +00:00
|
|
|
paint(&img, engine, format, script, QFileInfo(filePath).absoluteFilePath());
|
2012-10-29 09:34:20 +00:00
|
|
|
rendered = img;
|
2011-04-27 10:05:43 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
|
|
|
} else if (engine == OpenGL) {
|
2012-10-29 09:34:20 +00:00
|
|
|
QWindow win;
|
|
|
|
win.setSurfaceType(QSurface::OpenGLSurface);
|
2016-07-27 13:45:31 +00:00
|
|
|
win.setFormat(contextFormat);
|
2012-10-29 09:34:20 +00:00
|
|
|
win.create();
|
|
|
|
QOpenGLContext ctx;
|
2016-07-27 13:45:31 +00:00
|
|
|
ctx.setFormat(contextFormat);
|
2013-09-30 12:07:24 +00:00
|
|
|
QVERIFY(ctx.create());
|
|
|
|
QVERIFY(ctx.makeCurrent(&win));
|
2021-01-11 10:21:05 +00:00
|
|
|
QOpenGLFramebufferObjectFormat fmt;
|
|
|
|
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
|
|
|
fmt.setSamples(4);
|
|
|
|
if (format == QImage::Format_BGR30)
|
|
|
|
fmt.setInternalTextureFormat(ctx.isOpenGLES() ? GL_RGB10_A2 : GL_RGB10);
|
2012-10-29 09:34:20 +00:00
|
|
|
QOpenGLFramebufferObject fbo(800, 800, fmt);
|
|
|
|
fbo.bind();
|
|
|
|
QOpenGLPaintDevice pdv(800, 800);
|
2017-05-23 11:57:20 +00:00
|
|
|
paint(&pdv, engine, format, script, QFileInfo(filePath).absoluteFilePath());
|
2012-10-29 09:34:20 +00:00
|
|
|
rendered = fbo.toImage().convertToFormat(format);
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
2021-09-23 08:00:22 +00:00
|
|
|
} else if (engine == Pdf) {
|
2021-10-01 08:02:36 +00:00
|
|
|
#if QT_CONFIG(process)
|
2021-09-23 08:00:22 +00:00
|
|
|
QString tempStem(QDir::tempPath() + QLatin1String("/lancelot_XXXXXX_") + qpsFile.chopped(4));
|
|
|
|
|
|
|
|
QTemporaryFile pdfFile(tempStem + QLatin1String(".pdf"));
|
|
|
|
pdfFile.open();
|
|
|
|
QPdfWriter writer(&pdfFile);
|
|
|
|
writer.setPdfVersion(QPdfWriter::PdfVersion_1_6);
|
|
|
|
writer.setResolution(150);
|
|
|
|
paint(&writer, engine, format, script, QFileInfo(filePath).absoluteFilePath());
|
|
|
|
pdfFile.close();
|
|
|
|
|
|
|
|
// Convert pdf to something we can read into a QImage, using macOS' sips utility
|
|
|
|
QTemporaryFile pngFile(tempStem + QLatin1String(".png"));
|
|
|
|
pngFile.open(); // Just create the file name
|
|
|
|
pngFile.close();
|
|
|
|
QProcess proc;
|
|
|
|
const char *rawArgs = "-s format png --cropOffset 20 20 -c 800 800 -o";
|
|
|
|
QStringList argList = QString::fromLatin1(rawArgs).split(QLatin1Char(' '));
|
|
|
|
proc.start(QLatin1String("sips"), argList << pngFile.fileName() << pdfFile.fileName());
|
|
|
|
proc.waitForFinished(2 * 60 * 1000); // May need some time
|
|
|
|
|
|
|
|
rendered = QImage(pngFile.fileName());
|
2021-10-01 08:02:36 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
QBASELINE_TEST(rendered);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2017-05-23 11:57:20 +00:00
|
|
|
void tst_Lancelot::paint(QPaintDevice *device, GraphicsEngine engine, QImage::Format format, const QStringList &script, const QString &filePath)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QPainter p(device);
|
2017-05-23 11:57:20 +00:00
|
|
|
PaintCommands pcmd(script, 800, 800, format);
|
2011-04-27 10:05:43 +00:00
|
|
|
//pcmd.setShouldDrawText(false);
|
2012-10-29 09:34:20 +00:00
|
|
|
switch (engine) {
|
|
|
|
case OpenGL:
|
2016-07-27 13:45:31 +00:00
|
|
|
pcmd.setType(OpenGLBufferType); // version/profile is communicated through the context's format()
|
2012-10-29 09:34:20 +00:00
|
|
|
break;
|
2021-09-23 08:00:22 +00:00
|
|
|
case Pdf:
|
|
|
|
pcmd.setType(PdfType);
|
|
|
|
break;
|
2012-10-29 09:34:20 +00:00
|
|
|
case Raster: // fallthrough
|
|
|
|
default:
|
|
|
|
pcmd.setType(ImageType);
|
|
|
|
break;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
pcmd.setPainter(&p);
|
|
|
|
pcmd.setFilePath(filePath);
|
|
|
|
pcmd.runCommands();
|
|
|
|
p.end();
|
|
|
|
}
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
#define main _realmain
|
2011-04-27 10:05:43 +00:00
|
|
|
QTEST_MAIN(tst_Lancelot)
|
|
|
|
#undef main
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2022-08-19 09:57:32 +00:00
|
|
|
// Avoid rendering variations caused by QHash randomization
|
|
|
|
QHashSeed::setDeterministicGlobalSeed();
|
2012-10-29 09:34:20 +00:00
|
|
|
|
|
|
|
QBaselineTest::handleCmdLineArgs(&argc, &argv);
|
|
|
|
return _realmain(argc, argv);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 12:36:48 +00:00
|
|
|
#include "tst_baseline_painting.moc"
|