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) = 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 virtual QSGTextNode::RenderType processTextRenderType(QSGTextNode::RenderType renderType) = 0;
129
130 static QSGContext *createDefaultContext();
131 static QQuickTextureFactory *createTextureFactoryFromImage(const QImage &image);
132 static QSGRenderLoop *createWindowManager();
133
134 static void setBackend(const QString &backend);
135 static QString backend();
136};
137
138class Q_QUICK_EXPORT QSGRenderContext : public QObject
139{
140 Q_OBJECT
141public:
142 enum CreateTextureFlags {
143 CreateTexture_Alpha = 0x1,
144 CreateTexture_Atlas = 0x2,
145 CreateTexture_Mipmap = 0x4
146 };
147
148 QSGRenderContext(QSGContext *context);
149 ~QSGRenderContext() override;
150
151 QSGContext *sceneGraphContext() const { return m_sg; }
152 virtual bool isValid() const { return true; }
153
154 struct InitParams { };
155 virtual void initialize(const InitParams *params);
156 virtual void invalidate();
157
158 using RenderPassCallback = void (*)(void *);
159
160 virtual void prepareSync(qreal devicePixelRatio,
161 QRhiCommandBuffer *cb,
162 const QQuickGraphicsConfiguration &config);
163
164 virtual void beginNextFrame(QSGRenderer *renderer, const QSGRenderTarget &renderTarget,
165 RenderPassCallback mainPassRecordingStart,
166 RenderPassCallback mainPassRecordingEnd,
167 void *callbackUserData);
168 virtual void renderNextFrame(QSGRenderer *renderer) = 0;
169 virtual void endNextFrame(QSGRenderer *renderer);
170
171 virtual void endSync();
172
173 virtual void preprocess();
174 virtual void invalidateGlyphCaches();
175 virtual void flushGlyphCaches();
176 virtual QSGDistanceFieldGlyphCache *distanceFieldGlyphCache(const QRawFont &font, int renderTypeQuality);
177 virtual QSGCurveGlyphAtlas *curveGlyphAtlas(const QRawFont &font);
178 QSGTexture *textureForFactory(QQuickTextureFactory *factory, QQuickWindow *window);
179
180 virtual QSGTexture *createTexture(const QImage &image, uint flags = CreateTexture_Alpha) const = 0;
181 virtual QSGRenderer *createRenderer(QSGRendererInterface::RenderMode renderMode = QSGRendererInterface::RenderMode2D) = 0;
182 virtual QSGTexture *compressedTextureForFactory(const QSGCompressedTextureFactory *) const;
183
184 virtual int maxTextureSize() const = 0;
185
186 void unregisterFontengineForCleanup(QFontEngine *engine);
187 void registerFontengineForCleanup(QFontEngine *engine);
188
189 virtual QRhi *rhi() const;
190
191Q_SIGNALS:
192 void initialized();
193 void invalidated();
194 void releaseCachedResourcesRequested();
195
196public Q_SLOTS:
197 void textureFactoryDestroyed(QObject *o);
198
199protected:
200 struct FontKey {
201 FontKey(const QRawFont &font, int renderTypeQuality);
202
203 QFontEngine::FaceId faceId;
204 QFont::Style style;
205 int weight;
206 int renderTypeQuality;
207 QString familyName;
208 QString styleName;
209 };
210 friend bool operator==(const QSGRenderContext::FontKey &f1, const QSGRenderContext::FontKey &f2);
211 friend size_t qHash(const QSGRenderContext::FontKey &f, size_t seed);
212
213 // Hold m_sg with QPointer in the rare case it gets deleted before us.
214 QPointer<QSGContext> m_sg;
215
216 QMutex m_mutex;
217 QHash<QObject *, QSGTexture *> m_textures;
218 QSet<QSGTexture *> m_texturesToDelete;
219 QHash<FontKey, QSGDistanceFieldGlyphCache *> m_glyphCaches;
220 QList<QSGDistanceFieldGlyphCache *> m_staleGlyphCaches;
221
222 // References to font engines that are currently in use by native rendering glyph nodes
223 // and which must be kept alive as long as they are used in the render thread.
224 QHash<QFontEngine *, int> m_fontEnginesToClean;
225};
226
227inline bool operator ==(const QSGRenderContext::FontKey &f1, const QSGRenderContext::FontKey &f2)
228{
229 return f1.faceId == f2.faceId
230 && f1.style == f2.style
231 && f1.weight == f2.weight
232 && f1.renderTypeQuality == f2.renderTypeQuality
233 && f1.familyName == f2.familyName
234 && f1.styleName == f2.styleName;
235}
236
237inline size_t qHash(const QSGRenderContext::FontKey &f, size_t seed = 0)
238{
239 return qHashMulti(seed, f.faceId, f.renderTypeQuality, f.familyName, f.styleName, f.style, f.weight);
240}
241
242
243QT_END_NAMESPACE
244
245#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:815
\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