| 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 QWAYLANDSHMBACKINGSTORE_H |
| 5 | #define QWAYLANDSHMBACKINGSTORE_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtWaylandClient/private/qwaylandbuffer_p.h> |
| 19 | |
| 20 | #include <qpa/qplatformbackingstore.h> |
| 21 | #include <QtGui/QImage> |
| 22 | #include <qpa/qplatformwindow.h> |
| 23 | #include <QMutex> |
| 24 | |
| 25 | #include <list> |
| 26 | |
| 27 | QT_BEGIN_NAMESPACE |
| 28 | |
| 29 | namespace QtWaylandClient { |
| 30 | |
| 31 | class QWaylandDisplay; |
| 32 | class QWaylandAbstractDecoration; |
| 33 | class QWaylandWindow; |
| 34 | |
| 35 | class Q_WAYLANDCLIENT_EXPORT QWaylandShmBuffer : public QWaylandBuffer { |
| 36 | public: |
| 37 | QWaylandShmBuffer(QWaylandDisplay *display, |
| 38 | const QSize &size, QImage::Format format, qreal scale = 1); |
| 39 | ~QWaylandShmBuffer() override; |
| 40 | QSize size() const override { return mImage.size(); } |
| 41 | int scale() const override { return int(mImage.devicePixelRatio()); } |
| 42 | QImage *image() { return &mImage; } |
| 43 | |
| 44 | QImage *imageInsideMargins(const QMargins &margins); |
| 45 | |
| 46 | QRegion &dirtyRegion() { return mDirtyRegion; } |
| 47 | private: |
| 48 | QImage mImage; |
| 49 | struct wl_shm_pool *mShmPool = nullptr; |
| 50 | QMargins mMargins; |
| 51 | QImage *mMarginsImage = nullptr; |
| 52 | QRegion mDirtyRegion; |
| 53 | }; |
| 54 | |
| 55 | class Q_WAYLANDCLIENT_EXPORT QWaylandShmBackingStore : public QPlatformBackingStore |
| 56 | { |
| 57 | public: |
| 58 | QWaylandShmBackingStore(QWindow *window, QWaylandDisplay *display); |
| 59 | ~QWaylandShmBackingStore() override; |
| 60 | |
| 61 | QPaintDevice *paintDevice() override; |
| 62 | void flush(QWindow *window, const QRegion ®ion, const QPoint &offset) override; |
| 63 | void resize(const QSize &size, const QRegion &staticContents) override; |
| 64 | void beginPaint(const QRegion ®ion) override; |
| 65 | void endPaint() override; |
| 66 | |
| 67 | QWaylandAbstractDecoration *windowDecoration() const; |
| 68 | |
| 69 | QMargins windowDecorationMargins() const; |
| 70 | QImage *entireSurface() const; |
| 71 | QImage *contentSurface() const; |
| 72 | bool recreateBackBufferIfNeeded(); |
| 73 | |
| 74 | QWaylandWindow *waylandWindow() const; |
| 75 | void iterateBuffer(); |
| 76 | |
| 77 | #if QT_CONFIG(opengl) |
| 78 | QImage toImage() const override; |
| 79 | #endif |
| 80 | |
| 81 | private: |
| 82 | void updateDirtyStates(const QRegion ®ion); |
| 83 | void updateDecorations(); |
| 84 | QWaylandShmBuffer *getBuffer(const QSize &size, bool &bufferWasRecreated); |
| 85 | |
| 86 | QWaylandDisplay *mDisplay = nullptr; |
| 87 | std::list<QWaylandShmBuffer *> mBuffers; |
| 88 | QWaylandShmBuffer *mFrontBuffer = nullptr; |
| 89 | QWaylandShmBuffer *mBackBuffer = nullptr; |
| 90 | bool mPainting = false; |
| 91 | bool mPendingFlush = false; |
| 92 | QRegion mPendingRegion; |
| 93 | QMutex mMutex; |
| 94 | |
| 95 | QSize mRequestedSize; |
| 96 | Qt::WindowFlags mCurrentWindowFlags; |
| 97 | }; |
| 98 | |
| 99 | } |
| 100 | |
| 101 | QT_END_NAMESPACE |
| 102 | |
| 103 | #endif |
| 104 | |