[WebGL] accelerated texImage2D for video doesn't respect flipY
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Sep 2017 19:28:29 +0000 (19:28 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Sep 2017 19:28:29 +0000 (19:28 +0000)
commite0380de823c82c2ebccfb07d6dc60da0f38b2119
treee0dba246aacc21ec47af207db9ec537b35b43c6b
parente5e8e5322174e8ac995205e4ceddd7c5db833e5c
[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 2 - this was rolled out due to a test failure, but the following
commit will fix that)

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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221932 268f45cc-cd09-0410-ab3c-d52691b4dbfc
17 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
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