84class Q_QUICK_EXPORT QSGContext :
public QObject
89 enum AntialiasingMethod {
90 UndecidedAntialiasing,
95 explicit QSGContext(QObject *parent =
nullptr);
96 ~QSGContext() override;
98 virtual void renderContextInitialized(QSGRenderContext *renderContext);
99 virtual void renderContextInvalidated(QSGRenderContext *renderContext);
100 virtual QSGRenderContext *createRenderContext() = 0;
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;
114 virtual QAnimationDriver *createAnimationDriver(QObject *parent);
115 virtual float vsyncIntervalForAnimationDriver(QAnimationDriver *driver);
116 virtual bool isVSyncDependent(QAnimationDriver *driver);
118 virtual QSize minimumFBOSize()
const;
119 virtual QSurfaceFormat defaultSurfaceFormat()
const = 0;
121 virtual QSGRendererInterface *rendererInterface(QSGRenderContext *renderContext);
123 virtual QSGTextNode *createTextNode(QSGRenderContext *renderContext);
124 virtual QSGRectangleNode *createRectangleNode() = 0;
125 virtual QSGImageNode *createImageNode() = 0;
126 virtual QSGNinePatchNode *createNinePatchNode() = 0;
128 static QSGContext *createDefaultContext();
129 static QQuickTextureFactory *createTextureFactoryFromImage(
const QImage &image);
130 static QSGRenderLoop *createWindowManager();
132 static void setBackend(
const QString &backend);
133 static QString backend();
140 enum CreateTextureFlags {
141 CreateTexture_Alpha = 0x1,
142 CreateTexture_Atlas = 0x2,
143 CreateTexture_Mipmap = 0x4
146 QSGRenderContext(QSGContext *context);
147 ~QSGRenderContext() override;
149 QSGContext *sceneGraphContext()
const {
return m_sg; }
150 virtual bool isValid()
const {
return true; }
152 struct InitParams { };
153 virtual void initialize(
const InitParams *params);
154 virtual void invalidate();
156 using RenderPassCallback =
void (*)(
void *);
158 virtual void prepareSync(qreal devicePixelRatio,
159 QRhiCommandBuffer *cb,
160 const QQuickGraphicsConfiguration &config);
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);
169 virtual void endSync();
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);
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;
182 virtual int maxTextureSize()
const = 0;
184 void unregisterFontengineForCleanup(QFontEngine *engine);
185 void registerFontengineForCleanup(QFontEngine *engine);
187 virtual QRhi *rhi()
const;
192 void releaseCachedResourcesRequested();
195 void textureFactoryDestroyed(QObject *o);
199 FontKey(
const QRawFont &font,
int renderTypeQuality);
201 QFontEngine::FaceId faceId;
204 int renderTypeQuality;
208 friend bool operator==(
const QSGRenderContext::FontKey &f1,
const QSGRenderContext::FontKey &f2);
209 friend size_t qHash(
const QSGRenderContext::FontKey &f, size_t seed);
212 QPointer<QSGContext> m_sg;
215 QHash<QObject *, QSGTexture *> m_textures;
216 QSet<QSGTexture *> m_texturesToDelete;
217 QHash<FontKey, QSGDistanceFieldGlyphCache *> m_glyphCaches;
218 QList<QSGDistanceFieldGlyphCache *> m_staleGlyphCaches;
222 QHash<QFontEngine *,
int> m_fontEnginesToClean;
225inline bool operator ==(
const QSGRenderContext::FontKey &f1,
const QSGRenderContext::FontKey &f2)
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;
235inline size_t qHash(
const QSGRenderContext::FontKey &f, size_t seed = 0)
237 return qHashMulti(seed, f.faceId, f.renderTypeQuality, f.familyName, f.styleName, f.style, f.weight);