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) = 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 virtual QSGTextNode::RenderType processTextRenderType(QSGTextNode::RenderType renderType) = 0;
130 static QSGContext *createDefaultContext();
131 static QQuickTextureFactory *createTextureFactoryFromImage(
const QImage &image);
132 static QSGRenderLoop *createWindowManager();
134 static void setBackend(
const QString &backend);
135 static QString backend();
142 enum CreateTextureFlags {
143 CreateTexture_Alpha = 0x1,
144 CreateTexture_Atlas = 0x2,
145 CreateTexture_Mipmap = 0x4
148 QSGRenderContext(QSGContext *context);
149 ~QSGRenderContext() override;
151 QSGContext *sceneGraphContext()
const {
return m_sg; }
152 virtual bool isValid()
const {
return true; }
154 struct InitParams { };
155 virtual void initialize(
const InitParams *params);
156 virtual void invalidate();
158 using RenderPassCallback =
void (*)(
void *);
160 virtual void prepareSync(qreal devicePixelRatio,
161 QRhiCommandBuffer *cb,
162 const QQuickGraphicsConfiguration &config);
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);
171 virtual void endSync();
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);
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;
184 virtual int maxTextureSize()
const = 0;
186 void unregisterFontengineForCleanup(QFontEngine *engine);
187 void registerFontengineForCleanup(QFontEngine *engine);
189 virtual QRhi *rhi()
const;
194 void releaseCachedResourcesRequested();
197 void textureFactoryDestroyed(QObject *o);
201 FontKey(
const QRawFont &font,
int renderTypeQuality);
203 QFontEngine::FaceId faceId;
206 int renderTypeQuality;
210 friend bool operator==(
const QSGRenderContext::FontKey &f1,
const QSGRenderContext::FontKey &f2);
211 friend size_t qHash(
const QSGRenderContext::FontKey &f, size_t seed);
214 QPointer<QSGContext> m_sg;
217 QHash<QObject *, QSGTexture *> m_textures;
218 QSet<QSGTexture *> m_texturesToDelete;
219 QHash<FontKey, QSGDistanceFieldGlyphCache *> m_glyphCaches;
220 QList<QSGDistanceFieldGlyphCache *> m_staleGlyphCaches;
224 QHash<QFontEngine *,
int> m_fontEnginesToClean;
227inline bool operator ==(
const QSGRenderContext::FontKey &f1,
const QSGRenderContext::FontKey &f2)
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;
237inline size_t qHash(
const QSGRenderContext::FontKey &f, size_t seed = 0)
239 return qHashMulti(seed, f.faceId, f.renderTypeQuality, f.familyName, f.styleName, f.style, f.weight);