diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2018-07-03 12:41:34 +0200 |
---|---|---|
committer | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2018-08-09 07:44:38 +0000 |
commit | abba0b6e2c00df2df39ad16a20eba3870e68f252 (patch) | |
tree | 1bac2923c62b4975bb9a9224caf90a39f09e4456 /src/quick/scenegraph/util | |
parent | 1c731335dcd90fd817180a623e489edcc31f5151 (diff) |
Compressed textures: Replace file decoding code with QtGui functionality
The functionality for reading and decoding texture files (currently
pkm and ktx formats) is now available in QtGui util API. Utilize that
instead of keeping equivalent code here.
Task-number: QTBUG-67026
Change-Id: Icb7c348eaa51cd15e41031508ef54164fc876c9e
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/quick/scenegraph/util')
-rw-r--r-- | src/quick/scenegraph/util/qsgatlastexture.cpp | 10 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgtexturereader.cpp | 64 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgtexturereader_p.h | 8 |
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 |