Title: [291621] trunk/Source/WebKit
Revision
291621
Author
mago...@igalia.com
Date
2022-03-22 08:37:25 -0700 (Tue, 22 Mar 2022)

Log Message

Ensure that proxies are invalidated before destroying them.
https://bugs.webkit.org/show_bug.cgi?id=237187

Reviewed by Carlos Garcia Campos.

* Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
(WebKit::CoordinatedGraphicsScene::updateSceneState):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (291620 => 291621)


--- trunk/Source/WebKit/ChangeLog	2022-03-22 15:30:27 UTC (rev 291620)
+++ trunk/Source/WebKit/ChangeLog	2022-03-22 15:37:25 UTC (rev 291621)
@@ -1,3 +1,13 @@
+2022-03-22  Miguel Gomez  <mago...@igalia.com>
+
+        Ensure that proxies are invalidated before destroying them.
+        https://bugs.webkit.org/show_bug.cgi?id=237187
+
+        Reviewed by Carlos Garcia Campos.
+
+        * Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
+        (WebKit::CoordinatedGraphicsScene::updateSceneState):
+
 2022-03-22  Per Arne Vollan  <pvol...@apple.com>
 
         Ensure there is a Network process after launching the WebContent process

Modified: trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp (291620 => 291621)


--- trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp	2022-03-22 15:30:27 UTC (rev 291620)
+++ trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp	2022-03-22 15:37:25 UTC (rev 291621)
@@ -230,10 +230,11 @@
         };
         Vector<ImageBacking> imageBacking;
     } layersByBacking;
+    HashSet<Ref<WebCore::TextureMapperPlatformLayerProxy>> replacedProxiesToInvalidate;
 
     // Access the scene state and perform state update for each layer.
     m_nicosia.scene->accessState(
-        [this, &layersByBacking](Nicosia::Scene::State& state)
+        [this, &layersByBacking, &replacedProxiesToInvalidate](Nicosia::Scene::State& state)
         {
             // FIXME: try to minimize the amount of work in case the Scene::State object
             // didn't change (i.e. no layer flush was done), but don't forget to properly
@@ -250,12 +251,24 @@
                 }
             }
 
-            // Gather all the to-be-removed layers so that composition-side state
-            // can be properly purged after the current state's set of layers is adopted.
             HashSet<RefPtr<Nicosia::CompositionLayer>> removedLayers;
             for (auto& layer : m_nicosia.state.layers) {
+                // Gather all the to-be-removed layers so that composition-side state
+                // can be properly purged after the current state's set of layers is adopted.
                 if (!state.layers.contains(layer))
                     removedLayers.add(layer);
+                else {
+                    // Store references to all the proxies that are being used by the layers that are kept in the tree.
+                    // When adopting the new state, the existent proxies may be replaced or detached from their layers, causing the
+                    // reference to be lost without having a chance to invalidate them. After the call to commitState, we will
+                    // invalidate all the proxies that are not being used anymore.
+                    layer->accessCommitted(
+                        [&replacedProxiesToInvalidate](const Nicosia::CompositionLayer::LayerState& committed)
+                        {
+                            if (committed.contentLayer)
+                                replacedProxiesToInvalidate.add(Ref { contentLayerImpl(*committed.contentLayer).proxy() });
+                        });
+                }
             }
 
             m_nicosia.state = state;
@@ -270,7 +283,7 @@
             for (auto& compositionLayer : m_nicosia.state.layers) {
                 auto& layer = texmapLayer(*compositionLayer);
                 compositionLayer->commitState(
-                    [&layer, &layersByBacking]
+                    [&layer, &layersByBacking, &replacedProxiesToInvalidate]
                     (const Nicosia::CompositionLayer::LayerState& layerState)
                     {
                         if (layerState.delta.positionChanged)
@@ -346,6 +359,7 @@
                             auto& impl = contentLayerImpl(*layerState.contentLayer);
                             layersByBacking.contentLayer.append(
                                 { std::ref(layer), std::ref(impl.proxy()), layerState.delta.contentLayerChanged });
+                            replacedProxiesToInvalidate.remove(Ref { impl.proxy() });
                         } else if (layerState.imageBacking) {
                             auto& impl = imageBackingImpl(*layerState.imageBacking);
                             layersByBacking.imageBacking.append(
@@ -407,6 +421,10 @@
 
     for (auto& proxy : proxiesForSwapping)
         proxy->swapBuffer();
+
+    for (auto& proxy : replacedProxiesToInvalidate)
+        proxy->invalidate();
+    replacedProxiesToInvalidate = { };
 }
 
 void CoordinatedGraphicsScene::ensureRootLayer()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to