Skip to content

Commit

Permalink
Adopt commitPriority to get rid of the 2 AVPL solution for PiP
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=158949
rdar://problem/26867866

Reviewed by Simon Fraser.

No new tests because there is no behavior change. This reverts changes from
https://bugs.webkit.org/show_bug.cgi?id=158148 and instead uses -[CAContext commitPriority:]
to prevent flicker when moving a layer between contexts.
commitPriority allows the layer to be added to the destination context before it is
removed from the source context.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: remove m_secondaryVideoLayer.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: ditto
(WebCore::MediaPlayerPrivateAVFoundationObjC::setVideoFullscreenGravity): ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::syncTextTrackBounds): ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::destroyVideoLayer): ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::updateVideoLayerGravity): ditto.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: ditto
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::addDisplayLayer): ditto
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: ditto
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::createPreviewLayers):ditto
* platform/graphics/avfoundation/objc/VideoFullscreenLayerManager.h: ditto
* platform/graphics/avfoundation/objc/VideoFullscreenLayerManager.mm: ditto
(WebCore::VideoFullscreenLayerManager::setVideoLayer): ditto
(WebCore::VideoFullscreenLayerManager::setVideoFullscreenLayer): ditto and adopt commitPriority.
(WebCore::VideoFullscreenLayerManager::setVideoFullscreenFrame): ditto
(WebCore::VideoFullscreenLayerManager::setVideoLayers): Deleted.
(WebCore::VideoFullscreenLayerManager::didDestroyVideoLayer): remove m_secondaryVideoLayer.
* platform/spi/cocoa/QuartzCoreSPI.h: Add commitPriority.

Canonical link: https://commits.webkit.org/177117@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202350 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Jeremy Jones committed Jun 22, 2016
1 parent a6a345e commit 50e007e
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 66 deletions.
33 changes: 33 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,36 @@
2016-06-20 Jeremy Jones <jeremyj@apple.com>

Adopt commitPriority to get rid of the 2 AVPL solution for PiP
https://bugs.webkit.org/show_bug.cgi?id=158949
rdar://problem/26867866

Reviewed by Simon Fraser.

No new tests because there is no behavior change. This reverts changes from
https://bugs.webkit.org/show_bug.cgi?id=158148 and instead uses -[CAContext commitPriority:]
to prevent flicker when moving a layer between contexts.
commitPriority allows the layer to be added to the destination context before it is
removed from the source context.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: remove m_secondaryVideoLayer.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: ditto
(WebCore::MediaPlayerPrivateAVFoundationObjC::setVideoFullscreenGravity): ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::syncTextTrackBounds): ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::destroyVideoLayer): ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::updateVideoLayerGravity): ditto.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: ditto
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::addDisplayLayer): ditto
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: ditto
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::createPreviewLayers):ditto
* platform/graphics/avfoundation/objc/VideoFullscreenLayerManager.h: ditto
* platform/graphics/avfoundation/objc/VideoFullscreenLayerManager.mm: ditto
(WebCore::VideoFullscreenLayerManager::setVideoLayer): ditto
(WebCore::VideoFullscreenLayerManager::setVideoFullscreenLayer): ditto and adopt commitPriority.
(WebCore::VideoFullscreenLayerManager::setVideoFullscreenFrame): ditto
(WebCore::VideoFullscreenLayerManager::setVideoLayers): Deleted.
(WebCore::VideoFullscreenLayerManager::didDestroyVideoLayer): remove m_secondaryVideoLayer.
* platform/spi/cocoa/QuartzCoreSPI.h: Add commitPriority.

2016-06-22 Simon Fraser <simon.fraser@apple.com>

REGRESSION (r201629): Weird button glitching on github.com
Expand Down
Expand Up @@ -340,7 +340,6 @@ class MediaPlayerPrivateAVFoundationObjC : public MediaPlayerPrivateAVFoundation
RetainPtr<AVPlayer> m_avPlayer;
RetainPtr<AVPlayerItem> m_avPlayerItem;
RetainPtr<AVPlayerLayer> m_videoLayer;
RetainPtr<AVPlayerLayer> m_secondaryVideoLayer;
#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
std::unique_ptr<VideoFullscreenLayerManager> m_videoFullscreenLayerManager;
MediaPlayer::VideoGravity m_videoFullscreenGravity;
Expand Down
Expand Up @@ -734,33 +734,24 @@ void receivedChallengeRejection(const AuthenticationChallenge&) override
[m_videoLayer setPlayer:m_avPlayer.get()];
[m_videoLayer setBackgroundColor:cachedCGColor(Color::black)];

#if PLATFORM(MAC)
m_secondaryVideoLayer = adoptNS([allocAVPlayerLayerInstance() init]);
[m_secondaryVideoLayer setPlayer:m_avPlayer.get()];
[m_secondaryVideoLayer setBackgroundColor:cachedCGColor(Color::black)];
#endif

#ifndef NDEBUG
[m_videoLayer setName:@"MediaPlayerPrivate AVPlayerLayer"];
[m_secondaryVideoLayer setName:@"MediaPlayerPrivate AVPlayerLayer secondary"];
#endif
[m_videoLayer addObserver:m_objcObserver.get() forKeyPath:@"readyForDisplay" options:NSKeyValueObservingOptionNew context:(void *)MediaPlayerAVFoundationObservationContextAVPlayerLayer];
updateVideoLayerGravity();
[m_videoLayer setContentsScale:player()->client().mediaPlayerContentsScale()];
[m_secondaryVideoLayer setContentsScale:player()->client().mediaPlayerContentsScale()];
IntSize defaultSize = snappedIntRect(player()->client().mediaPlayerContentBoxRect()).size();
LOG(Media, "MediaPlayerPrivateAVFoundationObjC::createVideoLayer(%p) - returning %p", this, m_videoLayer.get());

#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
m_videoFullscreenLayerManager->setVideoLayers(m_videoLayer.get(), m_secondaryVideoLayer.get(), defaultSize);
m_videoFullscreenLayerManager->setVideoLayer(m_videoLayer.get(), defaultSize);

#if PLATFORM(IOS)
if ([m_videoLayer respondsToSelector:@selector(setPIPModeEnabled:)])
[m_videoLayer setPIPModeEnabled:(player()->fullscreenMode() & MediaPlayer::VideoFullscreenModePictureInPicture)];
#endif
#else
[m_videoLayer setFrame:CGRectMake(0, 0, defaultSize.width(), defaultSize.height())];
[m_secondaryVideoLayer setFrame:CGRectMake(0, 0, defaultSize.width(), defaultSize.height())];
#endif
}

Expand All @@ -773,14 +764,12 @@ void receivedChallengeRejection(const AuthenticationChallenge&) override

[m_videoLayer removeObserver:m_objcObserver.get() forKeyPath:@"readyForDisplay"];
[m_videoLayer setPlayer:nil];
[m_secondaryVideoLayer setPlayer:nil];

#if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
m_videoFullscreenLayerManager->didDestroyVideoLayer();
#endif

m_videoLayer = nil;
m_secondaryVideoLayer = nil;
}

MediaTime MediaPlayerPrivateAVFoundationObjC::getStartDate() const
Expand Down Expand Up @@ -1231,8 +1220,7 @@ void receivedChallengeRejection(const AuthenticationChallenge&) override
{
m_videoFullscreenGravity = gravity;

auto activeLayer = m_secondaryVideoLayer.get() ?: m_videoLayer.get();
if (!activeLayer)
if (!m_videoLayer)
return;

NSString *videoGravity = AVLayerVideoGravityResizeAspect;
Expand All @@ -1245,10 +1233,10 @@ void receivedChallengeRejection(const AuthenticationChallenge&) override
else
ASSERT_NOT_REACHED();

if ([activeLayer videoGravity] == videoGravity)
if ([m_videoLayer videoGravity] == videoGravity)
return;

[activeLayer setVideoGravity:videoGravity];
[m_videoLayer setVideoGravity:videoGravity];
syncTextTrackBounds();
}

Expand Down Expand Up @@ -1901,7 +1889,6 @@ static void fulfillRequestWithKeyData(AVAssetResourceLoadingRequest *request, Ar
[CATransaction setDisableActions:YES];
NSString* gravity = shouldMaintainAspectRatio() ? AVLayerVideoGravityResizeAspect : AVLayerVideoGravityResize;
[m_videoLayer.get() setVideoGravity:gravity];
[m_secondaryVideoLayer.get() setVideoGravity:gravity];
[CATransaction commit];
}

Expand Down Expand Up @@ -2197,8 +2184,7 @@ void determineChangedTracksFromNewTracksAndOldItems(MediaSelectionGroupAVFObjC*
return;

FloatRect videoFullscreenFrame = m_videoFullscreenLayerManager->videoFullscreenFrame();
auto activeLayer = m_secondaryVideoLayer.get() ?: m_videoLayer.get();
CGRect textFrame = activeLayer ? [activeLayer videoRect] : CGRectMake(0, 0, videoFullscreenFrame.width(), videoFullscreenFrame.height());
CGRect textFrame = m_videoLayer ? [m_videoLayer videoRect] : CGRectMake(0, 0, videoFullscreenFrame.width(), videoFullscreenFrame.height());
[m_textTrackRepresentationLayer setFrame:textFrame];
#endif
}
Expand Down
Expand Up @@ -755,7 +755,7 @@ static void CMTimebaseEffectiveRateChangedCallback(CMNotificationCenterRef, cons
m_player->firstVideoFrameAvailable();

#if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
m_videoFullscreenLayerManager->setVideoLayers(m_sampleBufferDisplayLayer.get(), nil, snappedIntRect(m_player->client().mediaPlayerContentBoxRect()).size());
m_videoFullscreenLayerManager->setVideoLayer(m_sampleBufferDisplayLayer.get(), snappedIntRect(m_player->client().mediaPlayerContentBoxRect()).size());
#endif
}

Expand Down
Expand Up @@ -404,7 +404,7 @@
m_videoBackgroundLayer.get().name = @"MediaPlayerPrivateMediaStreamAVFObjC preview background layer";

#if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
m_videoFullscreenLayerManager->setVideoLayers(m_videoBackgroundLayer.get(), nil, snappedIntRect(m_player->client().mediaPlayerContentBoxRect()).size());
m_videoFullscreenLayerManager->setVideoLayer(m_videoBackgroundLayer.get(), snappedIntRect(m_player->client().mediaPlayerContentBoxRect()).size());
#endif
}

Expand Down
Expand Up @@ -44,7 +44,7 @@ class VideoFullscreenLayerManager {
PlatformLayer *videoInlineLayer() const { return m_videoInlineLayer.get(); }
PlatformLayer *videoFullscreenLayer() const { return m_videoFullscreenLayer.get(); }
FloatRect videoFullscreenFrame() const { return m_videoFullscreenFrame; }
void setVideoLayers(PlatformLayer *, PlatformLayer *, IntSize contentSize);
void setVideoLayer(PlatformLayer *, IntSize contentSize);
void setVideoFullscreenLayer(PlatformLayer *, std::function<void()> completionHandler);
void setVideoFullscreenFrame(FloatRect);
void didDestroyVideoLayer();
Expand All @@ -55,7 +55,6 @@ class VideoFullscreenLayerManager {
RetainPtr<PlatformLayer> m_videoInlineLayer;
RetainPtr<PlatformLayer> m_videoFullscreenLayer;
RetainPtr<PlatformLayer> m_videoLayer;
RetainPtr<PlatformLayer> m_secondaryVideoLayer;
FloatRect m_videoFullscreenFrame;
};

Expand Down
Expand Up @@ -66,27 +66,22 @@ - (void)setPosition:(CGPoint)position
{
}

void VideoFullscreenLayerManager::setVideoLayers(PlatformLayer *videoLayer, PlatformLayer *secondaryVideoLayer, IntSize contentSize)
void VideoFullscreenLayerManager::setVideoLayer(PlatformLayer *videoLayer, IntSize contentSize)
{
m_videoLayer = videoLayer;
m_secondaryVideoLayer = secondaryVideoLayer;

[m_videoLayer web_disableAllActions];
[m_secondaryVideoLayer web_disableAllActions];
m_videoInlineLayer = adoptNS([[WebVideoContainerLayer alloc] init]);
#ifndef NDEBUG
[m_videoInlineLayer setName:@"WebVideoContainerLayer"];
#endif
[m_videoInlineLayer setFrame:CGRectMake(0, 0, contentSize.width(), contentSize.height())];
if (m_videoFullscreenLayer) {
[m_videoLayer removeFromSuperlayer];
PlatformLayer *activeLayer = secondaryVideoLayer ? secondaryVideoLayer : videoLayer;
[activeLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())];
[m_videoFullscreenLayer insertSublayer:activeLayer atIndex:0];
[m_videoLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())];
[m_videoFullscreenLayer insertSublayer:m_videoLayer.get() atIndex:0];
} else {
[m_videoInlineLayer insertSublayer:m_videoLayer.get() atIndex:0];
[m_videoLayer setFrame:m_videoInlineLayer.get().bounds];
[m_secondaryVideoLayer removeFromSuperlayer];
}
}

Expand All @@ -102,47 +97,26 @@ - (void)setPosition:(CGPoint)position
[CATransaction begin];
[CATransaction setDisableActions:YES];

if (m_secondaryVideoLayer && m_videoLayer) {
if (m_videoFullscreenLayer) {
[m_videoFullscreenLayer insertSublayer:m_secondaryVideoLayer.get() atIndex:0];
[m_secondaryVideoLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())];
} else if (m_videoInlineLayer) {
[m_videoLayer setFrame:[m_videoInlineLayer bounds]];
[m_videoInlineLayer insertSublayer:m_videoLayer.get() atIndex:0];
}
if (m_videoLayer) {
CAContext *oldContext = [m_videoLayer context];

RetainPtr<PlatformLayer> fullscreenLayer = m_videoFullscreenLayer;
RetainPtr<PlatformLayer> videoLayer = m_videoLayer;
RetainPtr<PlatformLayer> secondaryVideoLayer = m_secondaryVideoLayer;

[CATransaction setCompletionBlock:[completionHandler, fullscreenLayer, videoLayer, secondaryVideoLayer] {
[CATransaction begin];
[CATransaction setDisableActions:YES];

if (fullscreenLayer)
[videoLayer removeFromSuperlayer];
else
[secondaryVideoLayer removeFromSuperlayer];

[CATransaction setCompletionBlock:[completionHandler] {
completionHandler();
}];
[CATransaction commit];
}];
} else if (m_videoLayer) {
if (m_videoFullscreenLayer) {
[m_videoFullscreenLayer insertSublayer:m_videoLayer.get() atIndex:0];
[m_videoLayer setFrame:CGRectMake(0, 0, m_videoFullscreenFrame.width(), m_videoFullscreenFrame.height())];
} else if (m_videoInlineLayer) {
[m_videoLayer setFrame:[m_videoInlineLayer bounds]];
[m_videoLayer removeFromSuperlayer];
[m_videoInlineLayer insertSublayer:m_videoLayer.get() atIndex:0];
} else
[m_videoLayer removeFromSuperlayer];

CAContext *oldContext = [m_videoFullscreenLayer context];
CAContext *newContext = [m_videoInlineLayer context];
CAContext *newContext = [m_videoLayer context];
if (oldContext && newContext && oldContext != newContext) {
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
if ([oldContext respondsToSelector:@selector(setCommitPriority:)]) {
[oldContext setCommitPriority:0];
[newContext setCommitPriority:1];
}
#endif
mach_port_t fencePort = [oldContext createFencePort];
[newContext setFencePort:fencePort];
mach_port_deallocate(mach_task_self(), fencePort);
Expand All @@ -166,18 +140,15 @@ - (void)setPosition:(CGPoint)position
if (!m_videoFullscreenLayer)
return;

PlatformLayer *activeLayer = m_secondaryVideoLayer.get() ? m_secondaryVideoLayer.get() : m_videoLayer.get();
[activeLayer setFrame:CGRectMake(0, 0, videoFullscreenFrame.width(), videoFullscreenFrame.height())];
[m_videoLayer setFrame:CGRectMake(0, 0, videoFullscreenFrame.width(), videoFullscreenFrame.height())];
}

void VideoFullscreenLayerManager::didDestroyVideoLayer()
{
[m_videoLayer removeFromSuperlayer];
[m_secondaryVideoLayer removeFromSuperlayer];

m_videoInlineLayer = nil;
m_videoLayer = nil;
m_secondaryVideoLayer = nil;
}

}
Expand Down
9 changes: 9 additions & 0 deletions Source/WebCore/platform/spi/cocoa/QuartzCoreSPI.h
Expand Up @@ -41,6 +41,12 @@
#import <QuartzCore/CADisplay.h>
#endif

#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
@interface CAContext ()
- (void)setCommitPriority:(uint32_t)commitPriority;
@end
#endif

#endif // __OBJC__

#else
Expand All @@ -59,6 +65,9 @@
- (mach_port_t)createFencePort;
- (void)setFencePort:(mach_port_t)port;
- (void)setFencePort:(mach_port_t)port commitHandler:(void(^)(void))block;
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
@property uint32_t commitPriority;
#endif
#if PLATFORM(MAC)
@property BOOL colorMatchUntaggedContent;
#endif
Expand Down

0 comments on commit 50e007e

Please sign in to comment.