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
25QT_BEGIN_NAMESPACE
26
27namespace QtWaylandClient {
28
29class QWaylandDisplay;
30class QWaylandAbstractDecoration;
31class QWaylandWindow;
32
33class Q_WAYLANDCLIENT_EXPORT QWaylandShmBuffer : public QWaylandBuffer {
34public:
35 QWaylandShmBuffer(QWaylandDisplay *display,
36 const QSize &size, QImage::Format format, qreal scale = 1, wl_event_queue *customEventQueue = nullptr);
37 ~QWaylandShmBuffer() override;
38 QSize size() const override { return mImage.size(); }
39 int scale() const override { return int(mImage.devicePixelRatio()); }
40 QImage *image() { return &mImage; }
41
42 QImage *imageInsideMargins(const QMargins &margins);
43
44 QRegion &dirtyRegion() { return mDirtyRegion; }
45
46 uint age() const { return mAge; }
47 void setAge(uint age) { mAge = age; }
48
49private:
50 QImage mImage;
51 struct wl_shm_pool *mShmPool = nullptr;
52 QMargins mMargins;
53 QImage *mMarginsImage = nullptr;
54 QRegion mDirtyRegion;
55 uint mAge = 0;
56};
57
58class Q_WAYLANDCLIENT_EXPORT QWaylandShmBackingStore : public QPlatformBackingStore
59{
60public:
61 QWaylandShmBackingStore(QWindow *window, QWaylandDisplay *display);
62 ~QWaylandShmBackingStore() override;
63
64 QPaintDevice *paintDevice() override;
65 void flush(QWindow *window, const QRegion &region, const QPoint &offset) override;
66 void resize(const QSize &size, const QRegion &staticContents) override;
67 void beginPaint(const QRegion &region) override;
68 void endPaint() override;
69 bool scroll(const QRegion &region, int dx, int dy) override;
70
71 QWaylandAbstractDecoration *windowDecoration() const;
72
73 QMargins windowDecorationMargins() const;
74 QImage *entireSurface() const;
75 QImage *contentSurface() const;
76 bool recreateBackBufferIfNeeded(const QRegion &nonDirtyRegion = QRegion());
77
78 QWaylandWindow *waylandWindow() const;
79 void iterateBuffer();
80
81#if QT_CONFIG(opengl)
82 QImage toImage() const override;
83#endif
84
85private:
86 void updateDirtyStates(const QRegion &region);
87 void updateDecorations();
88 QWaylandShmBuffer *getBuffer(const QSize &size, bool &bufferWasRecreated);
89
90 QWaylandDisplay *mDisplay = nullptr;
91 QList<QWaylandShmBuffer *> mBuffers;
92 QWaylandShmBuffer *mFrontBuffer = nullptr;
93 QWaylandShmBuffer *mBackBuffer = nullptr;
94 bool mPainting = false;
95 bool mPendingFlush = false;
96 QRegion mPendingRegion;
97 QMutex mMutex;
98
99 QSize mRequestedSize;
100 Qt::WindowFlags mCurrentWindowFlags;
101 struct wl_event_queue *mEventQueue = nullptr;
102};
103
104}
105
106QT_END_NAMESPACE
107
108#endif
109

source code of qtbase/src/plugins/platforms/wayland/qwaylandshmbackingstore_p.h