[Mac] 10X slower than Chrome when drawing a video into a canvas
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Nov 2013 21:37:02 +0000 (21:37 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Nov 2013 21:37:02 +0000 (21:37 +0000)
commit2b997a965881627ca9ff094874a67ddd22047665
treefa15001b62a0e15a88de2885b1bb7ca1753b3437
parent85a7660b1d2384cedd84d80e9e3f9d2f492865ff
[Mac] 10X slower than Chrome when drawing a video into a canvas
https://bugs.webkit.org/show_bug.cgi?id=124599

Reviewed by Dean Jackson.

Improve performance by creating a CGImageRef which directly references the CVPixelBuffer provided
by AVPlayerItemVideoOutput:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::CVPixelBufferGetBytePointerCallback):
(WebCore::CVPixelBufferReleaseBytePointerCallback):
(WebCore::CVPixelBufferReleaseInfoCallback):
(WebCore::createImageFromPixelBuffer):
(WebCore::MediaPlayerPrivateAVFoundationObjC::updateLastImage):

Additionally, when asked to paint with an AVPlayerItemVideoOutput, block until the output notifies
its delegate that a pixel buffer is available:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::globalPullDelegateQueue):
(WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC):
(WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoOutput):
(WebCore::MediaPlayerPrivateAVFoundationObjC::paintWithVideoOutput):
(WebCore::MediaPlayerPrivateAVFoundationObjC::nativeImageForCurrentTime):
(WebCore::MediaPlayerPrivateAVFoundationObjC::waitForVideoOutputMediaDataWillChange):
(WebCore::MediaPlayerPrivateAVFoundationObjC::outputMediaDataWillChange):
(-[WebCoreAVFPullDelegate initWithCallback:]):
(-[WebCoreAVFPullDelegate outputMediaDataWillChange:]):
(-[WebCoreAVFPullDelegate outputSequenceWasFlushed:]):

To further optimize video -> canvas drawing, add a method which can return a PassNativeImage to be
drawn directly onto the canvas, rather than rendering into an intermediary context:
* html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::nativeImageForCurrentTime):
* html/HTMLVideoElement.h:
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawImage):
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::nativeImageForCurrentTime):
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::nativeImageForCurrentTime):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@159518 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLVideoElement.cpp
Source/WebCore/html/HTMLVideoElement.h
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/MediaPlayerPrivate.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm