Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qwaylandeglclientbufferintegration.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
"qwaylandeglclientbufferintegration_p.h"
6
7
#
include
"qwaylandeglwindow_p.h"
8
#
include
"qwaylandglcontext_p.h"
9
10
#
include
<
wayland
-
client
-
core
.
h
>
11
12
#
include
<
QtCore
/
QDebug
>
13
#
include
<
private
/
qeglconvenience_p
.
h
>
14
#
include
<
private
/
qeglpbuffer_p
.
h
>
15
16
#
ifndef
EGL_EXT_platform_base
17
typedef
EGLDisplay
(*
PFNEGLGETPLATFORMDISPLAYEXTPROC
) (EGLenum platform,
void
*native_display,
const
EGLint *attrib_list);
18
#
endif
19
20
#
ifndef
EGL_PLATFORM_WAYLAND_KHR
21
#
define
EGL_PLATFORM_WAYLAND_KHR
0x31D8
22
#
endif
23
24
QT_BEGIN_NAMESPACE
25
26
namespace
QtWaylandClient
{
27
28
static
const
char
*
qwaylandegl_threadedgl_blacklist_vendor
[] = {
29
0
30
};
31
32
QWaylandEglClientBufferIntegration
::
QWaylandEglClientBufferIntegration
()
33
{
34
qCDebug
(
lcQpaWayland
) <<
"Using Wayland-EGL"
;
35
}
36
37
38
QWaylandEglClientBufferIntegration
::~
QWaylandEglClientBufferIntegration
()
39
{
40
eglTerminate
(
m_eglDisplay
);
41
}
42
43
void
QWaylandEglClientBufferIntegration
::
initialize
(
QWaylandDisplay
*
display
)
44
{
45
#
if
QT_CONFIG
(
egl_extension_platform_wayland
)
46
m_eglDisplay
=
eglGetPlatformDisplay
(
EGL_PLATFORM_WAYLAND_EXT
,
display
->
wl_display
(),
nullptr
);
47
#
else
48
if
(
q_hasEglExtension
(
EGL_NO_DISPLAY
,
"EGL_EXT_platform_base"
)) {
49
if
(
q_hasEglExtension
(
EGL_NO_DISPLAY
,
"EGL_KHR_platform_wayland"
) ||
50
q_hasEglExtension
(
EGL_NO_DISPLAY
,
"EGL_EXT_platform_wayland"
) ||
51
q_hasEglExtension
(
EGL_NO_DISPLAY
,
"EGL_MESA_platform_wayland"
)) {
52
53
static
PFNEGLGETPLATFORMDISPLAYEXTPROC
eglGetPlatformDisplay
=
nullptr
;
54
if
(!
eglGetPlatformDisplay
)
55
eglGetPlatformDisplay
= (
PFNEGLGETPLATFORMDISPLAYEXTPROC
)
eglGetProcAddress
(
"eglGetPlatformDisplayEXT"
);
56
57
m_eglDisplay
=
eglGetPlatformDisplay
(
EGL_PLATFORM_WAYLAND_KHR
,
display
->
wl_display
(),
nullptr
);
58
}
else
{
59
qCWarning
(
lcQpaWayland
) <<
"The EGL implementation does not support the Wayland platform"
;
60
return
;
61
}
62
}
else
{
63
QByteArray
eglPlatform
=
qgetenv
(
"EGL_PLATFORM"
);
64
if
(
eglPlatform
.
isEmpty
()) {
65
setenv
(
"EGL_PLATFORM"
,
"wayland"
,
true
);
66
}
67
68
m_eglDisplay
=
eglGetDisplay
((
EGLNativeDisplayType
)
display
->
wl_display
());
69
}
70
#
endif
71
72
m_display
=
display
;
73
74
if
(
m_eglDisplay
==
EGL_NO_DISPLAY
) {
75
qCWarning
(
lcQpaWayland
) <<
"EGL not available"
;
76
return
;
77
}
78
79
EGLint
major
,
minor
;
80
if
(!
eglInitialize
(
m_eglDisplay
, &
major
, &
minor
)) {
81
qCWarning
(
lcQpaWayland
) <<
"Failed to initialize EGL display"
<<
Qt
::
hex
<<
eglGetError
();
82
m_eglDisplay
=
EGL_NO_DISPLAY
;
83
return
;
84
}
85
86
const
EGLint
rgb888Attributes
[] = {
87
EGL_RED_SIZE
, 8,
88
EGL_GREEN_SIZE
, 8,
89
EGL_BLUE_SIZE
, 8,
90
EGL_SURFACE_TYPE
,
EGL_WINDOW_BIT
,
91
EGL_NONE
92
};
93
EGLint
rgb888ConfigCount
= 0;
94
m_hasRgb888WindowConfig
=
95
eglChooseConfig
(
m_eglDisplay
,
rgb888Attributes
,
nullptr
, 0, &
rgb888ConfigCount
)
96
&&
rgb888ConfigCount
> 0;
97
98
m_supportsThreading
=
true
;
99
if
(
qEnvironmentVariableIsSet
(
"QT_OPENGL_NO_SANITY_CHECK"
))
100
return
;
101
102
const
char
*
vendor
=
eglQueryString
(
m_eglDisplay
,
EGL_VENDOR
);
103
for
(
int
i
= 0;
qwaylandegl_threadedgl_blacklist_vendor
[
i
]; ++
i
) {
104
if
(
strstr
(
vendor
,
qwaylandegl_threadedgl_blacklist_vendor
[
i
]) != 0) {
105
m_supportsThreading
=
false
;
106
break
;
107
}
108
}
109
}
110
111
bool
QWaylandEglClientBufferIntegration
::
isValid
()
const
112
{
113
return
m_eglDisplay
!=
EGL_NO_DISPLAY
;
114
}
115
116
bool
QWaylandEglClientBufferIntegration
::
supportsThreadedOpenGL
()
const
117
{
118
return
m_supportsThreading
;
119
}
120
121
QWaylandWindow
*
QWaylandEglClientBufferIntegration
::
createEglWindow
(
QWindow
*
window
)
122
{
123
return
new
QWaylandEglWindow
(
window
,
m_display
);
124
}
125
126
QPlatformOpenGLContext
*
QWaylandEglClientBufferIntegration
::
createPlatformOpenGLContext
(
const
QSurfaceFormat
&
glFormat
,
QPlatformOpenGLContext
*
share
)
const
127
{
128
return
new
QWaylandGLContext
(
m_eglDisplay
,
adjustedFormat
(
glFormat
),
share
);
129
}
130
131
// Returns the format with 8 bits requested for each color channel when no
132
// color sizes have been specified.
133
//
134
// With unspecified color sizes, the EGL config sorting rules prefer the
135
// smallest buffer size, which typically results in a 16-bit (RGB565) config.
136
// Window surfaces used to request an alpha channel for the client-side
137
// decorations, which implied a 32-bit config. Since the decorations are now
138
// in subsurfaces, ask for 24-bit color explicitly instead. Explicitly
139
// requested sizes are left untouched, and so is the format when the display
140
// has no such config, as QEglConfigChooser never relaxes color sizes.
141
QSurfaceFormat
142
QWaylandEglClientBufferIntegration
::
adjustedFormat
(
const
QSurfaceFormat
&
format
)
const
143
{
144
QSurfaceFormat
fmt
=
format
;
145
if
(
m_hasRgb888WindowConfig
&&
fmt
.
redBufferSize
() <= 0 &&
fmt
.
greenBufferSize
() <= 0
146
&&
fmt
.
blueBufferSize
() <= 0) {
147
fmt
.
setRedBufferSize
(8);
148
fmt
.
setGreenBufferSize
(8);
149
fmt
.
setBlueBufferSize
(8);
150
}
151
return
fmt
;
152
}
153
154
QOpenGLContext
*
QWaylandEglClientBufferIntegration
::
createOpenGLContext
(
EGLContext
context
,
EGLDisplay
contextDisplay
,
QOpenGLContext
*
shareContext
)
const
155
{
156
return
QEGLPlatformContext
::
createFrom
<
QWaylandGLContext
>(
context
,
contextDisplay
,
m_eglDisplay
,
shareContext
);
157
}
158
159
bool
QWaylandEglClientBufferIntegration
::
canCreatePlatformOffscreenSurface
()
const
160
{
161
return
true
;
162
}
163
164
QPlatformOffscreenSurface
*
QWaylandEglClientBufferIntegration
::
createPlatformOffscreenSurface
(
QOffscreenSurface
*
surface
)
const
165
{
166
return
new
QEGLPbuffer
(
m_eglDisplay
,
surface
->
requestedFormat
(),
surface
);
167
}
168
169
void
*
QWaylandEglClientBufferIntegration
::
nativeResource
(
NativeResource
resource
)
170
{
171
switch
(
resource
) {
172
case
EglDisplay
:
173
return
m_eglDisplay
;
174
default
:
175
break
;
176
}
177
return
nullptr
;
178
}
179
180
void
*
QWaylandEglClientBufferIntegration
::
nativeResourceForContext
(
NativeResource
resource
,
QPlatformOpenGLContext
*
context
)
181
{
182
Q_ASSERT
(
context
);
183
switch
(
resource
) {
184
case
EglConfig
:
185
return
static_cast
<
QWaylandGLContext
*>(
context
)->
eglConfig
();
186
case
EglContext
:
187
return
static_cast
<
QWaylandGLContext
*>(
context
)->
eglContext
();
188
case
EglDisplay
:
189
return
m_eglDisplay
;
190
default
:
191
break
;
192
}
193
return
nullptr
;
194
}
195
196
EGLDisplay
QWaylandEglClientBufferIntegration
::
eglDisplay
()
const
197
{
198
return
m_eglDisplay
;
199
}
200
201
}
202
203
QT_END_NAMESPACE
QtWaylandClient
Definition
qwaylandclientextension.h:16
QtWaylandClient::qwaylandegl_threadedgl_blacklist_vendor
static const char * qwaylandegl_threadedgl_blacklist_vendor[]
Definition
qwaylandeglclientbufferintegration.cpp:28
EGL_PLATFORM_WAYLAND_KHR
#define EGL_PLATFORM_WAYLAND_KHR
Definition
qwaylandeglclientbufferintegration.cpp:21
PFNEGLGETPLATFORMDISPLAYEXTPROC
EGLDisplay(*) PFNEGLGETPLATFORMDISPLAYEXTPROC(EGLenum platform, void *native_display, const EGLint *attrib_list)
Definition
qwaylandeglclientbufferintegration.cpp:17
qtbase
src
plugins
platforms
wayland
plugins
hardwareintegration
wayland-egl
qwaylandeglclientbufferintegration.cpp
Generated on
for Qt by
1.18.0