[WebGL] accelerated texImage2D for video doesn't respect flipY
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Sep 2017 02:52:38 +0000 (02:52 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Sep 2017 02:52:38 +0000 (02:52 +0000)
commit9f5b333cec49bc29a0d246c2869ec20e68e22304
tree9f389ab20e17760c49d5e6d6a12c449e1178aa6b
parent4d9182f1e93d88a930c16f2850377645bb60a0bd
[WebGL] accelerated texImage2D for video doesn't respect flipY
https://bugs.webkit.org/show_bug.cgi?id=176491
<rdar://problem/33833511>

Reviewed by Jer Noble.

(Take 3 - this was rolled out due to a test failure)

Source/WebCore:

Previously, if UNPACK_FLIP_Y_WEBGL was set to true, we'd either fall
back to software or fail to upload texture data. Fix this by intercepting
the texImage2D call, checking the orientation of the video, and running
a small shader program to flip it if necessary.

While there, implement UNPACK_PREMULTIPLY_ALPHA_WEBGL as well, although
none of our media decoders support video with alpha, so unfortunately
this will have no visible change.

Tests: fast/canvas/webgl/texImage2D-video-flipY-false.html
       fast/canvas/webgl/texImage2D-video-flipY-true.html

* platform/cocoa/CoreVideoSoftLink.cpp: Add link to CVOpenGL(ES)TextureGetCleanTexCoords,
which is used to check the orientation of the source video.
* platform/cocoa/CoreVideoSoftLink.h:

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::copyVideoTextureToPlatformTexture): We can
now handle flipped or premultiplied requests.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::copyVideoTextureToPlatformTexture): Ditto.

* platform/graphics/cv/VideoTextureCopierCV.cpp:
(WebCore::VideoTextureCopierCV::VideoTextureCopierCV): Rename readFramebuffer to
simply framebuffer.
(WebCore::VideoTextureCopierCV::~VideoTextureCopierCV): Delete the program and buffer
if they were created.
(WebCore::VideoTextureCopierCV::initializeContextObjects): Sets up the shader program
and the vertex buffer for drawing. Also records the location of the uniforms.
(WebCore::VideoTextureCopierCV::copyVideoTextureToPlatformTexture): Create a new
framebuffer object, and render the video texture into that framebuffer using a
shader that can flip the coordinates.
(WebCore::VideoTextureCopierCV::GC3DStateSaver::GC3DStateSaver): Helper to restore
the state of the user's GraphicsContext3D while we're intercepting calls.
(WebCore::VideoTextureCopierCV::GC3DStateSaver::~GC3DStateSaver):
* platform/graphics/cv/VideoTextureCopierCV.h:

* platform/graphics/GraphicsContext3D.h: Add two new entry points, for direct shader
compilation and attribute access. This avoids going through ANGLE.
* platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
(WebCore::GraphicsContext3D::compileShader):
(WebCore::GraphicsContext3D::compileShaderDirect):
(WebCore::GraphicsContext3D::getAttribLocationDirect):

LayoutTests:

Test that exercises UNPACK_FLIP_Y_WEBGL for video on the accelerated
path.

* fast/canvas/webgl/resources/orientation-flipped.mp4: Added.
* fast/canvas/webgl/resources/orientation-normal.mp4: Added.
* fast/canvas/webgl/texImage2D-video-flipY-false-expected.txt: Added.
* fast/canvas/webgl/texImage2D-video-flipY-false.html: Added.
* fast/canvas/webgl/texImage2D-video-flipY-true-expected.txt: Added.
* fast/canvas/webgl/texImage2D-video-flipY-true.html: Added.
* platform/ios/TestExpectations: This test is macOS only.
* platform/mac/TestExpectations: Mark an existing WebGL test as flakey, while
  a bug exposed here is investigated.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222197 268f45cc-cd09-0410-ab3c-d52691b4dbfc
18 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/canvas/webgl/resources/orientation-flipped.mp4 [new file with mode: 0644]
LayoutTests/fast/canvas/webgl/resources/orientation-normal.mp4 [new file with mode: 0644]
LayoutTests/fast/canvas/webgl/texImage2D-video-flipY-false-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/webgl/texImage2D-video-flipY-false.html [new file with mode: 0644]
LayoutTests/fast/canvas/webgl/texImage2D-video-flipY-true-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/webgl/texImage2D-video-flipY-true.html [new file with mode: 0644]
LayoutTests/platform/ios/TestExpectations
LayoutTests/platform/mac/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/platform/cocoa/CoreVideoSoftLink.cpp
Source/WebCore/platform/cocoa/CoreVideoSoftLink.h
Source/WebCore/platform/graphics/GraphicsContext3D.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm
Source/WebCore/platform/graphics/cv/VideoTextureCopierCV.cpp
Source/WebCore/platform/graphics/cv/VideoTextureCopierCV.h
Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp