Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwlclientbuffer.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qwlclientbuffer_p.h"
6
7
#
if
QT_CONFIG
(
opengl
)
8
#
include
"hardware_integration/qwlclientbufferintegration_p.h"
9
#
include
<
qpa
/
qplatformopenglcontext
.
h
>
10
#
include
<
QOpenGLTexture
>
11
#
endif
12
13
#
include
<
QtCore
/
QDebug
>
14
15
#
include
<
QtWaylandCompositor
/
private
/
wayland
-
wayland
-
server
-
protocol
.
h
>
16
#
include
"qwaylandsharedmemoryformathelper_p.h"
17
18
#
include
<
QtWaylandCompositor
/
private
/
qwaylandcompositor_p
.
h
>
19
20
QT_BEGIN_NAMESPACE
21
22
namespace
QtWayland
{
23
24
ClientBuffer
::
ClientBuffer
(
struct
::
wl_resource
*
buffer
)
25
:
m_buffer
(
buffer
)
26
{
27
}
28
29
30
ClientBuffer
::~
ClientBuffer
()
31
{
32
if
(
m_buffer
&&
m_committed
&& !
m_destroyed
)
33
sendRelease
();
34
}
35
36
void
ClientBuffer
::
sendRelease
()
37
{
38
Q_ASSERT
(
m_buffer
);
39
wl_buffer_send_release
(
m_buffer
);
40
m_committed
=
false
;
41
}
42
43
void
ClientBuffer
::
setDestroyed
()
44
{
45
m_destroyed
=
true
;
46
m_committed
=
false
;
47
m_buffer
=
nullptr
;
48
49
if
(!
m_refCount
.
loadAcquire
())
50
delete
this
;
51
}
52
53
void
ClientBuffer
::
ref
()
54
{
55
m_refCount
.
ref
();
56
}
57
58
void
ClientBuffer
::
deref
()
59
{
60
if
(!
m_refCount
.
deref
()) {
61
if
(
isCommitted
() &&
m_buffer
&& !
m_destroyed
)
62
sendRelease
();
63
if
(
m_destroyed
)
64
delete
this
;
65
}
66
}
67
68
void
ClientBuffer
::
setCommitted
(
QRegion
&
damage
)
69
{
70
m_damage
=
damage
;
71
m_committed
=
true
;
72
m_textureDirty
=
true
;
73
}
74
75
QWaylandBufferRef
::
BufferFormatEgl
ClientBuffer
::
bufferFormatEgl
()
const
76
{
77
return
QWaylandBufferRef
::
BufferFormatEgl_Null
;
78
}
79
80
SharedMemoryBuffer
::
SharedMemoryBuffer
(
wl_resource
*
bufferResource
)
81
:
ClientBuffer
(
bufferResource
)
82
{
83
84
}
85
86
QSize
SharedMemoryBuffer
::
size
()
const
87
{
88
if
(
wl_shm_buffer
*
shmBuffer
=
wl_shm_buffer_get
(
m_buffer
)) {
89
int
width
=
wl_shm_buffer_get_width
(
shmBuffer
);
90
int
height
=
wl_shm_buffer_get_height
(
shmBuffer
);
91
return
QSize
(
width
,
height
);
92
}
93
return
QSize
();
94
}
95
96
QWaylandSurface
::
Origin
SharedMemoryBuffer
::
origin
()
const
97
{
98
return
QWaylandSurface
::
OriginTopLeft
;
99
}
100
101
static
void
shmBufferCleanup
(
void
*data)
102
{
103
auto
*pool =
static_cast
<
struct
wl_shm_pool *>(data);
104
wl_shm_pool_unref(pool);
105
}
106
107
QImage
SharedMemoryBuffer
::
image
()
const
108
{
109
if
(
wl_shm_buffer
*
shmBuffer
=
wl_shm_buffer_get
(
m_buffer
)) {
110
int
width
=
wl_shm_buffer_get_width
(
shmBuffer
);
111
int
height
=
wl_shm_buffer_get_height
(
shmBuffer
);
112
int
bytesPerLine
=
wl_shm_buffer_get_stride
(
shmBuffer
);
113
114
// TODO: try to avoid QImage::convertToFormat()
115
wl_shm_format
shmFormat
=
wl_shm_format
(
wl_shm_buffer_get_format
(
shmBuffer
));
116
QImage
::
Format
format
=
QWaylandSharedMemoryFormatHelper
::
fromWaylandShmFormat
(
shmFormat
);
117
118
auto
*
pool
=
wl_shm_buffer_ref_pool
(
shmBuffer
);
119
uchar
*
data
=
static_cast
<
uchar
*>(
wl_shm_buffer_get_data
(
shmBuffer
));
120
return
QImage
(
data
,
width
,
height
,
bytesPerLine
,
format
, &
shmBufferCleanup
,
pool
);
121
}
122
123
return
QImage
();
124
}
125
126
#
if
QT_CONFIG
(
opengl
)
127
QOpenGLTexture
*
SharedMemoryBuffer
::
toOpenGlTexture
(
int
plane
)
128
{
129
Q_UNUSED
(
plane
);
130
if
(
isSharedMemory
()) {
131
if
(!
m_shmTexture
) {
132
m_shmTexture
.
reset
(
new
QOpenGLTexture
(
QOpenGLTexture
::
Target2D
));
133
m_shmTexture
->
create
();
134
}
135
if
(
m_textureDirty
) {
136
m_textureDirty
=
false
;
137
m_shmTexture
->
bind
();
138
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_NEAREST
);
139
// TODO: partial texture upload
140
QImage
image
=
this
->
image
();
141
m_shmTexture
->
setSize
(
image
.
width
(),
image
.
height
());
142
if
(
image
.
hasAlphaChannel
()) {
143
m_shmTexture
->
setFormat
(
QOpenGLTexture
::
RGBAFormat
);
144
if
(
image
.
format
() !=
QImage
::
Format_RGBA8888
)
145
image
=
image
.
convertToFormat
(
QImage
::
Format_RGBA8888
);
146
glTexImage2D
(
GL_TEXTURE_2D
, 0,
GL_RGBA
,
image
.
width
(),
image
.
height
(), 0,
GL_RGBA
,
GL_UNSIGNED_BYTE
,
image
.
constBits
());
147
}
else
{
148
m_shmTexture
->
setFormat
(
QOpenGLTexture
::
RGBFormat
);
149
if
(
image
.
format
() !=
QImage
::
Format_RGBX8888
)
150
image
=
image
.
convertToFormat
(
QImage
::
Format_RGBX8888
);
151
glTexImage2D
(
GL_TEXTURE_2D
, 0,
GL_RGB
,
image
.
width
(),
image
.
height
(), 0,
GL_RGB
,
GL_UNSIGNED_BYTE
,
image
.
constBits
());
152
}
153
//we can release the buffer after uploading, since we have a copy
154
if
(
isCommitted
())
155
sendRelease
();
156
}
157
return
m_shmTexture
.
data
();
158
}
159
return
nullptr
;
160
}
161
#
endif
162
163
}
164
165
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtWayland
Definition
qwaylanddisplay_p.h:54
QtWayland::shmBufferCleanup
static void shmBufferCleanup(void *data)
Definition
qwlclientbuffer.cpp:101
qtwayland
src
compositor
wayland_wrapper
qwlclientbuffer.cpp
Generated on
for Qt by
1.16.1