diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2017-12-14 12:16:31 +0100 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-04-23 09:10:56 +0000 |
commit | 40e54cedaad19263c0dacadbb96a971b53c31b90 (patch) | |
tree | 6d9f46e3b9e4cadc481b2eb229ab115cf229fae9 /src/quick/items/context2d/qquickcontext2dtexture.cpp | |
parent | f23d1d54a06b0f3473e17300c3a1c495bcc25fdc (diff) |
QQuickContext2DFBOTexture: use normalized sub rect when using FBO with POT texture
When creating a Canvas item with renderStrategy set to Canvas.FramebufferObject
we might end up creating an FBO with a POT texture (e.g on iOS) that doesn't match
the size of the canvas. The result will be that the image turn out scaled.
QSGTexture::normalizedTextureSubRect() is a function that needs to be
overridden to be used. So this patch will create a subclass of QSGPlainTexture
that overrides it, and returns the normalized subrect inside the
FBO that that matches the size of the canvas.
Task-number: QTBUG-59192
Change-Id: I0f0e57e117656df21a94b7015bd160c44485046d
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/quick/items/context2d/qquickcontext2dtexture.cpp')
-rw-r--r-- | src/quick/items/context2d/qquickcontext2dtexture.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/quick/items/context2d/qquickcontext2dtexture.cpp b/src/quick/items/context2d/qquickcontext2dtexture.cpp index a8bf14ba9f..75a8429e98 100644 --- a/src/quick/items/context2d/qquickcontext2dtexture.cpp +++ b/src/quick/items/context2d/qquickcontext2dtexture.cpp @@ -91,6 +91,17 @@ struct GLAcquireContext { } QOpenGLContext *ctx; }; + +class QSGPlainTextureWithSubRect : public QSGPlainTexture +{ +public: + QSGPlainTextureWithSubRect(const QRectF &subRect) : m_subRect(subRect) {} + QRectF normalizedTextureSubRect() const override { return m_subRect; } + +private: + QRectF m_subRect; +}; + #endif QQuickContext2DTexture::QQuickContext2DTexture() : m_context(0) @@ -454,14 +465,18 @@ QVector2D QQuickContext2DFBOTexture::scaleFactor() const QSGTexture *QQuickContext2DFBOTexture::textureForNextFrame(QSGTexture *lastTexture, QQuickWindow *) { - QSGPlainTexture *texture = static_cast<QSGPlainTexture *>(lastTexture); + QSGPlainTextureWithSubRect *texture = static_cast<QSGPlainTextureWithSubRect *>(lastTexture); if (m_onCustomThread) m_mutex.lock(); if (m_fbo) { if (!texture) { - texture = new QSGPlainTexture(); + // Since the FBO might be have a POT size, we need to set a sub rect + qreal normalizedCanvasWidth = m_canvasDevicePixelRatio * qreal(m_canvasSize.width()) / m_fbo->size().width(); + qreal normalizedCanvasHeight = m_canvasDevicePixelRatio * qreal(m_canvasSize.height()) / m_fbo->size().height(); + + texture = new QSGPlainTextureWithSubRect(QRectF(0, 0, normalizedCanvasWidth, normalizedCanvasHeight)); texture->setHasAlphaChannel(true); texture->setOwnsTexture(false); m_dirtyTexture = true; |