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