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 QPLATFORMBACKINGSTORE_H |
5 | #define QPLATFORMBACKINGSTORE_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is part of the QPA API and is not meant to be used |
12 | // in applications. Usage of this API may make your code |
13 | // source and binary incompatible with future versions of Qt. |
14 | // |
15 | |
16 | #include <QtGui/qtguiglobal.h> |
17 | #include <QtCore/qloggingcategory.h> |
18 | #include <QtCore/qrect.h> |
19 | #include <QtCore/qobject.h> |
20 | |
21 | #include <QtGui/qwindow.h> |
22 | #include <QtGui/qregion.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | Q_DECLARE_EXPORTED_LOGGING_CATEGORY(lcQpaBackingStore, Q_GUI_EXPORT) |
27 | |
28 | class QRegion; |
29 | class QRect; |
30 | class QPoint; |
31 | class QImage; |
32 | class QPlatformBackingStorePrivate; |
33 | class QPlatformTextureList; |
34 | class QPlatformTextureListPrivate; |
35 | class QPlatformGraphicsBuffer; |
36 | class QRhi; |
37 | class QRhiTexture; |
38 | class QRhiResourceUpdateBatch; |
39 | |
40 | struct Q_GUI_EXPORT QPlatformBackingStoreRhiConfig |
41 | { |
42 | Q_GADGET |
43 | public: |
44 | enum Api { |
45 | OpenGL, |
46 | Metal, |
47 | Vulkan, |
48 | D3D11, |
49 | D3D12, |
50 | Null |
51 | }; |
52 | Q_ENUM(Api) |
53 | |
54 | QPlatformBackingStoreRhiConfig() |
55 | : m_enable(false) |
56 | { } |
57 | |
58 | QPlatformBackingStoreRhiConfig(Api api) |
59 | : m_enable(true), |
60 | m_api(api) |
61 | { } |
62 | |
63 | bool isEnabled() const { return m_enable; } |
64 | void setEnabled(bool enable) { m_enable = enable; } |
65 | |
66 | Api api() const { return m_api; } |
67 | void setApi(Api api) { m_api = api; } |
68 | |
69 | bool isDebugLayerEnabled() const { return m_debugLayer; } |
70 | void setDebugLayer(bool enable) { m_debugLayer = enable; } |
71 | |
72 | private: |
73 | bool m_enable; |
74 | Api m_api = Null; |
75 | bool m_debugLayer = false; |
76 | friend bool operator==(const QPlatformBackingStoreRhiConfig &a, const QPlatformBackingStoreRhiConfig &b); |
77 | }; |
78 | |
79 | inline bool operator==(const QPlatformBackingStoreRhiConfig &a, const QPlatformBackingStoreRhiConfig &b) |
80 | { |
81 | return a.m_enable == b.m_enable |
82 | && a.m_api == b.m_api |
83 | && a.m_debugLayer == b.m_debugLayer; |
84 | } |
85 | |
86 | inline bool operator!=(const QPlatformBackingStoreRhiConfig &a, const QPlatformBackingStoreRhiConfig &b) |
87 | { |
88 | return !(a == b); |
89 | } |
90 | |
91 | class Q_GUI_EXPORT QPlatformTextureList : public QObject |
92 | { |
93 | Q_OBJECT |
94 | Q_DECLARE_PRIVATE(QPlatformTextureList) |
95 | public: |
96 | enum Flag { |
97 | StacksOnTop = 0x01, |
98 | TextureIsSrgb = 0x02, |
99 | NeedsPremultipliedAlphaBlending = 0x04, |
100 | MirrorVertically = 0x08 |
101 | }; |
102 | Q_DECLARE_FLAGS(Flags, Flag) |
103 | |
104 | explicit QPlatformTextureList(QObject *parent = nullptr); |
105 | ~QPlatformTextureList(); |
106 | |
107 | int count() const; |
108 | bool isEmpty() const { return count() == 0; } |
109 | QRhiTexture *texture(int index) const; |
110 | QRhiTexture *(int index) const; |
111 | QRect geometry(int index) const; |
112 | QRect clipRect(int index) const; |
113 | void *source(int index); |
114 | Flags flags(int index) const; |
115 | void lock(bool on); |
116 | bool isLocked() const; |
117 | |
118 | void appendTexture(void *source, QRhiTexture *texture, const QRect &geometry, |
119 | const QRect &clipRect = QRect(), Flags flags = { }); |
120 | |
121 | void appendTexture(void *source, QRhiTexture *textureLeft, QRhiTexture *textureRight, const QRect &geometry, |
122 | const QRect &clipRect = QRect(), Flags flags = { }); |
123 | void clear(); |
124 | |
125 | Q_SIGNALS: |
126 | void locked(bool); |
127 | }; |
128 | Q_DECLARE_OPERATORS_FOR_FLAGS(QPlatformTextureList::Flags) |
129 | |
130 | class Q_GUI_EXPORT QPlatformBackingStore |
131 | { |
132 | public: |
133 | enum FlushResult { |
134 | FlushSuccess, |
135 | FlushFailed, |
136 | FlushFailedDueToLostDevice |
137 | }; |
138 | |
139 | explicit QPlatformBackingStore(QWindow *window); |
140 | virtual ~QPlatformBackingStore(); |
141 | |
142 | QWindow *window() const; |
143 | QBackingStore *backingStore() const; |
144 | |
145 | virtual QPaintDevice *paintDevice() = 0; |
146 | |
147 | virtual void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); |
148 | |
149 | virtual FlushResult rhiFlush(QWindow *window, |
150 | qreal sourceDevicePixelRatio, |
151 | const QRegion ®ion, |
152 | const QPoint &offset, |
153 | QPlatformTextureList *textures, |
154 | bool translucentBackground); |
155 | |
156 | virtual QImage toImage() const; |
157 | |
158 | enum TextureFlag { |
159 | TextureSwizzle = 0x01, |
160 | TextureFlip = 0x02, |
161 | TexturePremultiplied = 0x04 |
162 | }; |
163 | Q_DECLARE_FLAGS(TextureFlags, TextureFlag) |
164 | virtual QRhiTexture *toTexture(QRhiResourceUpdateBatch *resourceUpdates, |
165 | const QRegion &dirtyRegion, |
166 | TextureFlags *flags) const; |
167 | |
168 | virtual QPlatformGraphicsBuffer *graphicsBuffer() const; |
169 | |
170 | virtual void resize(const QSize &size, const QRegion &staticContents) = 0; |
171 | |
172 | virtual bool scroll(const QRegion &area, int dx, int dy); |
173 | |
174 | virtual void beginPaint(const QRegion &); |
175 | virtual void endPaint(); |
176 | |
177 | void createRhi(QWindow *window, QPlatformBackingStoreRhiConfig config); |
178 | QRhi *rhi(QWindow *window) const; |
179 | void surfaceAboutToBeDestroyed(); |
180 | void graphicsDeviceReportedLost(QWindow *window); |
181 | |
182 | private: |
183 | QPlatformBackingStorePrivate *d_ptr; |
184 | |
185 | void setBackingStore(QBackingStore *); |
186 | friend class QBackingStore; |
187 | }; |
188 | |
189 | Q_DECLARE_OPERATORS_FOR_FLAGS(QPlatformBackingStore::TextureFlags) |
190 | |
191 | QT_END_NAMESPACE |
192 | |
193 | #endif // QPLATFORMBACKINGSTORE_H |
194 | |