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