[GTK][WAYLAND] Create WaylandCompositorDisplay unconditionally when initializing...
authormagomez@igalia.com <magomez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Jun 2017 12:29:03 +0000 (12:29 +0000)
committermagomez@igalia.com <magomez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Jun 2017 12:29:03 +0000 (12:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173598

Reviewed by Carlos Garcia Campos.

Move WaylandCompositorDisplay code to its own files so it can be used from other classes. Then, instead of
storing the waylandCompositorDisplayName in the WebProcess, keep a WaylandCompositorDisplay instance that
is created during the initialization. This way the appropriate sharedDisplayForCompositing will be set
since the creation of the WebProcess.

* PlatformGTK.cmake:
* WebProcess/WebPage/gtk/AcceleratedSurfaceWayland.cpp:
(WebKit::AcceleratedSurfaceWayland::create):
(WebKit::AcceleratedSurfaceWayland::AcceleratedSurfaceWayland):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess):
* WebProcess/WebProcess.h:
(WebKit::WebProcess::waylandCompositorDisplay):
* WebProcess/gtk/WaylandCompositorDisplay.cpp: Added.
(WebKit::WaylandCompositorDisplay::create):
(WebKit::WaylandCompositorDisplay::bindSurfaceToPage):
(WebKit::WaylandCompositorDisplay::WaylandCompositorDisplay):
(WebKit::WaylandCompositorDisplay::registryGlobal):
* WebProcess/gtk/WaylandCompositorDisplay.h: Added.
* WebProcess/soup/WebProcessSoup.cpp:
(WebKit::WebProcess::platformInitializeWebProcess):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218629 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/PlatformGTK.cmake
Source/WebKit2/WebProcess/WebPage/gtk/AcceleratedSurfaceWayland.cpp
Source/WebKit2/WebProcess/WebProcess.cpp
Source/WebKit2/WebProcess/WebProcess.h
Source/WebKit2/WebProcess/gtk/WaylandCompositorDisplay.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/gtk/WaylandCompositorDisplay.h [new file with mode: 0644]
Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp

index 532591a..9c1fa2b 100644 (file)
@@ -1,3 +1,32 @@
+2017-06-21  Miguel Gomez  <magomez@igalia.com>
+
+        [GTK][WAYLAND] Create WaylandCompositorDisplay unconditionally when initializing the WebProcess
+        https://bugs.webkit.org/show_bug.cgi?id=173598
+
+        Reviewed by Carlos Garcia Campos.
+
+        Move WaylandCompositorDisplay code to its own files so it can be used from other classes. Then, instead of
+        storing the waylandCompositorDisplayName in the WebProcess, keep a WaylandCompositorDisplay instance that
+        is created during the initialization. This way the appropriate sharedDisplayForCompositing will be set
+        since the creation of the WebProcess.
+
+        * PlatformGTK.cmake:
+        * WebProcess/WebPage/gtk/AcceleratedSurfaceWayland.cpp:
+        (WebKit::AcceleratedSurfaceWayland::create):
+        (WebKit::AcceleratedSurfaceWayland::AcceleratedSurfaceWayland):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess):
+        * WebProcess/WebProcess.h:
+        (WebKit::WebProcess::waylandCompositorDisplay):
+        * WebProcess/gtk/WaylandCompositorDisplay.cpp: Added.
+        (WebKit::WaylandCompositorDisplay::create):
+        (WebKit::WaylandCompositorDisplay::bindSurfaceToPage):
+        (WebKit::WaylandCompositorDisplay::WaylandCompositorDisplay):
+        (WebKit::WaylandCompositorDisplay::registryGlobal):
+        * WebProcess/gtk/WaylandCompositorDisplay.h: Added.
+        * WebProcess/soup/WebProcessSoup.cpp:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
 2017-06-21  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Move WebGtkExtensionManager and WebGtkInjectedBundleMain to glib API dir
index 2215f3f..d8962de 100644 (file)
@@ -397,6 +397,7 @@ list(APPEND WebKit2_SOURCES
     WebProcess/WebPage/gtk/WebPageGtk.cpp
     WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp
 
+    WebProcess/gtk/WaylandCompositorDisplay.cpp
     WebProcess/gtk/WebProcessMainGtk.cpp
 
     WebProcess/soup/WebKitSoupRequestInputStream.cpp
@@ -795,6 +796,7 @@ list(APPEND WebKit2_INCLUDE_DIRECTORIES
     "${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/gtk/DOM"
     "${WEBKIT2_DIR}/WebProcess/Plugins/Netscape/unix"
     "${WEBKIT2_DIR}/WebProcess/Plugins/Netscape/x11"
+    "${WEBKIT2_DIR}/WebProcess/gtk"
     "${WEBKIT2_DIR}/WebProcess/soup"
     "${WEBKIT2_DIR}/WebProcess/unix"
     "${WEBKIT2_DIR}/WebProcess/WebCoreSupport/gtk"
index 3cf528a..c7332b6 100644 (file)
 
 #if PLATFORM(WAYLAND)
 
-#include "WebKit2WaylandClientProtocol.h"
+#include "WaylandCompositorDisplay.h"
 #include "WebProcess.h"
-#include <WebCore/PlatformDisplayWayland.h>
-#include <cstring>
 #include <wayland-egl.h>
-#include <wtf/NeverDestroyed.h>
 
 using namespace WebCore;
 
 namespace WebKit {
 
-class WaylandCompositorDisplay final : public PlatformDisplayWayland {
-    WTF_MAKE_NONCOPYABLE(WaylandCompositorDisplay);
-public:
-    static std::unique_ptr<WaylandCompositorDisplay> create()
-    {
-        struct wl_display* display = wl_display_connect(WebProcess::singleton().waylandCompositorDisplayName().utf8().data());
-        if (!display) {
-            WTFLogAlways("PlatformDisplayWayland initialization: failed to connect to the Wayland display: %s", WebProcess::singleton().waylandCompositorDisplayName().utf8().data());
-            return nullptr;
-        }
-
-        return std::unique_ptr<WaylandCompositorDisplay>(new WaylandCompositorDisplay(display));
-    }
-
-    void bindSurfaceToPage(struct wl_surface* surface, WebPage& page)
-    {
-        if (!m_webkitgtk)
-            return;
-
-        wl_webkitgtk_bind_surface_to_page(reinterpret_cast<struct wl_webkitgtk*>(m_webkitgtk.get()), surface, page.pageID());
-        wl_display_roundtrip(m_display);
-    }
-
-private:
-    WaylandCompositorDisplay(struct wl_display* display)
-    {
-        initialize(display);
-        PlatformDisplay::setSharedDisplayForCompositing(*this);
-    }
-
-    void registryGlobal(const char* interface, uint32_t name) override
-    {
-        PlatformDisplayWayland::registryGlobal(interface, name);
-        if (!std::strcmp(interface, "wl_webkitgtk"))
-            m_webkitgtk.reset(static_cast<struct wl_proxy*>(wl_registry_bind(m_registry.get(), name, &wl_webkitgtk_interface, 1)));
-    }
-
-    WlUniquePtr<struct wl_proxy> m_webkitgtk;
-};
-
-static std::unique_ptr<WaylandCompositorDisplay>& waylandCompositorDisplay()
-{
-    static NeverDestroyed<std::unique_ptr<WaylandCompositorDisplay>> waylandDisplay(WaylandCompositorDisplay::create());
-    return waylandDisplay;
-}
-
 std::unique_ptr<AcceleratedSurfaceWayland> AcceleratedSurfaceWayland::create(WebPage& webPage, Client& client)
 {
-    return waylandCompositorDisplay() ? std::unique_ptr<AcceleratedSurfaceWayland>(new AcceleratedSurfaceWayland(webPage, client)) : nullptr;
+    return WebProcess::singleton().waylandCompositorDisplay() ? std::unique_ptr<AcceleratedSurfaceWayland>(new AcceleratedSurfaceWayland(webPage, client)) : nullptr;
 }
 
 AcceleratedSurfaceWayland::AcceleratedSurfaceWayland(WebPage& webPage, Client& client)
     : AcceleratedSurface(webPage, client)
-    , m_surface(waylandCompositorDisplay()->createSurface())
+    , m_surface(WebProcess::singleton().waylandCompositorDisplay()->createSurface())
     , m_window(wl_egl_window_create(m_surface.get(), std::max(1, m_size.width()), std::max(1, m_size.height())))
 {
-    waylandCompositorDisplay()->bindSurfaceToPage(m_surface.get(), m_webPage);
+    WebProcess::singleton().waylandCompositorDisplay()->bindSurfaceToPage(m_surface.get(), m_webPage);
 }
 
 AcceleratedSurfaceWayland::~AcceleratedSurfaceWayland()
index 0359d23..4575354 100644 (file)
 #include <wtf/RunLoop.h>
 #include <wtf/text/StringHash.h>
 
+#if PLATFORM(WAYLAND)
+#include "WaylandCompositorDisplay.h"
+#endif
+
 #if PLATFORM(COCOA)
 #include "CookieStorageShim.h"
 #include "ObjCObjectGraph.h"
@@ -313,10 +317,6 @@ void WebProcess::initializeWebProcess(WebProcessCreationParameters&& parameters)
     m_applicationCacheStorage->setDefaultOriginQuota(25ULL * 1024 * 1024);
 #endif
 
-#if PLATFORM(WAYLAND)
-    m_waylandCompositorDisplayName = parameters.waylandCompositorDisplayName;
-#endif
-
 #if ENABLE(VIDEO)
     if (!parameters.mediaCacheDirectory.isEmpty())
         WebCore::HTMLMediaElement::setMediaCacheDirectory(parameters.mediaCacheDirectory);
index abf0804..c4656e1 100644 (file)
@@ -79,6 +79,7 @@ class LibWebRTCNetwork;
 class NetworkProcessConnection;
 class ObjCObjectGraph;
 class UserData;
+class WaylandCompositorDisplay;
 class WebAutomationSessionProxy;
 class WebConnectionToUIProcess;
 class WebFrame;
@@ -206,7 +207,7 @@ public:
 #endif
 
 #if PLATFORM(WAYLAND)
-    String waylandCompositorDisplayName() const { return m_waylandCompositorDisplayName; }
+    WaylandCompositorDisplay* waylandCompositorDisplay() const { return m_waylandCompositorDisplay.get(); }
 #endif
 
     RefPtr<API::Object> transformHandlesToObjects(API::Object*);
@@ -430,7 +431,7 @@ private:
     HashMap<WebCore::UserGestureToken *, uint64_t> m_userGestureTokens;
 
 #if PLATFORM(WAYLAND)
-    String m_waylandCompositorDisplayName;
+    std::unique_ptr<WaylandCompositorDisplay> m_waylandCompositorDisplay;
 #endif
 };
 
diff --git a/Source/WebKit2/WebProcess/gtk/WaylandCompositorDisplay.cpp b/Source/WebKit2/WebProcess/gtk/WaylandCompositorDisplay.cpp
new file mode 100644 (file)
index 0000000..8112ead
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WaylandCompositorDisplay.h"
+
+#if PLATFORM(WAYLAND)
+
+#include "WebKit2WaylandClientProtocol.h"
+#include "WebPage.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+std::unique_ptr<WaylandCompositorDisplay> WaylandCompositorDisplay::create(const String& displayName)
+{
+    if (displayName.isNull())
+        return nullptr;
+
+    struct wl_display* display = wl_display_connect(displayName.utf8().data());
+    if (!display) {
+        WTFLogAlways("PlatformDisplayWayland initialization: failed to connect to the Wayland display: %s", displayName.utf8().data());
+        return nullptr;
+    }
+
+    return std::unique_ptr<WaylandCompositorDisplay>(new WaylandCompositorDisplay(display));
+}
+
+void WaylandCompositorDisplay::bindSurfaceToPage(struct wl_surface* surface, WebPage& page)
+{
+    if (!m_webkitgtk)
+        return;
+
+    wl_webkitgtk_bind_surface_to_page(reinterpret_cast<struct wl_webkitgtk*>(m_webkitgtk.get()), surface, page.pageID());
+    wl_display_roundtrip(m_display);
+}
+
+WaylandCompositorDisplay::WaylandCompositorDisplay(struct wl_display* display)
+{
+    initialize(display);
+    PlatformDisplay::setSharedDisplayForCompositing(*this);
+}
+
+void WaylandCompositorDisplay::registryGlobal(const char* interface, uint32_t name)
+{
+    PlatformDisplayWayland::registryGlobal(interface, name);
+    if (!std::strcmp(interface, "wl_webkitgtk"))
+        m_webkitgtk.reset(static_cast<struct wl_proxy*>(wl_registry_bind(m_registry.get(), name, &wl_webkitgtk_interface, 1)));
+}
+
+} // namespace WebKit
+
+#endif // PLATFORM(WAYLAND)
diff --git a/Source/WebKit2/WebProcess/gtk/WaylandCompositorDisplay.h b/Source/WebKit2/WebProcess/gtk/WaylandCompositorDisplay.h
new file mode 100644 (file)
index 0000000..60e2f6b
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if PLATFORM(WAYLAND)
+
+#include <WebCore/PlatformDisplayWayland.h>
+#include <WebCore/WlUniquePtr.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+class WebPage;
+
+class WaylandCompositorDisplay final : public WebCore::PlatformDisplayWayland {
+    WTF_MAKE_NONCOPYABLE(WaylandCompositorDisplay);
+public:
+    static std::unique_ptr<WaylandCompositorDisplay> create(const String&);
+    ~WaylandCompositorDisplay() = default;
+    void bindSurfaceToPage(struct wl_surface*, WebPage&);
+
+private:
+    WaylandCompositorDisplay(struct wl_display*);
+    void registryGlobal(const char*, uint32_t) override;
+
+    WebCore::WlUniquePtr<struct wl_proxy> m_webkitgtk;
+};
+
+} // namespace WebKit
+
+#endif // PLATFORM(WAYLAND)
index c854cd7..07104be 100644 (file)
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/SoupNetworkSession.h>
 
+#if PLATFORM(WAYLAND)
+#include "WaylandCompositorDisplay.h"
+#endif
+
 namespace WebKit {
 
 void WebProcess::platformSetCacheModel(CacheModel cacheModel)
@@ -43,6 +47,10 @@ void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters&& par
 {
     if (parameters.proxySettings.mode != WebCore::SoupNetworkProxySettings::Mode::Default)
         setNetworkProxySettings(parameters.proxySettings);
+
+#if PLATFORM(WAYLAND)
+    m_waylandCompositorDisplay = WaylandCompositorDisplay::create(parameters.waylandCompositorDisplayName);
+#endif
 }
 
 void WebProcess::platformTerminate()