Title: [263213] branches/safari-610.1.17-branch
Revision
263213
Author
[email protected]
Date
2020-06-18 09:52:08 -0700 (Thu, 18 Jun 2020)

Log Message

Cherry-pick r263128. rdar://problem/64492837

    REGRESSION (r262643): DumpRenderTree at com.apple.WebCore: WebCore::Document::prepareCanvasesForDisplayIfNeeded
    https://bugs.webkit.org/show_bug.cgi?id=213221
    rdar://64260400

    Reviewed by Simon Fraser.

    Source/WebCore:

    A Document could still be holding a pointer to an HTMLCanvasElement after the
    canvas had been deleted because the CanvasObserver protocol was disconnected
    too early. The fix is to explicitly clear the canvas from the Document as it
    stops observing.

    Test: webgl/preparation-removed-from-document.html

    * dom/Document.cpp:
    (WebCore::Document::prepareCanvasesForDisplayIfNeeded): Copy the HashSet to a Vector
    just in case something weird happens to the set during iteration.
    (WebCore::Document::clearCanvasPreparation): Remove the canvas from the list of
    of elements that need preparation.
    * dom/Document.h: Add the new clearCanvasPreparation method.

    * html/HTMLCanvasElement.cpp:
    (WebCore::HTMLCanvasElement::~HTMLCanvasElement): Clear the document.
    (WebCore::HTMLCanvasElement::didMoveToNewDocument): Ditto.
    (WebCore::HTMLCanvasElement::removedFromAncestor): Ditto.

    LayoutTests:

    Test that triggers a rendering on a canvas, then rips it out of
    the document before drawing.

    * webgl/preparation-removed-from-document-expected.txt: Added.
    * webgl/preparation-removed-from-document.html: Added.

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-610.1.17-branch/LayoutTests/ChangeLog (263212 => 263213)


--- branches/safari-610.1.17-branch/LayoutTests/ChangeLog	2020-06-18 16:52:05 UTC (rev 263212)
+++ branches/safari-610.1.17-branch/LayoutTests/ChangeLog	2020-06-18 16:52:08 UTC (rev 263213)
@@ -1,3 +1,58 @@
+2020-06-18  Alan Coon  <[email protected]>
+
+        Cherry-pick r263128. rdar://problem/64492837
+
+    REGRESSION (r262643): DumpRenderTree at com.apple.WebCore: WebCore::Document::prepareCanvasesForDisplayIfNeeded
+    https://bugs.webkit.org/show_bug.cgi?id=213221
+    rdar://64260400
+    
+    Reviewed by Simon Fraser.
+    
+    Source/WebCore:
+    
+    A Document could still be holding a pointer to an HTMLCanvasElement after the
+    canvas had been deleted because the CanvasObserver protocol was disconnected
+    too early. The fix is to explicitly clear the canvas from the Document as it
+    stops observing.
+    
+    Test: webgl/preparation-removed-from-document.html
+    
+    * dom/Document.cpp:
+    (WebCore::Document::prepareCanvasesForDisplayIfNeeded): Copy the HashSet to a Vector
+    just in case something weird happens to the set during iteration.
+    (WebCore::Document::clearCanvasPreparation): Remove the canvas from the list of
+    of elements that need preparation.
+    * dom/Document.h: Add the new clearCanvasPreparation method.
+    
+    * html/HTMLCanvasElement.cpp:
+    (WebCore::HTMLCanvasElement::~HTMLCanvasElement): Clear the document.
+    (WebCore::HTMLCanvasElement::didMoveToNewDocument): Ditto.
+    (WebCore::HTMLCanvasElement::removedFromAncestor): Ditto.
+    
+    LayoutTests:
+    
+    Test that triggers a rendering on a canvas, then rips it out of
+    the document before drawing.
+    
+    * webgl/preparation-removed-from-document-expected.txt: Added.
+    * webgl/preparation-removed-from-document.html: Added.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@263128 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-06-16  Dean Jackson  <[email protected]>
+
+            REGRESSION (r262643): DumpRenderTree at com.apple.WebCore: WebCore::Document::prepareCanvasesForDisplayIfNeeded
+            https://bugs.webkit.org/show_bug.cgi?id=213221
+            rdar://64260400
+
+            Reviewed by Simon Fraser.
+
+            Test that triggers a rendering on a canvas, then rips it out of
+            the document before drawing.
+
+            * webgl/preparation-removed-from-document-expected.txt: Added.
+            * webgl/preparation-removed-from-document.html: Added.
+
 2020-06-15  Megan Gardner  <[email protected]>
 
         Text form controls can scroll by 1px when value is the same length as size. No scrolling should happen.

Added: branches/safari-610.1.17-branch/LayoutTests/webgl/preparation-removed-from-document-expected.txt (0 => 263213)


--- branches/safari-610.1.17-branch/LayoutTests/webgl/preparation-removed-from-document-expected.txt	                        (rev 0)
+++ branches/safari-610.1.17-branch/LayoutTests/webgl/preparation-removed-from-document-expected.txt	2020-06-18 16:52:08 UTC (rev 263213)
@@ -0,0 +1 @@
+

Added: branches/safari-610.1.17-branch/LayoutTests/webgl/preparation-removed-from-document.html (0 => 263213)


--- branches/safari-610.1.17-branch/LayoutTests/webgl/preparation-removed-from-document.html	                        (rev 0)
+++ branches/safari-610.1.17-branch/LayoutTests/webgl/preparation-removed-from-document.html	2020-06-18 16:52:08 UTC (rev 263213)
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<style>
+canvas {
+    width: 200px;
+    height: 200px;
+}
+</style>
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+
+let canvas;
+
+function startTest()
+{
+    canvas = document.createElement("canvas");
+    canvas.width = 200;
+    canvas.height = 200;
+    document.body.appendChild(canvas);
+    requestAnimationFrame(updateAndRemoveCanvas);
+}
+
+function updateAndRemoveCanvas()
+{
+    let gl = canvas.getContext("webgl");
+    gl.clearColor(0, 1, 0, 1);
+    gl.clear(gl.COLOR_BUFFER_BIT);
+    canvas.remove();
+    canvas = null;
+    gl = null;
+    if (window.GCController)
+        GCController.collect();
+
+    requestAnimationFrame(finishTest);
+}
+
+function finishTest()
+{
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+window.addEventListener("DOMContentLoaded", startTest, false);
+</script>

Modified: branches/safari-610.1.17-branch/Source/WebCore/ChangeLog (263212 => 263213)


--- branches/safari-610.1.17-branch/Source/WebCore/ChangeLog	2020-06-18 16:52:05 UTC (rev 263212)
+++ branches/safari-610.1.17-branch/Source/WebCore/ChangeLog	2020-06-18 16:52:08 UTC (rev 263213)
@@ -1,5 +1,73 @@
 2020-06-18  Alan Coon  <[email protected]>
 
+        Cherry-pick r263128. rdar://problem/64492837
+
+    REGRESSION (r262643): DumpRenderTree at com.apple.WebCore: WebCore::Document::prepareCanvasesForDisplayIfNeeded
+    https://bugs.webkit.org/show_bug.cgi?id=213221
+    rdar://64260400
+    
+    Reviewed by Simon Fraser.
+    
+    Source/WebCore:
+    
+    A Document could still be holding a pointer to an HTMLCanvasElement after the
+    canvas had been deleted because the CanvasObserver protocol was disconnected
+    too early. The fix is to explicitly clear the canvas from the Document as it
+    stops observing.
+    
+    Test: webgl/preparation-removed-from-document.html
+    
+    * dom/Document.cpp:
+    (WebCore::Document::prepareCanvasesForDisplayIfNeeded): Copy the HashSet to a Vector
+    just in case something weird happens to the set during iteration.
+    (WebCore::Document::clearCanvasPreparation): Remove the canvas from the list of
+    of elements that need preparation.
+    * dom/Document.h: Add the new clearCanvasPreparation method.
+    
+    * html/HTMLCanvasElement.cpp:
+    (WebCore::HTMLCanvasElement::~HTMLCanvasElement): Clear the document.
+    (WebCore::HTMLCanvasElement::didMoveToNewDocument): Ditto.
+    (WebCore::HTMLCanvasElement::removedFromAncestor): Ditto.
+    
+    LayoutTests:
+    
+    Test that triggers a rendering on a canvas, then rips it out of
+    the document before drawing.
+    
+    * webgl/preparation-removed-from-document-expected.txt: Added.
+    * webgl/preparation-removed-from-document.html: Added.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@263128 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-06-16  Dean Jackson  <[email protected]>
+
+            REGRESSION (r262643): DumpRenderTree at com.apple.WebCore: WebCore::Document::prepareCanvasesForDisplayIfNeeded
+            https://bugs.webkit.org/show_bug.cgi?id=213221
+            rdar://64260400
+
+            Reviewed by Simon Fraser.
+
+            A Document could still be holding a pointer to an HTMLCanvasElement after the
+            canvas had been deleted because the CanvasObserver protocol was disconnected
+            too early. The fix is to explicitly clear the canvas from the Document as it
+            stops observing.
+
+            Test: webgl/preparation-removed-from-document.html
+
+            * dom/Document.cpp:
+            (WebCore::Document::prepareCanvasesForDisplayIfNeeded): Copy the HashSet to a Vector
+            just in case something weird happens to the set during iteration.
+            (WebCore::Document::clearCanvasPreparation): Remove the canvas from the list of
+            of elements that need preparation.
+            * dom/Document.h: Add the new clearCanvasPreparation method.
+
+            * html/HTMLCanvasElement.cpp:
+            (WebCore::HTMLCanvasElement::~HTMLCanvasElement): Clear the document.
+            (WebCore::HTMLCanvasElement::didMoveToNewDocument): Ditto.
+            (WebCore::HTMLCanvasElement::removedFromAncestor): Ditto.
+
+2020-06-18  Alan Coon  <[email protected]>
+
         Cherry-pick r263119. rdar://problem/64492834
 
     Web Inspector: replace completion handler with a function in interception.

Modified: branches/safari-610.1.17-branch/Source/WebCore/dom/Document.cpp (263212 => 263213)


--- branches/safari-610.1.17-branch/Source/WebCore/dom/Document.cpp	2020-06-18 16:52:05 UTC (rev 263212)
+++ branches/safari-610.1.17-branch/Source/WebCore/dom/Document.cpp	2020-06-18 16:52:08 UTC (rev 263213)
@@ -8589,7 +8589,7 @@
 {
     // Some canvas contexts need to do work when rendering has finished but
     // before their content is composited.
-    for (auto* canvas : m_canvasesNeedingDisplayPreparation) {
+    for (auto* canvas : copyToVector(m_canvasesNeedingDisplayPreparation)) {
         // However, if they are not in the document body, then they won't
         // be composited and thus don't need preparation. Unfortunately they
         // can't tell at the time they were added to the list, since they
@@ -8603,6 +8603,11 @@
     m_canvasesNeedingDisplayPreparation.clear();
 }
 
+void Document::clearCanvasPreparation(HTMLCanvasElement* canvas)
+{
+    m_canvasesNeedingDisplayPreparation.remove(canvas);
+}
+
 void Document::canvasChanged(CanvasBase& canvasBase, const FloatRect&)
 {
     if (is<HTMLCanvasElement>(canvasBase)) {

Modified: branches/safari-610.1.17-branch/Source/WebCore/dom/Document.h (263212 => 263213)


--- branches/safari-610.1.17-branch/Source/WebCore/dom/Document.h	2020-06-18 16:52:05 UTC (rev 263212)
+++ branches/safari-610.1.17-branch/Source/WebCore/dom/Document.h	2020-06-18 16:52:08 UTC (rev 263213)
@@ -1596,6 +1596,7 @@
     const FrameSelection& selection() const { return m_selection; }
 
     void prepareCanvasesForDisplayIfNeeded();
+    void clearCanvasPreparation(HTMLCanvasElement*);
     void canvasChanged(CanvasBase&, const FloatRect&) final;
     void canvasResized(CanvasBase&) final { };
     void canvasDestroyed(CanvasBase&) final;

Modified: branches/safari-610.1.17-branch/Source/WebCore/html/HTMLCanvasElement.cpp (263212 => 263213)


--- branches/safari-610.1.17-branch/Source/WebCore/html/HTMLCanvasElement.cpp	2020-06-18 16:52:05 UTC (rev 263212)
+++ branches/safari-610.1.17-branch/Source/WebCore/html/HTMLCanvasElement.cpp	2020-06-18 16:52:08 UTC (rev 263213)
@@ -146,8 +146,8 @@
     // FIXME: This has to be called here because CSSCanvasValue::CanvasObserverProxy::canvasDestroyed()
     // downcasts the CanvasBase object to HTMLCanvasElement. That invokes virtual methods, which should be
     // avoided in destructors, but works as long as it's done before HTMLCanvasElement destructs completely.
-    // This will also cause the document to remove itself as an observer.
     notifyObserversCanvasDestroyed();
+    document().clearCanvasPreparation(this);
 
     m_context = nullptr; // Ensure this goes away before the ImageBuffer.
     setImageBuffer(nullptr);
@@ -1001,6 +1001,7 @@
 
 void HTMLCanvasElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
+    oldDocument.clearCanvasPreparation(this);
     removeObserver(oldDocument);
     addObserver(newDocument);
 
@@ -1009,8 +1010,10 @@
 
 void HTMLCanvasElement::removedFromAncestor(RemovalType removalType, ContainerNode& oldParentOfRemovedTree)
 {
-    if (removalType.disconnectedFromDocument)
+    if (removalType.disconnectedFromDocument) {
+        oldParentOfRemovedTree.document().clearCanvasPreparation(this);
         removeObserver(oldParentOfRemovedTree.document());
+    }
 
     HTMLElement::removedFromAncestor(removalType, oldParentOfRemovedTree);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to