OpenCoverage

qsgcompressedatlastexture.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2018 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#include "qsgcompressedatlastexture_p.h"-
41-
42#include <QtCore/QVarLengthArray>-
43#include <QtCore/QElapsedTimer>-
44#include <QtCore/QtMath>-
45-
46#include <QtGui/QOpenGLContext>-
47#include <QtGui/QGuiApplication>-
48#include <QtGui/QScreen>-
49#include <QtGui/QSurface>-
50#include <QtGui/QWindow>-
51#include <QtGui/QOpenGLFunctions>-
52#include <QtGui/QOpenGLTexture>-
53#include <QDebug>-
54-
55#include <private/qqmlglobal_p.h>-
56#include <private/qquickprofiler_p.h>-
57#include <private/qsgtexture_p.h>-
58#include <private/qsgcompressedtexture_p.h>-
59#include <private/qsgpkmhandler_p.h>-
60-
61QT_BEGIN_NAMESPACE-
62-
63static QElapsedTimer qsg_renderer_timer;-
64-
65namespace QSGCompressedAtlasTexture-
66{-
67-
68Atlas::Atlas(const QSize &size, uint format)-
69 : QSGAtlasTexture::AtlasBase(size)-
70 , m_format(format)-
71{-
72}
never executed: end of block
0
73-
74Atlas::~Atlas()-
75{-
76}-
77-
78Texture *Atlas::create(const QByteArray &data, int dataLength, int dataOffset, const QSize &size, const QSize &paddedSize)-
79{-
80 // No need to lock, as manager already locked it.-
81 QRect rect = m_allocator.allocate(paddedSize);-
82 if (rect.width() > 0 && rect.height() > 0) {
rect.width() > 0Description
TRUEnever evaluated
FALSEnever evaluated
rect.height() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
83 Texture *t = new Texture(this, rect, data, dataLength, dataOffset, size);-
84 m_pending_uploads << t;-
85 return t;
never executed: return t;
0
86 }-
87 return nullptr;
never executed: return nullptr;
0
88}-
89-
90void Atlas::generateTexture()-
91{-
92 QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();-
93 funcs->glCompressedTexImage2D(GL_TEXTURE_2D, 0, m_format,-
94 m_size.width(), m_size.height(), 0,-
95 (m_size.width() * m_size.height()) / 2,-
96 nullptr);-
97}
never executed: end of block
0
98-
99void Atlas::uploadPendingTexture(int i)-
100{-
101 Texture *texture = static_cast<Texture*>(m_pending_uploads.at(i));-
102-
103 const QRect &r = texture->atlasSubRect();-
104-
105 QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();-
106 funcs->glCompressedTexSubImage2D(GL_TEXTURE_2D, 0,-
107 r.x(), r.y(), r.width(), r.height(), m_format,-
108 texture->sizeInBytes(),-
109 texture->data().constData() + texture->dataOffset());-
110-
111 qCDebug(QSG_LOG_TIME_TEXTURE).nospace() << "compressed atlastexture uploaded in: " << qsg_renderer_timer.elapsed()
never executed: QMessageLogger(__FILE__, 111, __PRETTY_FUNCTION__, QSG_LOG_TIME_TEXTURE().categoryName()).debug().nospace() << "compressed atlastexture uploaded in: " << qsg_renderer_timer.elapsed() << "ms (" << texture->textureSize().width() << "x" << texture->textureSize().height() << ")";
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
112 << "ms (" << texture->textureSize().width() << "x"
never executed: QMessageLogger(__FILE__, 111, __PRETTY_FUNCTION__, QSG_LOG_TIME_TEXTURE().categoryName()).debug().nospace() << "compressed atlastexture uploaded in: " << qsg_renderer_timer.elapsed() << "ms (" << texture->textureSize().width() << "x" << texture->textureSize().height() << ")";
0
113 << texture->textureSize().height() << ")";
never executed: QMessageLogger(__FILE__, 111, __PRETTY_FUNCTION__, QSG_LOG_TIME_TEXTURE().categoryName()).debug().nospace() << "compressed atlastexture uploaded in: " << qsg_renderer_timer.elapsed() << "ms (" << texture->textureSize().width() << "x" << texture->textureSize().height() << ")";
0
114-
115 // TODO: consider releasing the data (as is done in the regular atlas)?-
116 // The advantage of keeping this data around is that it makes it much easier-
117 // to remove the texture from the atlas-
118}
never executed: end of block
0
119-
120Texture::Texture(Atlas *atlas, const QRect &textureRect, const QByteArray &data, int dataLength, int dataOffset, const QSize &size)-
121 : QSGAtlasTexture::TextureBase(atlas, textureRect)-
122 , m_nonatlas_texture(nullptr)-
123 , m_data(data)-
124 , m_size(size)-
125 , m_dataLength(dataLength)-
126 , m_dataOffset(dataOffset)-
127{-
128 float w = atlas->size().width();-
129 float h = atlas->size().height();-
130 QRect nopad = atlasSubRect();-
131 // offset by half-pixel to prevent bleeding when scaling-
132 m_texture_coords_rect = QRectF((nopad.x() + .5) / w,-
133 (nopad.y() + .5) / h,-
134 (nopad.width() - 1.) / w,-
135 (nopad.height() - 1.) / h);-
136}
never executed: end of block
0
137-
138Texture::~Texture()-
139{-
140 delete m_nonatlas_texture;-
141}
never executed: end of block
0
142-
143bool Texture::hasAlphaChannel() const-
144{-
145 return QSGCompressedTexture::formatIsOpaque(static_cast<Atlas*>(m_atlas)->format());
never executed: return QSGCompressedTexture::formatIsOpaque(static_cast<Atlas*>(m_atlas)->format());
0
146}-
147-
148QSGTexture *Texture::removedFromAtlas() const-
149{-
150 if (m_nonatlas_texture) {
m_nonatlas_textureDescription
TRUEnever evaluated
FALSEnever evaluated
0
151 m_nonatlas_texture->setMipmapFiltering(mipmapFiltering());-
152 m_nonatlas_texture->setFiltering(filtering());-
153 return m_nonatlas_texture;
never executed: return m_nonatlas_texture;
0
154 }-
155-
156 if (!m_data.isEmpty()) {
!m_data.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
157 QSGCompressedTexture::DataPtr texData(QSGCompressedTexture::DataPtr::create());-
158 texData->data = m_data;-
159 texData->size = m_size;-
160 texData->format = static_cast<Atlas*>(m_atlas)->format();-
161 texData->hasAlpha = hasAlphaChannel();-
162 texData->dataLength = m_dataLength;-
163 texData->dataOffset = m_dataOffset;-
164 m_nonatlas_texture = new QSGCompressedTexture(texData);-
165 m_nonatlas_texture->setMipmapFiltering(mipmapFiltering());-
166 m_nonatlas_texture->setFiltering(filtering());-
167 }
never executed: end of block
0
168-
169 return m_nonatlas_texture;
never executed: return m_nonatlas_texture;
0
170}-
171-
172}-
173-
174QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0