Title: [250204] releases/WebKitGTK/webkit-2.26/Source/WebKit
Revision
250204
Author
carlo...@webkit.org
Date
2019-09-23 01:21:01 -0700 (Mon, 23 Sep 2019)

Log Message

Merge r249947 - [GTK] Crash closing web view while hardware acceleration is enabled
https://bugs.webkit.org/show_bug.cgi?id=200856

Reviewed by Michael Catanzaro.

The crash happens when destroying the WaylandCompositor::Surface because the web view GL context is used to
release the texture, but the GL context is no longer valid after web view
unrealize. AcceleratedBackingStoreWayland should handle the web view unrealize to destroy the GL context. It
will be created on demand again after the web view is realized.

* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseRealize): Notify AcceleratedBackingStore.
(webkitWebViewBaseUnrealize): Ditto.
* UIProcess/gtk/AcceleratedBackingStore.h:
(WebKit::AcceleratedBackingStore::realize): Added.
(WebKit::AcceleratedBackingStore::unrealize): Added.
* UIProcess/gtk/AcceleratedBackingStoreWayland.cpp:
(WebKit::AcceleratedBackingStoreWayland::realize): In case of using WaylandCompositor, call
WaylandCompositor::bindWebPage() to bind the WebPageProxy to the Wayland surface.
(WebKit::AcceleratedBackingStoreWayland::unrealize): Destroy GL resources and the GL context.
(WebKit::AcceleratedBackingStoreWayland::tryEnsureGLContext): Do not try to create the GL context if the web
view is not realized.
(WebKit::AcceleratedBackingStoreWayland::displayBuffer): Remove the code to initialize the texture.
(WebKit::AcceleratedBackingStoreWayland::paint): And add it here.
* UIProcess/gtk/AcceleratedBackingStoreWayland.h:
* UIProcess/gtk/WaylandCompositor.cpp:
(WebKit::WaylandCompositor::Surface::setWebPage): Return early if given page is the current one already.
(WebKit::WaylandCompositor::bindWebPage): Set the surface WebPageProxy.
(WebKit::WaylandCompositor::unbindWebPage): Unset the surface WebPageProxy.
* UIProcess/gtk/WaylandCompositor.h:
* WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp:
(WebKit::DrawingAreaCoordinatedGraphics::enterAcceleratedCompositingMode): When restoring a previous layer tree
host, always call resumeRendering() to balance the suspendRendering() called in exitAcceleratedCompositingMode().

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.26/Source/WebKit/ChangeLog (250203 => 250204)


--- releases/WebKitGTK/webkit-2.26/Source/WebKit/ChangeLog	2019-09-23 08:20:55 UTC (rev 250203)
+++ releases/WebKitGTK/webkit-2.26/Source/WebKit/ChangeLog	2019-09-23 08:21:01 UTC (rev 250204)
@@ -1,3 +1,39 @@
+2019-09-17  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Crash closing web view while hardware acceleration is enabled
+        https://bugs.webkit.org/show_bug.cgi?id=200856
+
+        Reviewed by Michael Catanzaro.
+
+        The crash happens when destroying the WaylandCompositor::Surface because the web view GL context is used to
+        release the texture, but the GL context is no longer valid after web view
+        unrealize. AcceleratedBackingStoreWayland should handle the web view unrealize to destroy the GL context. It
+        will be created on demand again after the web view is realized.
+
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewBaseRealize): Notify AcceleratedBackingStore.
+        (webkitWebViewBaseUnrealize): Ditto.
+        * UIProcess/gtk/AcceleratedBackingStore.h:
+        (WebKit::AcceleratedBackingStore::realize): Added.
+        (WebKit::AcceleratedBackingStore::unrealize): Added.
+        * UIProcess/gtk/AcceleratedBackingStoreWayland.cpp:
+        (WebKit::AcceleratedBackingStoreWayland::realize): In case of using WaylandCompositor, call
+        WaylandCompositor::bindWebPage() to bind the WebPageProxy to the Wayland surface.
+        (WebKit::AcceleratedBackingStoreWayland::unrealize): Destroy GL resources and the GL context.
+        (WebKit::AcceleratedBackingStoreWayland::tryEnsureGLContext): Do not try to create the GL context if the web
+        view is not realized.
+        (WebKit::AcceleratedBackingStoreWayland::displayBuffer): Remove the code to initialize the texture.
+        (WebKit::AcceleratedBackingStoreWayland::paint): And add it here.
+        * UIProcess/gtk/AcceleratedBackingStoreWayland.h:
+        * UIProcess/gtk/WaylandCompositor.cpp:
+        (WebKit::WaylandCompositor::Surface::setWebPage): Return early if given page is the current one already.
+        (WebKit::WaylandCompositor::bindWebPage): Set the surface WebPageProxy.
+        (WebKit::WaylandCompositor::unbindWebPage): Unset the surface WebPageProxy.
+        * UIProcess/gtk/WaylandCompositor.h:
+        * WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp:
+        (WebKit::DrawingAreaCoordinatedGraphics::enterAcceleratedCompositingMode): When restoring a previous layer tree
+        host, always call resumeRendering() to balance the suspendRendering() called in exitAcceleratedCompositingMode().
+
 2019-09-16  Carlos Garcia Campos  <cgar...@igalia.com>
 
         REGRESSION(r249142): [GTK] Epiphany delayed page loads continue indefinitely

Modified: releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp (250203 => 250204)


--- releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp	2019-09-23 08:20:55 UTC (rev 250203)
+++ releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp	2019-09-23 08:21:01 UTC (rev 250204)
@@ -422,6 +422,9 @@
     gdk_window_set_user_data(window, widget);
 
     gtk_im_context_set_client_window(priv->inputMethodFilter.context(), window);
+
+    if (priv->acceleratedBackingStore)
+        priv->acceleratedBackingStore->realize();
 }
 
 static void webkitWebViewBaseUnrealize(GtkWidget* widget)
@@ -429,6 +432,9 @@
     WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(widget);
     gtk_im_context_set_client_window(webView->priv->inputMethodFilter.context(), nullptr);
 
+    if (webView->priv->acceleratedBackingStore)
+        webView->priv->acceleratedBackingStore->unrealize();
+
     GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->unrealize(widget);
 }
 

Modified: releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/AcceleratedBackingStore.h (250203 => 250204)


--- releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/AcceleratedBackingStore.h	2019-09-23 08:20:55 UTC (rev 250203)
+++ releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/AcceleratedBackingStore.h	2019-09-23 08:21:01 UTC (rev 250204)
@@ -47,6 +47,8 @@
 
     virtual void update(const LayerTreeContext&) { }
     virtual bool paint(cairo_t*, const WebCore::IntRect&) = 0;
+    virtual void realize() { };
+    virtual void unrealize() { };
     virtual bool makeContextCurrent() { return false; }
     virtual int renderHostFileDescriptor() { return -1; }
 

Modified: releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.cpp (250203 => 250204)


--- releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.cpp	2019-09-23 08:20:55 UTC (rev 250203)
+++ releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.cpp	2019-09-23 08:21:01 UTC (rev 250204)
@@ -148,9 +148,37 @@
         gdk_gl_context_clear_current();
 }
 
+void AcceleratedBackingStoreWayland::realize()
+{
+#if !USE(WPE_RENDERER)
+    WaylandCompositor::singleton().bindWebPage(m_webPage);
+#endif
+}
+
+void AcceleratedBackingStoreWayland::unrealize()
+{
+    if (!m_glContextInitialized)
+        return;
+
+#if USE(WPE_RENDERER)
+    if (m_viewTexture) {
+        if (makeContextCurrent())
+            glDeleteTextures(1, &m_viewTexture);
+        m_viewTexture = 0;
+    }
+#else
+    WaylandCompositor::singleton().unbindWebPage(m_webPage);
+#endif
+
+    if (m_gdkGLContext && m_gdkGLContext.get() == gdk_gl_context_get_current())
+        gdk_gl_context_clear_current();
+
+    m_glContextInitialized = false;
+}
+
 void AcceleratedBackingStoreWayland::tryEnsureGLContext()
 {
-    if (m_glContextInitialized)
+    if (m_glContextInitialized || !gtk_widget_get_realized(m_webPage.viewWidget()))
         return;
 
     m_glContextInitialized = true;
@@ -208,18 +236,6 @@
         return;
     }
 
-    if (!m_viewTexture) {
-        if (!makeContextCurrent())
-            return;
-
-        glGenTextures(1, &m_viewTexture);
-        glBindTexture(GL_TEXTURE_2D, m_viewTexture);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    }
-
     if (m_pendingImage)
         wpe_view_backend_exportable_fdo_egl_dispatch_release_exported_image(m_exportable, m_pendingImage);
     m_pendingImage = image;
@@ -235,7 +251,7 @@
 
 #if USE(WPE_RENDERER)
     if (!makeContextCurrent())
-        return false;
+        return true;
 
     if (m_pendingImage) {
         wpe_view_backend_exportable_fdo_dispatch_frame_complete(m_exportable);
@@ -249,6 +265,14 @@
     if (!m_committedImage)
         return true;
 
+    if (!m_viewTexture) {
+        glGenTextures(1, &m_viewTexture);
+        glBindTexture(GL_TEXTURE_2D, m_viewTexture);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+    }
     glBindTexture(GL_TEXTURE_2D, m_viewTexture);
     glImageTargetTexture2D(GL_TEXTURE_2D, wpe_fdo_egl_exported_image_get_egl_image(m_committedImage));
 

Modified: releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.h (250203 => 250204)


--- releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.h	2019-09-23 08:20:55 UTC (rev 250203)
+++ releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.h	2019-09-23 08:21:01 UTC (rev 250204)
@@ -65,6 +65,8 @@
 #endif
 
     bool paint(cairo_t*, const WebCore::IntRect&) override;
+    void realize() override;
+    void unrealize() override;
     bool makeContextCurrent() override;
 #if USE(WPE_RENDERER)
     void update(const LayerTreeContext&) override;

Modified: releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/WaylandCompositor.cpp (250203 => 250204)


--- releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/WaylandCompositor.cpp	2019-09-23 08:20:55 UTC (rev 250203)
+++ releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/WaylandCompositor.cpp	2019-09-23 08:21:01 UTC (rev 250204)
@@ -167,6 +167,9 @@
 
 void WaylandCompositor::Surface::setWebPage(WebPageProxy* webPage)
 {
+    if (m_webPage == webPage)
+        return;
+
     if (m_webPage) {
         flushPendingFrameCallbacks();
         flushFrameCallbacks();
@@ -563,6 +566,18 @@
     m_pageMap.set(webPage, makeWeakPtr(*surface));
 }
 
+void WaylandCompositor::bindWebPage(WebPageProxy& webPage)
+{
+    if (WeakPtr<Surface> surface = m_pageMap.get(&webPage))
+        surface->setWebPage(&webPage);
+}
+
+void WaylandCompositor::unbindWebPage(WebPageProxy& webPage)
+{
+    if (WeakPtr<Surface> surface = m_pageMap.get(&webPage))
+        surface->setWebPage(nullptr);
+}
+
 void WaylandCompositor::registerWebPage(WebPageProxy& webPage)
 {
     m_pageMap.add(&webPage, nullptr);

Modified: releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/WaylandCompositor.h (250203 => 250204)


--- releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/WaylandCompositor.h	2019-09-23 08:20:55 UTC (rev 250203)
+++ releases/WebKitGTK/webkit-2.26/Source/WebKit/UIProcess/gtk/WaylandCompositor.h	2019-09-23 08:21:01 UTC (rev 250204)
@@ -104,6 +104,8 @@
     String displayName() const { return m_displayName; }
 
     void bindSurfaceToWebPage(Surface*, WebCore::PageIdentifier);
+    void bindWebPage(WebPageProxy&);
+    void unbindWebPage(WebPageProxy&);
     void registerWebPage(WebPageProxy&);
     void unregisterWebPage(WebPageProxy&);
 

Modified: releases/WebKitGTK/webkit-2.26/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp (250203 => 250204)


--- releases/WebKitGTK/webkit-2.26/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp	2019-09-23 08:20:55 UTC (rev 250203)
+++ releases/WebKitGTK/webkit-2.26/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp	2019-09-23 08:21:01 UTC (rev 250204)
@@ -550,8 +550,7 @@
     if (m_previousLayerTreeHost) {
         m_layerTreeHost = WTFMove(m_previousLayerTreeHost);
         m_layerTreeHost->setIsDiscardable(false);
-        if (!m_isPaintingSuspended)
-            m_layerTreeHost->resumeRendering();
+        m_layerTreeHost->resumeRendering();
         if (!m_layerTreeStateIsFrozen)
             m_layerTreeHost->setLayerFlushSchedulingEnabled(true);
     } else {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to