aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiDe Zhang <zhangjide@uniontech.com>2023-08-28 15:27:40 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-09-06 11:23:14 +0000
commita19479c8d78f5936c85d4fc312f8bddc30347b17 (patch)
tree260938ce48826d2345f07455bbe02487b7260015
parentcf1947adab78af00305562de2b5e44ac0360c503 (diff)
Fix QML item is missing if its parent's clip property is true
If using QQuickRenderTarget to the QQuickWindow, and set true in QQuickRenderTarget::setMirrorVertically, the QQuickWindow will apply flip Y to the matrix with native NDC, this behovior is wrong, If QRhi::isYUpInNDC is true, must ensure the QSGAbstractRenderer::projectionMatrixWithNativeNDC is following QSGAbstractRenderer::projectionMatrix, otherwise must ensure its flip Y relative to QSGAbstractRenderer::projectionMatrix. Fixes: QTBUG-116587 Change-Id: I12b5f6e37ed5bad8656cf46bf1a25e534db24b62 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> (cherry picked from commit e898c06759b5c5a6138fac6f9a2cb31388ea3da9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quick/items/qquickwindow.cpp18
-rw-r--r--src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp61
-rw-r--r--src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h2
3 files changed, 51 insertions, 30 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index a1a9c01ced..23da3e8dcc 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -626,13 +626,6 @@ void QQuickWindowPrivate::renderSceneGraph()
emit q->beforeRendering();
runAndClearJobs(&beforeRenderingJobs);
- QSGAbstractRenderer::MatrixTransformFlags matrixFlags;
- bool flipY = rhi ? !rhi->isYUpInNDC() : false;
- if (!customRenderTarget.isNull() && customRenderTarget.mirrorVertically())
- flipY = !flipY;
- if (flipY)
- matrixFlags |= QSGAbstractRenderer::MatrixTransformFlipY;
-
const qreal devicePixelRatio = q->effectiveDevicePixelRatio();
QSize pixelSize;
if (redirect.rt.renderTarget)
@@ -647,7 +640,16 @@ void QQuickWindowPrivate::renderSceneGraph()
renderer->setDevicePixelRatio(devicePixelRatio);
renderer->setDeviceRect(QRect(QPoint(0, 0), pixelSize));
renderer->setViewportRect(QRect(QPoint(0, 0), pixelSize));
- renderer->setProjectionMatrixToRect(QRectF(QPointF(0, 0), pixelSize / devicePixelRatio), matrixFlags);
+
+ QSGAbstractRenderer::MatrixTransformFlags matrixFlags;
+ bool flipY = rhi ? !rhi->isYUpInNDC() : false;
+ if (!customRenderTarget.isNull() && customRenderTarget.mirrorVertically())
+ flipY = !flipY;
+ if (flipY)
+ matrixFlags |= QSGAbstractRenderer::MatrixTransformFlipY;
+
+ const QRectF rect(QPointF(0, 0), pixelSize / devicePixelRatio);
+ renderer->setProjectionMatrixToRect(rect, matrixFlags, rhi && !rhi->isYUpInNDC());
context->renderNextFrame(renderer);
diff --git a/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp b/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp
index a51521eeaa..bb374f8aaa 100644
--- a/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp
@@ -193,15 +193,7 @@ QRect QSGAbstractRenderer::viewportRect() const
*/
void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect)
{
- QMatrix4x4 matrix;
- matrix.ortho(rect.x(),
- rect.x() + rect.width(),
- rect.y() + rect.height(),
- rect.y(),
- 1,
- -1);
- setProjectionMatrix(matrix);
- setProjectionMatrixWithNativeNDC(matrix);
+ setProjectionMatrixToRect(rect, {}, false);
}
/*!
@@ -217,24 +209,49 @@ void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect)
*/
void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags)
{
+ setProjectionMatrixToRect(rect, flags, flags.testFlag(MatrixTransformFlipY));
+}
+
+/*!
+ Convenience method that calls setProjectionMatrix() with an
+ orthographic matrix generated from \a rect.
+
+ Set MatrixTransformFlipY in \a flags when the graphics API uses Y down in
+ its normalized device coordinate system (for example, Vulkan).
+
+ Convenience method that calls setProjectionMatrixWithNativeNDC() with an
+ orthographic matrix generated from \a rect.
+
+ Set true to \a nativeNDCFlipY to flip the Y axis relative to
+ projection matrix in its normalized device coordinate system.
+
+ \sa setProjectionMatrix(), projectionMatrix()
+ \sa setProjectionMatrixWithNativeNDC(), projectionMatrixWithNativeNDC()
+
+ \since 6.7
+ */
+void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags,
+ bool nativeNDCFlipY)
+{
const bool flipY = flags.testFlag(MatrixTransformFlipY);
+
+ const float left = rect.x();
+ const float right = rect.x() + rect.width();
+ float bottom = rect.y() + rect.height();
+ float top = rect.y();
+
+ if (flipY)
+ std::swap(top, bottom);
+
QMatrix4x4 matrix;
- matrix.ortho(rect.x(),
- rect.x() + rect.width(),
- flipY ? rect.y() : rect.y() + rect.height(),
- flipY ? rect.y() + rect.height() : rect.y(),
- 1,
- -1);
+ matrix.ortho(left, right, bottom, top, 1, -1);
setProjectionMatrix(matrix);
- if (flipY) {
+ if (nativeNDCFlipY) {
+ std::swap(top, bottom);
+
matrix.setToIdentity();
- matrix.ortho(rect.x(),
- rect.x() + rect.width(),
- rect.y() + rect.height(),
- rect.y(),
- 1,
- -1);
+ matrix.ortho(left, right, bottom, top, 1, -1);
}
setProjectionMatrixWithNativeNDC(matrix);
}
diff --git a/src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h b/src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h
index ec2cb66662..81263111cb 100644
--- a/src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h
+++ b/src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h
@@ -61,6 +61,8 @@ public:
void setProjectionMatrixToRect(const QRectF &rect);
void setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags);
+ void setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags,
+ bool nativeNDCFlipY);
void setProjectionMatrix(const QMatrix4x4 &matrix);
void setProjectionMatrixWithNativeNDC(const QMatrix4x4 &matrix);
QMatrix4x4 projectionMatrix() const;