Skip to content

Commit

Permalink
[visionOS] Video briefly resizes to full-window when entering LinearM…
Browse files Browse the repository at this point in the history
…ediaPlayer fullscreen

https://bugs.webkit.org/show_bug.cgi?id=271032
rdar://123315074

Reviewed by Jer Noble.

Prior to this change, VideoPresentationInterfaceIOS would create a new UIWindow in which the player
view controller would be presented. However, LinearMediaKit would immediately hide this window and
present the fullscreen video in a new UIScene. When entering LinearMediaPlayer fullscreen, this
resulted in the UIWindow briefly appearing then being hidden prior to the LinearMediaKit scene being
presented.

To avoid this, skip creating the UIWindow for LinearMediaPlayer fullscreen. Instead, embed the
LMPlayableViewController in WKWebView's presenting view controller with its root view sized to match
the inline video element. Then, allow LinearMediaKit to hide the WKWebView's UIWindowScene and
present its own scene. This results in a less flashy, more direct transition from inline to
fullscreen.

* Source/WebCore/platform/ios/VideoPresentationInterfaceIOS.h:
(WebCore::VideoPresentationInterfaceIOS::hasMode const):
(WebCore::VideoPresentationInterfaceIOS::fullscreenViewController const):
* Source/WebCore/platform/ios/VideoPresentationInterfaceIOS.mm:
(WebCore::VideoPresentationInterfaceIOS::presentingViewController):
(WebCore::VideoPresentationInterfaceIOS::doSetup):
(WebCore::VideoPresentationInterfaceIOS::cleanupFullscreen):

Canonical link: https://commits.webkit.org/276177@main
  • Loading branch information
aestes committed Mar 15, 2024
1 parent 9494ab0 commit 1294f70
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 0 additions & 2 deletions Source/WebCore/platform/ios/VideoPresentationInterfaceIOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,8 @@ class VideoPresentationInterfaceIOS
WEBCORE_EXPORT void setMode(HTMLMediaElementEnums::VideoFullscreenMode, bool shouldNotifyModel);
void clearMode(HTMLMediaElementEnums::VideoFullscreenMode, bool shouldNotifyModel);
bool hasMode(HTMLMediaElementEnums::VideoFullscreenMode mode) const { return m_currentMode.hasMode(mode); }
#if PLATFORM(WATCHOS) || PLATFORM(APPLETV)
WEBCORE_EXPORT UIViewController *presentingViewController();
UIViewController *fullscreenViewController() const { return m_viewController.get(); }
#endif
WEBCORE_EXPORT virtual bool pictureInPictureWasStartedWhenEnteringBackground() const = 0;

WEBCORE_EXPORT std::optional<MediaPlayerIdentifier> playerIdentifier() const;
Expand Down
27 changes: 16 additions & 11 deletions Source/WebCore/platform/ios/VideoPresentationInterfaceIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ @interface UIViewController ()
static const Seconds defaultWatchdogTimerInterval { 1_s };
static bool ignoreWatchdogForDebugging = false;

#if PLATFORM(WATCHOS) || PLATFORM(APPLETV)
static UIViewController *fallbackViewController(UIView *view)
{
// FIXME: This logic to find a fallback view controller should move out of WebCore,
Expand All @@ -99,7 +98,6 @@ @interface UIViewController ()

return controller;
}
#endif

VideoPresentationInterfaceIOS::VideoPresentationInterfaceIOS(PlaybackSessionInterfaceIOS& playbackSessionInterface)
: m_watchdogTimer(RunLoop::main(), this, &VideoPresentationInterfaceIOS::watchdogTimerFired)
Expand Down Expand Up @@ -215,7 +213,7 @@ @interface UIViewController ()
[CATransaction begin];
[CATransaction setDisableActions:YES];

#if !PLATFORM(WATCHOS)
#if !PLATFORM(WATCHOS) && !ENABLE(LINEAR_MEDIA_PLAYER)
if (![[m_parentView window] _isHostedInAnotherProcess] && !m_window) {
m_window = adoptNS([PAL::allocUIWindowInstance() initWithWindowScene:[[m_parentView window] windowScene]]);
[m_window setBackgroundColor:clearUIColor()];
Expand All @@ -231,7 +229,7 @@ @interface UIViewController ()
[m_window setWindowLevel:textEffectsWindowLevel - 1];
[m_window makeKeyAndVisible];
}
#endif // !PLATFORM(WATCHOS)
#endif // !PLATFORM(WATCHOS) && !ENABLE(LINEAR_MEDIA_PLAYER)

if (!m_playerLayerView)
m_playerLayerView = adoptNS([allocWebAVPlayerLayerViewInstance() init]);
Expand All @@ -252,12 +250,19 @@ @interface UIViewController ()

UIViewController *playerViewController = this->playerViewController();

UIView *parentView;
UIViewController *presentingViewController;
if (m_viewController) {
[m_viewController addChildViewController:playerViewController];
[[m_viewController view] addSubview:playerViewController.view];
[playerViewController didMoveToParentViewController:m_viewController.get()];
} else
[m_parentView addSubview:playerViewController.view];
parentView = [m_viewController view];
presentingViewController = m_viewController.get();
} else {
parentView = m_parentView.get();
presentingViewController = this->presentingViewController();
}

[presentingViewController addChildViewController:playerViewController];
[parentView addSubview:playerViewController.view];
[playerViewController didMoveToParentViewController:presentingViewController];

playerViewController.view.frame = [m_parentView convertRect:m_inlineRect toView:playerViewController.view.superview];
playerViewController.view.backgroundColor = clearUIColor();
Expand Down Expand Up @@ -538,9 +543,9 @@ @interface UIViewController ()
});
}

[playerViewController willMoveToParentViewController:nil];
[[playerViewController view] removeFromSuperview];
if (m_viewController)
[playerViewController removeFromParentViewController];
[playerViewController removeFromParentViewController];

[m_playerLayerView setVideoView:nil];
[m_playerLayerView removeFromSuperview];
Expand Down

0 comments on commit 1294f70

Please sign in to comment.