Skip to content
Permalink
Browse files
Video Texture set to repeat is clamped
https://bugs.webkit.org/show_bug.cgi?id=248543
rdar://problem/102912865

Reviewed by Kenneth Russell.

The texImage2D fast-path would change the target texture wrap and min/mag properties.
The FBO where the target texture will be bound is complete regardless
of the properties.

* LayoutTests/webgl/resources/pot-video.mp4: Added.
* LayoutTests/webgl/tex-2d-video-no-change-wrap-expected.txt: Added.
* LayoutTests/webgl/tex-2d-video-no-change-wrap.html: Added.
* Source/WebCore/platform/graphics/cv/GraphicsContextGLCVCocoa.cpp:
(WebCore::GraphicsContextGLCVCocoa::copyVideoSampleToTexture):

Canonical link: https://commits.webkit.org/257365@main
  • Loading branch information
kkinnunen-apple committed Dec 5, 2022
1 parent 285ff73 commit c340b7473bca7f6b64867669aeca7ebc169531a8
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 4 deletions.
@@ -1461,6 +1461,7 @@ webgl/webgl-draft-extensions-flag-on.html [ Skip ]

webgl/conformance/extensions/s3tc-and-rgtc.html [ Pass Failure ]

webgl/tex-2d-video-no-change-wrap.html [ Failure ]

#////////////////////////////////////////////////////////////////////////////////////////
# End of WebGL-related bugs
Binary file not shown.
@@ -0,0 +1,30 @@
Texture upload should not change texture wrap parameters

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".

TEST COMPLETE: 19 PASS, 0 FAIL

PASS gl = wtu.create3DContext(canvas, undefined, 2) is non-null.


PASS getError was expected value: NO_ERROR :
PASS bottom left should be 16,32,48
PASS bottom right pixels should be 64,80,96
PASS top left pixels should be 112,128,144
PASS top right pixels should be 160,176,192
PASS bottom left should be 16,32,48
PASS bottom right pixels should be 64,80,96
PASS top left pixels should be 112,128,144
PASS top right pixels should be 160,176,192
PASS bottom left should be 16,32,48
PASS bottom right pixels should be 64,80,96
PASS top left pixels should be 112,128,144
PASS top right pixels should be 160,176,192
PASS bottom left should be 16,32,48
PASS bottom right pixels should be 64,80,96
PASS top left pixels should be 112,128,144
PASS top right pixels should be 160,176,192
PASS successfullyParsed is true

TEST COMPLETE

@@ -0,0 +1,86 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL test for texture upload should not change texture wrap parameters</title>
<link rel="stylesheet" href="resources/webgl_test_files/resources/js-test-style.css"/>
<script src="resources/webgl_test_files/js/js-test-pre.js"></script>
<script src="resources/webgl_test_files/js/webgl-test-utils.js"></script>
</head>
<body>
<canvas id="canvas" width="256" height="256"> </canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";

var wtu = WebGLTestUtils;
var gl;
// Video with:
// ffmpeg -f lavfi -i color=c=red@0.2:d=1:s=512x512:r=25 -pix_fmt yuv420p -filter_complex "drawbox=t=fill:x=0:y=0:w=256:h=256:color=0x102030, drawbox=t=fill:x=255:y=0:w=256:h=256:color=0x405060, drawbox=t=fill:x=0:y=255:w=256:h=256:color=0x708090, drawbox=t=fill:x=255:y=255:w=256:h=256:color=0xA0B0C0" -colorspace bt709 -color_primaries bt709 -color_trc iec61966_2_1 pot-video.mp4 -y

async function testVideoTextureUploadDoesNotChangeWrap() {
var program = wtu.setupSimpleTextureProgram(gl, 0, 1, `precision mediump float;
uniform sampler2D tex;
varying vec2 texCoord;
void main() {
gl_FragData[0] = texture2D(tex, 2. * texCoord);
}`);
wtu.setupUnitQuad(gl);
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);

debug("");

var 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.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
let video = document.createElement("video");
video.loop = true;
video.playsInline = true;
video.src = "resources/pot-video.mp4";
await video.play();
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, video);
wtu.clearAndDrawUnitQuad(gl, [0, 0, 0, 255]);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
let allRects = [];
let color0 = [ 0x10, 0x20, 0x30 ];
let color1 = [ 0x40, 0x50, 0x60 ];
let color2 = [ 0x70, 0x80, 0x90 ];
let color3 = [ 0xA0, 0xB0, 0xC0 ];
var w = gl.drawingBufferWidth / 4;
var h = gl.drawingBufferHeight / 4;
for (let qy = 0; qy < 2; ++qy) {
for (let qx = 0; qx < 2; ++qx) {
var x = qx * w*2;
var y = qy * h*2;
var rects = [
wtu.makeCheckRect(x, y, w, h, color0, "bottom left should be " + color0, 5),
wtu.makeCheckRect(x + w, y, w, h, color1, "bottom right pixels should be " + color1, 5),
wtu.makeCheckRect(x, y + h, w, h, color2, "top left pixels should be " + color2, 5),
wtu.makeCheckRect(x + w, y + h, w, h, color3, "top right pixels should be " + color3, 5),
];
allRects = allRects.concat(rects);
}
}
wtu.checkCanvasRects(gl, allRects);
gl.deleteTexture(texture);
finishTest();
}

description("Texture upload should not change texture wrap parameters");

var canvas = document.getElementById("canvas");
shouldBeNonNull("gl = wtu.create3DContext(canvas, undefined, 2)");

testVideoTextureUploadDoesNotChangeWrap();

debug("");
var successfullyParsed = true;

</script>

</body>
</html>
@@ -683,10 +683,6 @@ bool GraphicsContextGLCVCocoa::copyVideoSampleToTexture(const VideoFrameCV& vide
});
// Allocate memory for the output texture.
GL_BindTexture(GL_TEXTURE_2D, outputTexture);
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);
GL_TexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type, nullptr);

GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, outputTexture, level);

0 comments on commit c340b74

Please sign in to comment.