Title: [288434] trunk
Revision
288434
Author
[email protected]
Date
2022-01-24 03:52:46 -0800 (Mon, 24 Jan 2022)

Log Message

texImage2d fails to set same video frame to multiple textures
https://bugs.webkit.org/show_bug.cgi?id=203148
<rdar://problem/56436745>

Patch by Kimmo Kinnunen <[email protected]> on 2022-01-24
Reviewed by Darin Adler.

Source/WebCore:

WebGL optimizes repeated video uploads to same texture, due to this being
usual practice among pages. Reason is that there are no API to know when the
video frame updates.
The algorithm was:
 - If the IOSurface is the same as in the last call
 - If the texture contents has not changed since we last modified this texture
 then skip the upload.
However, this logic skips errorneously if the "last call" updates some other texture.
Fix and test the above.

There are other issues for the current algorithm. This patch fixes some other theoretical ones:
 - If the texture is deleted and new one gets assigned the same texture id and the content
   seed would clash
 - Video was uploaded to a different level

The previous implementation was keeping per-texture seed value map in the context
(GraphicsContextGLANGLE) and per-teture seed value map in the texture upload helper
(GraphicsContextGLCVCocoa) and last uploaded IOSurface seed in the upload helper (not per
texture).

The implementation in this patch keeps per-texture known content description in the texture
upload helper and invalidates this when each texture changes. The known content description
is the parameter list of the texture upload call.

Test: webgl/pending/conformance/textures/misc/tex-image-video-repeated.html

* platform/graphics/GraphicsContextGLState.h:
(WebCore::GraphicsContextGLState::setBoundTexture):
* platform/graphics/angle/GraphicsContextGLANGLE.cpp:
(WebCore::GraphicsContextGLANGLE::texImage2D):
(WebCore::GraphicsContextGLANGLE::texSubImage2D):
(WebCore::GraphicsContextGLANGLE::compressedTexImage2D):
(WebCore::GraphicsContextGLANGLE::compressedTexSubImage2D):
(WebCore::GraphicsContextGLANGLE::texStorage2D):
(WebCore::GraphicsContextGLANGLE::texStorage3D):
(WebCore::GraphicsContextGLANGLE::texImage2DDirect):
(WebCore::GraphicsContextGLANGLE::framebufferTexture2D):
(WebCore::GraphicsContextGLANGLE::createTexture):
(WebCore::GraphicsContextGLANGLE::deleteTexture):
(WebCore::GraphicsContextGLANGLE::invalidateKnownTextureContent):
(WebCore::GraphicsContextGLANGLE::textureSeed): Deleted.
* platform/graphics/angle/GraphicsContextGLANGLE.h:
* platform/graphics/cocoa/GraphicsContextGLCocoa.h:
* platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
(WebCore::GraphicsContextGLCocoa::invalidateKnownTextureContent):
* platform/graphics/cv/GraphicsContextGLCVCocoa.cpp:
(WebCore::GraphicsContextGLCVCocoa::TextureContent::operator== const):
(WebCore::GraphicsContextGLCVCocoa::copyVideoSampleToTexture):
(WebCore::GraphicsContextGLCVCocoa::invalidateKnownTextureContent):
* platform/graphics/cv/GraphicsContextGLCVCocoa.h:

LayoutTests:

Add a test for testing the bug in which some video texture uploads
were skipped errorneously.

* webgl/pending/conformance/textures/misc/tex-image-video-repeated.html: Added.
* webgl/pending/conformance/textures/misc/tex-image-video-repeated-expected.txt: Added.
* webgl/pending/resources/webgl_test_files/conformance/textures/misc/tex-image-video-repeated.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (288433 => 288434)


--- trunk/LayoutTests/ChangeLog	2022-01-24 10:59:39 UTC (rev 288433)
+++ trunk/LayoutTests/ChangeLog	2022-01-24 11:52:46 UTC (rev 288434)
@@ -1,3 +1,18 @@
+2022-01-24  Kimmo Kinnunen  <[email protected]>
+
+        texImage2d fails to set same video frame to multiple textures
+        https://bugs.webkit.org/show_bug.cgi?id=203148
+        <rdar://problem/56436745>
+
+        Reviewed by Darin Adler.
+
+        Add a test for testing the bug in which some video texture uploads
+        were skipped errorneously.
+
+        * webgl/pending/conformance/textures/misc/tex-image-video-repeated.html: Added.
+        * webgl/pending/conformance/textures/misc/tex-image-video-repeated-expected.txt: Added.
+        * webgl/pending/resources/webgl_test_files/conformance/textures/misc/tex-image-video-repeated.html: Added.
+
 2022-01-24  Antoine Quint  <[email protected]>
 
         [Web Animations] add support for animation-composition CSS property

Added: trunk/LayoutTests/webgl/pending/conformance/textures/misc/tex-image-video-repeated-expected.txt (0 => 288434)


--- trunk/LayoutTests/webgl/pending/conformance/textures/misc/tex-image-video-repeated-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webgl/pending/conformance/textures/misc/tex-image-video-repeated-expected.txt	2022-01-24 11:52:46 UTC (rev 288434)
@@ -0,0 +1,4 @@
+This test runs the WebGL Test listed below in an iframe and reports PASS or FAIL.
+
+Test: ../../../resources/webgl_test_files/conformance/textures/misc/tex-image-video-repeated.html
+[ PASS ] All tests passed

Added: trunk/LayoutTests/webgl/pending/conformance/textures/misc/tex-image-video-repeated.html (0 => 288434)


--- trunk/LayoutTests/webgl/pending/conformance/textures/misc/tex-image-video-repeated.html	                        (rev 0)
+++ trunk/LayoutTests/webgl/pending/conformance/textures/misc/tex-image-video-repeated.html	2022-01-24 11:52:46 UTC (rev 288434)
@@ -0,0 +1,18 @@
+<!-- This file is manually edited and should be deleted once the test is merged in WebGL conformance tests and imported back to LayoutTests. -->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>WebGL Conformance Test Wrapper for context-attributes-alpha-depth-stencil-antialias.html</title>
+<script type="text/_javascript_" src=""
+<script type="text/_javascript_" src=""
+</head>
+<body>
+<p>This test runs the WebGL Test listed below in an iframe and reports PASS or FAIL.</p>
+Test: <a href=""
+<div id="iframe">
+<iframe src="" width="800" height="600"></iframe>
+</div>
+<div id="result"></div>
+</body>
+</html>

Added: trunk/LayoutTests/webgl/pending/resources/webgl_test_files/conformance/textures/misc/tex-image-video-repeated.html (0 => 288434)


--- trunk/LayoutTests/webgl/pending/resources/webgl_test_files/conformance/textures/misc/tex-image-video-repeated.html	                        (rev 0)
+++ trunk/LayoutTests/webgl/pending/resources/webgl_test_files/conformance/textures/misc/tex-image-video-repeated.html	2022-01-24 11:52:46 UTC (rev 288434)
@@ -0,0 +1,108 @@
+<!--
+Copyright (c) 2022 The Khronos Group Inc.
+Use of this source code is governed by an MIT-style license that can be
+found in the LICENSE.txt file.
+-->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<link rel="stylesheet" href=""
+<script src=""
+<script src=""
+<script>
+"use strict";
+var wtu = WebGLTestUtils;
+var gl = null;
+var textureLoc = null;
+var successfullyParsed = false;
+var blue = [0, 0, 248];
+var yellow = [255, 255, 0];
+var black = [0, 0, 0];
+initTestingHarness();
+
+function init()
+{
+    description('Verify optimization of repeated uploads of HTMLVideoElement to a texture');
+
+    const canvas = document.getElementById("example");
+    gl = wtu.create3DContext(canvas, { antialias: false, depth: false });
+    const program = wtu.setupTexturedQuad(gl);
+    gl.clearColor(0,0,0,1);
+    gl.clearDepth(1);
+    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+    const textureLoc = gl.getUniformLocation(program, "tex");
+    gl.uniform1i(textureLoc, 0);
+    gl.viewport(0, 0, canvas.width, canvas.height);
+
+    const video1 = document.getElementById("video1");
+    const video2 = document.getElementById("video2");
+    wtu.startPlayingAndWaitForVideo(video1, (video) => {
+        wtu.startPlayingAndWaitForVideo(video2, (video) => {
+            runTest(video1, video2);
+        });
+    });
+}
+
+function checkFramebufferHasVideo2(gl)
+{
+    const leftColor = blue;
+    const rightColor = yellow;
+    const tolerance = 5;
+    debug("Checking mid left border");
+    wtu.checkCanvasRect(gl, 4, 20, 2, 2, leftColor, "shouldBe " + leftColor, tolerance);
+    debug("Checking mid right border");
+    wtu.checkCanvasRect(gl, gl.canvas.width - 4, gl.canvas.height - 20, 2, 2, rightColor, "shouldBe " + rightColor, tolerance);
+}
+
+function testTwoTexturesBug1(video1, video2)
+{
+    debug("Testing uploading same video to two different textures does not skip the latter upload")
+    const textures = [gl.createTexture(), gl.createTexture()];
+    // Initialize texture[0] to some specific content that fails the test.
+    // Initialization is done with video to exercise the video content identification
+    // algorithm.
+    gl.bindTexture(gl.TEXTURE_2D, textures[0]);
+    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, video1);
+
+    // Try to fool the video content identification algorithm by first uploading
+    // the passing content to some other, untested texture.
+    gl.bindTexture(gl.TEXTURE_2D, textures[1]);
+    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, video2);
+
+    // Update texture[0] to some content that passes the test.
+    gl.bindTexture(gl.TEXTURE_2D, textures[0]);
+    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, video2);
+
+    // Verify that the texture[0] received the new content.
+    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+    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);
+
+    wtu.clearAndDrawUnitQuad(gl, [255, 0, 0, 255]);
+    checkFramebufferHasVideo2(gl);
+}
+
+function runTest(video1, video2)
+{
+    testTwoTexturesBug1(video1, video2);
+    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
+    finishTest();
+}
+</script>
+</head>
+<body _onload_="init()">
+<canvas id="example" width="64" height="48"></canvas>
+<div id="description"></div>
+<div id="console"></div>
+<video id="video1" >
+  <source src=""  type='video/mp4; codecs="avc1.42E01E"' />
+  <source src="" type='video/webm; codecs="vp8"' />
+  <source src=""  type='video/ogg; codecs="theora"' />
+</video>
+<video id="video2" >
+    <source src=""  type='video/mp4; codecs="avc1.42E01E"' />
+  </video>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (288433 => 288434)


--- trunk/Source/WebCore/ChangeLog	2022-01-24 10:59:39 UTC (rev 288433)
+++ trunk/Source/WebCore/ChangeLog	2022-01-24 11:52:46 UTC (rev 288434)
@@ -1,3 +1,62 @@
+2022-01-24  Kimmo Kinnunen  <[email protected]>
+
+        texImage2d fails to set same video frame to multiple textures
+        https://bugs.webkit.org/show_bug.cgi?id=203148
+        <rdar://problem/56436745>
+
+        Reviewed by Darin Adler.
+
+        WebGL optimizes repeated video uploads to same texture, due to this being
+        usual practice among pages. Reason is that there are no API to know when the 
+        video frame updates.
+        The algorithm was:
+         - If the IOSurface is the same as in the last call
+         - If the texture contents has not changed since we last modified this texture
+         then skip the upload.
+        However, this logic skips errorneously if the "last call" updates some other texture.
+        Fix and test the above.
+
+        There are other issues for the current algorithm. This patch fixes some other theoretical ones:
+         - If the texture is deleted and new one gets assigned the same texture id and the content
+           seed would clash
+         - Video was uploaded to a different level
+
+        The previous implementation was keeping per-texture seed value map in the context
+        (GraphicsContextGLANGLE) and per-teture seed value map in the texture upload helper
+        (GraphicsContextGLCVCocoa) and last uploaded IOSurface seed in the upload helper (not per
+        texture).
+
+        The implementation in this patch keeps per-texture known content description in the texture
+        upload helper and invalidates this when each texture changes. The known content description
+        is the parameter list of the texture upload call.
+
+        Test: webgl/pending/conformance/textures/misc/tex-image-video-repeated.html
+
+        * platform/graphics/GraphicsContextGLState.h:
+        (WebCore::GraphicsContextGLState::setBoundTexture):
+        * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+        (WebCore::GraphicsContextGLANGLE::texImage2D):
+        (WebCore::GraphicsContextGLANGLE::texSubImage2D):
+        (WebCore::GraphicsContextGLANGLE::compressedTexImage2D):
+        (WebCore::GraphicsContextGLANGLE::compressedTexSubImage2D):
+        (WebCore::GraphicsContextGLANGLE::texStorage2D):
+        (WebCore::GraphicsContextGLANGLE::texStorage3D):
+        (WebCore::GraphicsContextGLANGLE::texImage2DDirect):
+        (WebCore::GraphicsContextGLANGLE::framebufferTexture2D):
+        (WebCore::GraphicsContextGLANGLE::createTexture):
+        (WebCore::GraphicsContextGLANGLE::deleteTexture):
+        (WebCore::GraphicsContextGLANGLE::invalidateKnownTextureContent):
+        (WebCore::GraphicsContextGLANGLE::textureSeed): Deleted.
+        * platform/graphics/angle/GraphicsContextGLANGLE.h:
+        * platform/graphics/cocoa/GraphicsContextGLCocoa.h:
+        * platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
+        (WebCore::GraphicsContextGLCocoa::invalidateKnownTextureContent):
+        * platform/graphics/cv/GraphicsContextGLCVCocoa.cpp:
+        (WebCore::GraphicsContextGLCVCocoa::TextureContent::operator== const):
+        (WebCore::GraphicsContextGLCVCocoa::copyVideoSampleToTexture):
+        (WebCore::GraphicsContextGLCVCocoa::invalidateKnownTextureContent):
+        * platform/graphics/cv/GraphicsContextGLCVCocoa.h:
+
 2022-01-24  Antoine Quint  <[email protected]>
 
         [Web Animations] add support for animation-composition CSS property

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContextGLState.h (288433 => 288434)


--- trunk/Source/WebCore/platform/graphics/GraphicsContextGLState.h	2022-01-24 10:59:39 UTC (rev 288433)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContextGLState.h	2022-01-24 11:52:46 UTC (rev 288434)
@@ -69,9 +69,6 @@
     {
         boundTextureMap.set(textureUnit, std::make_pair(texture, target));
     }
-
-    using TextureSeedCount = HashCountedSet<GCGLuint, IntHash<GCGLuint>, WTF::UnsignedWithZeroKeyHashTraits<GCGLuint>>;
-    TextureSeedCount textureSeedCount;
 };
 
 }

Modified: trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp (288433 => 288434)


--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp	2022-01-24 10:59:39 UTC (rev 288433)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp	2022-01-24 11:52:46 UTC (rev 288434)
@@ -359,8 +359,8 @@
     if (!makeContextCurrent())
         return;
     GL_TexImage2DRobustANGLE(target, level, internalformat, width, height, border, format, type, pixels.bufSize, pixels.data);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
-    }
+    invalidateKnownTextureContent(m_state.currentBoundTexture());
+}
 
 void GraphicsContextGLANGLE::texImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, GCGLintptr offset)
 {
@@ -374,7 +374,7 @@
 
     // FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size.
     GL_TexSubImage2DRobustANGLE(target, level, xoff, yoff, width, height, format, type, pixels.bufSize, pixels.data);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
+    invalidateKnownTextureContent(m_state.currentBoundTexture());
 }
 
 void GraphicsContextGLANGLE::texSubImage2D(GCGLenum target, GCGLint level, GCGLint xoff, GCGLint yoff, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLenum type, GCGLintptr offset)
@@ -388,7 +388,7 @@
         return;
 
     GL_CompressedTexImage2DRobustANGLE(target, level, internalformat, width, height, border, imageSize, data.bufSize, data.data);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
+    invalidateKnownTextureContent(m_state.currentBoundTexture());
 }
 
 void GraphicsContextGLANGLE::compressedTexImage2D(GCGLenum target, int level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, int border, GCGLsizei imageSize, GCGLintptr offset)
@@ -402,7 +402,7 @@
         return;
 
     GL_CompressedTexSubImage2DRobustANGLE(target, level, xoffset, yoffset, width, height, format, imageSize, data.bufSize, data.data);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
+    invalidateKnownTextureContent(m_state.currentBoundTexture());
 }
 
 void GraphicsContextGLANGLE::compressedTexSubImage2D(GCGLenum target, int level, int xoffset, int yoffset, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLsizei imageSize, GCGLintptr offset)
@@ -852,7 +852,7 @@
         return;
 
     GL_TexStorage2D(target, levels, internalformat, width, height);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
+    invalidateKnownTextureContent(m_state.currentBoundTexture());
 }
 
 void GraphicsContextGLANGLE::texStorage3D(GCGLenum target, GCGLsizei levels, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLsizei depth)
@@ -861,7 +861,7 @@
         return;
 
     GL_TexStorage3D(target, levels, internalformat, width, height, depth);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
+    invalidateKnownTextureContent(m_state.currentBoundTexture());
 }
 
 void GraphicsContextGLANGLE::texImage3D(GCGLenum target, int level, int internalformat, GCGLsizei width, GCGLsizei height, GCGLsizei depth, int border, GCGLenum format, GCGLenum type, GCGLSpan<const GCGLvoid> pixels)
@@ -1000,7 +1000,7 @@
     if (!makeContextCurrent())
         return;
     GL_TexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
+    invalidateKnownTextureContent(m_state.currentBoundTexture());
 }
 
 void GraphicsContextGLANGLE::copyTexImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLint x, GCGLint y, GCGLsizei width, GCGLsizei height, GCGLint border)
@@ -1151,7 +1151,7 @@
         return;
 
     GL_FramebufferTexture2D(target, attachment, textarget, texture, level);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
+    invalidateKnownTextureContent(m_state.currentBoundTexture());
 }
 
 void GraphicsContextGLANGLE::frontFace(GCGLenum mode)
@@ -2093,7 +2093,7 @@
 
     GLuint o = 0;
     GL_GenTextures(1, &o);
-    m_state.textureSeedCount.add(o);
+    invalidateKnownTextureContent(o);
     return o;
 }
 
@@ -2155,7 +2155,7 @@
         return keyValue.value.first == texture;
     });
     GL_DeleteTextures(1, &texture);
-    m_state.textureSeedCount.removeAll(texture);
+    invalidateKnownTextureContent(texture);
 }
 
 void GraphicsContextGLANGLE::synthesizeGLError(GCGLenum error)
@@ -2993,9 +2993,8 @@
     return readCompositedResults();
 }
 
-unsigned GraphicsContextGLANGLE::textureSeed(GCGLuint texture)
+void GraphicsContextGLANGLE::invalidateKnownTextureContent(GCGLuint)
 {
-    return m_state.textureSeedCount.count(texture);
 }
 
 }

Modified: trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h (288433 => 288434)


--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h	2022-01-24 10:59:39 UTC (rev 288433)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h	2022-01-24 11:52:46 UTC (rev 288434)
@@ -355,8 +355,6 @@
     std::optional<PixelBuffer> readRenderingResultsForPainting();
     std::optional<PixelBuffer> readCompositedResultsForPainting();
 
-    unsigned textureSeed(GCGLuint texture);
-
     constexpr static EGLNativeDisplayType defaultDisplay = EGL_DEFAULT_DISPLAY;
 #if PLATFORM(COCOA)
     constexpr static EGLNativeDisplayType lowPowerDisplay = EGL_CAST(EGLNativeDisplayType, -1);
@@ -406,6 +404,8 @@
     // Platform specific behavior for releaseResources();
     static void platformReleaseThreadResources();
 
+    virtual void invalidateKnownTextureContent(GCGLuint);
+
     GCGLuint m_texture { 0 };
     GCGLuint m_fbo { 0 };
     GCGLuint m_depthStencilBuffer { 0 };

Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h (288433 => 288434)


--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h	2022-01-24 10:59:39 UTC (rev 288433)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h	2022-01-24 11:52:46 UTC (rev 288434)
@@ -80,6 +80,10 @@
 protected:
     GraphicsContextGLCocoa(WebCore::GraphicsContextGLAttributes&&, ProcessIdentity&& resourceOwner);
     bool isValid() const;
+
+    // GraphicsContextGLANGLE overrides.
+    void invalidateKnownTextureContent(GCGLuint) final;
+
 #if ENABLE(VIDEO)
     std::unique_ptr<GraphicsContextGLCVCocoa> m_cv;
 #endif

Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm (288433 => 288434)


--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm	2022-01-24 10:59:39 UTC (rev 288433)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm	2022-01-24 11:52:46 UTC (rev 288434)
@@ -820,6 +820,12 @@
     return nullptr;
 }
 
+void GraphicsContextGLCocoa::invalidateKnownTextureContent(GCGLuint texture)
+{
+    if (m_cv)
+        m_cv->invalidateKnownTextureContent(texture);
 }
 
+}
+
 #endif // ENABLE(WEBGL)

Modified: trunk/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVCocoa.cpp (288433 => 288434)


--- trunk/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVCocoa.cpp	2022-01-24 10:59:39 UTC (rev 288433)
+++ trunk/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVCocoa.cpp	2022-01-24 11:52:46 UTC (rev 288434)
@@ -444,6 +444,18 @@
     return iterator->second;
 }
 
+inline bool GraphicsContextGLCVCocoa::TextureContent::operator==(const TextureContent& other) const
+{
+    return surface == other.surface
+        && surfaceSeed == other.surfaceSeed
+        && level == other.level
+        && internalFormat == other.internalFormat
+        && format == other.format
+        && type == other.type
+        && unpackFlipY == other.unpackFlipY
+        && ImageOrientation::Orientation(orientation) == ImageOrientation::Orientation(other.orientation);
+}
+
 std::unique_ptr<GraphicsContextGLCVCocoa> GraphicsContextGLCVCocoa::create(GraphicsContextGLCocoa& context)
 {
     std::unique_ptr<GraphicsContextGLCVCocoa> cv { new GraphicsContextGLCVCocoa(context) };
@@ -593,11 +605,9 @@
         return false;
 
     auto orientation = videoFrame.orientation();
-    auto newSurfaceSeed = IOSurfaceGetSeed(surface);
-    if (ImageOrientation::Orientation(orientation) == ImageOrientation::Orientation(m_lastSurfaceOrientation)
-        && unpackFlipY == m_lastUnpackFlipY
-        && newSurfaceSeed == m_lastSurfaceSeed
-        && lastTextureSeed(outputTexture) == m_owner.textureSeed(outputTexture)) {
+    TextureContent content { reinterpret_cast<intptr_t>(surface), IOSurfaceGetSeed(surface), level, internalFormat, format, type, unpackFlipY, orientation };
+    auto it = m_knownContent.find(outputTexture);
+    if (it != m_knownContent.end() && it->value == content) {
         // If the texture hasn't been modified since the last time we copied to it, and the
         // image hasn't been modified since the last time it was copied, this is a no-op.
         return true;
@@ -746,15 +756,16 @@
     // Do the actual drawing.
     GL_DrawArrays(GL_TRIANGLES, 0, 6);
 
-    m_lastUnpackFlipY = unpackFlipY;
-    m_lastSurface = surface;
-    m_lastSurfaceSeed = newSurfaceSeed;
-    m_lastSurfaceOrientation = orientation;
-    m_lastTextureSeed.set(outputTexture, m_owner.textureSeed(outputTexture));
+    m_knownContent.set(outputTexture, content);
     autoClearTextureOnError.release();
     return true;
 }
 
+void GraphicsContextGLCVCocoa::invalidateKnownTextureContent(GCGLuint texture)
+{
+    m_knownContent.remove(texture);
 }
 
+}
+
 #endif

Modified: trunk/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVCocoa.h (288433 => 288434)


--- trunk/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVCocoa.h	2022-01-24 10:59:39 UTC (rev 288433)
+++ trunk/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVCocoa.h	2022-01-24 11:52:46 UTC (rev 288434)
@@ -30,7 +30,6 @@
 #include "GraphicsContextGLCV.h"
 #include "ImageOrientation.h"
 #include <memory>
-#include <wtf/UnsafePointer.h>
 
 namespace WebCore {
 class GraphicsContextGLCocoa;
@@ -46,13 +45,10 @@
 
     bool copyVideoSampleToTexture(const MediaSampleVideoFrame&, PlatformGLObject outputTexture, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, FlipY) final;
 
+    void invalidateKnownTextureContent(GCGLuint texture);
 private:
     GraphicsContextGLCVCocoa(GraphicsContextGLCocoa&);
 
-    unsigned lastTextureSeed(GCGLuint texture)
-    {
-        return m_lastTextureSeed.get(texture);
-    }
 
     GraphicsContextGLCocoa& m_owner;
     PlatformGraphicsContextGLDisplay m_display { nullptr };
@@ -71,13 +67,22 @@
     GCGLint m_yTextureSizeUniformLocation { -1 };
     GCGLint m_uvTextureSizeUniformLocation { -1 };
 
-    FlipY m_lastUnpackFlipY { FlipY::No };
-    ImageOrientation m_lastSurfaceOrientation;
-    UnsafePointer<IOSurfaceRef> m_lastSurface;
-    uint32_t m_lastSurfaceSeed { 0 };
+    struct TextureContent {
+        // FIXME: Switch back to UnsafePointer<IOSurfaceRef> once UnsafePointer is safe to compare.
+        // http://webkit.org/b/235435
+        intptr_t surface { 0 };
+        uint32_t surfaceSeed { 0 };
+        GCGLint level { 0 };
+        GCGLenum internalFormat { 0 };
+        GCGLenum format { 0 };
+        GCGLenum type { 0 };
+        FlipY unpackFlipY { FlipY::No };
+        ImageOrientation orientation;
 
-    using TextureSeedMap = HashMap<GCGLuint, unsigned, IntHash<GCGLuint>, WTF::UnsignedWithZeroKeyHashTraits<GCGLuint>>;
-    TextureSeedMap m_lastTextureSeed;
+        bool operator==(const TextureContent&) const;
+    };
+    using TextureContentMap = HashMap<GCGLuint, TextureContent, IntHash<GCGLuint>, WTF::UnsignedWithZeroKeyHashTraits<GCGLuint>>;
+    TextureContentMap m_knownContent;
 };
 
 }

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp (288433 => 288434)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp	2022-01-24 10:59:39 UTC (rev 288433)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.cpp	2022-01-24 11:52:46 UTC (rev 288434)
@@ -1013,7 +1013,6 @@
         return;
 
     ::glFramebufferTexture2DEXT(target, attachment, textarget, texture, level);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
 }
 
 void GraphicsContextGLOpenGL::frontFace(GCGLenum mode)
@@ -2193,7 +2192,6 @@
 
     // FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size.
     ::glTexSubImage2D(target, level, xoff, yoff, width, height, format, type, pixels.data);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
 }
 
 void GraphicsContextGLOpenGL::compressedTexImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLsizei imageSize, GCGLSpan<const GCGLvoid> data)
@@ -2202,7 +2200,6 @@
         return;
 
     ::glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data.data);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
 }
 
 void GraphicsContextGLOpenGL::compressedTexSubImage2D(GCGLenum target, GCGLint level, GCGLint xoffset, GCGLint yoffset, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLsizei imageSize, GCGLSpan<const GCGLvoid> data)
@@ -2211,7 +2208,6 @@
         return;
 
     ::glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data.data);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
 }
 
 PlatformGLObject GraphicsContextGLOpenGL::createBuffer()
@@ -2267,7 +2263,6 @@
 
     GLuint o = 0;
     glGenTextures(1, &o);
-    m_state.textureSeedCount.add(o);
     return o;
 }
 
@@ -2327,7 +2322,6 @@
         return keyValue.value.first == texture;
     });
     glDeleteTextures(1, &texture);
-    m_state.textureSeedCount.removeAll(texture);
 }
 
 void GraphicsContextGLOpenGL::synthesizeGLError(GCGLenum error)
@@ -2363,7 +2357,6 @@
         return;
 
     ::glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
 }
 
 void GraphicsContextGLOpenGL::drawArraysInstanced(GCGLenum mode, GCGLint first, GCGLsizei count, GCGLsizei primcount)
@@ -2510,7 +2503,6 @@
         return;
 
     ::glTexStorage2D(target, levels, internalformat, width, height);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
 }
 
 void GraphicsContextGLOpenGL::texStorage3D(GCGLenum target, GCGLsizei levels, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLsizei depth)
@@ -2519,7 +2511,6 @@
         return;
 
     ::glTexStorage3D(target, levels, internalformat, width, height, depth);
-    m_state.textureSeedCount.add(m_state.currentBoundTexture());
 }
 #else
 void GraphicsContextGLOpenGL::getInternalformativ(GCGLenum, GCGLenum, GCGLenum, GCGLSpan<GCGLint>)

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (288433 => 288434)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2022-01-24 10:59:39 UTC (rev 288433)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h	2022-01-24 11:52:46 UTC (rev 288434)
@@ -412,8 +412,6 @@
 
     void simulateEventForTesting(SimulatedEventForTesting) override;
 
-    unsigned textureSeed(GCGLuint texture) { return m_state.textureSeedCount.count(texture); }
-
     void prepareForDisplay() override;
 
 protected:
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to