| 1 | /* |
| 2 | * Copyright (C) 2017 Igalia S.L. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 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. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE 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 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. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "WaylandCompositorDisplay.h" |
| 28 | |
| 29 | #if PLATFORM(WAYLAND) |
| 30 | |
| 31 | #include "WebKitWaylandClientProtocol.h" |
| 32 | #include "WebPage.h" |
| 33 | |
| 34 | namespace WebKit { |
| 35 | using namespace WebCore; |
| 36 | |
| 37 | std::unique_ptr<WaylandCompositorDisplay> WaylandCompositorDisplay::create(const String& displayName) |
| 38 | { |
| 39 | if (displayName.isNull()) |
| 40 | return nullptr; |
| 41 | |
| 42 | if (PlatformDisplay::sharedDisplay().type() != PlatformDisplay::Type::Wayland) |
| 43 | return nullptr; |
| 44 | |
| 45 | struct wl_display* display = wl_display_connect(displayName.utf8().data()); |
| 46 | if (!display) { |
| 47 | WTFLogAlways("WaylandCompositorDisplay initialization: failed to connect to the Wayland display: %s" , displayName.utf8().data()); |
| 48 | return nullptr; |
| 49 | } |
| 50 | |
| 51 | auto compositorDisplay = std::unique_ptr<WaylandCompositorDisplay>(new WaylandCompositorDisplay(display)); |
| 52 | compositorDisplay->initialize(); |
| 53 | return compositorDisplay; |
| 54 | } |
| 55 | |
| 56 | void WaylandCompositorDisplay::bindSurfaceToPage(struct wl_surface* surface, WebPage& page) |
| 57 | { |
| 58 | if (!m_webkitgtk) |
| 59 | return; |
| 60 | |
| 61 | wl_webkitgtk_bind_surface_to_page(reinterpret_cast<struct wl_webkitgtk*>(m_webkitgtk.get()), surface, page.pageID()); |
| 62 | wl_display_roundtrip(m_display); |
| 63 | } |
| 64 | |
| 65 | WaylandCompositorDisplay::WaylandCompositorDisplay(struct wl_display* display) |
| 66 | : PlatformDisplayWayland(display, NativeDisplayOwned::Yes) |
| 67 | { |
| 68 | PlatformDisplay::setSharedDisplayForCompositing(*this); |
| 69 | } |
| 70 | |
| 71 | void WaylandCompositorDisplay::registryGlobal(const char* interface, uint32_t name) |
| 72 | { |
| 73 | PlatformDisplayWayland::registryGlobal(interface, name); |
| 74 | if (!std::strcmp(interface, "wl_webkitgtk" )) |
| 75 | m_webkitgtk.reset(static_cast<struct wl_proxy*>(wl_registry_bind(m_registry.get(), name, &wl_webkitgtk_interface, 1))); |
| 76 | } |
| 77 | |
| 78 | } // namespace WebKit |
| 79 | |
| 80 | #endif // PLATFORM(WAYLAND) |
| 81 | |