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
qsgcontext_p.h
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
5#ifndef QSGCONTEXT_H
6#define QSGCONTEXT_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/QObject>
20#include <QtCore/qabstractanimation.h>
21#include <QtCore/QMutex>
22
23#include <QtGui/QImage>
24#include <QtGui/QSurfaceFormat>
25
26#include <private/qtquickglobal_p.h>
27#include <private/qrawfont_p.h>
28#include <private/qfontengine_p.h>
29
30#include <QtQuick/qsgnode.h>
31#include <QtQuick/qsgrendererinterface.h>
32#include <QtQuick/qsgtextnode.h>
33
34#include <QtCore/qpointer.h>
35
37
38Q_DECLARE_LOGGING_CATEGORY(lcQsgLeak)
39
40class QSGContextPrivate;
41class QSGInternalRectangleNode;
42class QSGInternalImageNode;
43class QSGInternalTextNode;
44class QSGPainterNode;
45class QSGGlyphNode;
46class QSGRenderer;
47class QSGDistanceFieldGlyphCache;
48class QQuickWindow;
49class QSGTexture;
50class QSGMaterial;
51class QSGRenderLoop;
52class QSGLayer;
53class QQuickTextureFactory;
54class QSGCompressedTextureFactory;
55class QSGContext;
56class QQuickPaintedItem;
57class QSGRendererInterface;
58class QSGShaderEffectNode;
59class QSGGuiThreadShaderEffectManager;
60class QSGRectangleNode;
61class QSGTextNode;
62class QSGImageNode;
63class QSGNinePatchNode;
64class QSGSpriteNode;
65class QSGRenderContext;
66class QSGRenderTarget;
67class QRhi;
68class QRhiRenderTarget;
69class QRhiRenderPassDescriptor;
70class QRhiCommandBuffer;
71class QQuickGraphicsConfiguration;
72class QQuickItem;
73class QSGCurveGlyphAtlas;
74
75Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_RENDERLOOP)
76Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_COMPILATION)
77Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_TEXTURE)
78Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_GLYPH)
79Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_RENDERER)
80
81Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_INFO)
82Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_RENDERLOOP)
83
84class Q_QUICK_EXPORT QSGContext : public QObject
85{
86 Q_OBJECT
87
88public:
89 enum AntialiasingMethod {
90 UndecidedAntialiasing,
91 VertexAntialiasing,
92 MsaaAntialiasing
93 };
94
95 explicit QSGContext(QObject *parent = nullptr);
96 ~QSGContext() override;
97
98 virtual void renderContextInitialized(QSGRenderContext *renderContext);
99 virtual void renderContextInvalidated(QSGRenderContext *renderContext);
100 virtual QSGRenderContext *createRenderContext() = 0;
101
102 QSGInternalRectangleNode *createInternalRectangleNode(const QRectF &rect, const QColor &c);
103 virtual QSGInternalRectangleNode *createInternalRectangleNode() = 0;
104 virtual QSGInternalImageNode *createInternalImageNode(QSGRenderContext *renderContext) = 0;
105 virtual QSGInternalTextNode *createInternalTextNode(QSGRenderContext *renderContext);
106 virtual QSGPainterNode *createPainterNode(QQuickPaintedItem *item) = 0;
107 virtual QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, QSGTextNode::RenderType renderType, int renderTypeQuality) = 0;
108 virtual QSGLayer *createLayer(QSGRenderContext *renderContext) = 0;
109 virtual QSGGuiThreadShaderEffectManager *createGuiThreadShaderEffectManager();
110 virtual QSGShaderEffectNode *createShaderEffectNode(QSGRenderContext *renderContext);
111#if QT_CONFIG(quick_sprite)
112 virtual QSGSpriteNode *createSpriteNode() = 0;
113#endif
114 virtual QAnimationDriver *createAnimationDriver(QObject *parent);
115 virtual float vsyncIntervalForAnimationDriver(QAnimationDriver *driver);
116 virtual bool isVSyncDependent(QAnimationDriver *driver);
117
118 virtual QSize minimumFBOSize() const;
119 virtual QSurfaceFormat defaultSurfaceFormat() const = 0;
120
121 virtual QSGRendererInterface *rendererInterface(QSGRenderContext *renderContext);
122
123 virtual QSGTextNode *createTextNode(QSGRenderContext *renderContext);
124 virtual QSGRectangleNode *createRectangleNode() = 0;
125 virtual QSGImageNode *createImageNode() = 0;
126 virtual QSGNinePatchNode *createNinePatchNode() = 0;
127
128 static QSGContext *createDefaultContext();
129 static QQuickTextureFactory *createTextureFactoryFromImage(const QImage &image);
130 static QSGRenderLoop *createWindowManager();
131
132 static void setBackend(const QString &backend);
133 static QString backend();
134};
135
136class Q_QUICK_EXPORT QSGRenderContext : public QObject
137{
138 Q_OBJECT
139public:
140 enum CreateTextureFlags {
141 CreateTexture_Alpha = 0x1,
142 CreateTexture_Atlas = 0x2,
143 CreateTexture_Mipmap = 0x4
144 };
145
146 QSGRenderContext(QSGContext *context);
147 ~QSGRenderContext() override;
148
149 QSGContext *sceneGraphContext() const { return m_sg; }
150 virtual bool isValid() const { return true; }
151
152 struct InitParams { };
153 virtual void initialize(const InitParams *params);
154 virtual void invalidate();
155
156 using RenderPassCallback = void (*)(void *);
157
158 virtual void prepareSync(qreal devicePixelRatio,
159 QRhiCommandBuffer *cb,
160 const QQuickGraphicsConfiguration &config);
161
162 virtual void beginNextFrame(QSGRenderer *renderer, const QSGRenderTarget &renderTarget,
163 RenderPassCallback mainPassRecordingStart,
164 RenderPassCallback mainPassRecordingEnd,
165 void *callbackUserData);
166 virtual void renderNextFrame(QSGRenderer *renderer) = 0;
167 virtual void endNextFrame(QSGRenderer *renderer);
168
169 virtual void endSync();
170
171 virtual void preprocess();
172 virtual void invalidateGlyphCaches();
173 virtual void flushGlyphCaches();
174 virtual QSGDistanceFieldGlyphCache *distanceFieldGlyphCache(const QRawFont &font, int renderTypeQuality);
175 virtual QSGCurveGlyphAtlas *curveGlyphAtlas(const QRawFont &font);
176 QSGTexture *textureForFactory(QQuickTextureFactory *factory, QQuickWindow *window);
177
178 virtual QSGTexture *createTexture(const QImage &image, uint flags = CreateTexture_Alpha) const = 0;
179 virtual QSGRenderer *createRenderer(QSGRendererInterface::RenderMode renderMode = QSGRendererInterface::RenderMode2D) = 0;
180 virtual QSGTexture *compressedTextureForFactory(const QSGCompressedTextureFactory *) const;
181
182 virtual int maxTextureSize() const = 0;
183
184 void unregisterFontengineForCleanup(QFontEngine *engine);
185 void registerFontengineForCleanup(QFontEngine *engine);
186
187 virtual QRhi *rhi() const;
188
189Q_SIGNALS:
190 void initialized();
191 void invalidated();
192 void releaseCachedResourcesRequested();
193
194public Q_SLOTS:
195 void textureFactoryDestroyed(QObject *o);
196
197protected:
198 struct FontKey {
199 FontKey(const QRawFont &font, int renderTypeQuality);
200
201 QFontEngine::FaceId faceId;
202 QFont::Style style;
203 int weight;
204 int renderTypeQuality;
205 QString familyName;
206 QString styleName;
207 };
208 friend bool operator==(const QSGRenderContext::FontKey &f1, const QSGRenderContext::FontKey &f2);
209 friend size_t qHash(const QSGRenderContext::FontKey &f, size_t seed);
210
211 // Hold m_sg with QPointer in the rare case it gets deleted before us.
212 QPointer<QSGContext> m_sg;
213
214 QMutex m_mutex;
215 QHash<QObject *, QSGTexture *> m_textures;
216 QSet<QSGTexture *> m_texturesToDelete;
217 QHash<FontKey, QSGDistanceFieldGlyphCache *> m_glyphCaches;
218 QList<QSGDistanceFieldGlyphCache *> m_staleGlyphCaches;
219
220 // References to font engines that are currently in use by native rendering glyph nodes
221 // and which must be kept alive as long as they are used in the render thread.
222 QHash<QFontEngine *, int> m_fontEnginesToClean;
223};
224
225inline bool operator ==(const QSGRenderContext::FontKey &f1, const QSGRenderContext::FontKey &f2)
226{
227 return f1.faceId == f2.faceId
228 && f1.style == f2.style
229 && f1.weight == f2.weight
230 && f1.renderTypeQuality == f2.renderTypeQuality
231 && f1.familyName == f2.familyName
232 && f1.styleName == f2.styleName;
233}
234
235inline size_t qHash(const QSGRenderContext::FontKey &f, size_t seed = 0)
236{
237 return qHashMulti(seed, f.faceId, f.renderTypeQuality, f.familyName, f.styleName, f.style, f.weight);
238}
239
240
241QT_END_NAMESPACE
242
243#endif // QSGCONTEXT_H
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
Definition qbytearray.h:807
\inmodule QtQuick
Combined button and popup list for selecting options.
#define QSG_RHI_DISTANCEFIELD_GLYPH_CACHE_PADDING
#define FROM_FIXED_POINT(value)
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:192