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
qsgdefaultrendercontext_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 QSGDEFAULTRENDERCONTEXT_H
6#define QSGDEFAULTRENDERCONTEXT_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 <QtQuick/private/qsgcontext_p.h>
20#include <rhi/qshader.h>
21
23
24class QRhi;
25class QRhiCommandBuffer;
26class QRhiRenderPassDescriptor;
27class QRhiResourceUpdateBatch;
28class QRhiTexture;
29class QRhiRenderBuffer;
30class QSGMaterialShader;
31class QSurface;
32class QSGDefaultRenderContext;
33
35 class Manager;
36}
37
39{
40public:
42 QSGDepthStencilBuffer(QRhiRenderBuffer *ds) : ds(ds) { }
44 QRhiRenderBuffer *ds = nullptr;
45 QSGDefaultRenderContext *rc = nullptr;
46};
47
48class Q_QUICK_EXPORT QSGDefaultRenderContext : public QSGRenderContext
49{
50 Q_OBJECT
51public:
52 QSGDefaultRenderContext(QSGContext *context);
53
54 QRhi *rhi() const override { return m_rhi; }
55 bool isValid() const override { return m_rhi != nullptr; }
56
57 static const int INIT_PARAMS_MAGIC = 0x50E;
58 struct InitParams : public QSGRenderContext::InitParams {
59 int sType = INIT_PARAMS_MAGIC; // help discovering broken code passing something else as 'context'
60 QRhi *rhi = nullptr;
61 int sampleCount = 1; // 1, 4, 8, ...
62 // only used as a hint f.ex. in the texture atlas init
63 QSize initialSurfacePixelSize;
64 // The first window that will be used with this rc, if available.
65 // Only a hint, to help picking better values for atlases.
66 QSurface *maybeSurface = nullptr;
67 };
68
69 void initialize(const QSGRenderContext::InitParams *params) override;
70 void invalidate() override;
71
72 void prepareSync(qreal devicePixelRatio,
73 QRhiCommandBuffer *cb,
74 const QQuickGraphicsConfiguration &config) override;
75
76 void beginNextFrame(QSGRenderer *renderer, const QSGRenderTarget &renderTarget,
77 RenderPassCallback mainPassRecordingStart,
78 RenderPassCallback mainPassRecordingEnd,
79 void *callbackUserData) override;
80 void renderNextFrame(QSGRenderer *renderer) override;
81 void endNextFrame(QSGRenderer *renderer) override;
82
83 void preprocess() override;
84 void invalidateGlyphCaches() override;
85 void flushGlyphCaches() override;
86 QSGDistanceFieldGlyphCache *distanceFieldGlyphCache(const QRawFont &font, int renderTypeQuality) override;
87 QSGCurveGlyphAtlas *curveGlyphAtlas(const QRawFont &font) override;
88
89 QSGTexture *createTexture(const QImage &image, uint flags) const override;
90 QSGRenderer *createRenderer(QSGRendererInterface::RenderMode renderMode = QSGRendererInterface::RenderMode2D) override;
91 QSGTexture *compressedTextureForFactory(const QSGCompressedTextureFactory *factory) const override;
92
93 virtual void initializeRhiShader(QSGMaterialShader *shader, QShader::Variant shaderVariant);
94
95 int maxTextureSize() const override { return m_maxTextureSize; }
96 bool useDepthBufferFor2D() const { return m_useDepthBufferFor2D; }
97 int msaaSampleCount() const { return m_initParams.sampleCount; }
98
99 QRhiCommandBuffer *currentFrameCommandBuffer() const {
100 // may be null if not in an active frame, but returning null is valid then
101 return m_currentFrameCommandBuffer;
102 }
103 QRhiRenderPassDescriptor *currentFrameRenderPass() const {
104 // may be null if not in an active frame, but returning null is valid then
105 return m_currentFrameRenderPass;
106 }
107
108 qreal currentDevicePixelRatio() const
109 {
110 // Valid starting from QQuickWindow::syncSceneGraph(). This takes the
111 // redirections, e.g. QQuickWindow::setRenderTarget(), into account.
112 // This calculation logic matches what the renderer does, so this is
113 // the same value that gets exposed in RenderState::devicePixelRatio()
114 // to material shaders. This getter is useful to perform dpr-related
115 // operations in the sync phase (in updatePaintNode()).
116 return m_currentDevicePixelRatio;
117 }
118
119 QRhiResourceUpdateBatch *maybeGlyphCacheResourceUpdates();
120 QRhiResourceUpdateBatch *glyphCacheResourceUpdates();
121 void deferredReleaseGlyphCacheTexture(QRhiTexture *texture);
122 void resetGlyphCacheResources();
123
124 QSharedPointer<QSGDepthStencilBuffer> getDepthStencilBuffer(const QSize &size, int sampleCount);
125 void addDepthStencilBuffer(const QSharedPointer<QSGDepthStencilBuffer> &ds);
126
127protected:
128 InitParams m_initParams;
129 QRhi *m_rhi;
130 int m_maxTextureSize;
131 QSGRhiAtlasTexture::Manager *m_rhiAtlasManager;
132 QRhiCommandBuffer *m_currentFrameCommandBuffer;
133 QRhiRenderPassDescriptor *m_currentFrameRenderPass;
134 qreal m_currentDevicePixelRatio;
135 bool m_useDepthBufferFor2D;
136 QRhiResourceUpdateBatch *m_glyphCacheResourceUpdates;
137 QSet<QRhiTexture *> m_pendingGlyphCacheTextures;
138 QHash<FontKey, QSGCurveGlyphAtlas *> m_curveGlyphAtlases;
139 QHash<std::pair<QSize, int>, QWeakPointer<QSGDepthStencilBuffer>> m_depthStencilBuffers;
140
141 friend class QSGDepthStencilBuffer;
142};
143
144QT_END_NAMESPACE
145
146#endif // QSGDEFAULTRENDERCONTEXT_H
QSGDepthStencilBuffer(QRhiRenderBuffer *ds)
QSGDefaultRenderContext * rc
Combined button and popup list for selecting options.
static QFontEngine * fontEngineOfRawFont(const QRawFont &font)