diff options
author | Jaehak Lee <jaehak.lee@mobis.co.kr> | 2023-04-25 18:17:58 +0900 |
---|---|---|
committer | Seokha Ko <seokha.ko@qt.io> | 2023-05-15 11:41:05 +0000 |
commit | ed69a9d4f3e889b05548e7cebe957afc3a3e577f (patch) | |
tree | bc1f88838da205f1f500d59704a7b151b2df0246 | |
parent | e6dd62ff191de0276d2dee5d6b1a073b4d63c4cb (diff) | |
download | qtdeclarative-ed69a9d4f3e889b05548e7cebe957afc3a3e577f.tar.gz |
NinePatchImage: support the compressed texture image
The compressed texture image is supported by qquickimage and
the qquickninepatchimage is inherited by qquickimage.
But the compressed texture is not shown when the source of
qquickninepatchimage is set as compressed texture because the
updatePaintNode of qquickninepatchimage only consider non-compressed
texture.
This patch is not intended to use the HW compressed image as an
actual 9-patch image, but to display them using the super class
qquickimage in the case of an HW compressed image other than a normal
pixmap image.
If the source is HW compressed textures such as ASTC, KTX, and PKM,
we have to call updatePaintNode of QQuickImage before checking the
validity of the pixmap image.
(because nullptr is returned if pixmap image is not valid)
The containers themselves (pkm, ktx) are universally supported but
the compressed texture formats is up to the underlying 3D API
implementation and may vary.
So, if the format is not supported by RHI, we skip the test.
Refer to QTBUG-113565 for a detailed discussion on texture formats.
And when using the software backend, we also skip test cases.
Fixes: QTBUG-113446
Pick-to: 6.2 6.4 6.5
Change-Id: I2704f86e94b50b3c187eca359fdc1a69eb217811
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r-- | src/quickcontrolsimpl/qquickninepatchimage.cpp | 6 | ||||
-rw-r--r-- | tests/auto/quickcontrols/qquickninepatchimage/CMakeLists.txt | 6 | ||||
-rw-r--r-- | tests/auto/quickcontrols/qquickninepatchimage/data/logo.pkm | bin | 0 -> 32784 bytes | |||
-rw-r--r-- | tests/auto/quickcontrols/qquickninepatchimage/data/o1_bc1.ktx | bin | 0 -> 2116 bytes | |||
-rw-r--r-- | tests/auto/quickcontrols/qquickninepatchimage/data/qt4.astc | bin | 0 -> 12816 bytes | |||
-rw-r--r-- | tests/auto/quickcontrols/qquickninepatchimage/tst_qquickninepatchimage.cpp | 59 |
6 files changed, 63 insertions, 8 deletions
diff --git a/src/quickcontrolsimpl/qquickninepatchimage.cpp b/src/quickcontrolsimpl/qquickninepatchimage.cpp index 3f8a9e03e9..cc3869ded9 100644 --- a/src/quickcontrolsimpl/qquickninepatchimage.cpp +++ b/src/quickcontrolsimpl/qquickninepatchimage.cpp @@ -443,6 +443,9 @@ QSGNode *QQuickNinePatchImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNode d->resetNode = false; } + if (d->ninePatch.isNull()) + return QQuickImage::updatePaintNode(oldNode, data); + QSizeF sz = size(); QImage image = d->pix.image(); if (!sz.isValid() || image.isNull()) { @@ -452,9 +455,6 @@ QSGNode *QQuickNinePatchImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNode return nullptr; } - if (d->ninePatch.isNull()) - return QQuickImage::updatePaintNode(oldNode, data); - QQuickNinePatchNode *patchNode = static_cast<QQuickNinePatchNode *>(oldNode); if (!patchNode) patchNode = new QQuickNinePatchNode; diff --git a/tests/auto/quickcontrols/qquickninepatchimage/CMakeLists.txt b/tests/auto/quickcontrols/qquickninepatchimage/CMakeLists.txt index 0523912506..e8a4e733b8 100644 --- a/tests/auto/quickcontrols/qquickninepatchimage/CMakeLists.txt +++ b/tests/auto/quickcontrols/qquickninepatchimage/CMakeLists.txt @@ -16,11 +16,7 @@ endif() # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/data/*.qml) -list(APPEND test_data ${test_data_glob}) -file(GLOB_RECURSE test_data_glob - RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/data/*.png) + ${CMAKE_CURRENT_SOURCE_DIR}/data/*) list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qquickninepatchimage diff --git a/tests/auto/quickcontrols/qquickninepatchimage/data/logo.pkm b/tests/auto/quickcontrols/qquickninepatchimage/data/logo.pkm Binary files differnew file mode 100644 index 0000000000..c0987c5c36 --- /dev/null +++ b/tests/auto/quickcontrols/qquickninepatchimage/data/logo.pkm diff --git a/tests/auto/quickcontrols/qquickninepatchimage/data/o1_bc1.ktx b/tests/auto/quickcontrols/qquickninepatchimage/data/o1_bc1.ktx Binary files differnew file mode 100644 index 0000000000..d61194a745 --- /dev/null +++ b/tests/auto/quickcontrols/qquickninepatchimage/data/o1_bc1.ktx diff --git a/tests/auto/quickcontrols/qquickninepatchimage/data/qt4.astc b/tests/auto/quickcontrols/qquickninepatchimage/data/qt4.astc Binary files differnew file mode 100644 index 0000000000..7f7a3f4739 --- /dev/null +++ b/tests/auto/quickcontrols/qquickninepatchimage/data/qt4.astc diff --git a/tests/auto/quickcontrols/qquickninepatchimage/tst_qquickninepatchimage.cpp b/tests/auto/quickcontrols/qquickninepatchimage/tst_qquickninepatchimage.cpp index c1fb1f7264..dc88d0c5ed 100644 --- a/tests/auto/quickcontrols/qquickninepatchimage/tst_qquickninepatchimage.cpp +++ b/tests/auto/quickcontrols/qquickninepatchimage/tst_qquickninepatchimage.cpp @@ -11,8 +11,10 @@ #include <QtQuick/qquickview.h> #include <QtQuick/qquickitemgrabresult.h> #include <QtQuick/private/qquickimage_p.h> +#include <QtQuick/private/qquickimage_p_p.h> #include <QtQuickTestUtils/private/qmlutils_p.h> #include <QtQuickTestUtils/private/visualtestutils_p.h> +#include <QtGui/private/qrhi_p.h> using namespace QQuickVisualTestUtils; @@ -32,6 +34,8 @@ private slots: void inset(); void implicitSize_data(); void implicitSize(); + void hwCompressedImages_data(); + void hwCompressedImages(); }; static QImage grabItemToImage(QQuickItem *item) @@ -230,6 +234,61 @@ void tst_qquickninepatchimage::implicitSize() QCOMPARE(ninePatchImage->implicitHeight(), implicitSize.height()); } +void tst_qquickninepatchimage::hwCompressedImages_data() +{ + QTest::addColumn<int>("dpr"); + QTest::addColumn<QString>("file"); + QTest::addColumn<QSize>("size"); + QTest::addColumn<QRhiTexture::Format>("format"); + + const struct TestFile { + QString name; + QSize size; + QRhiTexture::Format format; + } testFiles [] = { + { "o1_bc1.ktx", QSize(64, 64), QRhiTexture::BC1 }, + { "logo.pkm", QSize(256, 256), QRhiTexture::ETC2_RGB8 }, + { "qt4.astc", QSize(250, 200), QRhiTexture::ASTC_8x8 } + }; + + for (const TestFile &file : testFiles) { + for (int dpr = 1; dpr <= 4; ++dpr) + QTest::newRow(qPrintable(QString::fromLatin1("%1 DPR=%2").arg(file.name).arg(dpr))) << dpr << file.name << file.size << file.format; + } +} + +void tst_qquickninepatchimage::hwCompressedImages() +{ + QFETCH(int, dpr); + QFETCH(QString, file); + QFETCH(QSize, size); + QFETCH(QRhiTexture::Format, format); + + QHighDpiScaling::setGlobalFactor(dpr); + + QQuickView view(testFileUrl("ninepatchimage.qml")); + QCOMPARE(view.status(), QQuickView::Ready); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + if (!QSGRendererInterface::isApiRhiBased(view.rendererInterface()->graphicsApi())) + QSKIP("Skipping due to using software backend"); + + QRhi *rhi = static_cast<QRhi *>(view.rendererInterface()->getResource(&view, QSGRendererInterface::RhiResource)); + if (!rhi->isTextureFormatSupported(format)) + QSKIP(qPrintable(QString::fromLatin1("%1 not supported, skip").arg(format))); + + QQuickImage *ninePatchImage = qobject_cast<QQuickImage *>(view.rootObject()); + QVERIFY(ninePatchImage); + ninePatchImage->setSource(testFileUrl(file)); + ninePatchImage->setSize(size); + QSignalSpy spy(&view, SIGNAL(afterSynchronizing())); + QTRY_VERIFY(spy.size() >= 1); + + QQuickImagePrivate *ninePatchImagePrivate = static_cast<QQuickImagePrivate *>(QQuickItemPrivate::get(ninePatchImage)); + QVERIFY(ninePatchImagePrivate->paintNode); +} + QTEST_MAIN(tst_qquickninepatchimage) #include "tst_qquickninepatchimage.moc" |