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
46QT_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 QPlatformGraphicsBuffer is intended to be created by using platform specific
64 APIs available from QtPlatformHeaders, or there might be accessor functions
65 similar to the accessor function that QPlatformBackingstore has.
66
67 \internal
68*/
69
70/*!
71 \enum QPlatformGraphicsBuffer::AccessType
72
73 This enum describes the access that is desired or granted for the graphics
74 buffer.
75
76 \value None
77 \value SWReadAccess
78 \value SWWriteAccess
79 \value TextureAccess
80 \value HWCompositor
81*/
82
83/*!
84 \enum QPlatformGraphicsBuffer::Origin
85
86 This enum describes the origin of the content of the buffer.
87
88 \value OriginTopLeft
89 \value OriginBottomLeft
90*/
91
92/*!
93 Protected constructor to initialize the private members.
94
95 \a size is the size of the buffer.
96 \a format is the format of the buffer.
97
98 \sa size() format()
99*/
100QPlatformGraphicsBuffer::QPlatformGraphicsBuffer(const QSize &size, const QPixelFormat &format)
101 : m_size(size)
102 , m_format(format)
103{
104}
105
106
107/*!
108 Virtual destructor.
109*/
110QPlatformGraphicsBuffer::~QPlatformGraphicsBuffer()
111{
112}
113
114/*!
115 Binds the content of this graphics buffer into the currently bound texture.
116
117 This function should fail for buffers not capable of locking to TextureAccess.
118
119 \a rect is the subrect which is desired to be bounded to the texture. This
120 argument has a no less than semantic, meaning more (if not all) of the buffer
121 can be bounded to the texture. An empty QRect is interpreted as entire buffer
122 should be bound.
123
124 This function only supports binding buffers to the GL_TEXTURE_2D texture
125 target.
126
127 Returns true on success, otherwise false.
128*/
129bool QPlatformGraphicsBuffer::bindToTexture(const QRect &rect) const
130{
131 Q_UNUSED(rect);
132 return false;
133}
134
135/*!
136 \fn QPlatformGraphicsBuffer::AccessTypes QPlatformGraphicsBuffer::isLocked() const
137 Function to check if the buffer is locked.
138
139 \sa lock()
140*/
141
142/*!
143 Before the data can be retrieved or before a buffer can be bound to a
144 texture it needs to be locked. This is a separate function call since this
145 operation might be time consuming, and it would not be satisfactory to do
146 it per function call.
147
148 \a access is the access type wanted.
149
150 \a rect is the subrect which is desired to be locked. This
151 argument has a no less than semantic, meaning more (if not all) of the buffer
152 can be locked. An empty QRect is interpreted as entire buffer should be locked.
153
154 Return true on successfully locking all AccessTypes specified \a access
155 otherwise returns false and no locks have been granted.
156*/
157bool QPlatformGraphicsBuffer::lock(AccessTypes access, const QRect &rect)
158{
159 bool locked = doLock(access, rect);
160 if (locked)
161 m_lock_access |= access;
162
163 return locked;
164}
165
166/*!
167 Unlocks the current buffer lock.
168
169 This function calls doUnlock, and then emits the unlocked signal with the
170 AccessTypes from before doUnlock was called.
171*/
172void QPlatformGraphicsBuffer::unlock()
173{
174 if (m_lock_access == None)
175 return;
176 AccessTypes previous = m_lock_access;
177 doUnlock();
178 m_lock_access = None;
179 emit unlocked(previousAccessTypes: previous);
180}
181
182
183/*!
184 \fn QPlatformGraphicsBuffer::doLock(AccessTypes access, const QRect &rect = QRect())
185
186 This function should be reimplemented by subclasses. If one of the \a
187 access types specified cannot be locked, then all should fail and this
188 function should return false.
189
190 \a rect is the subrect which is desired to be locked. This
191 argument has a no less than semantic, meaning more (if not all) of the
192 buffer can be locked. An empty QRect should be interpreted as the entire buffer
193 should be locked.
194
195 It is safe to call isLocked() to verify the current lock state.
196*/
197
198/*!
199 \fn QPlatformGraphicsBuffer::doUnlock()
200
201 This function should remove all locks set on the buffer.
202
203 It is safe to call isLocked() to verify the current lock state.
204*/
205
206/*!
207 \fn QPlatformGraphicsBuffer::unlocked(AccessTypes previousAccessTypes)
208
209 Signal that is emitted after unlocked has been called.
210
211 \a previousAccessTypes is the access types locked before unlock was called.
212*/
213
214/*!
215 Accessor for the bytes of the buffer. This function needs to be called on a
216 buffer with SWReadAccess access lock. Behavior is undefined for modifying
217 the memory returned when not having a SWWriteAccess.
218*/
219const uchar *QPlatformGraphicsBuffer::data() const
220{ return nullptr; }
221
222/*!
223 Accessor for the bytes of the buffer. This function needs to be called on a
224 buffer with SWReadAccess access lock. Behavior is undefined for modifying
225 the memory returned when not having a SWWriteAccess.
226*/
227uchar *QPlatformGraphicsBuffer::data()
228{
229 return nullptr;
230}
231
232/*!
233 Accessor for the length of the data buffer. This function is a convenience
234 function multiplying height of buffer with bytesPerLine().
235
236 \sa data() bytesPerLine() size()
237*/
238int QPlatformGraphicsBuffer::byteCount() const
239{
240 return size().height() * bytesPerLine();
241}
242
243/*!
244 Accessor for bytes per line in the graphics buffer.
245*/
246int QPlatformGraphicsBuffer::bytesPerLine() const
247{
248 return 0;
249}
250
251
252/*!
253 In origin of the content of the graphics buffer.
254
255 Default implementation is OriginTopLeft, as this is the coordinate
256 system default for Qt. However, for most regular OpenGL textures
257 this will be OriginBottomLeft.
258*/
259QPlatformGraphicsBuffer::Origin QPlatformGraphicsBuffer::origin() const
260{
261 return OriginTopLeft;
262}
263
264/*!
265 \fn QPlatformGraphicsBuffer::size() const
266
267 Accessor for content size.
268*/
269
270/*!
271 \fn QPlatformGraphicsBuffer::format() const
272
273 Accessor for the pixel format of the buffer.
274*/
275
276QT_END_NAMESPACE
277

source code of qtbase/src/gui/kernel/qplatformgraphicsbuffer.cpp