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
qwaylandeglwindow.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qwaylandeglwindow_p.h"
6
7
#
include
<
QtWaylandClient
/
private
/
qwaylandscreen_p
.
h
>
8
#
include
<
QtWaylandClient
/
private
/
qwaylandsurface_p
.
h
>
9
#
include
"qwaylandglcontext_p.h"
10
11
#
include
<
QtGui
/
private
/
qeglconvenience_p
.
h
>
12
13
#
include
<
QDebug
>
14
#
include
<
QtGui
/
QWindow
>
15
#
include
<
qpa
/
qwindowsysteminterface
.
h
>
16
#
include
<
QOpenGLFramebufferObject
>
17
#
include
<
QOpenGLContext
>
18
19
QT_BEGIN_NAMESPACE
20
21
namespace
QtWaylandClient
{
22
23
QWaylandEglWindow
::
QWaylandEglWindow
(
QWindow
*
window
,
QWaylandDisplay
*
display
)
24
:
QWaylandWindow
(
window
,
display
)
25
,
m_clientBufferIntegration
(
static_cast
<
QWaylandEglClientBufferIntegration
*>(
mDisplay
->
clientBufferIntegration
()))
26
{
27
connect
(
display
, &
QWaylandDisplay
::
connected
,
this
, [
this
] {
28
m_clientBufferIntegration
=
static_cast
<
QWaylandEglClientBufferIntegration
*>(
29
mDisplay
->
clientBufferIntegration
());
30
});
31
ensureSize
();
32
}
33
34
QWaylandEglWindow
::~
QWaylandEglWindow
()
35
{
36
if
(
m_eglSurface
) {
37
eglDestroySurface
(
m_clientBufferIntegration
->
eglDisplay
(),
m_eglSurface
);
38
m_eglSurface
= 0;
39
}
40
41
if
(
m_waylandEglWindow
)
42
wl_egl_window_destroy
(
m_waylandEglWindow
);
43
44
delete
m_contentFBO
;
45
}
46
47
QWaylandWindow
::
WindowType
QWaylandEglWindow
::
windowType
()
const
48
{
49
return
QWaylandWindow
::
Egl
;
50
}
51
52
void
QWaylandEglWindow
::
ensureSize
()
53
{
54
// this is always called on the main thread
55
QRect
rect
=
geometry
();
56
QMargins
margins
=
clientSideMargins
();
57
QSize
sizeWithMargins
= (
rect
.
size
() +
QSize
(
margins
.
left
() +
margins
.
right
(),
margins
.
top
() +
margins
.
bottom
())) *
scale
();
58
{
59
// keep a cache of the size that is safely accessible from the render thread
60
QWriteLocker
lock
(&
m_bufferSizeLock
);
61
m_bufferSize
=
sizeWithMargins
;
62
}
63
}
64
65
QSize
QWaylandEglWindow
::
bufferSize
()
const
66
{
67
QReadLocker
lock
(&
m_bufferSizeLock
);
68
return
m_bufferSize
;
69
}
70
71
void
QWaylandEglWindow
::
updateSurfaceSize
(
const
QSize
&
initialSize
)
72
{
73
// potentially called from a render thread
74
// eglSurfaceLock should be locked before calling this method
75
76
if
(!
m_waylandEglWindow
)
77
return
;
78
79
int
current_width
= 0;
80
int
current_height
= 0;
81
static
bool
disableResizeCheck
=
qgetenv
(
"QT_WAYLAND_DISABLE_RESIZECHECK"
).
toInt
();
82
83
if
(!
disableResizeCheck
) {
84
wl_egl_window_get_attached_size
(
m_waylandEglWindow
, &
current_width
, &
current_height
);
85
}
86
if
(
disableResizeCheck
|| (
current_width
!=
initialSize
.
width
() ||
current_height
!=
initialSize
.
height
()) ||
m_appliedBufferSize
!=
initialSize
) {
87
wl_egl_window_resize
(
m_waylandEglWindow
,
initialSize
.
width
(),
initialSize
.
height
(),
mOffset
.
x
(),
mOffset
.
y
());
88
m_appliedBufferSize
=
initialSize
;
89
mOffset
=
QPoint
();
90
m_resize
=
true
;
91
}
92
}
93
94
void
QWaylandEglWindow
::
createSurface
(
const
QSize
&
initialSize
)
95
{
96
// potentially called from a render thread
97
// eglSurfaceLock should be locked before calling this method
98
99
QReadLocker
locker
(&
mSurfaceLock
);
100
if
(
mSurface
) {
101
wl_egl_window
*
eglWindow
=
wl_egl_window_create
(
mSurface
->
object
(),
initialSize
.
width
(),
initialSize
.
height
());
102
if
(
Q_UNLIKELY
(!
eglWindow
)) {
103
qCWarning
(
lcQpaWayland
,
"Could not create wl_egl_window with size %dx%d\n"
,
initialSize
.
width
(),
initialSize
.
height
());
104
return
;
105
}
106
107
QSurfaceFormat
fmt
=
window
()->
requestedFormat
();
108
if
(
mDisplay
->
supportsWindowDecoration
())
109
fmt
.
setAlphaBufferSize
(8);
110
EGLConfig
eglConfig
=
q_configFromGLFormat
(
m_clientBufferIntegration
->
eglDisplay
(),
fmt
);
111
setFormat
(
q_glFormatFromConfig
(
m_clientBufferIntegration
->
eglDisplay
(),
eglConfig
,
fmt
));
112
113
EGLSurface
eglSurface
=
eglCreateWindowSurface
(
m_clientBufferIntegration
->
eglDisplay
(),
eglConfig
, (
EGLNativeWindowType
)
eglWindow
, 0);
114
if
(
Q_UNLIKELY
(
eglSurface
==
EGL_NO_SURFACE
)) {
115
qCWarning
(
lcQpaWayland
,
"Could not create EGL surface (EGL error 0x%x)\n"
,
eglGetError
());
116
wl_egl_window_destroy
(
eglWindow
);
117
return
;
118
}
119
120
m_waylandEglWindow
=
eglWindow
;
121
m_eglSurface
=
eglSurface
;
122
m_appliedBufferSize
=
initialSize
;
123
}
124
}
125
126
EGLSurface
QWaylandEglWindow
::
eglSurface
()
const
127
{
128
return
m_eglSurface
;
129
}
130
131
QRect
QWaylandEglWindow
::
contentsRect
()
const
132
{
133
QRect
r
=
geometry
();
134
QMargins
m
=
clientSideMargins
();
135
return
QRect
(
m
.
left
(),
m
.
bottom
(),
r
.
width
(),
r
.
height
());
136
}
137
138
void
QWaylandEglWindow
::
invalidateSurface
()
139
{
140
QMutexLocker
lock
(&
m_eglSurfaceLock
);
141
142
if
(
m_eglSurface
) {
143
eglDestroySurface
(
m_clientBufferIntegration
->
eglDisplay
(),
m_eglSurface
);
144
m_eglSurface
= 0;
145
}
146
if
(
m_waylandEglWindow
) {
147
wl_egl_window_destroy
(
m_waylandEglWindow
);
148
m_waylandEglWindow
=
nullptr
;
149
}
150
delete
m_contentFBO
;
151
m_contentFBO
=
nullptr
;
152
}
153
154
QMutex
*
QWaylandEglWindow
::
eglSurfaceLock
()
155
{
156
return
&
m_eglSurfaceLock
;
157
}
158
GLuint
QWaylandEglWindow
::
contentFBO
()
const
159
{
160
if
(!
decoration
())
161
return
0;
162
163
if
(
m_resize
|| !
m_contentFBO
) {
164
QOpenGLFramebufferObject
*
old
=
m_contentFBO
;
165
QSize
fboSize
=
geometry
().
size
() *
scale
();
166
m_contentFBO
=
new
QOpenGLFramebufferObject
(
fboSize
.
width
(),
fboSize
.
height
(),
QOpenGLFramebufferObject
::
CombinedDepthStencil
);
167
168
delete
old
;
169
m_resize
=
false
;
170
}
171
172
return
m_contentFBO
->
handle
();
173
}
174
175
GLuint
QWaylandEglWindow
::
contentTexture
()
const
176
{
177
return
m_contentFBO
->
texture
();
178
}
179
180
void
QWaylandEglWindow
::
bindContentFBO
()
181
{
182
if
(
decoration
()) {
183
contentFBO
();
184
m_contentFBO
->
bind
();
185
}
186
}
187
188
}
189
190
QT_END_NAMESPACE
191
192
#
include
"moc_qwaylandeglwindow_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qrandomaccessasyncfile_darwin.mm:17
QtWaylandClient
Definition
qwaylandclientextension.h:16
qtbase
src
plugins
platforms
wayland
plugins
hardwareintegration
wayland-egl
qwaylandeglwindow.cpp
Generated on
for Qt by
1.16.1