diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-10-02 16:42:33 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-10-03 09:38:11 +0200 |
commit | 5bc1ae578ed79ef295e86901e4620d9c37687ed7 (patch) | |
tree | 39bce8d408bf813e018b7f802c53f112d8d4b935 /src/quick/scenegraph/qsgdefaultrendercontext_p.h | |
parent | ee9319f63c2e9d307bcda41669aaed9934d013ad (diff) |
Fix device pixel ratio with QRhi for native text
Calculating values based on the dpr is not possible in the sync phase,
because the strictly correct dpr (that takes redirections into textures
into account) is not known until QQuickWindowPrivate::renderSceneGraph().
The text material implementation attempts to dig out something directly
from the context's associated surface, but this does not match the way
QQuickWindow calculates the value (although it would work without causing
any trouble in many cases).
This is of course incompatible with the QRhi-based abstraction since
neither the context nor the associated window (if there is one even) is
known to materials.
To solve this, create a proper solution that makes the
QQuickWindow-calculated dpr available already in the sync phase (so in
updatePaintNode() implementations): have QQuickWindow calculate
calculate the dpr in syncSceneGraph(), and pass it down via the
rendercontext.
Only the rhi-based code path is touched in this patch. The direct OpenGL
path could be fixed in a similar manner (by migrating to
rc->devicePixelRatio() in the sync phase and state.devicePixelRatio() in
the render phase), but that is left as a future exercise.
Task-number: QTBUG-78610
Change-Id: Id9d9d4b1fd5b9730a64834fbbf61c74af4a8ed07
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/quick/scenegraph/qsgdefaultrendercontext_p.h')
-rw-r--r-- | src/quick/scenegraph/qsgdefaultrendercontext_p.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/quick/scenegraph/qsgdefaultrendercontext_p.h b/src/quick/scenegraph/qsgdefaultrendercontext_p.h index 6a3462ae2b..2fdb3a48dd 100644 --- a/src/quick/scenegraph/qsgdefaultrendercontext_p.h +++ b/src/quick/scenegraph/qsgdefaultrendercontext_p.h @@ -104,6 +104,7 @@ public: void initialize(const QSGRenderContext::InitParams *params) override; void invalidate() override; + void prepareSync(qreal devicePixelRatio) override; void beginNextFrame(QSGRenderer *renderer, RenderPassCallback mainPassRecordingStart, RenderPassCallback mainPassRecordingEnd, @@ -151,6 +152,17 @@ public: return m_currentFrameRenderPass; } + qreal currentDevicePixelRatio() const + { + // Valid starting from QQuickWindow::syncSceneGraph(). This takes the + // redirections, e.g. QQuickWindow::setRenderTarget(), into account. + // This calculation logic matches what the renderer does, so this is + // the same value that gets exposed in RenderState::devicePixelRatio() + // to material shaders. This getter is useful to perform dpr-related + // operations in the sync phase (in updatePaintNode()). + return m_currentDevicePixelRatio; + } + protected: static QString fontKey(const QRawFont &font); @@ -166,6 +178,7 @@ protected: QSGRhiAtlasTexture::Manager *m_rhiAtlasManager; QRhiCommandBuffer *m_currentFrameCommandBuffer; QRhiRenderPassDescriptor *m_currentFrameRenderPass; + qreal m_currentDevicePixelRatio; }; QT_END_NAMESPACE |