summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qplatformgraphicsbuffer.cpp
blob: 91c2ba23c90e6ed7a4c81f3668a63f8aea115df3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qplatformgraphicsbuffer.h"
#include <QtGui/QOpenGLContext>
#include <QtGui/QOpenGLFunctions>
#include <QtGui/qopengl.h>
#include <QtCore/QDebug>

QT_BEGIN_NAMESPACE
/*!
    \class QPlatformGraphicsBuffer
    \inmodule QtGui
    \since 5.5
    \brief The QPlatformGraphicsBuffer is a windowsystem abstraction for native graphics buffers

    Different platforms have different ways of representing graphics buffers. On
    some platforms, it is possible to create one graphics buffer that you can bind
    to a texture and also get main memory access to the image bits. On the
    other hand, on some platforms all graphics buffer abstraction is completely
    hidden.

    QPlatformGraphicsBuffer is an abstraction of a single Graphics Buffer.

    There is no public constructor nor any public factory function.

    QPlatformGraphicsBuffer is intended to be created by using platform specific
    APIs available from QtPlatformHeaders, or there might be accessor functions
    similar to the accessor function that QPlatformBackingstore has.
*/

/*!
    \enum QPlatformGraphicsBuffer::AccessType

    This enum describes the access that is desired or granted for the graphics
    buffer.

    \value None
    \value SWReadAccess
    \value SWWriteAccess
    \value TextureAccess
    \value HWCompositor
*/

/*!
    \enum QPlatformGraphicsBuffer::Origin

    This enum describes the origin of the content of the buffer.

    \value OriginTopLeft
    \value OriginBottomLeft
*/

/*!
    Protected constructor to initialize the private members.

    \a size is the size of the buffer.
    \a format is the format of the buffer.

    \sa size() format()
*/
QPlatformGraphicsBuffer::QPlatformGraphicsBuffer(const QSize &size, const QPixelFormat &format)
    : m_size(size)
    , m_format(format)
{
}


/*!
    Virtual destructor.
*/
QPlatformGraphicsBuffer::~QPlatformGraphicsBuffer()
{
}

/*!
    Binds the content of this graphics buffer into the currently bound texture.

    This function should fail for buffers not capable of locking to TextureAccess.

    \a rect is the subrect which is desired to be bounded to the texture. This
    argument has a no less than semantic, meaning more (if not all) of the buffer
    can be bounded to the texture. An empty QRect is interpreted as entire buffer
    should be bound.

    This function only supports binding buffers to the GL_TEXTURE_2D texture
    target.

    Returns true on success, otherwise false.
*/
bool QPlatformGraphicsBuffer::bindToTexture(const QRect &rect) const
{
    Q_UNUSED(rect);
    return false;
}

/*!
    \fn QPlatformGraphicsBuffer::AccessTypes QPlatformGraphicsBuffer::isLocked() const
    Function to check if the buffer is locked.

    \sa lock()
*/

/*!
    Before the data can be retrieved or before a buffer can be bound to a
    texture it needs to be locked. This is a separate function call since this
    operation might be time consuming, and it would not be satisfactory to do
    it per function call.

    \a access is the access type wanted.

    \a rect is the subrect which is desired to be locked. This
    argument has a no less than semantic, meaning more (if not all) of the buffer
    can be locked. An empty QRect is interpreted as entire buffer should be locked.

    Return true on successfully locking all AccessTypes specified \a access
    otherwise returns false and no locks have been granted.
*/
bool QPlatformGraphicsBuffer::lock(AccessTypes access, const QRect &rect)
{
    bool locked = doLock(access, rect);
    if (locked)
        m_lock_access |= access;

    return locked;
}

/*!
    Unlocks the current buffer lock.

    This function calls doUnlock, and then emits the unlocked signal with the
    AccessTypes from before doUnlock was called.
*/
void QPlatformGraphicsBuffer::unlock()
{
    if (m_lock_access == None)
        return;
    AccessTypes previous = m_lock_access;
    doUnlock();
    m_lock_access = None;
    emit unlocked(previous);
}


/*!
    \fn QPlatformGraphicsBuffer::doLock(AccessTypes access, const QRect &rect = QRect())

    This function should be reimplemented by subclasses. If one of the \a
    access types specified can not be locked, then all should fail and this
    function should return false.

    \a rect is the subrect which is desired to be locked. This
    argument has a no less than semantic, meaning more (if not all) of the
    buffer can be locked. An empty QRect should be interpreted as the entire buffer
    should be locked.

    It is safe to call isLocked() to verify the current lock state.
*/

/*!
    \fn QPlatformGraphicsBuffer::doUnlock()

    This function should remove all locks set on the buffer.

    It is safe to call isLocked() to verify the current lock state.
*/

/*!
    \fn QPlatformGraphicsBuffer::unlocked(AccessTypes previousAccessTypes)

    Signal that is emitted after unlocked has been called.

    \a previousAccessTypes is the access types locked before unlock was called.
*/

/*!
    Accessor for the bytes of the buffer. This function needs to be called on a
    buffer with SWReadAccess access lock. Behavior is undefined for modifying
    the memory returned when not having a SWWriteAccess.
*/
const uchar *QPlatformGraphicsBuffer::data() const
{ return Q_NULLPTR; }

/*!
    Accessor for the bytes of the buffer. This function needs to be called on a
    buffer with SWReadAccess access lock. Behavior is undefined for modifying
    the memory returned when not having a SWWriteAccess.
*/
uchar *QPlatformGraphicsBuffer::data()
{
    return Q_NULLPTR;
}

/*!
    Accessor for the length of the data buffer. This function is a convenience
    function multiplying height of buffer with bytesPerLine().

    \sa data() bytesPerLine() size()
*/
int QPlatformGraphicsBuffer::byteCount() const
{
    Q_ASSERT(isLocked() & SWReadAccess);
    return size().height() * bytesPerLine();
}

/*!
    Accessor for bytes per line in the graphics buffer.
*/
int QPlatformGraphicsBuffer::bytesPerLine() const
{
    return 0;
}


/*!
    In origin of the content of the graphics buffer.

    Default implementation is OriginTopLeft, as this is the coordinate
    system default for Qt. However, for most regular OpenGL textures
    this will be OriginBottomLeft.
*/
QPlatformGraphicsBuffer::Origin QPlatformGraphicsBuffer::origin() const
{
    return OriginTopLeft;
}

/*!
    \fn QPlatformGraphicsBuffer::size() const

    Accessor for content size.
*/

/*!
    \fn QPlatformGraphicsBuffer::format() const

    Accessor for the pixel format of the buffer.
*/

QT_END_NAMESPACE