| 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 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | class QOffscreenIntegration; |
| 24 | class QOffscreenScreen : public QPlatformScreen |
| 25 | { |
| 26 | public: |
| 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 | |
| 43 | public: |
| 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) |
| 54 | class QOffscreenDrag : public QPlatformDrag |
| 55 | { |
| 56 | public: |
| 57 | Qt::DropAction drag(QDrag *) override { return Qt::IgnoreAction; } |
| 58 | }; |
| 59 | #endif |
| 60 | |
| 61 | class QOffscreenBackingStore : public QPlatformBackingStore |
| 62 | { |
| 63 | public: |
| 64 | QOffscreenBackingStore(QWindow *window); |
| 65 | ~QOffscreenBackingStore(); |
| 66 | |
| 67 | QPaintDevice *paintDevice() override; |
| 68 | void flush(QWindow *window, const QRegion ®ion, 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 | void beginPaint(const QRegion &) override; |
| 72 | |
| 73 | QPixmap grabWindow(WId window, const QRect &rect) const; |
| 74 | QImage toImage() const override { return m_image; } |
| 75 | |
| 76 | static QOffscreenBackingStore *backingStoreForWinId(WId id); |
| 77 | |
| 78 | private: |
| 79 | void clearHash(); |
| 80 | |
| 81 | QImage m_image; |
| 82 | QHash<WId, QRect> m_windowAreaHash; |
| 83 | |
| 84 | static QHash<WId, QOffscreenBackingStore *> m_backingStoreForWinIdHash; |
| 85 | }; |
| 86 | |
| 87 | class QOffscreenPlatformNativeInterface : public QPlatformNativeInterface |
| 88 | { |
| 89 | public: |
| 90 | QOffscreenPlatformNativeInterface(QOffscreenIntegration *integration); |
| 91 | ~QOffscreenPlatformNativeInterface(); |
| 92 | |
| 93 | static void setConfiguration(const QJsonObject &configuration, QOffscreenPlatformNativeInterface *iface); |
| 94 | static QJsonObject configuration(QOffscreenPlatformNativeInterface *iface); |
| 95 | |
| 96 | void *nativeResourceForIntegration(const QByteArray &resource) override; |
| 97 | private: |
| 98 | QOffscreenIntegration *m_integration; |
| 99 | }; |
| 100 | |
| 101 | QT_END_NAMESPACE |
| 102 | |
| 103 | #endif |
| 104 | |