diff options
Diffstat (limited to 'src/plugins/platforms/offscreen/qoffscreencommon.cpp')
-rw-r--r-- | src/plugins/platforms/offscreen/qoffscreencommon.cpp | 125 |
1 files changed, 70 insertions, 55 deletions
diff --git a/src/plugins/platforms/offscreen/qoffscreencommon.cpp b/src/plugins/platforms/offscreen/qoffscreencommon.cpp index de75a3e012..923fffb29c 100644 --- a/src/plugins/platforms/offscreen/qoffscreencommon.cpp +++ b/src/plugins/platforms/offscreen/qoffscreencommon.cpp @@ -1,45 +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> @@ -50,6 +17,16 @@ QT_BEGIN_NAMESPACE QPlatformWindow *QOffscreenScreen::windowContainingCursor = nullptr; + +QList<QPlatformScreen *> QOffscreenScreen::virtualSiblings() const +{ + QList<QPlatformScreen *> platformScreens; + for (auto screen : m_integration->screens()) { + platformScreens.append(screen); + } + return platformScreens; +} + class QOffscreenCursor : public QPlatformCursor { public: @@ -93,9 +70,10 @@ private: QPoint m_pos; }; -QOffscreenScreen::QOffscreenScreen() +QOffscreenScreen::QOffscreenScreen(const QOffscreenIntegration *integration) : m_geometry(0, 0, 800, 600) , m_cursor(new QOffscreenCursor) + , m_integration(integration) { } @@ -103,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); @@ -180,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; } @@ -208,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); } @@ -223,4 +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 |