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, int renderTypeQuality)
57{
58 Q_UNUSED(rc);
59 Q_UNUSED(renderType);
60 Q_UNUSED(renderTypeQuality);
61 return new QSGSoftwareGlyphNode();
62}
63
64QSGLayer *QSGSoftwareContext::createLayer(QSGRenderContext *renderContext)
65{
66 return new QSGSoftwareLayer(renderContext);
67}
68
69QSurfaceFormat QSGSoftwareContext::defaultSurfaceFormat() const
70{
71 QSurfaceFormat format = QSurfaceFormat::defaultFormat();
72 format.setRenderableType(QSurfaceFormat::DefaultRenderableType);
73 format.setMajorVersion(0);
74 format.setMinorVersion(0);
75 if (QQuickWindow::hasDefaultAlphaBuffer())
76 format.setAlphaBufferSize(8);
77 return format;
78}
79
80void QSGSoftwareRenderContext::initializeIfNeeded()
81{
82 if (m_initialized)
83 return;
84 m_initialized = true;
85 emit initialized();
86}
87
88void QSGSoftwareRenderContext::invalidate()
89{
90 qDeleteAll(m_texturesToDelete);
91 m_texturesToDelete.clear();
92
93 qDeleteAll(m_textures);
94 m_textures.clear();
95
96 Q_ASSERT(m_fontEnginesToClean.isEmpty());
97
98 qDeleteAll(m_glyphCaches);
99 m_glyphCaches.clear();
100
101 qDeleteAll(m_staleGlyphCaches);
102 m_staleGlyphCaches.clear();
103
104 m_sg->renderContextInvalidated(this);
105 emit invalidated();
106}
107
108QSGTexture *QSGSoftwareRenderContext::createTexture(const QImage &image, uint flags) const
109{
110 return new QSGSoftwarePixmapTexture(image, flags);
111}
112
113QSGRenderer *QSGSoftwareRenderContext::createRenderer(QSGRendererInterface::RenderMode)
114{
115 return new QSGSoftwareRenderer(this);
116}
117
118
119void QSGSoftwareRenderContext::renderNextFrame(QSGRenderer *renderer)
120{
121 renderer->renderScene();
122}
123
124int QSGSoftwareRenderContext::maxTextureSize() const
125{
126 return 2048;
127}
128
129QSGRendererInterface *QSGSoftwareContext::rendererInterface(QSGRenderContext *renderContext)
130{
131 Q_UNUSED(renderContext);
132 return this;
133}
134
135QSGRectangleNode *QSGSoftwareContext::createRectangleNode()
136{
137 return new QSGSoftwareRectangleNode;
138}
139
140QSGImageNode *QSGSoftwareContext::createImageNode()
141{
142 return new QSGSoftwareImageNode;
143}
144
145QSGNinePatchNode *QSGSoftwareContext::createNinePatchNode()
146{
147 return new QSGSoftwareNinePatchNode;
148}
149
150#if QT_CONFIG(quick_sprite)
151QSGSpriteNode *QSGSoftwareContext::createSpriteNode()
152{
153 return new QSGSoftwareSpriteNode;
154}
155#endif
156
157QSGRendererInterface::GraphicsApi QSGSoftwareContext::graphicsApi() const
158{
159 return Software;
160}
161
162QSGRendererInterface::ShaderType QSGSoftwareContext::shaderType() const
163{
164 return UnknownShadingLanguage;
165}
166
167QSGRendererInterface::ShaderCompilationTypes QSGSoftwareContext::shaderCompilationType() const
168{
169 return {};
170}
171
172QSGRendererInterface::ShaderSourceTypes QSGSoftwareContext::shaderSourceType() const
173{
174 return {};
175}
176
177void *QSGSoftwareContext::getResource(QQuickWindow *window, Resource resource) const
178{
179 if (!window)
180 return nullptr;
181
182 auto cd = QQuickWindowPrivate::get(window);
183
184 if (resource == PainterResource)
185 return window->isSceneGraphInitialized() ? static_cast<QSGSoftwareRenderContext *>(cd->context)->m_activePainter : nullptr;
186 else if (resource == RedirectPaintDevice)
187 return cd->redirect.rt.sw.paintDevice;
188
189 return nullptr;
190}
191
192QT_END_NAMESPACE
193
194#include "moc_qsgsoftwarecontext_p.cpp"