summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/offscreen/qoffscreencommon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/offscreen/qoffscreencommon.cpp')
-rw-r--r--src/plugins/platforms/offscreen/qoffscreencommon.cpp114
1 files changed, 59 insertions, 55 deletions
diff --git a/src/plugins/platforms/offscreen/qoffscreencommon.cpp b/src/plugins/platforms/offscreen/qoffscreencommon.cpp
index 33b98cfa1b..923fffb29c 100644
--- a/src/plugins/platforms/offscreen/qoffscreencommon.cpp
+++ b/src/plugins/platforms/offscreen/qoffscreencommon.cpp
@@ -1,47 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the plugins 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 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qoffscreencommon.h"
#include "qoffscreenintegration.h"
#include "qoffscreenwindow.h"
+#include <QtGui/QPainter>
#include <QtGui/private/qpixmap_raster_p.h>
#include <QtGui/private/qguiapplication_p.h>
@@ -55,7 +20,11 @@ QPlatformWindow *QOffscreenScreen::windowContainingCursor = nullptr;
QList<QPlatformScreen *> QOffscreenScreen::virtualSiblings() const
{
- return m_integration->screens();
+ QList<QPlatformScreen *> platformScreens;
+ for (auto screen : m_integration->screens()) {
+ platformScreens.append(screen);
+ }
+ return platformScreens;
}
class QOffscreenCursor : public QPlatformCursor
@@ -112,22 +81,25 @@ QPixmap QOffscreenScreen::grabWindow(WId id, int x, int y, int width, int height
{
QRect rect(x, y, width, height);
- QOffscreenWindow *window = QOffscreenWindow::windowForWinId(id);
- if (!window || window->window()->type() == Qt::Desktop) {
+ // id == 0 -> grab the screen, so all windows intersecting rect
+ if (!id) {
+ if (width == -1)
+ rect.setWidth(m_geometry.width());
+ if (height == -1)
+ rect.setHeight(m_geometry.height());
+ QPixmap screenImage(rect.size());
+ QPainter painter(&screenImage);
+ painter.translate(-x, -y);
const QWindowList wl = QGuiApplication::topLevelWindows();
- QWindow *containing = nullptr;
for (QWindow *w : wl) {
- if (w->type() != Qt::Desktop && w->isExposed() && w->geometry().contains(rect)) {
- containing = w;
- break;
+ if (w->isExposed() && w->geometry().intersects(rect)) {
+ QOffscreenBackingStore *store = QOffscreenBackingStore::backingStoreForWinId(w->winId());
+ const QImage windowImage = store ? store->toImage() : QImage();
+ if (!windowImage.isNull())
+ painter.drawImage(w->position(), windowImage);
}
}
-
- if (!containing)
- return QPixmap();
-
- id = containing->winId();
- rect = rect.translated(-containing->geometry().topLeft());
+ return screenImage;
}
QOffscreenBackingStore *store = QOffscreenBackingStore::backingStoreForWinId(id);
@@ -189,8 +161,8 @@ bool QOffscreenBackingStore::scroll(const QRegion &area, int dx, int dy)
if (m_image.isNull())
return false;
- for (const QRect &rect : area)
- qt_scrollRectInImage(m_image, rect, QPoint(dx, dy));
+ const QRect rect = area.boundingRect();
+ qt_scrollRectInImage(m_image, rect, QPoint(dx, dy));
return true;
}
@@ -217,13 +189,13 @@ QPixmap QOffscreenBackingStore::grabWindow(WId window, const QRect &rect) const
QOffscreenBackingStore *QOffscreenBackingStore::backingStoreForWinId(WId id)
{
- return m_backingStoreForWinIdHash.value(id, 0);
+ return m_backingStoreForWinIdHash.value(id, nullptr);
}
void QOffscreenBackingStore::clearHash()
{
for (auto it = m_windowAreaHash.cbegin(), end = m_windowAreaHash.cend(); it != end; ++it) {
- const auto it2 = qAsConst(m_backingStoreForWinIdHash).find(it.key());
+ const auto it2 = std::as_const(m_backingStoreForWinIdHash).find(it.key());
if (it2.value() == this)
m_backingStoreForWinIdHash.erase(it2);
}
@@ -232,6 +204,38 @@ void QOffscreenBackingStore::clearHash()
QHash<WId, QOffscreenBackingStore *> QOffscreenBackingStore::m_backingStoreForWinIdHash;
+QOffscreenPlatformNativeInterface::QOffscreenPlatformNativeInterface(QOffscreenIntegration *integration)
+ : m_integration(integration)
+{
+
+}
+
QOffscreenPlatformNativeInterface::~QOffscreenPlatformNativeInterface() = default;
+/*
+ Set platform configuration, e.g. screen configuration
+*/
+void QOffscreenPlatformNativeInterface::setConfiguration(const QJsonObject &configuration, QOffscreenPlatformNativeInterface *iface)
+{
+ iface->m_integration->setConfiguration(configuration);
+}
+
+/*
+ Get the current platform configuration
+*/
+QJsonObject QOffscreenPlatformNativeInterface::configuration(QOffscreenPlatformNativeInterface *iface)
+{
+ return iface->m_integration->configuration();
+}
+
+void *QOffscreenPlatformNativeInterface::nativeResourceForIntegration(const QByteArray &resource)
+{
+ if (resource == "setConfiguration")
+ return reinterpret_cast<void*>(&QOffscreenPlatformNativeInterface::setConfiguration);
+ else if (resource == "configuration")
+ return reinterpret_cast<void*>(&QOffscreenPlatformNativeInterface::configuration);
+ else
+ return nullptr;
+}
+
QT_END_NAMESPACE