| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/compressedtexture/qsgcompressedtexture.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | #include "qsgcompressedtexture_p.h" | - | ||||||||||||||||||
| 42 | #include <QOpenGLContext> | - | ||||||||||||||||||
| 43 | #include <QOpenGLTexture> | - | ||||||||||||||||||
| 44 | #include <QOpenGLFunctions> | - | ||||||||||||||||||
| 45 | #include <QDebug> | - | ||||||||||||||||||
| 46 | #include <QtQuick/private/qquickwindow_p.h> | - | ||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | Q_LOGGING_CATEGORY(QSG_LOG_TEXTUREIO, "qt.scenegraph.textureio"); never executed: return category; | 0 | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | bool QSGCompressedTextureData::isValid() const | - | ||||||||||||||||||
| 53 | { | - | ||||||||||||||||||
| 54 | if (data.isNull() || size.isEmpty() || !format)
| 0-110 | ||||||||||||||||||
| 55 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 56 | if (dataLength < 0 || dataOffset < 0 || dataOffset >= data.length())
| 0-110 | ||||||||||||||||||
| 57 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 58 | if (dataLength > 0 && qint64(dataOffset) + qint64(dataLength) > qint64(data.length()))
| 0-110 | ||||||||||||||||||
| 59 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | return true; executed 110 times by 1 test: return true;Executed by:
| 110 | ||||||||||||||||||
| 62 | } | - | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | int QSGCompressedTextureData::sizeInBytes() const | - | ||||||||||||||||||
| 65 | { | - | ||||||||||||||||||
| 66 | if (!isValid())
| 0-30 | ||||||||||||||||||
| 67 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 68 | return dataLength > 0 ? dataLength : data.length() - dataOffset; executed 30 times by 1 test: return dataLength > 0 ? dataLength : data.length() - dataOffset;Executed by:
| 30 | ||||||||||||||||||
| 69 | } | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug dbg, const QSGCompressedTextureData *d) | - | ||||||||||||||||||
| 72 | { | - | ||||||||||||||||||
| 73 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||
| 74 | - | |||||||||||||||||||
| 75 | dbg.nospace() << "QSGCompressedTextureData("; | - | ||||||||||||||||||
| 76 | if (d) {
| 0 | ||||||||||||||||||
| 77 | dbg << d->logName << ' '; | - | ||||||||||||||||||
| 78 | dbg << static_cast<QOpenGLTexture::TextureFormat>(d->format) | - | ||||||||||||||||||
| 79 | << "[0x" << hex << d->format << dec << "]"; | - | ||||||||||||||||||
| 80 | dbg.space() << (d->hasAlpha ? "with" : "no") << "alpha" << d->size | - | ||||||||||||||||||
| 81 | << "databuffer" << d->data.size() << "offset" << d->dataOffset << "length"; | - | ||||||||||||||||||
| 82 | dbg.nospace() << d->dataLength << ")"; | - | ||||||||||||||||||
| 83 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 84 | dbg << "null)"; | - | ||||||||||||||||||
| 85 | } never executed: end of block | 0 | ||||||||||||||||||
| 86 | return dbg; never executed: return dbg; | 0 | ||||||||||||||||||
| 87 | } | - | ||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | QSGCompressedTexture::QSGCompressedTexture(const DataPtr& texData) | - | ||||||||||||||||||
| 90 | : m_textureData(texData) | - | ||||||||||||||||||
| 91 | { | - | ||||||||||||||||||
| 92 | if (m_textureData) {
| 0 | ||||||||||||||||||
| 93 | m_size = m_textureData->size; | - | ||||||||||||||||||
| 94 | m_hasAlpha = m_textureData->hasAlpha; | - | ||||||||||||||||||
| 95 | } never executed: end of block | 0 | ||||||||||||||||||
| 96 | } never executed: end of block | 0 | ||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | QSGCompressedTexture::~QSGCompressedTexture() | - | ||||||||||||||||||
| 99 | { | - | ||||||||||||||||||
| 100 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
| 101 | if (m_textureId) {
| 0 | ||||||||||||||||||
| 102 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 103 | QOpenGLFunctions *funcs = ctx ? ctx->functions() : nullptr;
| 0 | ||||||||||||||||||
| 104 | if (!funcs)
| 0 | ||||||||||||||||||
| 105 | return; never executed: return; | 0 | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | funcs->glDeleteTextures(1, &m_textureId); | - | ||||||||||||||||||
| 108 | } never executed: end of block | 0 | ||||||||||||||||||
| 109 | #endif | - | ||||||||||||||||||
| 110 | } never executed: end of block | 0 | ||||||||||||||||||
| 111 | - | |||||||||||||||||||
| 112 | int QSGCompressedTexture::textureId() const | - | ||||||||||||||||||
| 113 | { | - | ||||||||||||||||||
| 114 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
| 115 | if (!m_textureId) {
| 0 | ||||||||||||||||||
| 116 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 117 | QOpenGLFunctions *funcs = ctx ? ctx->functions() : nullptr;
| 0 | ||||||||||||||||||
| 118 | if (!funcs)
| 0 | ||||||||||||||||||
| 119 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 120 | - | |||||||||||||||||||
| 121 | funcs->glGenTextures(1, &m_textureId); | - | ||||||||||||||||||
| 122 | } never executed: end of block | 0 | ||||||||||||||||||
| 123 | #endif | - | ||||||||||||||||||
| 124 | return m_textureId; never executed: return m_textureId; | 0 | ||||||||||||||||||
| 125 | } | - | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | QSize QSGCompressedTexture::textureSize() const | - | ||||||||||||||||||
| 128 | { | - | ||||||||||||||||||
| 129 | return m_size; never executed: return m_size; | 0 | ||||||||||||||||||
| 130 | } | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | bool QSGCompressedTexture::hasAlphaChannel() const | - | ||||||||||||||||||
| 133 | { | - | ||||||||||||||||||
| 134 | return m_hasAlpha; never executed: return m_hasAlpha; | 0 | ||||||||||||||||||
| 135 | } | - | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | bool QSGCompressedTexture::hasMipmaps() const | - | ||||||||||||||||||
| 138 | { | - | ||||||||||||||||||
| 139 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 140 | } | - | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | void QSGCompressedTexture::bind() | - | ||||||||||||||||||
| 143 | { | - | ||||||||||||||||||
| 144 | #if QT_CONFIG(opengl) | - | ||||||||||||||||||
| 145 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||||||||
| 146 | QOpenGLFunctions *funcs = ctx ? ctx->functions() : nullptr;
| 0 | ||||||||||||||||||
| 147 | if (!funcs)
| 0 | ||||||||||||||||||
| 148 | return; never executed: return; | 0 | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | if (!textureId())
| 0 | ||||||||||||||||||
| 151 | return; never executed: return; | 0 | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | funcs->glBindTexture(GL_TEXTURE_2D, m_textureId); | - | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | if (m_uploaded)
| 0 | ||||||||||||||||||
| 156 | return; never executed: return; | 0 | ||||||||||||||||||
| 157 | - | |||||||||||||||||||
| 158 | QByteArray logName(m_textureData ? m_textureData->logName : QByteArrayLiteral("(unset)")); never executed: return ba; | 0 | ||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | if (!m_textureData || !m_textureData->isValid()) {
| 0 | ||||||||||||||||||
| 161 | qCDebug(QSG_LOG_TEXTUREIO, "Invalid texture data for %s", logName.constData()); never executed: QMessageLogger(__FILE__, 161, __PRETTY_FUNCTION__, QSG_LOG_TEXTUREIO().categoryName()).debug("Invalid texture data for %s", logName.constData());
| 0 | ||||||||||||||||||
| 162 | funcs->glBindTexture(GL_TEXTURE_2D, 0); | - | ||||||||||||||||||
| 163 | return; never executed: return; | 0 | ||||||||||||||||||
| 164 | } | - | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | if (Q_UNLIKELY(QSG_LOG_TEXTUREIO().isDebugEnabled())) {
| 0 | ||||||||||||||||||
| 167 | qCDebug(QSG_LOG_TEXTUREIO) << "Uploading texture" << m_textureData.data(); never executed: QMessageLogger(__FILE__, 167, __PRETTY_FUNCTION__, QSG_LOG_TEXTUREIO().categoryName()).debug() << "Uploading texture" << m_textureData.data();
| 0 | ||||||||||||||||||
| 168 | while (funcs->glGetError() != GL_NO_ERROR); never executed: ;
| 0 | ||||||||||||||||||
| 169 | } never executed: end of block | 0 | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | funcs->glCompressedTexImage2D(GL_TEXTURE_2D, 0, m_textureData->format, | - | ||||||||||||||||||
| 172 | m_size.width(), m_size.height(), 0, m_textureData->sizeInBytes(), | - | ||||||||||||||||||
| 173 | m_textureData->data.constData() + m_textureData->dataOffset); | - | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | if (Q_UNLIKELY(QSG_LOG_TEXTUREIO().isDebugEnabled())) {
| 0 | ||||||||||||||||||
| 176 | GLuint error = funcs->glGetError(); | - | ||||||||||||||||||
| 177 | if (error != GL_NO_ERROR) {
| 0 | ||||||||||||||||||
| 178 | qCDebug(QSG_LOG_TEXTUREIO, "glCompressedTexImage2D failed for %s, error 0x%x", logName.constData(), error); never executed: QMessageLogger(__FILE__, 178, __PRETTY_FUNCTION__, QSG_LOG_TEXTUREIO().categoryName()).debug("glCompressedTexImage2D failed for %s, error 0x%x", logName.constData(), error);
| 0 | ||||||||||||||||||
| 179 | } never executed: end of block | 0 | ||||||||||||||||||
| 180 | } never executed: end of block | 0 | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | m_textureData.clear(); // Release this memory, not needed anymore | - | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | updateBindOptions(true); | - | ||||||||||||||||||
| 185 | m_uploaded = true; | - | ||||||||||||||||||
| 186 | #endif // QT_CONFIG(opengl) | - | ||||||||||||||||||
| 187 | } never executed: end of block | 0 | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | bool QSGCompressedTexture::formatIsOpaque(quint32 glTextureFormat) | - | ||||||||||||||||||
| 190 | { | - | ||||||||||||||||||
| 191 | switch (glTextureFormat) { | - | ||||||||||||||||||
| 192 | case QOpenGLTexture::RGB_DXT1: never executed: case QOpenGLTexture::RGB_DXT1: | 0 | ||||||||||||||||||
| 193 | case QOpenGLTexture::R_ATI1N_UNorm: never executed: case QOpenGLTexture::R_ATI1N_UNorm: | 0 | ||||||||||||||||||
| 194 | case QOpenGLTexture::R_ATI1N_SNorm: never executed: case QOpenGLTexture::R_ATI1N_SNorm: | 0 | ||||||||||||||||||
| 195 | case QOpenGLTexture::RG_ATI2N_UNorm: never executed: case QOpenGLTexture::RG_ATI2N_UNorm: | 0 | ||||||||||||||||||
| 196 | case QOpenGLTexture::RG_ATI2N_SNorm: never executed: case QOpenGLTexture::RG_ATI2N_SNorm: | 0 | ||||||||||||||||||
| 197 | case QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT: never executed: case QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT: | 0 | ||||||||||||||||||
| 198 | case QOpenGLTexture::RGB_BP_SIGNED_FLOAT: never executed: case QOpenGLTexture::RGB_BP_SIGNED_FLOAT: | 0 | ||||||||||||||||||
| 199 | case QOpenGLTexture::R11_EAC_UNorm: never executed: case QOpenGLTexture::R11_EAC_UNorm: | 0 | ||||||||||||||||||
| 200 | case QOpenGLTexture::R11_EAC_SNorm: never executed: case QOpenGLTexture::R11_EAC_SNorm: | 0 | ||||||||||||||||||
| 201 | case QOpenGLTexture::RG11_EAC_UNorm: never executed: case QOpenGLTexture::RG11_EAC_UNorm: | 0 | ||||||||||||||||||
| 202 | case QOpenGLTexture::RG11_EAC_SNorm: never executed: case QOpenGLTexture::RG11_EAC_SNorm: | 0 | ||||||||||||||||||
| 203 | case QOpenGLTexture::RGB8_ETC2: executed 4 times by 1 test: case QOpenGLTexture::RGB8_ETC2:Executed by:
| 4 | ||||||||||||||||||
| 204 | case QOpenGLTexture::SRGB8_ETC2: never executed: case QOpenGLTexture::SRGB8_ETC2: | 0 | ||||||||||||||||||
| 205 | case QOpenGLTexture::RGB8_ETC1: executed 4 times by 1 test: case QOpenGLTexture::RGB8_ETC1:Executed by:
| 4 | ||||||||||||||||||
| 206 | case QOpenGLTexture::SRGB_DXT1: never executed: case QOpenGLTexture::SRGB_DXT1: | 0 | ||||||||||||||||||
| 207 | return true; executed 8 times by 1 test: return true;Executed by:
| 8 | ||||||||||||||||||
| 208 | break; dead code: break; | - | ||||||||||||||||||
| 209 | default: executed 2 times by 1 test: default:Executed by:
| 2 | ||||||||||||||||||
| 210 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||
| 211 | } | - | ||||||||||||||||||
| 212 | } | - | ||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | QSGCompressedTextureFactory::QSGCompressedTextureFactory(const QSGCompressedTexture::DataPtr &texData) | - | ||||||||||||||||||
| 215 | : m_textureData(texData) | - | ||||||||||||||||||
| 216 | { | - | ||||||||||||||||||
| 217 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 218 | - | |||||||||||||||||||
| 219 | QSGTexture *QSGCompressedTextureFactory::createTexture(QQuickWindow *window) const | - | ||||||||||||||||||
| 220 | { | - | ||||||||||||||||||
| 221 | if (!m_textureData || !m_textureData->isValid())
| 0 | ||||||||||||||||||
| 222 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | // attempt to atlas the texture | - | ||||||||||||||||||
| 225 | QSGRenderContext *context = QQuickWindowPrivate::get(window)->context; | - | ||||||||||||||||||
| 226 | QSGTexture *t = context->compressedTextureForFactory(this); | - | ||||||||||||||||||
| 227 | if (t)
| 0 | ||||||||||||||||||
| 228 | return t; never executed: return t; | 0 | ||||||||||||||||||
| 229 | - | |||||||||||||||||||
| 230 | return new QSGCompressedTexture(m_textureData); never executed: return new QSGCompressedTexture(m_textureData); | 0 | ||||||||||||||||||
| 231 | } | - | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | int QSGCompressedTextureFactory::textureByteCount() const | - | ||||||||||||||||||
| 234 | { | - | ||||||||||||||||||
| 235 | return m_textureData ? m_textureData->sizeInBytes() : 0; executed 30 times by 1 test: return m_textureData ? m_textureData->sizeInBytes() : 0;Executed by:
| 30 | ||||||||||||||||||
| 236 | } | - | ||||||||||||||||||
| 237 | - | |||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | QSize QSGCompressedTextureFactory::textureSize() const | - | ||||||||||||||||||
| 240 | { | - | ||||||||||||||||||
| 241 | if (m_textureData && m_textureData->isValid())
| 0-70 | ||||||||||||||||||
| 242 | return m_textureData->size; executed 70 times by 1 test: return m_textureData->size;Executed by:
| 70 | ||||||||||||||||||
| 243 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||
| 244 | } | - | ||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |