From bc9b675b7e471ee23bcecaf6acef60c56f84b86a Mon Sep 17 00:00:00 2001 From: zhangkun Date: Thu, 11 Jul 2024 16:08:39 +0800 Subject: [PATCH] Import QQuickItemGrabResult-Grab-with-window-devicePixelRatio.patch https://github.com/qt/qtdeclarative/commit/91e75fc3478f4cbef1a1e5449e8f9236af7397ab Issue: https://github.com/linuxdeepin/developer-center/issues/8639 --- debian/changelog | 8 ++ ...lt-Grab-with-window-devicePixelRatio.patch | 103 ++++++++++++++++++ debian/patches/series | 2 + 3 files changed, 113 insertions(+) create mode 100644 debian/patches/deepin-0006-QQuickItemGrabResult-Grab-with-window-devicePixelRatio.patch diff --git a/debian/changelog b/debian/changelog index 5efd5d0c9..efa0250b7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +qt6-declarative (6.6.1+dfsg-1deepin5) unstable; urgency=medium + + * Import patch from upstream: + - QQuickItemGrabResult-Grab-with-window-devicePixelRatio.patch + https://github.com/qt/qtdeclarative/commit/91e75fc3478f4cbef1a1e5449e8f9236af7397ab + + -- Zhang Kun Thu, 11 Jul 2024 16:22:50 +0800 + qt6-declarative (6.6.1+dfsg-1deepin4) unstable; urgency=medium * Import patch from upstream: diff --git a/debian/patches/deepin-0006-QQuickItemGrabResult-Grab-with-window-devicePixelRatio.patch b/debian/patches/deepin-0006-QQuickItemGrabResult-Grab-with-window-devicePixelRatio.patch new file mode 100644 index 000000000..e527f1cf3 --- /dev/null +++ b/debian/patches/deepin-0006-QQuickItemGrabResult-Grab-with-window-devicePixelRatio.patch @@ -0,0 +1,103 @@ +From 4d0c341492261d0eb309da90e67a62141b07be60 Mon Sep 17 00:00:00 2001 +From: Kai Uwe Broulik +Date: Wed, 2 Aug 2023 22:47:40 +0200 +Subject: [PATCH] QQuickItemGrabResult: Grab with window devicePixelRatio + +Ensures the grabbed image has the same device pixel ratio +as the original item. + +[ChangeLog][QtQuick][Item][Important Behavior Change] grabToImage +now grabs the item taking into account its devicePixelRatio. + +Task-number: QTBUG-50693 +Change-Id: I63518438c8c9a84c2feee82119c47ea4a6b4a88e +Reviewed-by: Qt CI Bot +Reviewed-by: Laszlo Agocs +--- + src/quick/items/qquickitemgrabresult.cpp | 12 +++++++++--- + .../tst_qquickninepatchimage.cpp | 11 ++++++++--- + 2 files changed, 17 insertions(+), 6 deletions(-) + +diff --git a/src/quick/items/qquickitemgrabresult.cpp b/src/quick/items/qquickitemgrabresult.cpp +index bcd1afc19d..17ea8ef3c6 100644 +--- a/src/quick/items/qquickitemgrabresult.cpp ++++ b/src/quick/items/qquickitemgrabresult.cpp +@@ -30,6 +30,7 @@ public: + : cacheEntry(nullptr) + , qmlEngine(nullptr) + , texture(nullptr) ++ , devicePixelRatio(1.0) + { + } + +@@ -63,6 +64,7 @@ public: + QSGLayer *texture; + QSizeF itemSize; + QSize textureSize; ++ qreal devicePixelRatio; + }; + + /*! +@@ -235,7 +237,9 @@ void QQuickItemGrabResult::setup() + } + + QSGRenderContext *rc = QQuickWindowPrivate::get(d->window.data())->context; ++ d->devicePixelRatio = d->window->effectiveDevicePixelRatio(); + d->texture = rc->sceneGraphContext()->createLayer(rc); ++ d->texture->setDevicePixelRatio(d->devicePixelRatio); + d->texture->setItem(QQuickItemPrivate::get(d->item)->itemNode()); + d->itemSize = QSizeF(d->item->width(), d->item->height()); + } +@@ -248,11 +252,13 @@ void QQuickItemGrabResult::render() + + d->texture->setRect(QRectF(0, d->itemSize.height(), d->itemSize.width(), -d->itemSize.height())); + const QSize minSize = QQuickWindowPrivate::get(d->window.data())->context->sceneGraphContext()->minimumFBOSize(); +- d->texture->setSize(QSize(qMax(minSize.width(), d->textureSize.width()), +- qMax(minSize.height(), d->textureSize.height()))); ++ const QSize effectiveTextureSize = d->textureSize * d->devicePixelRatio; ++ d->texture->setSize(QSize(qMax(minSize.width(), effectiveTextureSize.width()), ++ qMax(minSize.height(), effectiveTextureSize.height()))); + d->texture->scheduleUpdate(); + d->texture->updateTexture(); +- d->image = d->texture->toImage(); ++ d->image = d->texture->toImage(); ++ d->image.setDevicePixelRatio(d->devicePixelRatio); + + delete d->texture; + d->texture = nullptr; +diff --git a/tests/auto/quickcontrols/qquickninepatchimage/tst_qquickninepatchimage.cpp b/tests/auto/quickcontrols/qquickninepatchimage/tst_qquickninepatchimage.cpp +index dc88d0c5ed..7699f59135 100644 +--- a/tests/auto/quickcontrols/qquickninepatchimage/tst_qquickninepatchimage.cpp ++++ b/tests/auto/quickcontrols/qquickninepatchimage/tst_qquickninepatchimage.cpp +@@ -95,20 +95,25 @@ void tst_qquickninepatchimage::ninePatch() + + // Generate an image to compare against the actual 9-patch image. + QImage generatedImage(size * dpr, ninePatchImageGrab.format()); ++ generatedImage.setDevicePixelRatio(dpr); + generatedImage.fill(Qt::red); + + QImage blueRect(4 * dpr, 4 * dpr, ninePatchImageGrab.format()); ++ blueRect.setDevicePixelRatio(dpr); + blueRect.fill(Qt::blue); + ++ const QSizeF generatedPaintedSize = generatedImage.deviceIndependentSize(); ++ const QSizeF blueRectPaintedSize = blueRect.deviceIndependentSize(); ++ + QPainter painter(&generatedImage); + // Top-left + painter.drawImage(0, 0, blueRect); + // Top-right +- painter.drawImage(generatedImage.width() - blueRect.width(), 0, blueRect); ++ painter.drawImage(generatedPaintedSize.width() - blueRectPaintedSize.width(), 0, blueRect); + // Bottom-right +- painter.drawImage(generatedImage.width() - blueRect.width(), generatedImage.height() - blueRect.height(), blueRect); ++ painter.drawImage(generatedPaintedSize.width() - blueRectPaintedSize.width(), generatedPaintedSize.height() - blueRectPaintedSize.height(), blueRect); + // Bottom-left +- painter.drawImage(0, generatedImage.height() - blueRect.height(), blueRect); ++ painter.drawImage(0, generatedPaintedSize.height() - blueRectPaintedSize.height(), blueRect); + + if ((QGuiApplication::platformName() == QLatin1String("offscreen")) + || (QGuiApplication::platformName() == QLatin1String("minimal"))) +-- +2.43.4 + diff --git a/debian/patches/series b/debian/patches/series index a9c2a8420..7975ee0d7 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -5,3 +5,5 @@ deepin-0004-Fix-corrupt-rendering-when-toggling-rendernode-based-items.patch # https://codereview.qt-project.org/c/qt/qtdeclarative/+/535176 deepin-0005-TextField-Only-enable-paste-action-if-clipboard-has-text.patch +# https://github.com/qt/qtdeclarative/commit/91e75fc3478f4cbef1a1e5449e8f9236af7397ab +deepin-0006-QQuickItemGrabResult-Grab-with-window-devicePixelRatio.patch \ No newline at end of file