Qt 6.x
The Qt SDK
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
5
8
9#include <wayland-client-core.h>
10
11#include <QtCore/QDebug>
12#include <private/qeglconvenience_p.h>
13
14#ifndef EGL_EXT_platform_base
16#endif
17
18#ifndef EGL_PLATFORM_WAYLAND_KHR
19#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
20#endif
21
23
24namespace QtWaylandClient {
25
27 0
28};
29
31{
32 qCDebug(lcQpaWayland) << "Using Wayland-EGL";
33}
34
35
37{
38 eglTerminate(m_eglDisplay);
39}
40
42{
43#if QT_CONFIG(egl_extension_platform_wayland)
44 m_eglDisplay = eglGetPlatformDisplay(EGL_PLATFORM_WAYLAND_EXT, display->wl_display(), nullptr);
45#else
46 if (q_hasEglExtension(EGL_NO_DISPLAY, "EGL_EXT_platform_base")) {
47 if (q_hasEglExtension(EGL_NO_DISPLAY, "EGL_KHR_platform_wayland") ||
48 q_hasEglExtension(EGL_NO_DISPLAY, "EGL_EXT_platform_wayland") ||
49 q_hasEglExtension(EGL_NO_DISPLAY, "EGL_MESA_platform_wayland")) {
50
51 static PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplay = nullptr;
52 if (!eglGetPlatformDisplay)
53 eglGetPlatformDisplay = (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
54
55 m_eglDisplay = eglGetPlatformDisplay(EGL_PLATFORM_WAYLAND_KHR, display->wl_display(), nullptr);
56 } else {
57 qCWarning(lcQpaWayland) << "The EGL implementation does not support the Wayland platform";
58 return;
59 }
60 } else {
61 QByteArray eglPlatform = qgetenv("EGL_PLATFORM");
62 if (eglPlatform.isEmpty()) {
63 setenv("EGL_PLATFORM","wayland",true);
64 }
65
66 m_eglDisplay = eglGetDisplay((EGLNativeDisplayType) display->wl_display());
67 }
68#endif
69
70 m_display = display;
71
72 if (m_eglDisplay == EGL_NO_DISPLAY) {
73 qCWarning(lcQpaWayland) << "EGL not available";
74 return;
75 }
76
77 EGLint major,minor;
78 if (!eglInitialize(m_eglDisplay, &major, &minor)) {
79 qCWarning(lcQpaWayland) << "Failed to initialize EGL display" << Qt::hex << eglGetError();
80 m_eglDisplay = EGL_NO_DISPLAY;
81 return;
82 }
83
84 m_supportsThreading = true;
85 if (qEnvironmentVariableIsSet("QT_OPENGL_NO_SANITY_CHECK"))
86 return;
87
88 const char *vendor = eglQueryString(m_eglDisplay, EGL_VENDOR);
89 for (int i = 0; qwaylandegl_threadedgl_blacklist_vendor[i]; ++i) {
90 if (strstr(vendor, qwaylandegl_threadedgl_blacklist_vendor[i]) != 0) {
91 m_supportsThreading = false;
92 break;
93 }
94 }
95}
96
98{
99 return m_eglDisplay != EGL_NO_DISPLAY;
100}
101
103{
104 return m_supportsThreading;
105}
106
108{
109 return true;
110}
111
113{
114 return new QWaylandEglWindow(window, m_display);
115}
116
118{
119 QSurfaceFormat fmt = glFormat;
120 if (m_display->supportsWindowDecoration())
121 fmt.setAlphaBufferSize(8);
122 return new QWaylandGLContext(m_eglDisplay, m_display, fmt, share);
123}
124
126{
127 switch (resource) {
128 case EglDisplay:
129 return m_eglDisplay;
130 default:
131 break;
132 }
133 return nullptr;
134}
135
137{
139 switch (resource) {
140 case EglConfig:
141 return static_cast<QWaylandGLContext *>(context)->eglConfig();
142 case EglContext:
143 return static_cast<QWaylandGLContext *>(context)->eglContext();
144 case EglDisplay:
145 return m_eglDisplay;
146 default:
147 break;
148 }
149 return nullptr;
150}
151
153{
154 return m_eglDisplay;
155}
156
157}
158
\inmodule QtCore
Definition qbytearray.h:57
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
Definition qbytearray.h:106
The QPlatformOpenGLContext class provides an abstraction for native GL contexts.
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
\inmodule QtGui
Definition qwindow.h:63
void * nativeResourceForContext(NativeResource resource, QPlatformOpenGLContext *context) override
QPlatformOpenGLContext * createPlatformOpenGLContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share) const override
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
static const char * qwaylandegl_threadedgl_blacklist_vendor[]
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
static void * context
bool q_hasEglExtension(EGLDisplay display, const char *extensionName)
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform
void * native_display
void const EGLint * attrib_list
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
QVideoFrameFormat::PixelFormat fmt
QT_BEGIN_NAMESPACE Platform platform()
EGLDisplay(* PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform, void *native_display, const EGLint *attrib_list)
aWidget window() -> setWindowTitle("New Window Title")
[2]