aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickitemgrabresult.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/qquickitemgrabresult.cpp')
-rw-r--r--src/quick/items/qquickitemgrabresult.cpp72
1 files changed, 21 insertions, 51 deletions
diff --git a/src/quick/items/qquickitemgrabresult.cpp b/src/quick/items/qquickitemgrabresult.cpp
index cb2f12ea8b..e2164129be 100644
--- a/src/quick/items/qquickitemgrabresult.cpp
+++ b/src/quick/items/qquickitemgrabresult.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <private/qtquickglobal_p.h>
#include "qquickitemgrabresult.h"
@@ -50,11 +14,13 @@
#include <QtQml/QQmlEngine>
#include <QtQml/QQmlInfo>
-#include <private/qquickpixmapcache_p.h>
+#include <private/qquickpixmap_p.h>
#include <private/qquickitem_p.h>
#include <private/qsgcontext_p.h>
#include <private/qsgadaptationlayer_p.h>
+#include <QtCore/qpointer.h>
+
QT_BEGIN_NAMESPACE
const QEvent::Type Event_Grab_Completed = static_cast<QEvent::Type>(QEvent::User + 1);
@@ -66,6 +32,7 @@ public:
: cacheEntry(nullptr)
, qmlEngine(nullptr)
, texture(nullptr)
+ , devicePixelRatio(1.0)
{
}
@@ -99,6 +66,7 @@ public:
QSGLayer *texture;
QSizeF itemSize;
QSize textureSize;
+ qreal devicePixelRatio;
};
/*!
@@ -183,13 +151,13 @@ QQuickItemGrabResult::QQuickItemGrabResult(QObject *parent)
* if successful; otherwise returns \c false.
*/
+// ### Qt 7: remove and keep only QUrl overload
/*!
* Saves the grab result as an image to \a fileName. Returns \c true
* if successful; otherwise returns \c false.
*
* \note In Qt versions prior to 5.9, this function is marked as non-\c{const}.
*/
-// ### Qt 7: remove and keep only QUrl overload
bool QQuickItemGrabResult::saveToFile(const QString &fileName) const
{
Q_D(const QQuickItemGrabResult);
@@ -223,7 +191,7 @@ bool QQuickItemGrabResult::saveToFile(const QUrl &filePath) const
*/
bool QQuickItemGrabResult::saveToFile(const QString &fileName)
{
- return qAsConst(*this).saveToFile(fileName);
+ return std::as_const(*this).saveToFile(fileName);
}
#endif
#endif // < Qt 6
@@ -271,7 +239,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());
}
@@ -284,11 +254,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;
@@ -381,17 +353,15 @@ QSharedPointer<QQuickItemGrabResult> QQuickItem::grabToImage(const QSize &target
*
* If the grab could not be initiated, the function returns \c false.
*
- * The following snippet shows how to grab an item and store the results to
- * a file.
+ * The following snippet shows how to grab an item and store the results in
+ * a file:
*
- * \snippet qml/itemGrab.qml grab-source
- * \snippet qml/itemGrab.qml grab-to-file
+ * \snippet qml/item/itemGrab.qml grab-to-file
*
* The following snippet shows how to grab an item and use the results in
- * another image element.
+ * another image element:
*
- * \snippet qml/itemGrab.qml grab-image-target
- * \snippet qml/itemGrab.qml grab-to-cache
+ * \snippet qml/item/itemGrab.qml grab-to-image
*
* \note This function will render the item to an offscreen surface and
* copy that surface from the GPU's memory into the CPU's memory, which can