1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qplatformgraphicsbuffer.h" |
41 | #include <QtGui/QOpenGLContext> |
42 | #include <QtGui/QOpenGLFunctions> |
43 | #include <QtGui/qopengl.h> |
44 | #include <QtCore/QDebug> |
45 | |
46 | QT_BEGIN_NAMESPACE |
47 | /*! |
48 | \class QPlatformGraphicsBuffer |
49 | \inmodule QtGui |
50 | \since 5.5 |
51 | \brief The QPlatformGraphicsBuffer is a windowsystem abstraction for native graphics buffers |
52 | |
53 | Different platforms have different ways of representing graphics buffers. On |
54 | some platforms, it is possible to create one graphics buffer that you can bind |
55 | to a texture and also get main memory access to the image bits. On the |
56 | other hand, on some platforms all graphics buffer abstraction is completely |
57 | hidden. |
58 | |
59 | QPlatformGraphicsBuffer is an abstraction of a single Graphics Buffer. |
60 | |
61 | There is no public constructor nor any public factory function. |
62 | |
63 | \internal |
64 | */ |
65 | |
66 | /*! |
67 | \enum QPlatformGraphicsBuffer::AccessType |
68 | |
69 | This enum describes the access that is desired or granted for the graphics |
70 | buffer. |
71 | |
72 | \value None |
73 | \value SWReadAccess |
74 | \value SWWriteAccess |
75 | \value TextureAccess |
76 | \value HWCompositor |
77 | */ |
78 | |
79 | /*! |
80 | \enum QPlatformGraphicsBuffer::Origin |
81 | |
82 | This enum describes the origin of the content of the buffer. |
83 | |
84 | \value OriginTopLeft |
85 | \value OriginBottomLeft |
86 | */ |
87 | |
88 | /*! |
89 | Protected constructor to initialize the private members. |
90 | |
91 | \a size is the size of the buffer. |
92 | \a format is the format of the buffer. |
93 | |
94 | \sa size() format() |
95 | */ |
96 | QPlatformGraphicsBuffer::QPlatformGraphicsBuffer(const QSize &size, const QPixelFormat &format) |
97 | : m_size(size) |
98 | , m_format(format) |
99 | { |
100 | } |
101 | |
102 | |
103 | /*! |
104 | Virtual destructor. |
105 | */ |
106 | QPlatformGraphicsBuffer::~QPlatformGraphicsBuffer() |
107 | { |
108 | } |
109 | |
110 | /*! |
111 | Binds the content of this graphics buffer into the currently bound texture. |
112 | |
113 | This function should fail for buffers not capable of locking to TextureAccess. |
114 | |
115 | \a rect is the subrect which is desired to be bounded to the texture. This |
116 | argument has a no less than semantic, meaning more (if not all) of the buffer |
117 | can be bounded to the texture. An empty QRect is interpreted as entire buffer |
118 | should be bound. |
119 | |
120 | This function only supports binding buffers to the GL_TEXTURE_2D texture |
121 | target. |
122 | |
123 | Returns true on success, otherwise false. |
124 | */ |
125 | bool QPlatformGraphicsBuffer::bindToTexture(const QRect &rect) const |
126 | { |
127 | Q_UNUSED(rect); |
128 | return false; |
129 | } |
130 | |
131 | /*! |
132 | \fn QPlatformGraphicsBuffer::AccessTypes QPlatformGraphicsBuffer::isLocked() const |
133 | Function to check if the buffer is locked. |
134 | |
135 | \sa lock() |
136 | */ |
137 | |
138 | /*! |
139 | Before the data can be retrieved or before a buffer can be bound to a |
140 | texture it needs to be locked. This is a separate function call since this |
141 | operation might be time consuming, and it would not be satisfactory to do |
142 | it per function call. |
143 | |
144 | \a access is the access type wanted. |
145 | |
146 | \a rect is the subrect which is desired to be locked. This |
147 | argument has a no less than semantic, meaning more (if not all) of the buffer |
148 | can be locked. An empty QRect is interpreted as entire buffer should be locked. |
149 | |
150 | Return true on successfully locking all AccessTypes specified \a access |
151 | otherwise returns false and no locks have been granted. |
152 | */ |
153 | bool QPlatformGraphicsBuffer::lock(AccessTypes access, const QRect &rect) |
154 | { |
155 | bool locked = doLock(access, rect); |
156 | if (locked) |
157 | m_lock_access |= access; |
158 | |
159 | return locked; |
160 | } |
161 | |
162 | /*! |
163 | Unlocks the current buffer lock. |
164 | |
165 | This function calls doUnlock, and then emits the unlocked signal with the |
166 | AccessTypes from before doUnlock was called. |
167 | */ |
168 | void QPlatformGraphicsBuffer::unlock() |
169 | { |
170 | if (m_lock_access == None) |
171 | return; |
172 | AccessTypes previous = m_lock_access; |
173 | doUnlock(); |
174 | m_lock_access = None; |
175 | emit unlocked(previous); |
176 | } |
177 | |
178 | |
179 | /*! |
180 | \fn QPlatformGraphicsBuffer::doLock(AccessTypes access, const QRect &rect = QRect()) |
181 | |
182 | This function should be reimplemented by subclasses. If one of the \a |
183 | access types specified cannot be locked, then all should fail and this |
184 | function should return false. |
185 | |
186 | \a rect is the subrect which is desired to be locked. This |
187 | argument has a no less than semantic, meaning more (if not all) of the |
188 | buffer can be locked. An empty QRect should be interpreted as the entire buffer |
189 | should be locked. |
190 | |
191 | It is safe to call isLocked() to verify the current lock state. |
192 | */ |
193 | |
194 | /*! |
195 | \fn QPlatformGraphicsBuffer::doUnlock() |
196 | |
197 | This function should remove all locks set on the buffer. |
198 | |
199 | It is safe to call isLocked() to verify the current lock state. |
200 | */ |
201 | |
202 | /*! |
203 | \fn QPlatformGraphicsBuffer::unlocked(AccessTypes previousAccessTypes) |
204 | |
205 | Signal that is emitted after unlocked has been called. |
206 | |
207 | \a previousAccessTypes is the access types locked before unlock was called. |
208 | */ |
209 | |
210 | /*! |
211 | Accessor for the bytes of the buffer. This function needs to be called on a |
212 | buffer with SWReadAccess access lock. Behavior is undefined for modifying |
213 | the memory returned when not having a SWWriteAccess. |
214 | */ |
215 | const uchar *QPlatformGraphicsBuffer::data() const |
216 | { return nullptr; } |
217 | |
218 | /*! |
219 | Accessor for the bytes of the buffer. This function needs to be called on a |
220 | buffer with SWReadAccess access lock. Behavior is undefined for modifying |
221 | the memory returned when not having a SWWriteAccess. |
222 | */ |
223 | uchar *QPlatformGraphicsBuffer::data() |
224 | { |
225 | return nullptr; |
226 | } |
227 | |
228 | /*! |
229 | Accessor for the length of the data buffer. This function is a convenience |
230 | function multiplying height of buffer with bytesPerLine(). |
231 | |
232 | \sa data() bytesPerLine() size() |
233 | */ |
234 | int QPlatformGraphicsBuffer::byteCount() const |
235 | { |
236 | return size().height() * bytesPerLine(); |
237 | } |
238 | |
239 | /*! |
240 | Accessor for bytes per line in the graphics buffer. |
241 | */ |
242 | int QPlatformGraphicsBuffer::bytesPerLine() const |
243 | { |
244 | return 0; |
245 | } |
246 | |
247 | |
248 | /*! |
249 | In origin of the content of the graphics buffer. |
250 | |
251 | Default implementation is OriginTopLeft, as this is the coordinate |
252 | system default for Qt. However, for most regular OpenGL textures |
253 | this will be OriginBottomLeft. |
254 | */ |
255 | QPlatformGraphicsBuffer::Origin QPlatformGraphicsBuffer::origin() const |
256 | { |
257 | return OriginTopLeft; |
258 | } |
259 | |
260 | /*! |
261 | \fn QPlatformGraphicsBuffer::size() const |
262 | |
263 | Accessor for content size. |
264 | */ |
265 | |
266 | /*! |
267 | \fn QPlatformGraphicsBuffer::format() const |
268 | |
269 | Accessor for the pixel format of the buffer. |
270 | */ |
271 | |
272 | QT_END_NAMESPACE |
273 | |