OpenCoverage

qsgengine.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/util/qsgengine.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 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 "qsgengine_p.h"-
41-
42#include <QtQuick/qsgtexture.h>-
43#include <private/qsgcontext_p.h>-
44#include <private/qsgrenderer_p.h>-
45#include <private/qsgtexture_p.h>-
46-
47#if QT_CONFIG(opengl)-
48# include <QtGui/QOpenGLContext>-
49# include <private/qsgdefaultrendercontext_p.h>-
50#endif-
51-
52QT_BEGIN_NAMESPACE-
53-
54-
55/*!-
56 \class QSGEngine-
57 \brief The QSGEngine class allows low level rendering of a scene graph.-
58 \inmodule QtQuick-
59 \since 5.4-
60-
61 A QSGEngine can be used to render a tree of QSGNode directly on a QWindow-
62 or QOpenGLFramebufferObject without any integration with QML, QQuickWindow-
63 or QQuickItem and the convenience that they provide.-
64-
65 This means that you must handle event propagation, animation timing,-
66 and node lifetime yourself.-
67-
68 \note This class is for very low level access to an independent scene graph.-
69 Most of the time you will instead want to subclass QQuickItem and insert-
70 your QSGNode in a normal QtQuick scene by overriding QQuickItem::updatePaintNode().-
71-
72 \sa QSGAbstractRenderer-
73 */-
74-
75/*!-
76 \enum QSGEngine::CreateTextureOption-
77-
78 The CreateTextureOption enums are used to customize how a texture is wrapped.-
79-
80 \value TextureHasAlphaChannel The texture has an alpha channel and should-
81 be drawn using blending.-
82-
83 \value TextureOwnsGLTexture The texture object owns the texture id and-
84 will delete the GL texture when the texture object is deleted.-
85-
86 \value TextureCanUseAtlas The image can be uploaded into a texture atlas.-
87-
88 \value TextureIsOpaque The texture object is opaque.-
89 */-
90-
91QSGEnginePrivate::QSGEnginePrivate()-
92 : sgContext(QSGContext::createDefaultContext())-
93 , sgRenderContext(sgContext.data()->createRenderContext())-
94{-
95}
never executed: end of block
0
96-
97/*!-
98 Constructs a new QSGEngine with its \a parent-
99 */-
100QSGEngine::QSGEngine(QObject *parent)-
101 : QObject(*(new QSGEnginePrivate), parent)-
102{-
103}
never executed: end of block
0
104-
105/*!-
106 Destroys the engine-
107 */-
108QSGEngine::~QSGEngine()-
109{-
110}-
111-
112/*!-
113 Initialize the engine with \a context.-
114-
115 \warning You have to make sure that you call-
116 QOpenGLContext::makeCurrent() on \a context before calling this.-
117 */-
118void QSGEngine::initialize(QOpenGLContext *context)-
119{-
120 Q_D(QSGEngine);-
121#if QT_CONFIG(opengl)-
122 if (context && QOpenGLContext::currentContext() != context) {
contextDescription
TRUEnever evaluated
FALSEnever evaluated
QOpenGLContext...t() != contextDescription
TRUEnever evaluated
FALSEnever evaluated
0
123 qWarning("WARNING: The context must be current before calling QSGEngine::initialize.");-
124 return;
never executed: return;
0
125 }-
126#endif-
127 if (d->sgRenderContext && !d->sgRenderContext->isValid()) {
d->sgRenderContextDescription
TRUEnever evaluated
FALSEnever evaluated
!d->sgRenderContext->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
128 d->sgRenderContext->setAttachToGraphicsContext(false);-
129 d->sgRenderContext->initialize(context);-
130#if QT_CONFIG(opengl)-
131 if (context)
contextDescription
TRUEnever evaluated
FALSEnever evaluated
0
132 connect(context, &QOpenGLContext::aboutToBeDestroyed, this, &QSGEngine::invalidate);
never executed: connect(context, &QOpenGLContext::aboutToBeDestroyed, this, &QSGEngine::invalidate);
0
133#endif-
134 }
never executed: end of block
0
135}
never executed: end of block
0
136-
137/*!-
138 Invalidate the engine releasing its resources-
139-
140 You will have to call initialize() and createRenderer() if you-
141 want to use it again.-
142 */-
143void QSGEngine::invalidate()-
144{-
145 Q_D(QSGEngine);-
146 d->sgRenderContext->invalidate();-
147}
never executed: end of block
0
148-
149/*!-
150 Returns a renderer that can be used to render a QSGNode tree-
151-
152 You call initialize() first with the QOpenGLContext that you-
153 want to use with this renderer. This will return a null-
154 renderer otherwise.-
155 */-
156QSGAbstractRenderer *QSGEngine::createRenderer() const-
157{-
158 Q_D(const QSGEngine);-
159 if (!d->sgRenderContext->isValid())
!d->sgRenderContext->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
160 return nullptr;
never executed: return nullptr;
0
161-
162 QSGRenderer *renderer = d->sgRenderContext->createRenderer();-
163 renderer->setCustomRenderMode(qgetenv("QSG_VISUALIZE"));-
164 return renderer;
never executed: return renderer;
0
165}-
166-
167/*!-
168 Creates a texture using the data of \a image-
169-
170 Valid \a options are TextureCanUseAtlas and TextureIsOpaque.-
171-
172 The caller takes ownership of the texture and the-
173 texture should only be used with this engine.-
174-
175 \sa createTextureFromId(), QSGSimpleTextureNode::setOwnsTexture(), QQuickWindow::createTextureFromImage()-
176 */-
177QSGTexture *QSGEngine::createTextureFromImage(const QImage &image, CreateTextureOptions options) const-
178{-
179 Q_D(const QSGEngine);-
180 if (!d->sgRenderContext->isValid())
!d->sgRenderContext->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
181 return nullptr;
never executed: return nullptr;
0
182 uint flags = 0;-
183 if (options & TextureCanUseAtlas) flags |= QSGRenderContext::CreateTexture_Atlas;
never executed: flags |= QSGRenderContext::CreateTexture_Atlas;
options & TextureCanUseAtlasDescription
TRUEnever evaluated
FALSEnever evaluated
0
184 if (!(options & TextureIsOpaque)) flags |= QSGRenderContext::CreateTexture_Alpha;
never executed: flags |= QSGRenderContext::CreateTexture_Alpha;
!(options & TextureIsOpaque)Description
TRUEnever evaluated
FALSEnever evaluated
0
185 return d->sgRenderContext->createTexture(image, flags);
never executed: return d->sgRenderContext->createTexture(image, flags);
0
186}-
187-
188/*!-
189 Creates a texture object that wraps the GL texture \a id uploaded with \a size-
190-
191 Valid \a options are TextureHasAlphaChannel and TextureOwnsGLTexture-
192-
193 The caller takes ownership of the texture object and the-
194 texture should only be used with this engine.-
195-
196 \sa createTextureFromImage(), QSGSimpleTextureNode::setOwnsTexture(), QQuickWindow::createTextureFromId()-
197 */-
198QSGTexture *QSGEngine::createTextureFromId(uint id, const QSize &size, CreateTextureOptions options) const-
199{-
200 Q_D(const QSGEngine);-
201 if (d->sgRenderContext->isValid()) {
d->sgRenderContext->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
202 QSGPlainTexture *texture = new QSGPlainTexture();-
203 texture->setTextureId(id);-
204 texture->setHasAlphaChannel(options & TextureHasAlphaChannel);-
205 texture->setOwnsTexture(options & TextureOwnsGLTexture);-
206 texture->setTextureSize(size);-
207 return texture;
never executed: return texture;
0
208 }-
209 return nullptr;
never executed: return nullptr;
0
210}-
211-
212/*!-
213 Returns the current renderer interface if there is one. Otherwise null is returned.-
214-
215 \sa QSGRenderNode, QSGRendererInterface-
216 \since 5.8-
217 */-
218QSGRendererInterface *QSGEngine::rendererInterface() const-
219{-
220 Q_D(const QSGEngine);-
221 return d->sgRenderContext->isValid()
never executed: return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->rendererInterface(d->sgRenderContext.data()) : nullptr;
0
222 ? d->sgRenderContext->sceneGraphContext()->rendererInterface(d->sgRenderContext.data())
never executed: return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->rendererInterface(d->sgRenderContext.data()) : nullptr;
0
223 : nullptr;
never executed: return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->rendererInterface(d->sgRenderContext.data()) : nullptr;
0
224}-
225-
226/*!-
227 Creates a simple rectangle node. When the scenegraph is not initialized, the return value is null.-
228-
229 This is cross-backend alternative to constructing a QSGSimpleRectNode directly.-
230-
231 \since 5.8-
232 \sa QSGRectangleNode-
233 */-
234QSGRectangleNode *QSGEngine::createRectangleNode() const-
235{-
236 Q_D(const QSGEngine);-
237 return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createRectangleNode() : nullptr;
never executed: return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createRectangleNode() : nullptr;
0
238}-
239-
240/*!-
241 Creates a simple image node. When the scenegraph is not initialized, the return value is null.-
242-
243 This is cross-backend alternative to constructing a QSGSimpleTextureNode directly.-
244-
245 \since 5.8-
246 \sa QSGImageNode-
247 */-
248-
249QSGImageNode *QSGEngine::createImageNode() const-
250{-
251 Q_D(const QSGEngine);-
252 return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createImageNode() : nullptr;
never executed: return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createImageNode() : nullptr;
0
253}-
254-
255/*!-
256 Creates a nine patch node. When the scenegraph is not initialized, the return value is null.-
257-
258 \since 5.8-
259 */-
260-
261QSGNinePatchNode *QSGEngine::createNinePatchNode() const-
262{-
263 Q_D(const QSGEngine);-
264 return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createNinePatchNode() : nullptr;
never executed: return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createNinePatchNode() : nullptr;
0
265}-
266-
267QT_END_NAMESPACE-
268-
269#include "moc_qsgengine.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0