summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorJonas Karlsson <jonas.karlsson@qt.io>2020-12-22 13:52:29 +0100
committerJonas Karlsson <jonas.karlsson@qt.io>2020-12-29 09:59:06 +0100
commit162a859045ec455321909af6aa03b99d9cbbda6e (patch)
tree6b691d1964590317e3979674094594f952a0b644 /src/gui
parent89b2b60e6374c62d97b739b3351753e552cd16bb (diff)
Add getDataView() method to QTextureFileData
This method will return a QByteArrayView of the data range corresponding to the level. This avoids a leaky abstraction by moving the needed data pointer arithmetic from the caller to the method. It will also make it easier adding cubemap support in the future. Change-Id: I2415bd88365d8d69ba14aefc77f5f1117f9e0033 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/util/qtexturefiledata.cpp11
-rw-r--r--src/gui/util/qtexturefiledata_p.h2
2 files changed, 13 insertions, 0 deletions
diff --git a/src/gui/util/qtexturefiledata.cpp b/src/gui/util/qtexturefiledata.cpp
index d271541e51..29c6acaeca 100644
--- a/src/gui/util/qtexturefiledata.cpp
+++ b/src/gui/util/qtexturefiledata.cpp
@@ -167,6 +167,17 @@ int QTextureFileData::dataLength(int level) const
return (d && d->lengths.size() > level) ? d->lengths.at(level) : 0;
}
+QByteArrayView QTextureFileData::getDataView(int level) const
+{
+ const int dataLength = this->dataLength(level);
+ const int dataOffset = this->dataOffset(level);
+
+ if (d == nullptr || dataLength == 0)
+ return QByteArrayView();
+
+ return QByteArrayView(d->data.constData() + dataOffset, dataLength);
+}
+
void QTextureFileData::setDataLength(int length, int level)
{
if (d.constData() && level >= 0) {
diff --git a/src/gui/util/qtexturefiledata_p.h b/src/gui/util/qtexturefiledata_p.h
index fb732cd84c..3d75d46c94 100644
--- a/src/gui/util/qtexturefiledata_p.h
+++ b/src/gui/util/qtexturefiledata_p.h
@@ -84,6 +84,8 @@ public:
int dataLength(int level = 0) const;
void setDataLength(int length, int level = 0);
+ QByteArrayView getDataView(int level = 0) const;
+
int numLevels() const;
void setNumLevels(int num);