Changeset 201474 in webkit
- Timestamp:
- May 27, 2016 4:58:28 PM (8 years ago)
- Location:
- trunk/Source
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r201471 r201474 1 2016-05-27 Jeremy Jones <jeremyj@apple.com> 2 3 Decrease flicker when changing video presentation mode. 4 https://bugs.webkit.org/show_bug.cgi?id=158148 5 rdar://problem/24476949 6 7 Reviewed by Jer Noble. 8 9 No new tests because there is no behavior change. This change is about the timing of 10 moving AVPlayerLayers between layers to prevent flicker. 11 12 1) Moving an AVPlayerLayer between CAContexts can flicker. So always keep two 13 AVPlayerLayers around and add and remove them from the inline and fullscreen contexts. 14 2) Wait to show the inline placeholder until the fullscreen video layer has been installed. 15 3) Wait to remove the fullscreen video layer until the placeholder has been removed. 16 17 * Modules/mediacontrols/MediaControlsHost.cpp: 18 (WebCore::MediaControlsHost::isVideoLayerInline): Expose isVideoLayerInline to the shadow DOM. 19 (WebCore::MediaControlsHost::setPreparedForInline): Expose setPreparedForInline to the shadow DOM. 20 * Modules/mediacontrols/MediaControlsHost.h: Add setPreparedForInline and isVideoLayerInline 21 * Modules/mediacontrols/MediaControlsHost.idl: Add setPreparedForInline and isVideoLayerInline 22 * Modules/mediacontrols/mediaControlsApple.js: 23 (Controller.prototype.showInlinePlaybackPlaceholderWhenSafe): Wait to show placeholder when entering fullscreen. 24 (Controller.prototype.handlePresentationModeChange): Wait to show placeholder, and notify when placeholder is removed. 25 * html/HTMLMediaElement.cpp: 26 (WebCore::HTMLMediaElement::setPreparedForInline): 27 (WebCore::HTMLMediaElement::waitForPreparedForInlineThen): Used to delay fullscreen cleanup until placeholder is removed. 28 (WebCore::HTMLMediaElement::setVideoFullscreenLayer): Add a callback so we can wait until this completes before continuing. 29 * html/HTMLMediaElement.h: 30 (WebCore::HTMLMediaElement::isVideoLayerInline): 31 (WebCore::HTMLMediaElement::waitForPreparedForInlineThen): 32 (WebCore::HTMLMediaElement::setVideoFullscreenLayer): Add completionHandler. 33 * platform/cocoa/WebVideoFullscreenModelVideoElement.h: 34 (WebCore::WebVideoFullscreenModelVideoElement::setVideoFullscreenLayer): Add completionHandler. 35 (WebCore::WebVideoFullscreenModelVideoElement::waitForPreparedForInlineThen): Added. 36 * platform/cocoa/WebVideoFullscreenModelVideoElement.mm: 37 (WebVideoFullscreenModelVideoElement::setVideoFullscreenLayer): Add completionHandler. 38 (WebVideoFullscreenModelVideoElement::waitForPreparedForInlineThen): 39 * platform/graphics/MediaPlayer.cpp: 40 (WebCore::MediaPlayer::setVideoFullscreenLayer): Add completionHandler. 41 * platform/graphics/MediaPlayer.h: 42 (WebCore::MediaPlayer::setVideoFullscreenLayer): Add completionHandler. 43 * platform/graphics/MediaPlayerPrivate.h: 44 (WebCore::MediaPlayerPrivateInterface::setVideoFullscreenLayer): Add completionHandler. 45 * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: 46 * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: 47 (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerLayer): Create two video layers. 48 (WebCore::MediaPlayerPrivateAVFoundationObjC::destroyVideoLayer): Allow two video layers. 49 (WebCore::MediaPlayerPrivateAVFoundationObjC::setVideoFullscreenLayer): Add completionHandler. 50 (WebCore::MediaPlayerPrivateAVFoundationObjC::updateVideoLayerGravity): Allow two video layers. 51 * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: 52 * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: 53 (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::addDisplayLayer): Allow two video layers. 54 (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::setVideoFullscreenLayer): Add completionHandler. 55 * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: 56 * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: 57 (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::createPreviewLayers): Allow two video layers. 58 (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::setVideoFullscreenLayer): Add completionHandler. 59 * platform/graphics/avfoundation/objc/VideoFullscreenLayerManager.h: 60 * platform/graphics/avfoundation/objc/VideoFullscreenLayerManager.mm: 61 (WebCore::VideoFullscreenLayerManager::setVideoLayers): Allow two video layers. 62 (WebCore::VideoFullscreenLayerManager::setVideoFullscreenLayer): Add completionHandler. 63 (WebCore::VideoFullscreenLayerManager::setVideoFullscreenFrame): Allow two video layers. 64 (WebCore::VideoFullscreenLayerManager::didDestroyVideoLayer): Allow two video layers. 65 (WebCore::VideoFullscreenLayerManager::setVideoLayer): Deleted. 66 * platform/ios/WebVideoFullscreenControllerAVKit.mm: 67 (WebVideoFullscreenControllerContext::didSetupFullscreen): Use completionHandler. 68 (WebVideoFullscreenControllerContext::didExitFullscreen): Use completionHandler. 69 1 70 2016-05-26 Ryosuke Niwa <rniwa@webkit.org> 2 71 -
trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp
r200361 r201474 211 211 } 212 212 213 bool MediaControlsHost::isVideoLayerInline() 214 { 215 return m_mediaElement->isVideoLayerInline(); 216 } 217 218 void MediaControlsHost::setPreparedForInline(bool value) 219 { 220 m_mediaElement->setPreparedForInline(value); 221 } 222 213 223 bool MediaControlsHost::userGestureRequired() const 214 224 { -
trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.h
r200361 r201474 65 65 bool allowsInlineMediaPlayback() const; 66 66 bool supportsFullscreen(); 67 bool isVideoLayerInline(); 67 68 bool userGestureRequired() const; 69 void setPreparedForInline(bool); 68 70 69 71 void updateCaptionDisplaySizes(); -
trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl
r199963 r201474 43 43 readonly attribute DOMString captionDisplayMode; 44 44 void setSelectedTextTrack(TextTrack? track); 45 void setPreparedForInline(boolean prepared); 45 46 readonly attribute HTMLElement textTrackContainer; 46 47 readonly attribute boolean allowsInlineMediaPlayback; 47 48 readonly attribute boolean supportsFullscreen; 49 readonly attribute boolean isVideoLayerInline; 48 50 readonly attribute boolean userGestureRequired; 49 51 -
trunk/Source/WebCore/Modules/mediacontrols/mediaControlsApple.js
r201355 r201474 83 83 webkitendfullscreen: 'handleFullscreenChange', 84 84 }, 85 PlaceholderPollingDelay: 33, 85 86 HideControlsDelay: 4 * 1000, 86 87 RewindAmount: 30, … … 838 839 }, 839 840 841 showInlinePlaybackPlaceholderWhenSafe: function() { 842 if (this.presentationMode() != 'picture-in-picture') 843 return; 844 845 if (!this.host.isVideoLayerInline) 846 this.controls.inlinePlaybackPlaceholder.classList.remove(this.ClassNames.hidden); 847 else 848 setTimeout(this.showInlinePlaybackPlaceholderWhenSafe.bind(this), this.PlaceholderPollingDelay); 849 }, 850 840 851 handlePresentationModeChange: function(event) 841 852 { … … 855 866 this.controls.panel.classList.add(this.ClassNames.pictureInPicture); 856 867 this.controls.inlinePlaybackPlaceholder.classList.add(this.ClassNames.pictureInPicture); 857 this. controls.inlinePlaybackPlaceholder.classList.remove(this.ClassNames.hidden);868 this.showInlinePlaybackPlaceholderWhenSafe(); 858 869 859 870 this.controls.inlinePlaybackPlaceholderTextTop.innerText = this.UIString('This video is playing in Picture in Picture'); … … 884 895 if (presentationMode != 'fullscreen' && this.video.paused && this.controlsAreHidden()) 885 896 this.showControls(); 897 this.host.setPreparedForInline(presentationMode === 'inline') 886 898 }, 887 899 -
trunk/Source/WebCore/html/HTMLMediaElement.cpp
r201441 r201474 5472 5472 } 5473 5473 5474 void HTMLMediaElement::setPreparedForInline(bool value) 5475 { 5476 m_preparedForInline = value; 5477 if (m_preparedForInline && m_preparedForInlineCompletionHandler) { 5478 m_preparedForInlineCompletionHandler(); 5479 m_preparedForInlineCompletionHandler = nullptr; 5480 } 5481 } 5482 5483 void HTMLMediaElement::waitForPreparedForInlineThen(std::function<void()> completionHandler) 5484 { 5485 ASSERT(!m_preparedForInlineCompletionHandler); 5486 if (m_preparedForInline) { 5487 completionHandler(); 5488 return; 5489 } 5490 5491 m_preparedForInlineCompletionHandler = completionHandler; 5492 } 5493 5474 5494 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) 5475 5495 5476 void HTMLMediaElement::setVideoFullscreenLayer(PlatformLayer* platformLayer) 5496 bool HTMLMediaElement::isVideoLayerInline() 5497 { 5498 return !m_videoFullscreenLayer; 5499 }; 5500 5501 void HTMLMediaElement::setVideoFullscreenLayer(PlatformLayer* platformLayer, std::function<void()> completionHandler) 5477 5502 { 5478 5503 m_videoFullscreenLayer = platformLayer; 5479 if (!m_player) 5480 return; 5504 if (!m_player) { 5505 completionHandler(); 5506 return; 5507 } 5481 5508 5482 m_player->setVideoFullscreenLayer(platformLayer );5509 m_player->setVideoFullscreenLayer(platformLayer, completionHandler); 5483 5510 setNeedsStyleRecalc(SyntheticStyleChange); 5484 5511 #if ENABLE(VIDEO_TRACK) … … 5500 5527 m_player->setVideoFullscreenGravity(gravity); 5501 5528 } 5529 5530 #else 5531 5532 bool HTMLMediaElement::isVideoLayerInline() 5533 { 5534 return true; 5535 }; 5502 5536 5503 5537 #endif -
trunk/Source/WebCore/html/HTMLMediaElement.h
r201435 r201474 134 134 WEBCORE_EXPORT PlatformMedia platformMedia() const; 135 135 PlatformLayer* platformLayer() const; 136 bool isVideoLayerInline(); 137 void setPreparedForInline(bool); 138 void waitForPreparedForInlineThen(std::function<void()> completionHandler = [] { }); 136 139 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) 137 void setVideoFullscreenLayer(PlatformLayer* );140 void setVideoFullscreenLayer(PlatformLayer*, std::function<void()> completionHandler = [] { }); 138 141 PlatformLayer* videoFullscreenLayer() const { return m_videoFullscreenLayer.get(); } 139 142 void setVideoFullscreenFrame(FloatRect); … … 848 851 849 852 VideoFullscreenMode m_videoFullscreenMode; 853 bool m_preparedForInline; 854 std::function<void()> m_preparedForInlineCompletionHandler; 850 855 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) 851 856 RetainPtr<PlatformLayer> m_videoFullscreenLayer; -
trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.h
r201305 r201474 35 35 #include "PlatformLayer.h" 36 36 #include "WebVideoFullscreenModel.h" 37 #include <functional> 37 38 #include <wtf/RefPtr.h> 38 39 #include <wtf/RetainPtr.h> … … 56 57 WEBCORE_EXPORT void setVideoElement(HTMLVideoElement*); 57 58 WEBCORE_EXPORT HTMLVideoElement* videoElement() const { return m_videoElement.get(); } 58 WEBCORE_EXPORT void setVideoFullscreenLayer(PlatformLayer*); 59 WEBCORE_EXPORT void setVideoFullscreenLayer(PlatformLayer*, std::function<void()> completionHandler = [] { }); 60 WEBCORE_EXPORT void waitForPreparedForInlineThen(std::function<void()> completionHandler = [] { }); 59 61 WebPlaybackSessionModelMediaElement& playbackSessionModel() { return m_playbackSessionModel; } 60 62 -
trunk/Source/WebCore/platform/cocoa/WebVideoFullscreenModelVideoElement.mm
r201305 r201474 121 121 } 122 122 123 void WebVideoFullscreenModelVideoElement::setVideoFullscreenLayer(PlatformLayer* videoLayer) 124 { 125 if (m_videoFullscreenLayer == videoLayer) 126 return; 123 void WebVideoFullscreenModelVideoElement::setVideoFullscreenLayer(PlatformLayer* videoLayer, std::function<void()> completionHandler) 124 { 125 if (m_videoFullscreenLayer == videoLayer) { 126 completionHandler(); 127 return; 128 } 127 129 128 130 m_videoFullscreenLayer = videoLayer; … … 134 136 [m_videoFullscreenLayer setBounds:m_videoFrame]; 135 137 136 if (m_videoElement) 137 m_videoElement->setVideoFullscreenLayer(m_videoFullscreenLayer.get()); 138 if (!m_videoElement) { 139 completionHandler(); 140 return; 141 } 142 143 m_videoElement->setVideoFullscreenLayer(m_videoFullscreenLayer.get(), completionHandler); 144 } 145 146 void WebVideoFullscreenModelVideoElement::waitForPreparedForInlineThen(std::function<void()> completionHandler) 147 { 148 if (!m_videoElement) { 149 completionHandler(); 150 return; 151 } 152 153 m_videoElement->waitForPreparedForInlineThen(completionHandler); 138 154 } 139 155 -
trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp
r199326 r201474 661 661 662 662 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) 663 void MediaPlayer::setVideoFullscreenLayer(PlatformLayer* layer )664 { 665 m_private->setVideoFullscreenLayer(layer );663 void MediaPlayer::setVideoFullscreenLayer(PlatformLayer* layer, std::function<void()> completionHandler) 664 { 665 m_private->setVideoFullscreenLayer(layer, completionHandler); 666 666 } 667 667 -
trunk/Source/WebCore/platform/graphics/MediaPlayer.h
r199326 r201474 309 309 310 310 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) 311 void setVideoFullscreenLayer(PlatformLayer* );311 void setVideoFullscreenLayer(PlatformLayer*, std::function<void()> completionHandler = [] { }); 312 312 void setVideoFullscreenFrame(FloatRect); 313 313 using MediaPlayerEnums::VideoGravity; -
trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h
r199326 r201474 60 60 61 61 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) 62 virtual void setVideoFullscreenLayer(PlatformLayer* ) {}62 virtual void setVideoFullscreenLayer(PlatformLayer*, std::function<void()> completionHandler) { completionHandler(); } 63 63 virtual void setVideoFullscreenFrame(FloatRect) { } 64 64 virtual void setVideoFullscreenGravity(MediaPlayer::VideoGravity) { } -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
r199672 r201474 173 173 PlatformLayer* platformLayer() const override; 174 174 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) 175 void setVideoFullscreenLayer(PlatformLayer* ) override;175 void setVideoFullscreenLayer(PlatformLayer*, std::function<void()> completionHandler) override; 176 176 void setVideoFullscreenFrame(FloatRect) override; 177 177 void setVideoFullscreenGravity(MediaPlayer::VideoGravity) override; … … 330 330 RetainPtr<AVPlayerItem> m_avPlayerItem; 331 331 RetainPtr<AVPlayerLayer> m_videoLayer; 332 RetainPtr<AVPlayerLayer> m_secondaryVideoLayer; 332 333 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) 333 334 std::unique_ptr<VideoFullscreenLayerManager> m_videoFullscreenLayerManager; -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
r201038 r201474 731 731 [m_videoLayer setPlayer:m_avPlayer.get()]; 732 732 [m_videoLayer setBackgroundColor:cachedCGColor(Color::black)]; 733 734 m_secondaryVideoLayer = adoptNS([allocAVPlayerLayerInstance() init]); 735 [m_secondaryVideoLayer setPlayer:m_avPlayer.get()]; 736 [m_secondaryVideoLayer setBackgroundColor:cachedCGColor(Color::black)]; 737 733 738 #ifndef NDEBUG 734 739 [m_videoLayer setName:@"MediaPlayerPrivate AVPlayerLayer"]; 740 [m_secondaryVideoLayer setName:@"MediaPlayerPrivate AVPlayerLayer secondary"]; 735 741 #endif 736 742 [m_videoLayer addObserver:m_objcObserver.get() forKeyPath:@"readyForDisplay" options:NSKeyValueObservingOptionNew context:(void *)MediaPlayerAVFoundationObservationContextAVPlayerLayer]; 737 743 updateVideoLayerGravity(); 738 744 [m_videoLayer setContentsScale:player()->client().mediaPlayerContentsScale()]; 745 [m_secondaryVideoLayer setContentsScale:player()->client().mediaPlayerContentsScale()]; 739 746 IntSize defaultSize = snappedIntRect(player()->client().mediaPlayerContentBoxRect()).size(); 740 747 LOG(Media, "MediaPlayerPrivateAVFoundationObjC::createVideoLayer(%p) - returning %p", this, m_videoLayer.get()); 741 748 742 749 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) 743 m_videoFullscreenLayerManager->setVideoLayer (m_videoLayer.get(), defaultSize);750 m_videoFullscreenLayerManager->setVideoLayers(m_videoLayer.get(), m_secondaryVideoLayer.get(), defaultSize); 744 751 745 752 #if PLATFORM(IOS) … … 749 756 #else 750 757 [m_videoLayer setFrame:CGRectMake(0, 0, defaultSize.width(), defaultSize.height())]; 758 [m_secondaryVideoLayer setFrame:CGRectMake(0, 0, defaultSize.width(), defaultSize.height())]; 751 759 #endif 752 760 } … … 759 767 LOG(Media, "MediaPlayerPrivateAVFoundationObjC::destroyVideoLayer(%p) - destroying %p", this, m_videoLayer.get()); 760 768 761 [m_videoLayer.get() removeObserver:m_objcObserver.get() forKeyPath:@"readyForDisplay"]; 762 [m_videoLayer.get() setPlayer:nil]; 769 [m_videoLayer removeObserver:m_objcObserver.get() forKeyPath:@"readyForDisplay"]; 770 [m_videoLayer setPlayer:nil]; 771 [m_secondaryVideoLayer setPlayer:nil]; 763 772 764 773 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) … … 767 776 768 777 m_videoLayer = nil; 778 m_secondaryVideoLayer = nil; 769 779 } 770 780 … … 1184 1194 1185 1195 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) 1186 void MediaPlayerPrivateAVFoundationObjC::setVideoFullscreenLayer(PlatformLayer* videoFullscreenLayer) 1187 { 1188 if (m_videoFullscreenLayerManager->videoFullscreenLayer() == videoFullscreenLayer) 1189 return; 1190 1191 m_videoFullscreenLayerManager->setVideoFullscreenLayer(videoFullscreenLayer); 1196 void MediaPlayerPrivateAVFoundationObjC::setVideoFullscreenLayer(PlatformLayer* videoFullscreenLayer, std::function<void()> completionHandler) 1197 { 1198 if (m_videoFullscreenLayerManager->videoFullscreenLayer() == videoFullscreenLayer) { 1199 completionHandler(); 1200 return; 1201 } 1202 1203 m_videoFullscreenLayerManager->setVideoFullscreenLayer(videoFullscreenLayer, completionHandler); 1192 1204 1193 1205 if (m_videoFullscreenLayerManager->videoFullscreenLayer() && m_textTrackRepresentationLayer) { … … 1873 1885 NSString* gravity = shouldMaintainAspectRatio() ? AVLayerVideoGravityResizeAspect : AVLayerVideoGravityResize; 1874 1886 [m_videoLayer.get() setVideoGravity:gravity]; 1887 [m_secondaryVideoLayer.get() setVideoGravity:gravity]; 1875 1888 [CATransaction commit]; 1876 1889 } -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h
r197563 r201474 88 88 89 89 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE) 90 void setVideoFullscreenLayer(PlatformLayer* ) override;90 void setVideoFullscreenLayer(PlatformLayer*, std::function<void()> completionHandler) override; 91 91 void setVideoFullscreenFrame(FloatRect) override; 92 92 #endif -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm
r200315 r201474 771 771 772 772 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE) 773 m_videoFullscreenLayerManager->setVideoLayer (m_sampleBufferDisplayLayer.get(), snappedIntRect(m_player->client().mediaPlayerContentBoxRect()).size());773 m_videoFullscreenLayerManager->setVideoLayers(m_sampleBufferDisplayLayer.get(), nil, snappedIntRect(m_player->client().mediaPlayerContentBoxRect()).size()); 774 774 #endif 775 775 } … … 829 829 830 830 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE) 831 void MediaPlayerPrivateMediaSourceAVFObjC::setVideoFullscreenLayer(PlatformLayer *videoFullscreenLayer )832 { 833 m_videoFullscreenLayerManager->setVideoFullscreenLayer(videoFullscreenLayer );831 void MediaPlayerPrivateMediaSourceAVFObjC::setVideoFullscreenLayer(PlatformLayer *videoFullscreenLayer, std::function<void()> completionHandler) 832 { 833 m_videoFullscreenLayerManager->setVideoFullscreenLayer(videoFullscreenLayer, completionHandler); 834 834 } 835 835 -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h
r197807 r201474 161 161 162 162 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE) 163 void setVideoFullscreenLayer(PlatformLayer* ) override;163 void setVideoFullscreenLayer(PlatformLayer*, std::function<void()> completionHandler) override; 164 164 void setVideoFullscreenFrame(FloatRect) override; 165 165 #endif -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm
r201333 r201474 405 405 406 406 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE) 407 m_videoFullscreenLayerManager->setVideoLayer (m_videoBackgroundLayer.get(), snappedIntRect(m_player->client().mediaPlayerContentBoxRect()).size());407 m_videoFullscreenLayerManager->setVideoLayers(m_videoBackgroundLayer.get(), nil, snappedIntRect(m_player->client().mediaPlayerContentBoxRect()).size()); 408 408 #endif 409 409 } … … 475 475 476 476 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE) 477 void MediaPlayerPrivateMediaStreamAVFObjC::setVideoFullscreenLayer(PlatformLayer *videoFullscreenLayer )478 { 479 m_videoFullscreenLayerManager->setVideoFullscreenLayer(videoFullscreenLayer );477 void MediaPlayerPrivateMediaStreamAVFObjC::setVideoFullscreenLayer(PlatformLayer *videoFullscreenLayer, std::function<void()> completionHandler) 478 { 479 m_videoFullscreenLayerManager->setVideoFullscreenLayer(videoFullscreenLayer, completionHandler); 480 480 } 481 481 -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/VideoFullscreenLayerManager.h
r195595 r201474 32 32 #include "IntSize.h" 33 33 #include "PlatformLayer.h" 34 #include <functional> 34 35 #include <wtf/RetainPtr.h> 35 36 … … 44 45 PlatformLayer *videoFullscreenLayer() const { return m_videoFullscreenLayer.get(); } 45 46 FloatRect videoFullscreenFrame() const { return m_videoFullscreenFrame; } 46 void setVideoLayer (PlatformLayer *, IntSize contentSize);47 void setVideoFullscreenLayer(PlatformLayer * );47 void setVideoLayers(PlatformLayer *, PlatformLayer *, IntSize contentSize); 48 void setVideoFullscreenLayer(PlatformLayer *, std::function<void()> completionHandler); 48 49 void setVideoFullscreenFrame(FloatRect); 49 50 void didDestroyVideoLayer(); … … 55 56 RetainPtr<PlatformLayer> m_videoFullscreenLayer; 56 57 RetainPtr<PlatformLayer> m_videoLayer; 58 RetainPtr<PlatformLayer> m_secondaryVideoLayer; 57 59 FloatRect m_videoFullscreenFrame; 58 60 }; -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/VideoFullscreenLayerManager.mm
r195595 r201474 67 67 } 68 68 69 void VideoFullscreenLayerManager::setVideoLayer (PlatformLayer *videoLayer, IntSize contentSize)69 void VideoFullscreenLayerManager::setVideoLayers(PlatformLayer *videoLayer, PlatformLayer *secondaryVideoLayer, IntSize contentSize) 70 70 { 71 71 m_videoLayer = videoLayer; 72 m_secondaryVideoLayer = secondaryVideoLayer; 72 73 73 74 [m_videoLayer web_disableAllActions]; 75 [m_secondaryVideoLayer web_disableAllActions]; 74 76 m_videoInlineLayer = adoptNS([[WebVideoContainerLayer alloc] init]); 75 77 #ifndef NDEBUG … … 78 80 [m_videoInlineLayer setFrame:CGRectMake(0, 0, contentSize.width(), contentSize.height())]; 79 81 if (m_videoFullscreenLayer) { 80 [m_videoLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())]; 81 [m_videoFullscreenLayer insertSublayer:m_videoLayer.get() atIndex:0]; 82 [m_videoLayer removeFromSuperlayer]; 83 PlatformLayer *activeLayer = secondaryVideoLayer ? secondaryVideoLayer : videoLayer; 84 [activeLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())]; 85 [m_videoFullscreenLayer insertSublayer:activeLayer atIndex:0]; 82 86 } else { 83 87 [m_videoInlineLayer insertSublayer:m_videoLayer.get() atIndex:0]; 84 88 [m_videoLayer setFrame:m_videoInlineLayer.get().bounds]; 89 [m_secondaryVideoLayer removeFromSuperlayer]; 85 90 } 86 91 } 87 92 88 void VideoFullscreenLayerManager::setVideoFullscreenLayer(PlatformLayer *videoFullscreenLayer )93 void VideoFullscreenLayerManager::setVideoFullscreenLayer(PlatformLayer *videoFullscreenLayer, std::function<void()> completionHandler) 89 94 { 90 if (m_videoFullscreenLayer == videoFullscreenLayer) 95 if (m_videoFullscreenLayer == videoFullscreenLayer) { 96 completionHandler(); 91 97 return; 98 } 92 99 93 100 m_videoFullscreenLayer = videoFullscreenLayer; … … 96 103 [CATransaction setDisableActions:YES]; 97 104 98 CAContext *oldContext = [m_videoLayer context]; 99 CAContext *newContext = nil; 105 if (m_secondaryVideoLayer && m_videoLayer) { 106 if (m_videoFullscreenLayer) { 107 [m_videoFullscreenLayer insertSublayer:m_secondaryVideoLayer.get() atIndex:0]; 108 [m_secondaryVideoLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())]; 109 } else if (m_videoInlineLayer) { 110 [m_videoLayer setFrame:[m_videoInlineLayer bounds]]; 111 [m_videoInlineLayer insertSublayer:m_videoLayer.get() atIndex:0]; 112 } 100 113 101 if (m_videoFullscreenLayer && m_videoLayer) { 102 [m_videoFullscreenLayer insertSublayer:m_videoLayer.get() atIndex:0]; 103 [m_videoLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())]; 104 newContext = [m_videoFullscreenLayer context]; 105 } else if (m_videoInlineLayer && m_videoLayer) { 106 [m_videoLayer setFrame:[m_videoInlineLayer bounds]]; 107 [m_videoLayer removeFromSuperlayer]; 108 [m_videoInlineLayer insertSublayer:m_videoLayer.get() atIndex:0]; 109 newContext = [m_videoInlineLayer context]; 110 } else if (m_videoLayer) 111 [m_videoLayer removeFromSuperlayer]; 114 RetainPtr<PlatformLayer> fullscreenLayer = m_videoFullscreenLayer; 115 RetainPtr<PlatformLayer> videoLayer = m_videoLayer; 116 RetainPtr<PlatformLayer> secondaryVideoLayer = m_secondaryVideoLayer; 112 117 113 if (oldContext && newContext && oldContext != newContext) { 114 mach_port_t fencePort = [oldContext createFencePort]; 115 [newContext setFencePort:fencePort]; 116 mach_port_deallocate(mach_task_self(), fencePort); 118 [CATransaction setCompletionBlock:[completionHandler, fullscreenLayer, videoLayer, secondaryVideoLayer] { 119 [CATransaction begin]; 120 [CATransaction setDisableActions:YES]; 121 122 if (fullscreenLayer) 123 [videoLayer removeFromSuperlayer]; 124 else 125 [secondaryVideoLayer removeFromSuperlayer]; 126 127 [CATransaction setCompletionBlock:[completionHandler] { 128 completionHandler(); 129 }]; 130 [CATransaction commit]; 131 }]; 132 } else if (m_videoLayer) { 133 if (m_videoFullscreenLayer) { 134 [m_videoFullscreenLayer insertSublayer:m_videoLayer.get() atIndex:0]; 135 [m_videoLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())]; 136 } else if (m_videoInlineLayer) { 137 [m_videoLayer setFrame:[m_videoInlineLayer bounds]]; 138 [m_videoLayer removeFromSuperlayer]; 139 [m_videoInlineLayer insertSublayer:m_videoLayer.get() atIndex:0]; 140 } else 141 [m_videoLayer removeFromSuperlayer]; 142 143 CAContext *oldContext = [m_videoFullscreenLayer context]; 144 CAContext *newContext = [m_videoInlineLayer context]; 145 if (oldContext && newContext && oldContext != newContext) { 146 mach_port_t fencePort = [oldContext createFencePort]; 147 [newContext setFencePort:fencePort]; 148 mach_port_deallocate(mach_task_self(), fencePort); 149 } 150 151 [CATransaction setCompletionBlock:[completionHandler] { 152 completionHandler(); 153 }]; 154 } else { 155 [CATransaction setCompletionBlock:[completionHandler] { 156 completionHandler(); 157 }]; 117 158 } 159 118 160 [CATransaction commit]; 119 161 } … … 125 167 return; 126 168 127 if (m_videoLayer)128 [m_videoLayer setFrame:CGRectMake(0, 0, videoFullscreenFrame.width(), videoFullscreenFrame.height())];169 PlatformLayer *activeLayer = m_secondaryVideoLayer.get() ? m_secondaryVideoLayer.get() : m_videoLayer.get(); 170 [activeLayer setFrame:CGRectMake(0, 0, videoFullscreenFrame.width(), videoFullscreenFrame.height())]; 129 171 } 130 172 131 173 void VideoFullscreenLayerManager::didDestroyVideoLayer() 132 174 { 133 if (m_videoFullscreenLayer)134 [m_videoLayer removeFromSuperlayer];175 [m_videoLayer removeFromSuperlayer]; 176 [m_secondaryVideoLayer removeFromSuperlayer]; 135 177 136 178 m_videoInlineLayer = nil; 137 179 m_videoLayer = nil; 180 m_secondaryVideoLayer = nil; 138 181 } 139 182 -
trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm
r201354 r201474 248 248 WebThreadRun([protectedThis, this, videoFullscreenLayer] { 249 249 [videoFullscreenLayer setBackgroundColor:cachedCGColor(WebCore::Color::transparent)]; 250 m_model->setVideoFullscreenLayer(videoFullscreenLayer.get()); 251 dispatch_async(dispatch_get_main_queue(), [protectedThis, this] { 252 m_interface->enterFullscreen(); 250 m_model->setVideoFullscreenLayer(videoFullscreenLayer.get(), [protectedThis, this] { 251 dispatch_async(dispatch_get_main_queue(), [protectedThis, this] { 252 m_interface->enterFullscreen(); 253 }); 253 254 }); 254 255 }); … … 260 261 RefPtr<WebVideoFullscreenControllerContext> protectedThis(this); 261 262 WebThreadRun([protectedThis, this] { 262 m_model->setVideoFullscreenLayer(nil); 263 dispatch_async(dispatch_get_main_queue(), [protectedThis, this] { 264 m_interface->cleanupFullscreen(); 263 m_model->setVideoFullscreenLayer(nil, [protectedThis, this] { 264 dispatch_async(dispatch_get_main_queue(), [protectedThis, this] { 265 m_interface->cleanupFullscreen(); 266 }); 265 267 }); 266 268 }); -
trunk/Source/WebKit2/ChangeLog
r201464 r201474 1 2016-05-27 Jeremy Jones <jeremyj@apple.com> 2 3 Decrease flicker when changing video presentation mode. 4 https://bugs.webkit.org/show_bug.cgi?id=158148 5 rdar://problem/24476949 6 7 Reviewed by Tim Horton. 8 9 Prevent flicker by using setVideoFullscreenLayer with a completion handler to delay 10 enter fullscreen and cleanup fullscreen until the video layer has completely been 11 installed or removed. 12 13 * WebProcess/cocoa/WebVideoFullscreenManager.mm: 14 (WebKit::WebVideoFullscreenManager::didSetupFullscreen): 15 (WebKit::WebVideoFullscreenManager::didExitFullscreen): 16 1 17 2016-05-27 Chris Dumez <cdumez@apple.com> 2 18 -
trunk/Source/WebKit2/WebProcess/cocoa/WebVideoFullscreenManager.mm
r200157 r201474 370 370 371 371 interface->layerHostingContext()->setRootLayer(videoLayer); 372 model->setVideoFullscreenLayer(videoLayer); 373 372 373 RefPtr<WebVideoFullscreenManager> strongThis(this); 374 375 model->setVideoFullscreenLayer(videoLayer, [strongThis, this, contextId] { 376 dispatch_async(dispatch_get_main_queue(), [strongThis, this, contextId] { 377 m_page->send(Messages::WebVideoFullscreenManagerProxy::EnterFullscreen(contextId), m_page->pageID()); 378 }); 379 }); 380 374 381 [CATransaction commit]; 375 376 RefPtr<WebVideoFullscreenManager> strongThis(this);377 dispatch_async(dispatch_get_main_queue(), [strongThis, this, contextId] {378 m_page->send(Messages::WebVideoFullscreenManagerProxy::EnterFullscreen(contextId), m_page->pageID());379 });380 382 } 381 383 … … 408 410 RefPtr<WebVideoFullscreenInterfaceContext> interface; 409 411 std::tie(model, interface) = ensureModelAndInterface(contextId); 410 411 model->setVideoFullscreenLayer(nil);412 413 412 RefPtr<WebVideoFullscreenManager> strongThis(this); 414 dispatch_async(dispatch_get_main_queue(), [strongThis, contextId, interface] { 415 if (interface->layerHostingContext()) { 416 interface->layerHostingContext()->setRootLayer(nullptr); 417 interface->setLayerHostingContext(nullptr); 418 } 419 if (strongThis->m_page) 420 strongThis->m_page->send(Messages::WebVideoFullscreenManagerProxy::CleanupFullscreen(contextId), strongThis->m_page->pageID()); 413 414 model->waitForPreparedForInlineThen([strongThis, this, contextId, interface, model] { 415 dispatch_async(dispatch_get_main_queue(), [strongThis, this, contextId, interface, model] { 416 model->setVideoFullscreenLayer(nil, [strongThis, this, contextId, interface] { 417 dispatch_async(dispatch_get_main_queue(), [strongThis, this, contextId, interface] { 418 if (interface->layerHostingContext()) { 419 interface->layerHostingContext()->setRootLayer(nullptr); 420 interface->setLayerHostingContext(nullptr); 421 } 422 if (strongThis->m_page) 423 strongThis->m_page->send(Messages::WebVideoFullscreenManagerProxy::CleanupFullscreen(contextId), strongThis->m_page->pageID()); 424 }); 425 }); 426 }); 421 427 }); 422 428 }
Note: See TracChangeset
for help on using the changeset viewer.