Title: [266544] branches/safari-610-branch
Revision
266544
Author
alanc...@apple.com
Date
2020-09-03 14:30:40 -0700 (Thu, 03 Sep 2020)

Log Message

Cherry-pick r266189. rdar://problem/68145721

    Flickering on sedona.dev
    https://bugs.webkit.org/show_bug.cgi?id=215141

    Reviewed by Darin Adler.

    Source/WebCore:

    Test: fast/canvas/webgl/compositing-without-drawing.html

    Our logic to determine if a canvas needs to be "repainted"
    was over-zealous for WebGL. We were marking any context
    that called draw commands as dirty, but they could in fact
    be rendering to an offscreen texture/framebuffer. Then, when
    it came time to composite, we'd happily swap buffers and
    show something that had never been rendered to.

    The fix is simply to ignore any of the dirtying notifications
    when we are not bound to the default (canvas) framebuffer.

    * html/canvas/WebGLRenderingContextBase.cpp:
    (WebCore::WebGLRenderingContextBase::markContextChangedAndNotifyCanvasObserver): Only
    mark if we're rendering to the default framebuffer.

    LayoutTests:

    Test that serves an animation frame that touches
    WebGL, but not in a way that requires a recomposite.

    * fast/canvas/webgl/compositing-without-drawing-expected.html: Added.
    * fast/canvas/webgl/compositing-without-drawing.html: Added.

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-610-branch/LayoutTests/ChangeLog (266543 => 266544)


--- branches/safari-610-branch/LayoutTests/ChangeLog	2020-09-03 21:30:37 UTC (rev 266543)
+++ branches/safari-610-branch/LayoutTests/ChangeLog	2020-09-03 21:30:40 UTC (rev 266544)
@@ -1,3 +1,53 @@
+2020-09-03  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r266189. rdar://problem/68145721
+
+    Flickering on sedona.dev
+    https://bugs.webkit.org/show_bug.cgi?id=215141
+    
+    Reviewed by Darin Adler.
+    
+    Source/WebCore:
+    
+    Test: fast/canvas/webgl/compositing-without-drawing.html
+    
+    Our logic to determine if a canvas needs to be "repainted"
+    was over-zealous for WebGL. We were marking any context
+    that called draw commands as dirty, but they could in fact
+    be rendering to an offscreen texture/framebuffer. Then, when
+    it came time to composite, we'd happily swap buffers and
+    show something that had never been rendered to.
+    
+    The fix is simply to ignore any of the dirtying notifications
+    when we are not bound to the default (canvas) framebuffer.
+    
+    * html/canvas/WebGLRenderingContextBase.cpp:
+    (WebCore::WebGLRenderingContextBase::markContextChangedAndNotifyCanvasObserver): Only
+    mark if we're rendering to the default framebuffer.
+    
+    LayoutTests:
+    
+    Test that serves an animation frame that touches
+    WebGL, but not in a way that requires a recomposite.
+    
+    * fast/canvas/webgl/compositing-without-drawing-expected.html: Added.
+    * fast/canvas/webgl/compositing-without-drawing.html: Added.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266189 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-08-26  Dean Jackson  <d...@apple.com>
+
+            Flickering on sedona.dev
+            https://bugs.webkit.org/show_bug.cgi?id=215141
+
+            Reviewed by Darin Adler.
+
+            Test that serves an animation frame that touches
+            WebGL, but not in a way that requires a recomposite.
+
+            * fast/canvas/webgl/compositing-without-drawing-expected.html: Added.
+            * fast/canvas/webgl/compositing-without-drawing.html: Added.
+
 2020-09-01  Alan Coon  <alanc...@apple.com>
 
         Cherry-pick r266280. rdar://problem/68177624

Added: branches/safari-610-branch/LayoutTests/fast/canvas/webgl/compositing-without-drawing-expected.html (0 => 266544)


--- branches/safari-610-branch/LayoutTests/fast/canvas/webgl/compositing-without-drawing-expected.html	                        (rev 0)
+++ branches/safari-610-branch/LayoutTests/fast/canvas/webgl/compositing-without-drawing-expected.html	2020-09-03 21:30:40 UTC (rev 266544)
@@ -0,0 +1,101 @@
+<style>
+body {
+    font-family: monospace;
+}
+canvas {
+    width: 10px;
+    height: 10px;
+}
+</style>
+<script>
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+}
+
+const WIDTH = 10;
+const HEIGHT = 10;
+
+const COLORS = [
+    [0, 0, 1, 1],
+    [0, 1, 1, 1],
+    [0, 0.5, 0, 1],
+    [1, 0, 1, 1],
+    [1, 1, 0.5, 1],
+    [0.5, 0, 1, 1],
+    [0.5, 0.5, 0.5, 1],
+    [0.5, 0.5, 1, 1],
+    [0.25, 1, 1, 1],
+    [0, 1, 0, 1]
+];
+
+let gl;
+let currentFrame = 0;
+
+function output(msg) {
+    const div = document.getElementById("output");
+    div.innerHTML += `${msg}<br>`;
+}
+
+function step1() {
+
+    output("Step 1. Create a WebGL canvas and render into it.");
+    output("We do this for 10 frames, each time a different color ending in pure green (0, 1, 0, 1).");
+    output("-----");
+
+    const canvas = document.querySelector("canvas");
+    canvas.width = WIDTH;
+    canvas.height = HEIGHT;
+
+    output("Create WebGL context");
+
+    gl = canvas.getContext("webgl");
+
+    function clearToColor() {
+        if (currentFrame >= COLORS.length) {
+            requestAnimationFrame(step2);
+            return;
+        }
+
+        output(`Clear to ${COLORS[currentFrame]}`);
+
+        gl.clearColor(...COLORS[currentFrame]);
+        gl.clear(gl.COLOR_BUFFER_BIT);
+
+        currentFrame++;
+        requestAnimationFrame(clearToColor);
+    }
+
+    clearToColor();
+}
+
+function step2() {
+
+    output("");
+    output("Step 2. Create a framebuffer and render into it, but don't draw into the canvas.");
+    output("-----");
+
+    output("Create a texture");
+
+    // THIS IS WHERE WE CREATE THE TEXTURE IN THE ACTUAL TEST.
+
+    output("Create and bind framebuffer");
+
+    // THIS IS WHERE WE CREATE THE FRAMEBUFFER IN THE ACTUAL TEST.
+
+    output("Clear framebuffer to red (1, 0, 0, 1). This was not used above.");
+
+    // DON'T DO ANYTHING HERE.
+
+    output("The canvas above should be green.");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+function runTest() {
+    requestAnimationFrame(step1);
+}
+
+window.addEventListener("load", runTest, false);
+</script>
+<canvas></canvas>
+<div id="output"></div>

Added: branches/safari-610-branch/LayoutTests/fast/canvas/webgl/compositing-without-drawing.html (0 => 266544)


--- branches/safari-610-branch/LayoutTests/fast/canvas/webgl/compositing-without-drawing.html	                        (rev 0)
+++ branches/safari-610-branch/LayoutTests/fast/canvas/webgl/compositing-without-drawing.html	2020-09-03 21:30:40 UTC (rev 266544)
@@ -0,0 +1,112 @@
+<style>
+body {
+    font-family: monospace;
+}
+canvas {
+    width: 10px;
+    height: 10px;
+}
+</style>
+<script>
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+}
+
+const WIDTH = 10;
+const HEIGHT = 10;
+
+const COLORS = [
+    [0, 0, 1, 1],
+    [0, 1, 1, 1],
+    [0, 0.5, 0, 1],
+    [1, 0, 1, 1],
+    [1, 1, 0.5, 1],
+    [0.5, 0, 1, 1],
+    [0.5, 0.5, 0.5, 1],
+    [0.5, 0.5, 1, 1],
+    [0.25, 1, 1, 1],
+    [0, 1, 0, 1]
+];
+
+let gl;
+let currentFrame = 0;
+
+function output(msg) {
+    const div = document.getElementById("output");
+    div.innerHTML += `${msg}<br>`;
+}
+
+function step1() {
+
+    output("Step 1. Create a WebGL canvas and render into it.");
+    output("We do this for 10 frames, each time a different color ending in pure green (0, 1, 0, 1).");
+    output("-----");
+
+    const canvas = document.querySelector("canvas");
+    canvas.width = WIDTH;
+    canvas.height = HEIGHT;
+
+    output("Create WebGL context");
+
+    gl = canvas.getContext("webgl");
+
+    function clearToColor() {
+        if (currentFrame >= COLORS.length) {
+            requestAnimationFrame(step2);
+            return;
+        }
+
+        output(`Clear to ${COLORS[currentFrame]}`);
+
+        gl.clearColor(...COLORS[currentFrame]);
+        gl.clear(gl.COLOR_BUFFER_BIT);
+
+        currentFrame++;
+        requestAnimationFrame(clearToColor);
+    }
+
+    clearToColor();
+}
+
+function step2() {
+
+    output("");
+    output("Step 2. Create a framebuffer and render into it, but don't draw into the canvas.");
+    output("-----");
+
+    output("Create a texture");
+
+    const texture = gl.createTexture();
+    gl.bindTexture(gl.TEXTURE_2D, texture);
+    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
+    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
+    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, WIDTH, HEIGHT, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
+
+    output("Create and bind framebuffer");
+
+    const framebuffer = gl.createFramebuffer();
+    gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
+    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
+
+    output("Clear framebuffer to red (1, 0, 0, 1). This was not used above.");
+
+    gl.clearColor(1, 0, 0, 1);
+    gl.clear(gl.COLOR_BUFFER_BIT);
+
+    gl.bindFramebuffer(gl.FRAMEBUFFER, null);
+
+    output("The canvas above should be green.");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+function runTest() {
+    requestAnimationFrame(step1);
+}
+
+window.addEventListener("load", runTest, false);
+</script>
+<canvas></canvas>
+<div id="output"></div>

Modified: branches/safari-610-branch/Source/WebCore/ChangeLog (266543 => 266544)


--- branches/safari-610-branch/Source/WebCore/ChangeLog	2020-09-03 21:30:37 UTC (rev 266543)
+++ branches/safari-610-branch/Source/WebCore/ChangeLog	2020-09-03 21:30:40 UTC (rev 266544)
@@ -1,3 +1,63 @@
+2020-09-03  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r266189. rdar://problem/68145721
+
+    Flickering on sedona.dev
+    https://bugs.webkit.org/show_bug.cgi?id=215141
+    
+    Reviewed by Darin Adler.
+    
+    Source/WebCore:
+    
+    Test: fast/canvas/webgl/compositing-without-drawing.html
+    
+    Our logic to determine if a canvas needs to be "repainted"
+    was over-zealous for WebGL. We were marking any context
+    that called draw commands as dirty, but they could in fact
+    be rendering to an offscreen texture/framebuffer. Then, when
+    it came time to composite, we'd happily swap buffers and
+    show something that had never been rendered to.
+    
+    The fix is simply to ignore any of the dirtying notifications
+    when we are not bound to the default (canvas) framebuffer.
+    
+    * html/canvas/WebGLRenderingContextBase.cpp:
+    (WebCore::WebGLRenderingContextBase::markContextChangedAndNotifyCanvasObserver): Only
+    mark if we're rendering to the default framebuffer.
+    
+    LayoutTests:
+    
+    Test that serves an animation frame that touches
+    WebGL, but not in a way that requires a recomposite.
+    
+    * fast/canvas/webgl/compositing-without-drawing-expected.html: Added.
+    * fast/canvas/webgl/compositing-without-drawing.html: Added.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266189 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-08-26  Dean Jackson  <d...@apple.com>
+
+            Flickering on sedona.dev
+            https://bugs.webkit.org/show_bug.cgi?id=215141
+
+            Reviewed by Darin Adler.
+
+            Test: fast/canvas/webgl/compositing-without-drawing.html
+
+            Our logic to determine if a canvas needs to be "repainted"
+            was over-zealous for WebGL. We were marking any context
+            that called draw commands as dirty, but they could in fact
+            be rendering to an offscreen texture/framebuffer. Then, when
+            it came time to composite, we'd happily swap buffers and
+            show something that had never been rendered to.
+
+            The fix is simply to ignore any of the dirtying notifications
+            when we are not bound to the default (canvas) framebuffer.
+
+            * html/canvas/WebGLRenderingContextBase.cpp:
+            (WebCore::WebGLRenderingContextBase::markContextChangedAndNotifyCanvasObserver): Only
+            mark if we're rendering to the default framebuffer.
+
 2020-09-02  Alan Coon  <alanc...@apple.com>
 
         Cherry-pick r266363. rdar://problem/68229370

Modified: branches/safari-610-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (266543 => 266544)


--- branches/safari-610-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2020-09-03 21:30:37 UTC (rev 266543)
+++ branches/safari-610-branch/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2020-09-03 21:30:40 UTC (rev 266544)
@@ -1086,6 +1086,10 @@
 
 void WebGLRenderingContextBase::markContextChangedAndNotifyCanvasObserver()
 {
+    // If we're not touching the default framebuffer, nothing visible has changed.
+    if (m_framebufferBinding)
+        return;
+
     markContextChanged();
     if (!isAccelerated())
         return;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to