Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgsoftwarecontext.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
15#if QT_CONFIG(quick_sprite)
16#include "qsgsoftwarespritenode_p.h"
17#endif
18
19#include <QtCore/QCoreApplication>
20#include <QtCore/QElapsedTimer>
21
22#include <QtGui/QWindow>
23#include <QtQuick/private/qquickwindow_p.h>
24#include <QtQuick/private/qquickitem_p.h>
25
26QT_BEGIN_NAMESPACE
27
28QSGSoftwareRenderContext::QSGSoftwareRenderContext(QSGContext *ctx)
29 : QSGRenderContext(ctx)
30 , m_initialized(false)
31 , m_activePainter(nullptr)
32{
33}
34
35QSGSoftwareContext::QSGSoftwareContext(QObject *parent)
36 : QSGContext(parent)
37{
38}
39
40QSGInternalRectangleNode *QSGSoftwareContext::createInternalRectangleNode()
41{
42 return new QSGSoftwareInternalRectangleNode();
43}
44
45QSGInternalImageNode *QSGSoftwareContext::createInternalImageNode(QSGRenderContext *renderContext)
46{
47 Q_UNUSED(renderContext);
48 return new QSGSoftwareInternalImageNode();
49}
50
51QSGPainterNode *QSGSoftwareContext::createPainterNode(QQuickPaintedItem *item)
52{
53 return new QSGSoftwarePainterNode(item);
54}
55
56QSGGlyphNode *QSGSoftwareContext::createGlyphNode(QSGRenderContext *rc, QSGTextNode::RenderType renderType)
57{
58 Q_UNUSED(rc);
59 Q_UNUSED(renderType);
60 return new QSGSoftwareGlyphNode();
61}
62
63QSGTextNode::RenderType QSGSoftwareContext::processTextRenderType(QSGTextNode::RenderType renderType)
64{
65 Q_UNUSED(renderType);
66 return QSGTextNode::NativeRendering;
67}
68
69QSGLayer *QSGSoftwareContext::createLayer(QSGRenderContext *renderContext)
70{
71 return new QSGSoftwareLayer(renderContext);
72}
73
74QSurfaceFormat QSGSoftwareContext::defaultSurfaceFormat() const
75{
76 QSurfaceFormat format = QSurfaceFormat::defaultFormat();
77 format.setRenderableType(QSurfaceFormat::DefaultRenderableType);
78 format.setMajorVersion(0);
79 format.setMinorVersion(0);
80 if (QQuickWindow::hasDefaultAlphaBuffer())
81 format.setAlphaBufferSize(8);
82 return format;
83}
84
85void QSGSoftwareRenderContext::initializeIfNeeded()
86{
87 if (m_initialized)
88 return;
89 m_initialized = true;
90 emit initialized();
91}
92
93void QSGSoftwareRenderContext::invalidate()
94{
95 qDeleteAll(m_texturesToDelete);
96 m_texturesToDelete.clear();
97
98 qDeleteAll(m_textures);
99 m_textures.clear();
100
101 Q_ASSERT(m_fontEnginesToClean.isEmpty());
102
103 qDeleteAll(m_glyphCaches);
104 m_glyphCaches.clear();
105
106 qDeleteAll(m_staleGlyphCaches);
107 m_staleGlyphCaches.clear();
108
109 m_sg->renderContextInvalidated(this);
110 emit invalidated();
111}
112
113QSGTexture *QSGSoftwareRenderContext::createTexture(const QImage &image, uint flags) const
114{
115 return new QSGSoftwarePixmapTexture(image, flags);
116}
117
118QSGRenderer *QSGSoftwareRenderContext::createRenderer(QSGRendererInterface::RenderMode)
119{
120 return new QSGSoftwareRenderer(this);
121}
122
123
124void QSGSoftwareRenderContext::renderNextFrame(QSGRenderer *renderer)
125{
126 renderer->renderScene();
127}
128
129int QSGSoftwareRenderContext::maxTextureSize() const
130{
131 return 2048;
132}
133
134QSGRendererInterface *QSGSoftwareContext::rendererInterface(QSGRenderContext *renderContext)
135{
136 Q_UNUSED(renderContext);
137 return this;
138}
139
140QSGRectangleNode *QSGSoftwareContext::createRectangleNode()
141{
142 return new QSGSoftwareRectangleNode;
143}
144
145QSGImageNode *QSGSoftwareContext::createImageNode()
146{
147 return new QSGSoftwareImageNode;
148}
149
150QSGNinePatchNode *QSGSoftwareContext::createNinePatchNode()
151{
152 return new QSGSoftwareNinePatchNode;
153}
154
155#if QT_CONFIG(quick_sprite)
156QSGSpriteNode *QSGSoftwareContext::createSpriteNode()
157{
158 return new QSGSoftwareSpriteNode;
159}
160#endif
161
162QSGRendererInterface::GraphicsApi QSGSoftwareContext::graphicsApi() const
163{
164 return Software;
165}
166
167QSGRendererInterface::ShaderType QSGSoftwareContext::shaderType() const
168{
169 return UnknownShadingLanguage;
170}
171
172QSGRendererInterface::ShaderCompilationTypes QSGSoftwareContext::shaderCompilationType() const
173{
174 return {};
175}
176
177QSGRendererInterface::ShaderSourceTypes QSGSoftwareContext::shaderSourceType() const
178{
179 return {};
180}
181
182void *QSGSoftwareContext::getResource(QQuickWindow *window, Resource resource) const
183{
184 if (!window)
185 return nullptr;
186
187 auto cd = QQuickWindowPrivate::get(window);
188
189 if (resource == PainterResource)
190 return window->isSceneGraphInitialized() ? static_cast<QSGSoftwareRenderContext *>(cd->context)->m_activePainter : nullptr;
191 else if (resource == RedirectPaintDevice)
192 return cd->redirect.rt.sw.paintDevice;
193
194 return nullptr;
195}
196
197QT_END_NAMESPACE
198
199#include "moc_qsgsoftwarecontext_p.cpp"