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 | class QRhiSwapChain; |
40 | |
41 | struct Q_GUI_EXPORT QPlatformBackingStoreRhiConfig |
42 | { |
43 | enum Api { |
44 | OpenGL, |
45 | Metal, |
46 | Vulkan, |
47 | D3D11, |
48 | D3D12, |
49 | Null |
50 | }; |
51 | |
52 | QPlatformBackingStoreRhiConfig() |
53 | : m_enable(false) |
54 | { } |
55 | |
56 | QPlatformBackingStoreRhiConfig(Api api) |
57 | : m_enable(true), |
58 | m_api(api) |
59 | { } |
60 | |
61 | bool isEnabled() const { return m_enable; } |
62 | void setEnabled(bool enable) { m_enable = enable; } |
63 | |
64 | Api api() const { return m_api; } |
65 | void setApi(Api api) { m_api = api; } |
66 | |
67 | bool isDebugLayerEnabled() const { return m_debugLayer; } |
68 | void setDebugLayer(bool enable) { m_debugLayer = enable; } |
69 | |
70 | private: |
71 | bool m_enable; |
72 | Api m_api = Null; |
73 | bool m_debugLayer = false; |
74 | friend bool operator==(const QPlatformBackingStoreRhiConfig &a, const QPlatformBackingStoreRhiConfig &b); |
75 | }; |
76 | |
77 | inline bool operator==(const QPlatformBackingStoreRhiConfig &a, const QPlatformBackingStoreRhiConfig &b) |
78 | { |
79 | return a.m_enable == b.m_enable |
80 | && a.m_api == b.m_api |
81 | && a.m_debugLayer == b.m_debugLayer; |
82 | } |
83 | |
84 | inline bool operator!=(const QPlatformBackingStoreRhiConfig &a, const QPlatformBackingStoreRhiConfig &b) |
85 | { |
86 | return !(a == b); |
87 | } |
88 | |
89 | class Q_GUI_EXPORT QPlatformTextureList : public QObject |
90 | { |
91 | Q_OBJECT |
92 | Q_DECLARE_PRIVATE(QPlatformTextureList) |
93 | public: |
94 | enum Flag { |
95 | StacksOnTop = 0x01, |
96 | TextureIsSrgb = 0x02, |
97 | NeedsPremultipliedAlphaBlending = 0x04 |
98 | }; |
99 | Q_DECLARE_FLAGS(Flags, Flag) |
100 | |
101 | explicit QPlatformTextureList(QObject *parent = nullptr); |
102 | ~QPlatformTextureList(); |
103 | |
104 | int count() const; |
105 | bool isEmpty() const { return count() == 0; } |
106 | QRhiTexture *texture(int index) const; |
107 | QRhiTexture *(int index) const; |
108 | QRect geometry(int index) const; |
109 | QRect clipRect(int index) const; |
110 | void *source(int index); |
111 | Flags flags(int index) const; |
112 | void lock(bool on); |
113 | bool isLocked() const; |
114 | |
115 | void appendTexture(void *source, QRhiTexture *texture, const QRect &geometry, |
116 | const QRect &clipRect = QRect(), Flags flags = { }); |
117 | |
118 | void appendTexture(void *source, QRhiTexture *textureLeft, QRhiTexture *textureRight, const QRect &geometry, |
119 | const QRect &clipRect = QRect(), Flags flags = { }); |
120 | void clear(); |
121 | |
122 | Q_SIGNALS: |
123 | void locked(bool); |
124 | }; |
125 | Q_DECLARE_OPERATORS_FOR_FLAGS(QPlatformTextureList::Flags) |
126 | |
127 | class Q_GUI_EXPORT QPlatformBackingStore |
128 | { |
129 | public: |
130 | enum FlushResult { |
131 | FlushSuccess, |
132 | FlushFailed, |
133 | FlushFailedDueToLostDevice |
134 | }; |
135 | |
136 | explicit QPlatformBackingStore(QWindow *window); |
137 | virtual ~QPlatformBackingStore(); |
138 | |
139 | QWindow *window() const; |
140 | QBackingStore *backingStore() const; |
141 | |
142 | virtual QPaintDevice *paintDevice() = 0; |
143 | |
144 | virtual void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); |
145 | |
146 | virtual FlushResult rhiFlush(QWindow *window, |
147 | qreal sourceDevicePixelRatio, |
148 | const QRegion ®ion, |
149 | const QPoint &offset, |
150 | QPlatformTextureList *textures, |
151 | bool translucentBackground); |
152 | |
153 | virtual QImage toImage() const; |
154 | |
155 | enum TextureFlag { |
156 | TextureSwizzle = 0x01, |
157 | TextureFlip = 0x02, |
158 | TexturePremultiplied = 0x04 |
159 | }; |
160 | Q_DECLARE_FLAGS(TextureFlags, TextureFlag) |
161 | virtual QRhiTexture *toTexture(QRhiResourceUpdateBatch *resourceUpdates, |
162 | const QRegion &dirtyRegion, |
163 | TextureFlags *flags) const; |
164 | |
165 | virtual QPlatformGraphicsBuffer *graphicsBuffer() const; |
166 | |
167 | virtual void resize(const QSize &size, const QRegion &staticContents) = 0; |
168 | |
169 | virtual bool scroll(const QRegion &area, int dx, int dy); |
170 | |
171 | virtual void beginPaint(const QRegion &); |
172 | virtual void endPaint(); |
173 | |
174 | void setRhiConfig(const QPlatformBackingStoreRhiConfig &config); |
175 | QRhi *rhi() const; |
176 | QRhiSwapChain *rhiSwapChain() const; |
177 | void surfaceAboutToBeDestroyed(); |
178 | void graphicsDeviceReportedLost(); |
179 | |
180 | private: |
181 | QPlatformBackingStorePrivate *d_ptr; |
182 | |
183 | void setBackingStore(QBackingStore *); |
184 | friend class QBackingStore; |
185 | }; |
186 | |
187 | Q_DECLARE_OPERATORS_FOR_FLAGS(QPlatformBackingStore::TextureFlags) |
188 | |
189 | QT_END_NAMESPACE |
190 | |
191 | #endif // QPLATFORMBACKINGSTORE_H |
192 | |