83class Q_QUICK_EXPORT QSGContext :
public QObject
88 enum AntialiasingMethod {
89 UndecidedAntialiasing,
94 explicit QSGContext(QObject *parent =
nullptr);
95 ~QSGContext() override;
97 virtual void renderContextInitialized(QSGRenderContext *renderContext);
98 virtual void renderContextInvalidated(QSGRenderContext *renderContext);
99 virtual QSGRenderContext *createRenderContext() = 0;
101 QSGInternalRectangleNode *createInternalRectangleNode(
const QRectF &rect,
const QColor &c);
102 virtual QSGInternalRectangleNode *createInternalRectangleNode() = 0;
103 virtual QSGInternalImageNode *createInternalImageNode(QSGRenderContext *renderContext) = 0;
104 virtual QSGInternalTextNode *createInternalTextNode(QSGRenderContext *renderContext);
105 virtual QSGPainterNode *createPainterNode(QQuickPaintedItem *item) = 0;
106 virtual QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, QSGTextNode::RenderType renderType,
int renderTypeQuality) = 0;
107 virtual QSGLayer *createLayer(QSGRenderContext *renderContext) = 0;
108 virtual QSGGuiThreadShaderEffectManager *createGuiThreadShaderEffectManager();
109 virtual QSGShaderEffectNode *createShaderEffectNode(QSGRenderContext *renderContext);
110#if QT_CONFIG(quick_sprite)
111 virtual QSGSpriteNode *createSpriteNode() = 0;
113 virtual QAnimationDriver *createAnimationDriver(QObject *parent);
114 virtual float vsyncIntervalForAnimationDriver(QAnimationDriver *driver);
115 virtual bool isVSyncDependent(QAnimationDriver *driver);
117 virtual QSize minimumFBOSize()
const;
118 virtual QSurfaceFormat defaultSurfaceFormat()
const = 0;
120 virtual QSGRendererInterface *rendererInterface(QSGRenderContext *renderContext);
122 virtual QSGTextNode *createTextNode(QSGRenderContext *renderContext);
123 virtual QSGRectangleNode *createRectangleNode() = 0;
124 virtual QSGImageNode *createImageNode() = 0;
125 virtual QSGNinePatchNode *createNinePatchNode() = 0;
127 static QSGContext *createDefaultContext();
128 static QQuickTextureFactory *createTextureFactoryFromImage(
const QImage &image);
129 static QSGRenderLoop *createWindowManager();
131 static void setBackend(
const QString &backend);
132 static QString backend();
139 enum CreateTextureFlags {
140 CreateTexture_Alpha = 0x1,
141 CreateTexture_Atlas = 0x2,
142 CreateTexture_Mipmap = 0x4
145 QSGRenderContext(QSGContext *context);
146 ~QSGRenderContext() override;
148 QSGContext *sceneGraphContext()
const {
return m_sg; }
149 virtual bool isValid()
const {
return true; }
151 struct InitParams { };
152 virtual void initialize(
const InitParams *params);
153 virtual void invalidate();
155 using RenderPassCallback =
void (*)(
void *);
157 virtual void prepareSync(qreal devicePixelRatio,
158 QRhiCommandBuffer *cb,
159 const QQuickGraphicsConfiguration &config);
161 virtual void beginNextFrame(QSGRenderer *renderer,
const QSGRenderTarget &renderTarget,
162 RenderPassCallback mainPassRecordingStart,
163 RenderPassCallback mainPassRecordingEnd,
164 void *callbackUserData);
165 virtual void renderNextFrame(QSGRenderer *renderer) = 0;
166 virtual void endNextFrame(QSGRenderer *renderer);
168 virtual void endSync();
170 virtual void preprocess();
171 virtual void invalidateGlyphCaches();
172 virtual void flushGlyphCaches();
173 virtual QSGDistanceFieldGlyphCache *distanceFieldGlyphCache(
const QRawFont &font,
int renderTypeQuality);
174 virtual QSGCurveGlyphAtlas *curveGlyphAtlas(
const QRawFont &font);
175 QSGTexture *textureForFactory(QQuickTextureFactory *factory, QQuickWindow *window);
177 virtual QSGTexture *createTexture(
const QImage &image, uint flags = CreateTexture_Alpha)
const = 0;
178 virtual QSGRenderer *createRenderer(QSGRendererInterface::RenderMode renderMode = QSGRendererInterface::RenderMode2D) = 0;
179 virtual QSGTexture *compressedTextureForFactory(
const QSGCompressedTextureFactory *)
const;
181 virtual int maxTextureSize()
const = 0;
183 void unregisterFontengineForCleanup(QFontEngine *engine);
184 void registerFontengineForCleanup(QFontEngine *engine);
186 virtual QRhi *rhi()
const;
191 void releaseCachedResourcesRequested();
194 void textureFactoryDestroyed(QObject *o);
198 FontKey(
const QRawFont &font,
int renderTypeQuality);
200 QFontEngine::FaceId faceId;
203 int renderTypeQuality;
207 friend bool operator==(
const QSGRenderContext::FontKey &f1,
const QSGRenderContext::FontKey &f2);
208 friend size_t qHash(
const QSGRenderContext::FontKey &f, size_t seed);
211 QPointer<QSGContext> m_sg;
214 QHash<QObject *, QSGTexture *> m_textures;
215 QSet<QSGTexture *> m_texturesToDelete;
216 QHash<FontKey, QSGDistanceFieldGlyphCache *> m_glyphCaches;
217 QList<QSGDistanceFieldGlyphCache *> m_staleGlyphCaches;
221 QHash<QFontEngine *,
int> m_fontEnginesToClean;
224inline bool operator ==(
const QSGRenderContext::FontKey &f1,
const QSGRenderContext::FontKey &f2)
226 return f1.faceId == f2.faceId
227 && f1.style == f2.style
228 && f1.weight == f2.weight
229 && f1.renderTypeQuality == f2.renderTypeQuality
230 && f1.familyName == f2.familyName
231 && f1.styleName == f2.styleName;
234inline size_t qHash(
const QSGRenderContext::FontKey &f, size_t seed = 0)
236 return qHashMulti(seed, f.faceId, f.renderTypeQuality, f.familyName, f.styleName, f.style, f.weight);