Skip to content

Commit ed69a9d

Browse files
Jaehak Leeseokhako
authored andcommitted
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 <[email protected]>
1 parent e6dd62f commit ed69a9d

File tree

6 files changed

+63
-8
lines changed

6 files changed

+63
-8
lines changed

src/quickcontrolsimpl/qquickninepatchimage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,9 @@ QSGNode *QQuickNinePatchImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNode
443443
d->resetNode = false;
444444
}
445445

446+
if (d->ninePatch.isNull())
447+
return QQuickImage::updatePaintNode(oldNode, data);
448+
446449
QSizeF sz = size();
447450
QImage image = d->pix.image();
448451
if (!sz.isValid() || image.isNull()) {
@@ -452,9 +455,6 @@ QSGNode *QQuickNinePatchImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNode
452455
return nullptr;
453456
}
454457

455-
if (d->ninePatch.isNull())
456-
return QQuickImage::updatePaintNode(oldNode, data);
457-
458458
QQuickNinePatchNode *patchNode = static_cast<QQuickNinePatchNode *>(oldNode);
459459
if (!patchNode)
460460
patchNode = new QQuickNinePatchNode;

tests/auto/quickcontrols/qquickninepatchimage/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ endif()
1616
# Collect test data
1717
file(GLOB_RECURSE test_data_glob
1818
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
19-
${CMAKE_CURRENT_SOURCE_DIR}/data/*.qml)
20-
list(APPEND test_data ${test_data_glob})
21-
file(GLOB_RECURSE test_data_glob
22-
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
23-
${CMAKE_CURRENT_SOURCE_DIR}/data/*.png)
19+
${CMAKE_CURRENT_SOURCE_DIR}/data/*)
2420
list(APPEND test_data ${test_data_glob})
2521

2622
qt_internal_add_test(tst_qquickninepatchimage
32 KB
Binary file not shown.
2.07 KB
Binary file not shown.
12.5 KB
Binary file not shown.

tests/auto/quickcontrols/qquickninepatchimage/tst_qquickninepatchimage.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
#include <QtQuick/qquickview.h>
1212
#include <QtQuick/qquickitemgrabresult.h>
1313
#include <QtQuick/private/qquickimage_p.h>
14+
#include <QtQuick/private/qquickimage_p_p.h>
1415
#include <QtQuickTestUtils/private/qmlutils_p.h>
1516
#include <QtQuickTestUtils/private/visualtestutils_p.h>
17+
#include <QtGui/private/qrhi_p.h>
1618

1719
using namespace QQuickVisualTestUtils;
1820

@@ -32,6 +34,8 @@ private slots:
3234
void inset();
3335
void implicitSize_data();
3436
void implicitSize();
37+
void hwCompressedImages_data();
38+
void hwCompressedImages();
3539
};
3640

3741
static QImage grabItemToImage(QQuickItem *item)
@@ -230,6 +234,61 @@ void tst_qquickninepatchimage::implicitSize()
230234
QCOMPARE(ninePatchImage->implicitHeight(), implicitSize.height());
231235
}
232236

237+
void tst_qquickninepatchimage::hwCompressedImages_data()
238+
{
239+
QTest::addColumn<int>("dpr");
240+
QTest::addColumn<QString>("file");
241+
QTest::addColumn<QSize>("size");
242+
QTest::addColumn<QRhiTexture::Format>("format");
243+
244+
const struct TestFile {
245+
QString name;
246+
QSize size;
247+
QRhiTexture::Format format;
248+
} testFiles [] = {
249+
{ "o1_bc1.ktx", QSize(64, 64), QRhiTexture::BC1 },
250+
{ "logo.pkm", QSize(256, 256), QRhiTexture::ETC2_RGB8 },
251+
{ "qt4.astc", QSize(250, 200), QRhiTexture::ASTC_8x8 }
252+
};
253+
254+
for (const TestFile &file : testFiles) {
255+
for (int dpr = 1; dpr <= 4; ++dpr)
256+
QTest::newRow(qPrintable(QString::fromLatin1("%1 DPR=%2").arg(file.name).arg(dpr))) << dpr << file.name << file.size << file.format;
257+
}
258+
}
259+
260+
void tst_qquickninepatchimage::hwCompressedImages()
261+
{
262+
QFETCH(int, dpr);
263+
QFETCH(QString, file);
264+
QFETCH(QSize, size);
265+
QFETCH(QRhiTexture::Format, format);
266+
267+
QHighDpiScaling::setGlobalFactor(dpr);
268+
269+
QQuickView view(testFileUrl("ninepatchimage.qml"));
270+
QCOMPARE(view.status(), QQuickView::Ready);
271+
view.show();
272+
QVERIFY(QTest::qWaitForWindowExposed(&view));
273+
274+
if (!QSGRendererInterface::isApiRhiBased(view.rendererInterface()->graphicsApi()))
275+
QSKIP("Skipping due to using software backend");
276+
277+
QRhi *rhi = static_cast<QRhi *>(view.rendererInterface()->getResource(&view, QSGRendererInterface::RhiResource));
278+
if (!rhi->isTextureFormatSupported(format))
279+
QSKIP(qPrintable(QString::fromLatin1("%1 not supported, skip").arg(format)));
280+
281+
QQuickImage *ninePatchImage = qobject_cast<QQuickImage *>(view.rootObject());
282+
QVERIFY(ninePatchImage);
283+
ninePatchImage->setSource(testFileUrl(file));
284+
ninePatchImage->setSize(size);
285+
QSignalSpy spy(&view, SIGNAL(afterSynchronizing()));
286+
QTRY_VERIFY(spy.size() >= 1);
287+
288+
QQuickImagePrivate *ninePatchImagePrivate = static_cast<QQuickImagePrivate *>(QQuickItemPrivate::get(ninePatchImage));
289+
QVERIFY(ninePatchImagePrivate->paintNode);
290+
}
291+
233292
QTEST_MAIN(tst_qquickninepatchimage)
234293

235294
#include "tst_qquickninepatchimage.moc"

0 commit comments

Comments
 (0)