diff options
author | JiDe Zhang <zhangjide@uniontech.com> | 2023-08-28 15:27:40 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-09-06 13:41:27 +0000 |
commit | 683d775464273767a07e428d266c800293743ba0 (patch) | |
tree | d7707abe7174f2c5377486510373887936c6feaf | |
parent | 08cce27c5ea37ec646934c076bc3008529df4ee4 (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.cpp | 18 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp | 61 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h | 2 |
3 files changed, 51 insertions, 30 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index c2aa11ef28..90cf1287f4 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -635,13 +635,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) @@ -656,7 +649,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; |