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 "qsgsoftwarecontext_p.h"
41
42#include "qsgsoftwareinternalrectanglenode_p.h"
43#include "qsgsoftwareinternalimagenode_p.h"
44#include "qsgsoftwarepainternode_p.h"
45#include "qsgsoftwarepixmaptexture_p.h"
46#include "qsgsoftwareglyphnode_p.h"
47#include "qsgsoftwarepublicnodes_p.h"
48#include "qsgsoftwarelayer_p.h"
49#include "qsgsoftwarerenderer_p.h"
50#if QT_CONFIG(quick_sprite)
51#include "qsgsoftwarespritenode_p.h"
52#endif
53
54#include <QtCore/QCoreApplication>
55#include <QtCore/QElapsedTimer>
56
57#include <QtGui/QWindow>
58#include <QtQuick/private/qquickwindow_p.h>
59
60// Used for very high-level info about the renderering and gl context
61// Includes GL_VERSION, type of render loop, atlas size, etc.
62Q_LOGGING_CATEGORY(QSG_RASTER_LOG_INFO, "qt.scenegraph.info")
63
64// Used to debug the renderloop logic. Primarily useful for platform integrators
65// and when investigating the render loop logic.
66Q_LOGGING_CATEGORY(QSG_RASTER_LOG_RENDERLOOP, "qt.scenegraph.renderloop")
67
68// GLSL shader compilation
69Q_LOGGING_CATEGORY(QSG_RASTER_LOG_TIME_COMPILATION, "qt.scenegraph.time.compilation")
70
71// polish, animations, sync, render and swap in the render loop
72Q_LOGGING_CATEGORY(QSG_RASTER_LOG_TIME_RENDERLOOP, "qt.scenegraph.time.renderloop")
73
74// Texture uploads and swizzling
75Q_LOGGING_CATEGORY(QSG_RASTER_LOG_TIME_TEXTURE, "qt.scenegraph.time.texture")
76
77// Glyph preparation (only for distance fields atm)
78Q_LOGGING_CATEGORY(QSG_RASTER_LOG_TIME_GLYPH, "qt.scenegraph.time.glyph")
79
80// Timing inside the renderer base class
81Q_LOGGING_CATEGORY(QSG_RASTER_LOG_TIME_RENDERER, "qt.scenegraph.time.renderer")
82
83QT_BEGIN_NAMESPACE
84
85QSGSoftwareRenderContext::QSGSoftwareRenderContext(QSGContext *ctx)
86 : QSGRenderContext(ctx)
87 , m_initialized(false)
88 , m_activePainter(nullptr)
89{
90}
91
92QSGSoftwareContext::QSGSoftwareContext(QObject *parent)
93 : QSGContext(parent)
94{
95}
96
97QSGInternalRectangleNode *QSGSoftwareContext::createInternalRectangleNode()
98{
99 return new QSGSoftwareInternalRectangleNode();
100}
101
102QSGInternalImageNode *QSGSoftwareContext::createInternalImageNode(QSGRenderContext *renderContext)
103{
104 Q_UNUSED(renderContext);
105 return new QSGSoftwareInternalImageNode();
106}
107
108QSGPainterNode *QSGSoftwareContext::createPainterNode(QQuickPaintedItem *item)
109{
110 return new QSGSoftwarePainterNode(item);
111}
112
113QSGGlyphNode *QSGSoftwareContext::createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode)
114{
115 Q_UNUSED(rc);
116 Q_UNUSED(preferNativeGlyphNode);
117 return new QSGSoftwareGlyphNode();
118}
119
120QSGLayer *QSGSoftwareContext::createLayer(QSGRenderContext *renderContext)
121{
122 return new QSGSoftwareLayer(renderContext);
123}
124
125QSurfaceFormat QSGSoftwareContext::defaultSurfaceFormat() const
126{
127 QSurfaceFormat format = QSurfaceFormat::defaultFormat();
128 format.setRenderableType(QSurfaceFormat::DefaultRenderableType);
129 format.setMajorVersion(0);
130 format.setMinorVersion(0);
131 return format;
132}
133
134void QSGSoftwareRenderContext::initializeIfNeeded()
135{
136 if (m_initialized)
137 return;
138 m_initialized = true;
139 emit initialized();
140}
141
142void QSGSoftwareRenderContext::invalidate()
143{
144 m_sg->renderContextInvalidated(renderContext: this);
145 emit invalidated();
146}
147
148QSGTexture *QSGSoftwareRenderContext::createTexture(const QImage &image, uint flags) const
149{
150 return new QSGSoftwarePixmapTexture(image, flags);
151}
152
153QSGRenderer *QSGSoftwareRenderContext::createRenderer()
154{
155 return new QSGSoftwareRenderer(this);
156}
157
158
159void QSGSoftwareRenderContext::renderNextFrame(QSGRenderer *renderer, uint fbo)
160{
161 renderer->renderScene(fboId: fbo);
162}
163
164int QSGSoftwareRenderContext::maxTextureSize() const
165{
166 return 2048;
167}
168
169QSGRendererInterface *QSGSoftwareContext::rendererInterface(QSGRenderContext *renderContext)
170{
171 Q_UNUSED(renderContext);
172 return this;
173}
174
175QSGRectangleNode *QSGSoftwareContext::createRectangleNode()
176{
177 return new QSGSoftwareRectangleNode;
178}
179
180QSGImageNode *QSGSoftwareContext::createImageNode()
181{
182 return new QSGSoftwareImageNode;
183}
184
185QSGNinePatchNode *QSGSoftwareContext::createNinePatchNode()
186{
187 return new QSGSoftwareNinePatchNode;
188}
189
190#if QT_CONFIG(quick_sprite)
191QSGSpriteNode *QSGSoftwareContext::createSpriteNode()
192{
193 return new QSGSoftwareSpriteNode;
194}
195#endif
196
197QSGRendererInterface::GraphicsApi QSGSoftwareContext::graphicsApi() const
198{
199 return Software;
200}
201
202QSGRendererInterface::ShaderType QSGSoftwareContext::shaderType() const
203{
204 return UnknownShadingLanguage;
205}
206
207QSGRendererInterface::ShaderCompilationTypes QSGSoftwareContext::shaderCompilationType() const
208{
209 return {};
210}
211
212QSGRendererInterface::ShaderSourceTypes QSGSoftwareContext::shaderSourceType() const
213{
214 return {};
215}
216
217void *QSGSoftwareContext::getResource(QQuickWindow *window, Resource resource) const
218{
219 if (resource == PainterResource && window && window->isSceneGraphInitialized())
220 return static_cast<QSGSoftwareRenderContext *>(QQuickWindowPrivate::get(c: window)->context)->m_activePainter;
221
222 return nullptr;
223}
224
225QT_END_NAMESPACE
226
227#include "moc_qsgsoftwarecontext_p.cpp"
228

source code of qtdeclarative/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp