Changeset View
Changeset View
Standalone View
Standalone View
abstract_egl_backend.cpp
Show All 13 Lines | |||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "abstract_egl_backend.h" | 20 | #include "abstract_egl_backend.h" | ||
21 | #include "options.h" | 21 | #include "options.h" | ||
22 | #include "platform.h" | ||||
22 | #include "wayland_server.h" | 23 | #include "wayland_server.h" | ||
23 | #include <KWayland/Server/buffer_interface.h> | 24 | #include <KWayland/Server/buffer_interface.h> | ||
24 | #include <KWayland/Server/display.h> | 25 | #include <KWayland/Server/display.h> | ||
25 | #include <KWayland/Server/surface_interface.h> | 26 | #include <KWayland/Server/surface_interface.h> | ||
26 | // kwin libs | 27 | // kwin libs | ||
27 | #include <kwinglplatform.h> | 28 | #include <kwinglplatform.h> | ||
28 | // Qt | 29 | // Qt | ||
29 | #include <QOpenGLContext> | 30 | #include <QOpenGLContext> | ||
Show All 21 Lines | |||||
51 | 52 | | |||
52 | AbstractEglBackend::AbstractEglBackend() | 53 | AbstractEglBackend::AbstractEglBackend() | ||
53 | : OpenGLBackend() | 54 | : OpenGLBackend() | ||
54 | { | 55 | { | ||
55 | } | 56 | } | ||
56 | 57 | | |||
57 | AbstractEglBackend::~AbstractEglBackend() = default; | 58 | AbstractEglBackend::~AbstractEglBackend() = default; | ||
58 | 59 | | |||
59 | void AbstractEglBackend::cleanup() | 60 | void AbstractEglBackend::unbindWaylandDisplay() | ||
60 | { | 61 | { | ||
61 | if (eglUnbindWaylandDisplayWL && eglDisplay() != EGL_NO_DISPLAY) { | 62 | auto display = kwinApp()->platform()->sceneEglDisplay(); | ||
62 | eglUnbindWaylandDisplayWL(eglDisplay(), *(WaylandServer::self()->display())); | 63 | if (eglUnbindWaylandDisplayWL && display != EGL_NO_DISPLAY) { | ||
64 | eglUnbindWaylandDisplayWL(display, *(WaylandServer::self()->display())); | ||||
65 | } | ||||
63 | } | 66 | } | ||
67 | | ||||
68 | void AbstractEglBackend::cleanup() | ||||
69 | { | ||||
64 | cleanupGL(); | 70 | cleanupGL(); | ||
65 | doneCurrent(); | 71 | doneCurrent(); | ||
66 | eglDestroyContext(m_display, m_context); | 72 | eglDestroyContext(m_display, m_context); | ||
67 | cleanupSurfaces(); | 73 | cleanupSurfaces(); | ||
68 | eglTerminate(m_display); | | |||
69 | eglReleaseThread(); | 74 | eglReleaseThread(); | ||
70 | } | 75 | } | ||
71 | 76 | | |||
72 | void AbstractEglBackend::cleanupSurfaces() | 77 | void AbstractEglBackend::cleanupSurfaces() | ||
73 | { | 78 | { | ||
74 | if (m_surface != EGL_NO_SURFACE) { | 79 | if (m_surface != EGL_NO_SURFACE) { | ||
75 | eglDestroySurface(m_display, m_surface); | 80 | eglDestroySurface(m_display, m_surface); | ||
76 | } | 81 | } | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | |||||
132 | { | 137 | { | ||
133 | if (!WaylandServer::self()) { | 138 | if (!WaylandServer::self()) { | ||
134 | return; | 139 | return; | ||
135 | } | 140 | } | ||
136 | if (hasGLExtension(QByteArrayLiteral("EGL_WL_bind_wayland_display"))) { | 141 | if (hasGLExtension(QByteArrayLiteral("EGL_WL_bind_wayland_display"))) { | ||
137 | eglBindWaylandDisplayWL = (eglBindWaylandDisplayWL_func)eglGetProcAddress("eglBindWaylandDisplayWL"); | 142 | eglBindWaylandDisplayWL = (eglBindWaylandDisplayWL_func)eglGetProcAddress("eglBindWaylandDisplayWL"); | ||
138 | eglUnbindWaylandDisplayWL = (eglUnbindWaylandDisplayWL_func)eglGetProcAddress("eglUnbindWaylandDisplayWL"); | 143 | eglUnbindWaylandDisplayWL = (eglUnbindWaylandDisplayWL_func)eglGetProcAddress("eglUnbindWaylandDisplayWL"); | ||
139 | eglQueryWaylandBufferWL = (eglQueryWaylandBufferWL_func)eglGetProcAddress("eglQueryWaylandBufferWL"); | 144 | eglQueryWaylandBufferWL = (eglQueryWaylandBufferWL_func)eglGetProcAddress("eglQueryWaylandBufferWL"); | ||
145 | // only bind if not already done | ||||
146 | if (waylandServer()->display()->eglDisplay() != eglDisplay()) { | ||||
140 | if (!eglBindWaylandDisplayWL(eglDisplay(), *(WaylandServer::self()->display()))) { | 147 | if (!eglBindWaylandDisplayWL(eglDisplay(), *(WaylandServer::self()->display()))) { | ||
141 | eglUnbindWaylandDisplayWL = nullptr; | 148 | eglUnbindWaylandDisplayWL = nullptr; | ||
142 | eglQueryWaylandBufferWL = nullptr; | 149 | eglQueryWaylandBufferWL = nullptr; | ||
143 | } else { | 150 | } else { | ||
144 | waylandServer()->display()->setEglDisplay(eglDisplay()); | 151 | waylandServer()->display()->setEglDisplay(eglDisplay()); | ||
145 | } | 152 | } | ||
146 | } | 153 | } | ||
147 | } | 154 | } | ||
155 | } | ||||
148 | 156 | | |||
149 | void AbstractEglBackend::initClientExtensions() | 157 | void AbstractEglBackend::initClientExtensions() | ||
150 | { | 158 | { | ||
151 | // Get the list of client extensions | 159 | // Get the list of client extensions | ||
152 | const char* clientExtensionsCString = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); | 160 | const char* clientExtensionsCString = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); | ||
153 | const QByteArray clientExtensionsString = QByteArray::fromRawData(clientExtensionsCString, qstrlen(clientExtensionsCString)); | 161 | const QByteArray clientExtensionsString = QByteArray::fromRawData(clientExtensionsCString, qstrlen(clientExtensionsCString)); | ||
154 | if (clientExtensionsString.isEmpty()) { | 162 | if (clientExtensionsString.isEmpty()) { | ||
155 | // If eglQueryString() returned NULL, the implementation doesn't support | 163 | // If eglQueryString() returned NULL, the implementation doesn't support | ||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | 200 | { | |||
258 | if (ctx == EGL_NO_CONTEXT) { | 266 | if (ctx == EGL_NO_CONTEXT) { | ||
259 | qCCritical(KWIN_CORE) << "Create Context failed"; | 267 | qCCritical(KWIN_CORE) << "Create Context failed"; | ||
260 | return false; | 268 | return false; | ||
261 | } | 269 | } | ||
262 | m_context = ctx; | 270 | m_context = ctx; | ||
263 | return true; | 271 | return true; | ||
264 | } | 272 | } | ||
265 | 273 | | |||
274 | void AbstractEglBackend::setEglDisplay(const EGLDisplay &display) { | ||||
275 | m_display = display; | ||||
276 | kwinApp()->platform()->setSceneEglDisplay(display); | ||||
277 | } | ||||
278 | | ||||
266 | AbstractEglTexture::AbstractEglTexture(SceneOpenGL::Texture *texture, AbstractEglBackend *backend) | 279 | AbstractEglTexture::AbstractEglTexture(SceneOpenGL::Texture *texture, AbstractEglBackend *backend) | ||
267 | : SceneOpenGL::TexturePrivate() | 280 | : SceneOpenGL::TexturePrivate() | ||
268 | , q(texture) | 281 | , q(texture) | ||
269 | , m_backend(backend) | 282 | , m_backend(backend) | ||
270 | , m_image(EGL_NO_IMAGE_KHR) | 283 | , m_image(EGL_NO_IMAGE_KHR) | ||
271 | { | 284 | { | ||
272 | m_target = GL_TEXTURE_2D; | 285 | m_target = GL_TEXTURE_2D; | ||
273 | } | 286 | } | ||
▲ Show 20 Lines • Show All 212 Lines • Show Last 20 Lines |