2 * Copyright (C) 2014 Igalia S.L.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "PlatformDisplayWayland.h"
31 #include "GLContextEGL.h"
33 // These includes need to be in this order because wayland-egl.h defines WL_EGL_PLATFORM
34 // and egl.h checks that to decide whether it's Wayland platform.
35 #include <wayland-egl.h>
37 #include <EGL/eglext.h>
38 #include <wtf/Assertions.h>
42 const struct wl_registry_listener PlatformDisplayWayland::s_registryListener = {
44 [](void* data, struct wl_registry*, uint32_t name, const char* interface, uint32_t) {
45 static_cast<PlatformDisplayWayland*>(data)->registryGlobal(interface, name);
47 // globalRemoveCallback
48 [](void*, struct wl_registry*, uint32_t)
53 PlatformDisplayWayland::PlatformDisplayWayland(struct wl_display* display)
58 PlatformDisplayWayland::~PlatformDisplayWayland()
62 void PlatformDisplayWayland::initialize(wl_display* display)
65 m_registry.reset(wl_display_get_registry(m_display));
66 wl_registry_add_listener(m_registry.get(), &s_registryListener, this);
67 wl_display_roundtrip(m_display);
70 #if defined(EGL_KHR_platform_wayland)
71 const char* extensions = eglQueryString(nullptr, EGL_EXTENSIONS);
72 if (GLContext::isExtensionSupported(extensions, "EGL_KHR_platform_base")) {
73 if (auto* getPlatformDisplay = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress("eglGetPlatformDisplay")))
74 m_eglDisplay = getPlatformDisplay(EGL_PLATFORM_WAYLAND_KHR, m_display, nullptr);
75 } else if (GLContext::isExtensionSupported(extensions, "EGL_EXT_platform_base")) {
76 if (auto* getPlatformDisplay = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress("eglGetPlatformDisplayEXT")))
77 m_eglDisplay = getPlatformDisplay(EGL_PLATFORM_WAYLAND_KHR, m_display, nullptr);
80 m_eglDisplay = eglGetDisplay(m_display);
82 PlatformDisplay::initializeEGLDisplay();
86 void PlatformDisplayWayland::registryGlobal(const char* interface, uint32_t name)
88 if (!std::strcmp(interface, "wl_compositor"))
89 m_compositor.reset(static_cast<struct wl_compositor*>(wl_registry_bind(m_registry.get(), name, &wl_compositor_interface, 1)));
92 WlUniquePtr<struct wl_surface> PlatformDisplayWayland::createSurface() const
97 return WlUniquePtr<struct wl_surface>(wl_compositor_create_surface(m_compositor.get()));
100 } // namespace WebCore
102 #endif // PLATFORM(WAYLAND)