aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/scenegraph/util')
-rw-r--r--src/quick/scenegraph/util/qsgatlastexture.cpp10
-rw-r--r--src/quick/scenegraph/util/qsgtexturereader.cpp64
-rw-r--r--src/quick/scenegraph/util/qsgtexturereader_p.h8
3 files changed, 25 insertions, 57 deletions
diff --git a/src/quick/scenegraph/util/qsgatlastexture.cpp b/src/quick/scenegraph/util/qsgatlastexture.cpp
index 97203db867..66c6d3a882 100644
--- a/src/quick/scenegraph/util/qsgatlastexture.cpp
+++ b/src/quick/scenegraph/util/qsgatlastexture.cpp
@@ -143,11 +143,11 @@ QSGTexture *Manager::create(const QImage &image, bool hasAlphaChannel)
QSGTexture *Manager::create(const QSGCompressedTextureFactory *factory)
{
QSGTexture *t = nullptr;
- if (!qsgEnableCompressedAtlas() || !factory->m_textureData || !factory->m_textureData->isValid())
+ if (!qsgEnableCompressedAtlas() || !factory->m_textureData.isValid())
return t;
// TODO: further abstract the atlas and remove this restriction
- unsigned int format = factory->m_textureData->format;
+ unsigned int format = factory->m_textureData.glInternalFormat();
switch (format) {
case QOpenGLTexture::RGB8_ETC1:
case QOpenGLTexture::RGB8_ETC2:
@@ -158,15 +158,15 @@ QSGTexture *Manager::create(const QSGCompressedTextureFactory *factory)
return t;
}
- QSize size = factory->m_textureData->size;
+ QSize size = factory->m_textureData.size();
if (size.width() < m_atlas_size_limit && size.height() < m_atlas_size_limit) {
QHash<unsigned int, QSGCompressedAtlasTexture::Atlas*>::iterator i = m_atlases.find(format);
if (i == m_atlases.end())
i = m_atlases.insert(format, new QSGCompressedAtlasTexture::Atlas(m_atlas_size, format));
// must be multiple of 4
QSize paddedSize(((size.width() + 3) / 4) * 4, ((size.height() + 3) / 4) * 4);
- QByteArray data = factory->m_textureData->data;
- t = i.value()->create(data, factory->m_textureData->sizeInBytes(), factory->m_textureData->dataOffset, size, paddedSize);
+ QByteArray data = factory->m_textureData.data();
+ t = i.value()->create(data, factory->m_textureData.dataLength(), factory->m_textureData.dataOffset(), size, paddedSize);
}
return t;
}
diff --git a/src/quick/scenegraph/util/qsgtexturereader.cpp b/src/quick/scenegraph/util/qsgtexturereader.cpp
index 8e95f27120..27ba119f63 100644
--- a/src/quick/scenegraph/util/qsgtexturereader.cpp
+++ b/src/quick/scenegraph/util/qsgtexturereader.cpp
@@ -38,36 +38,37 @@
****************************************************************************/
#include "qsgtexturereader_p.h"
-
-#include <private/qtquickglobal_p.h>
-
-#include <private/qsgtexturefilehandler_p.h>
-
-#if QT_CONFIG(opengl)
-#include <private/qsgpkmhandler_p.h>
-#include <private/qsgktxhandler_p.h>
-#endif
-
-#include <QFileInfo>
+#include <private/qsgcompressedtexture_p.h>
+#include <private/qtexturefilereader_p.h>
QT_BEGIN_NAMESPACE
QSGTextureReader::QSGTextureReader(QIODevice *device, const QString &fileName)
- : m_device(device), m_fileInfo(fileName)
{
+#if QT_CONFIG(opengl)
+ m_reader = new QTextureFileReader(device, fileName);
+#else
+ Q_UNUSED(device);
+ Q_UNUSED(fileName);
+#endif
}
QSGTextureReader::~QSGTextureReader()
{
- delete m_handler;
+ delete m_reader;
}
QQuickTextureFactory *QSGTextureReader::read()
{
#if QT_CONFIG(opengl)
- if (!isTexture())
+ if (!m_reader)
+ return nullptr;
+
+ QTextureFileData texData = m_reader->read();
+ if (!texData.isValid())
return nullptr;
- return m_handler->read();
+
+ return new QSGCompressedTextureFactory(texData);
#else
return nullptr;
#endif
@@ -75,41 +76,12 @@ QQuickTextureFactory *QSGTextureReader::read()
bool QSGTextureReader::isTexture()
{
-#if QT_CONFIG(opengl)
- if (!checked) {
- checked = true;
- if (!init())
- return false;
-
- QByteArray headerBlock = m_device->peek(64);
- QByteArray suffix = m_fileInfo.suffix().toLower().toLatin1();
- QByteArray logName = m_fileInfo.fileName().toUtf8();
-
- // Currently the handlers are hardcoded; later maybe a list of plugins
- if (QSGPkmHandler::canRead(suffix, headerBlock)) {
- m_handler = new QSGPkmHandler(m_device, logName);
- } else if (QSGKtxHandler::canRead(suffix, headerBlock)) {
- m_handler = new QSGKtxHandler(m_device, logName);
- }
- // else if OtherHandler::canRead() ...etc.
- }
- return (m_handler != nullptr);
-#else
- return false;
-#endif
+ return m_reader ? m_reader->canRead() : false;
}
QList<QByteArray> QSGTextureReader::supportedFileFormats()
{
- // Hardcoded for now
- return {QByteArrayLiteral("pkm"), QByteArrayLiteral("ktx")};
-}
-
-bool QSGTextureReader::init()
-{
- if (!m_device)
- return false;
- return m_device->isReadable();
+ return QTextureFileReader::supportedFileFormats();
}
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgtexturereader_p.h b/src/quick/scenegraph/util/qsgtexturereader_p.h
index 19e33bf5c3..20c17fce50 100644
--- a/src/quick/scenegraph/util/qsgtexturereader_p.h
+++ b/src/quick/scenegraph/util/qsgtexturereader_p.h
@@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE
class QIODevice;
class QQuickTextureFactory;
-class QSGTextureFileHandler;
+class QTextureFileReader;
class QSGTextureReader
{
@@ -75,11 +75,7 @@ public:
static QList<QByteArray> supportedFileFormats();
private:
- bool init();
- QIODevice *m_device = nullptr;
- QFileInfo m_fileInfo;
- QSGTextureFileHandler *m_handler = nullptr;
- bool checked = false;
+ QTextureFileReader *m_reader = nullptr;
};
QT_END_NAMESPACE