diff options
| author | JiDe Zhang <zhangjide@uniontech.com> | 2022-04-09 21:35:00 +0800 |
|---|---|---|
| committer | JiDe Zhang <zhangjide@uniontech.com> | 2022-05-03 12:14:41 +0800 |
| commit | bcc0f4fb1c47aea84d14fcecf51ce137904851df (patch) | |
| tree | 4c6343c38768cf784a46903723efea725c8ad3fa | |
| parent | 8a781d9e2429814edf41bd3213b449c9d8f8bc13 (diff) | |
Add setMirrorVertically for QQuickRenderTarget
Allow control the matrix transform of a render target in the
QQuickWindowPrivate::renderSceneGraph.
[ChangeLog][QtQuick][QQuickRenderTarget] Added QQuickRenderTarget::setMirrorVertically,
Allowed to control the mirror vertically of render target.
Task-number: QTBUG-102317
Change-Id: Ifc9aac77f28200594297ea15d07f41a864130f58
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
| -rw-r--r-- | src/quick/items/qquickrendertarget.cpp | 41 | ||||
| -rw-r--r-- | src/quick/items/qquickrendertarget.h | 3 | ||||
| -rw-r--r-- | src/quick/items/qquickrendertarget_p.h | 2 | ||||
| -rw-r--r-- | src/quick/items/qquickwindow.cpp | 4 |
4 files changed, 47 insertions, 3 deletions
diff --git a/src/quick/items/qquickrendertarget.cpp b/src/quick/items/qquickrendertarget.cpp index 317acddf71..f45a878ae7 100644 --- a/src/quick/items/qquickrendertarget.cpp +++ b/src/quick/items/qquickrendertarget.cpp @@ -66,7 +66,8 @@ QQuickRenderTargetPrivate::QQuickRenderTargetPrivate(const QQuickRenderTargetPri pixelSize(other->pixelSize), devicePixelRatio(other->devicePixelRatio), sampleCount(other->sampleCount), - u(other->u) + u(other->u), + mirrorVertically(other->mirrorVertically) { } @@ -160,6 +161,41 @@ void QQuickRenderTarget::setDevicePixelRatio(qreal ratio) } /*! + \return Returns whether the render target is mirrored vertically. + + The default value is \c {false}. + + \since 6.4 + + \sa setMirrorVertically() +*/ +bool QQuickRenderTarget::mirrorVertically() const +{ + return d->mirrorVertically; +} + + +/*! + Sets the size of the render target contents should be mirrored vertically to + \a enable when drawing. This allows easy integration of third-party rendering + code that does not follow the standard expectations. + + \note This function should not be used when using the \c software backend. + + \since 6.4 + + \sa mirrorVertically() + */ +void QQuickRenderTarget::setMirrorVertically(bool enable) +{ + if (d->mirrorVertically == enable) + return; + + detach(); + d->mirrorVertically = enable; +} + +/*! \return a new QQuickRenderTarget referencing an OpenGL texture object specified by \a textureId. @@ -465,7 +501,8 @@ bool QQuickRenderTarget::isEqual(const QQuickRenderTarget &other) const noexcept if (d->type != other.d->type || d->pixelSize != other.d->pixelSize || d->devicePixelRatio != other.d->devicePixelRatio - || d->sampleCount != other.d->sampleCount) + || d->sampleCount != other.d->sampleCount + || d->mirrorVertically != other.d->mirrorVertically) { return false; } diff --git a/src/quick/items/qquickrendertarget.h b/src/quick/items/qquickrendertarget.h index c9e20fff6b..d78e968e2c 100644 --- a/src/quick/items/qquickrendertarget.h +++ b/src/quick/items/qquickrendertarget.h @@ -70,6 +70,9 @@ public: qreal devicePixelRatio() const; void setDevicePixelRatio(qreal ratio); + bool mirrorVertically() const; + void setMirrorVertically(bool enable); + #if QT_CONFIG(opengl) || defined(Q_CLANG_QDOC) static QQuickRenderTarget fromOpenGLTexture(uint textureId, const QSize &pixelSize, int sampleCount = 1); static QQuickRenderTarget fromOpenGLRenderBuffer(uint renderbufferId, const QSize &pixelSize, int sampleCount = 1); diff --git a/src/quick/items/qquickrendertarget_p.h b/src/quick/items/qquickrendertarget_p.h index 4ea41bc2d8..ddad46069a 100644 --- a/src/quick/items/qquickrendertarget_p.h +++ b/src/quick/items/qquickrendertarget_p.h @@ -92,6 +92,8 @@ public: QRhiRenderTarget *rhiRt; QPaintDevice *paintDevice; } u; + + bool mirrorVertically = false; }; QT_END_NAMESPACE diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index ca5e3192e3..35e7dd165f 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -675,7 +675,9 @@ void QQuickWindowPrivate::renderSceneGraph(const QSize &size, const QSize &surfa runAndClearJobs(&beforeRenderingJobs); QSGAbstractRenderer::MatrixTransformFlags matrixFlags; - const bool flipY = rhi ? !rhi->isYUpInNDC() : false; + bool flipY = rhi ? !rhi->isYUpInNDC() : false; + if (!customRenderTarget.isNull() && customRenderTarget.mirrorVertically()) + flipY = !flipY; if (flipY) matrixFlags |= QSGAbstractRenderer::MatrixTransformFlipY; |
