1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QOFFSCREENCOMMON_H
5#define QOFFSCREENCOMMON_H
6
7#include <qpa/qplatformbackingstore.h>
8#if QT_CONFIG(draganddrop)
9#include <qpa/qplatformdrag.h>
10#endif
11#include <qpa/qplatformintegration.h>
12#include <qpa/qplatformnativeinterface.h>
13#include <qpa/qplatformscreen.h>
14#include <qpa/qplatformwindow.h>
15
16#include <qscopedpointer.h>
17#include <qimage.h>
18#include <qjsonobject.h>
19#include <qhash.h>
20
21QT_BEGIN_NAMESPACE
22
23class QOffscreenIntegration;
24class QOffscreenScreen : public QPlatformScreen
25{
26public:
27 QOffscreenScreen(const QOffscreenIntegration *integration);
28
29 QRect geometry() const override { return m_geometry; }
30 int depth() const override { return 32; }
31 QImage::Format format() const override { return QImage::Format_RGB32; }
32 QDpi logicalDpi() const override { return QDpi(m_logicalDpi, m_logicalDpi); }
33 QDpi logicalBaseDpi() const override { return QDpi(m_logicalBaseDpi, m_logicalBaseDpi); }
34 qreal devicePixelRatio() const override { return m_dpr; }
35 QString name() const override { return m_name; }
36 QPlatformCursor *cursor() const override { return m_cursor.data(); }
37 QList<QPlatformScreen *> virtualSiblings() const override;
38
39 QPixmap grabWindow(WId window, int x, int y, int width, int height) const override;
40
41 static QPlatformWindow *windowContainingCursor;
42
43public:
44 QString m_name;
45 QRect m_geometry;
46 int m_logicalDpi = 96;
47 int m_logicalBaseDpi= 96;
48 qreal m_dpr = 1;
49 QScopedPointer<QPlatformCursor> m_cursor;
50 const QOffscreenIntegration *m_integration;
51};
52
53#if QT_CONFIG(draganddrop)
54class QOffscreenDrag : public QPlatformDrag
55{
56public:
57 Qt::DropAction drag(QDrag *) override { return Qt::IgnoreAction; }
58};
59#endif
60
61class QOffscreenBackingStore : public QPlatformBackingStore
62{
63public:
64 QOffscreenBackingStore(QWindow *window);
65 ~QOffscreenBackingStore();
66
67 QPaintDevice *paintDevice() override;
68 void flush(QWindow *window, const QRegion &region, const QPoint &offset) override;
69 void resize(const QSize &size, const QRegion &staticContents) override;
70 bool scroll(const QRegion &area, int dx, int dy) override;
71
72 QPixmap grabWindow(WId window, const QRect &rect) const;
73 QImage toImage() const override { return m_image; }
74
75 static QOffscreenBackingStore *backingStoreForWinId(WId id);
76
77private:
78 void clearHash();
79
80 QImage m_image;
81 QHash<WId, QRect> m_windowAreaHash;
82
83 static QHash<WId, QOffscreenBackingStore *> m_backingStoreForWinIdHash;
84};
85
86class QOffscreenPlatformNativeInterface : public QPlatformNativeInterface
87{
88public:
89 QOffscreenPlatformNativeInterface(QOffscreenIntegration *integration);
90 ~QOffscreenPlatformNativeInterface();
91
92 static void setConfiguration(const QJsonObject &configuration, QOffscreenPlatformNativeInterface *iface);
93 static QJsonObject configuration(QOffscreenPlatformNativeInterface *iface);
94
95 void *nativeResourceForIntegration(const QByteArray &resource) override;
96private:
97 QOffscreenIntegration *m_integration;
98};
99
100QT_END_NAMESPACE
101
102#endif
103

source code of qtbase/src/plugins/platforms/offscreen/qoffscreencommon.h