Title: [277242] trunk/Source
Revision
277242
Author
[email protected]
Date
2021-05-08 21:53:33 -0700 (Sat, 08 May 2021)

Log Message

[GPUP] A small video element enters fullscreen with strange animations
https://bugs.webkit.org/show_bug.cgi?id=225548

Reviewed by Eric Carlson.

Use `FloatRect` instead of `IntRect` to exchange video element location/size
information between WebContent processes and the UI process to avoid information
mismatch due to floating-point rounding.

Source/WebCore:

Manually tested.

* platform/ios/VideoFullscreenInterfaceAVKit.h:
* platform/ios/VideoFullscreenInterfaceAVKit.mm:
(VideoFullscreenInterfaceAVKit::setupFullscreen):
(VideoFullscreenInterfaceAVKit::exitFullscreen):
(VideoFullscreenInterfaceAVKit::preparedToReturnToInline):
(VideoFullscreenInterfaceAVKit::setInlineRect):

Source/WebKit:

Deal with the video element resizing differently for two cases:
1) Video is playing in the inline mode.
2) Video is entering fullscreen/picture-in-picture.
For the latter case, `-[WKVideoLayerRemote layoutSublayers]` will scale the layer
with the same factor in both X and Y direction.

* GPUProcess/media/RemoteMediaPlayerProxy.h:
* GPUProcess/media/RemoteMediaPlayerProxy.messages.in:
* GPUProcess/media/cocoa/RemoteMediaPlayerProxyCocoa.mm:
(WebKit::setVideoInlineSizeIfPossible):
(WebKit::RemoteMediaPlayerProxy::setVideoInlineSizeFenced):

* UIProcess/Cocoa/VideoFullscreenManagerProxy.h:
* UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in:
* UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
(WebKit::VideoFullscreenManagerProxy::setupFullscreenWithID):
(WebKit::VideoFullscreenManagerProxy::exitFullscreen):
(WebKit::VideoFullscreenManagerProxy::setInlineRect):
(WebKit::VideoFullscreenManagerProxy::preparedToReturnToInline):

* WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
(WebKit::MediaPlayerPrivateRemote::setVideoInlineSizeFenced):
(WebKit::MediaPlayerPrivateRemote::inVideoFullscreenOrPictureInPicture const):
* WebProcess/GPU/media/MediaPlayerPrivateRemote.h:
* WebProcess/GPU/media/cocoa/VideoLayerRemoteCocoa.mm:
(-[WKVideoLayerRemote layoutSublayers]):
(-[WKVideoLayerRemote resolveBounds]):
* WebProcess/cocoa/VideoFullscreenManager.mm:
(WebKit::inlineVideoFrame):
(WebKit::VideoFullscreenManager::requestUpdateInlineRect):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (277241 => 277242)


--- trunk/Source/WebCore/ChangeLog	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebCore/ChangeLog	2021-05-09 04:53:33 UTC (rev 277242)
@@ -1,3 +1,23 @@
+2021-05-08  Peng Liu  <[email protected]>
+
+        [GPUP] A small video element enters fullscreen with strange animations
+        https://bugs.webkit.org/show_bug.cgi?id=225548
+
+        Reviewed by Eric Carlson.
+
+        Use `FloatRect` instead of `IntRect` to exchange video element location/size
+        information between WebContent processes and the UI process to avoid information
+        mismatch due to floating-point rounding.
+
+        Manually tested.
+
+        * platform/ios/VideoFullscreenInterfaceAVKit.h:
+        * platform/ios/VideoFullscreenInterfaceAVKit.mm:
+        (VideoFullscreenInterfaceAVKit::setupFullscreen):
+        (VideoFullscreenInterfaceAVKit::exitFullscreen):
+        (VideoFullscreenInterfaceAVKit::preparedToReturnToInline):
+        (VideoFullscreenInterfaceAVKit::setInlineRect):
+
 2021-05-08  Sam Weinig  <[email protected]>
 
         Factor out pixel buffer from DOM specific ImageData class

Modified: trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h (277241 => 277242)


--- trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.h	2021-05-09 04:53:33 UTC (rev 277242)
@@ -54,7 +54,7 @@
 OBJC_CLASS NSError;
 
 namespace WebCore {
-class IntRect;
+class FloatRect;
 class FloatSize;
 class VideoFullscreenModel;
 class VideoFullscreenChangeObserver;
@@ -80,16 +80,16 @@
     // PlaybackSessionModelClient
     WEBCORE_EXPORT void externalPlaybackChanged(bool enabled, PlaybackSessionModel::ExternalPlaybackTargetType, const String& localizedDeviceName) final;
 
-    WEBCORE_EXPORT void setupFullscreen(UIView& videoView, const IntRect& initialRect, const FloatSize& videoDimensions, UIView* parentView, HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicturePlayback, bool standby, bool blocksReturnToFullscreenFromPictureInPicture);
+    WEBCORE_EXPORT void setupFullscreen(UIView& videoView, const FloatRect& initialRect, const FloatSize& videoDimensions, UIView* parentView, HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicturePlayback, bool standby, bool blocksReturnToFullscreenFromPictureInPicture);
     WEBCORE_EXPORT void enterFullscreen();
-    WEBCORE_EXPORT bool exitFullscreen(const IntRect& finalRect);
+    WEBCORE_EXPORT bool exitFullscreen(const FloatRect& finalRect);
     WEBCORE_EXPORT void cleanupFullscreen();
     WEBCORE_EXPORT void invalidate();
     WEBCORE_EXPORT void requestHideAndExitFullscreen();
-    WEBCORE_EXPORT void preparedToReturnToInline(bool visible, const IntRect& inlineRect);
+    WEBCORE_EXPORT void preparedToReturnToInline(bool visible, const FloatRect& inlineRect);
     WEBCORE_EXPORT void preparedToExitFullscreen();
     WEBCORE_EXPORT void setHasVideoContentLayer(bool);
-    WEBCORE_EXPORT void setInlineRect(const IntRect&, bool visible);
+    WEBCORE_EXPORT void setInlineRect(const FloatRect&, bool visible);
     WEBCORE_EXPORT void preparedToReturnToStandby();
     bool changingStandbyOnly() { return m_changingStandbyOnly; }
 

Modified: trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm (277241 => 277242)


--- trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm	2021-05-09 04:53:33 UTC (rev 277242)
@@ -926,7 +926,7 @@
     LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::applicationDidBecomeActive(%p)", this);
 }
 
-void VideoFullscreenInterfaceAVKit::setupFullscreen(UIView& videoView, const IntRect& initialRect, const FloatSize& videoDimensions, UIView* parentView, HTMLMediaElementEnums::VideoFullscreenMode mode, bool allowsPictureInPicturePlayback, bool standby, bool blocksReturnToFullscreenFromPictureInPicture)
+void VideoFullscreenInterfaceAVKit::setupFullscreen(UIView& videoView, const FloatRect& initialRect, const FloatSize& videoDimensions, UIView* parentView, HTMLMediaElementEnums::VideoFullscreenMode mode, bool allowsPictureInPicturePlayback, bool standby, bool blocksReturnToFullscreenFromPictureInPicture)
 {
     ASSERT(standby || mode != HTMLMediaElementEnums::VideoFullscreenModeNone);
     LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::setupFullscreen(%p)", this);
@@ -956,7 +956,7 @@
     doEnterFullscreen();
 }
 
-bool VideoFullscreenInterfaceAVKit::exitFullscreen(const IntRect& finalRect)
+bool VideoFullscreenInterfaceAVKit::exitFullscreen(const FloatRect& finalRect)
 {
     m_watchdogTimer.stop();
 
@@ -1066,7 +1066,7 @@
     }
 }
 
-void VideoFullscreenInterfaceAVKit::preparedToReturnToInline(bool visible, const IntRect& inlineRect)
+void VideoFullscreenInterfaceAVKit::preparedToReturnToInline(bool visible, const FloatRect& inlineRect)
 {
     LOG(Fullscreen, "VideoFullscreenInterfaceAVKit::preparedToReturnToInline(%p) - visible(%s)", this, boolString(visible));
     setInlineRect(inlineRect, visible);
@@ -1301,7 +1301,7 @@
         doExitFullscreen();
 }
 
-void VideoFullscreenInterfaceAVKit::setInlineRect(const IntRect& inlineRect, bool visible)
+void VideoFullscreenInterfaceAVKit::setInlineRect(const FloatRect& inlineRect, bool visible)
 {
     m_inlineRect = inlineRect;
     m_inlineIsVisible = visible;

Modified: trunk/Source/WebKit/ChangeLog (277241 => 277242)


--- trunk/Source/WebKit/ChangeLog	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebKit/ChangeLog	2021-05-09 04:53:33 UTC (rev 277242)
@@ -1,3 +1,45 @@
+2021-05-08  Peng Liu  <[email protected]>
+
+        [GPUP] A small video element enters fullscreen with strange animations
+        https://bugs.webkit.org/show_bug.cgi?id=225548
+
+        Reviewed by Eric Carlson.
+
+        Use `FloatRect` instead of `IntRect` to exchange video element location/size
+        information between WebContent processes and the UI process to avoid information
+        mismatch due to floating-point rounding.
+
+        Deal with the video element resizing differently for two cases:
+        1) Video is playing in the inline mode.
+        2) Video is entering fullscreen/picture-in-picture.
+        For the latter case, `-[WKVideoLayerRemote layoutSublayers]` will scale the layer
+        with the same factor in both X and Y direction.
+
+        * GPUProcess/media/RemoteMediaPlayerProxy.h:
+        * GPUProcess/media/RemoteMediaPlayerProxy.messages.in:
+        * GPUProcess/media/cocoa/RemoteMediaPlayerProxyCocoa.mm:
+        (WebKit::setVideoInlineSizeIfPossible):
+        (WebKit::RemoteMediaPlayerProxy::setVideoInlineSizeFenced):
+
+        * UIProcess/Cocoa/VideoFullscreenManagerProxy.h:
+        * UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in:
+        * UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:
+        (WebKit::VideoFullscreenManagerProxy::setupFullscreenWithID):
+        (WebKit::VideoFullscreenManagerProxy::exitFullscreen):
+        (WebKit::VideoFullscreenManagerProxy::setInlineRect):
+        (WebKit::VideoFullscreenManagerProxy::preparedToReturnToInline):
+
+        * WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
+        (WebKit::MediaPlayerPrivateRemote::setVideoInlineSizeFenced):
+        (WebKit::MediaPlayerPrivateRemote::inVideoFullscreenOrPictureInPicture const):
+        * WebProcess/GPU/media/MediaPlayerPrivateRemote.h:
+        * WebProcess/GPU/media/cocoa/VideoLayerRemoteCocoa.mm:
+        (-[WKVideoLayerRemote layoutSublayers]):
+        (-[WKVideoLayerRemote resolveBounds]):
+        * WebProcess/cocoa/VideoFullscreenManager.mm:
+        (WebKit::inlineVideoFrame):
+        (WebKit::VideoFullscreenManager::requestUpdateInlineRect):
+
 2021-05-08  Darin Adler  <[email protected]>
 
         Remove uses of the WTF::String::toInt family of functions from WebKit framework sources

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h (277241 => 277242)


--- trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h	2021-05-09 04:53:33 UTC (rev 277242)
@@ -146,7 +146,7 @@
     void didLoadingProgress(CompletionHandler<void(bool)>&&);
 
 #if PLATFORM(COCOA)
-    void setVideoInlineSizeFenced(const WebCore::IntSize&, const WTF::MachSendRight&);
+    void setVideoInlineSizeFenced(const WebCore::FloatSize&, const WTF::MachSendRight&);
 #endif
 
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
@@ -333,7 +333,7 @@
     Seconds m_videoPlaybackMetricsUpdateInterval;
     MonotonicTime m_nextPlaybackQualityMetricsUpdateTime;
 
-    WebCore::IntSize m_videoInlineSize;
+    WebCore::FloatSize m_videoInlineSize;
     float m_videoContentScale { 1.0 };
 
     bool m_bufferedChanged { true };

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.messages.in (277241 => 277242)


--- trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.messages.in	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.messages.in	2021-05-09 04:53:33 UTC (rev 277242)
@@ -66,7 +66,7 @@
     SetBufferingPolicy(WebCore::MediaPlayer::BufferingPolicy policy)
 
 #if PLATFORM(COCOA)
-    SetVideoInlineSizeFenced(WebCore::IntSize size, MachSendRight machSendRight)
+    SetVideoInlineSizeFenced(WebCore::FloatSize size, MachSendRight machSendRight)
 #endif
 
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)

Modified: trunk/Source/WebKit/GPUProcess/media/cocoa/RemoteMediaPlayerProxyCocoa.mm (277241 => 277242)


--- trunk/Source/WebKit/GPUProcess/media/cocoa/RemoteMediaPlayerProxyCocoa.mm	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebKit/GPUProcess/media/cocoa/RemoteMediaPlayerProxyCocoa.mm	2021-05-09 04:53:33 UTC (rev 277242)
@@ -31,15 +31,15 @@
 #import "LayerHostingContext.h"
 #import "MediaPlayerPrivateRemoteMessages.h"
 #import <QuartzCore/QuartzCore.h>
+#import <WebCore/FloatSize.h>
 #import <WebCore/IOSurface.h>
-#import <WebCore/IntSize.h>
 #import <wtf/MachSendRight.h>
 
 namespace WebKit {
 
-static void setVideoInlineSizeIfPossible(LayerHostingContext& context, const WebCore::IntSize& size)
+static void setVideoInlineSizeIfPossible(LayerHostingContext& context, const WebCore::FloatSize& size)
 {
-    if (!context.rootLayer())
+    if (!context.rootLayer() || size.isEmpty())
         return;
 
     // We do not want animations here.
@@ -70,7 +70,7 @@
     m_webProcessConnection->send(Messages::MediaPlayerPrivateRemote::FirstVideoFrameAvailable(), m_id);
 }
 
-void RemoteMediaPlayerProxy::setVideoInlineSizeFenced(const WebCore::IntSize& size, const WTF::MachSendRight& machSendRight)
+void RemoteMediaPlayerProxy::setVideoInlineSizeFenced(const WebCore::FloatSize& size, const WTF::MachSendRight& machSendRight)
 {
     m_inlineLayerHostingContext->setFencePort(machSendRight.sendRight());
 

Modified: trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h (277241 => 277242)


--- trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.h	2021-05-09 04:53:33 UTC (rev 277242)
@@ -174,15 +174,15 @@
     void hasVideoInPictureInPictureDidChange(bool);
 
     // Messages from VideoFullscreenManager
-    void setupFullscreenWithID(PlaybackSessionContextIdentifier, WebKit::LayerHostingContextID videoLayerID, const WebCore::IntRect& initialRect, const WebCore::FloatSize& videoDimensions, float hostingScaleFactor, WebCore::HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicture, bool standby, bool blocksReturnToFullscreenFromPictureInPicture);
-    void setInlineRect(PlaybackSessionContextIdentifier, const WebCore::IntRect& inlineRect, bool visible);
+    void setupFullscreenWithID(PlaybackSessionContextIdentifier, WebKit::LayerHostingContextID videoLayerID, const WebCore::FloatRect& initialRect, const WebCore::FloatSize& videoDimensions, float hostingScaleFactor, WebCore::HTMLMediaElementEnums::VideoFullscreenMode, bool allowsPictureInPicture, bool standby, bool blocksReturnToFullscreenFromPictureInPicture);
+    void setInlineRect(PlaybackSessionContextIdentifier, const WebCore::FloatRect& inlineRect, bool visible);
     void setHasVideoContentLayer(PlaybackSessionContextIdentifier, bool value);
     void setHasVideo(PlaybackSessionContextIdentifier, bool);
     void setVideoDimensions(PlaybackSessionContextIdentifier, const WebCore::FloatSize&);
     void enterFullscreen(PlaybackSessionContextIdentifier);
-    void exitFullscreen(PlaybackSessionContextIdentifier, WebCore::IntRect finalRect, CompletionHandler<void(bool)>&&);
+    void exitFullscreen(PlaybackSessionContextIdentifier, WebCore::FloatRect finalRect, CompletionHandler<void(bool)>&&);
     void cleanupFullscreen(PlaybackSessionContextIdentifier);
-    void preparedToReturnToInline(PlaybackSessionContextIdentifier, bool visible, WebCore::IntRect inlineRect);
+    void preparedToReturnToInline(PlaybackSessionContextIdentifier, bool visible, WebCore::FloatRect inlineRect);
     void preparedToExitFullscreen(PlaybackSessionContextIdentifier);
     void exitFullscreenWithoutAnimationToMode(PlaybackSessionContextIdentifier, WebCore::HTMLMediaElementEnums::VideoFullscreenMode);
 

Modified: trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in (277241 => 277242)


--- trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.messages.in	2021-05-09 04:53:33 UTC (rev 277242)
@@ -24,15 +24,15 @@
 messages -> VideoFullscreenManagerProxy {
     SetHasVideo(WebKit::PlaybackSessionContextIdentifier contextId, bool hasVideo)
     SetVideoDimensions(WebKit::PlaybackSessionContextIdentifier contextId, WebCore::FloatSize videoDimensions)
-    SetupFullscreenWithID(WebKit::PlaybackSessionContextIdentifier contextId, WebKit::LayerHostingContextID videoLayerID, WebCore::IntRect initialRect, WebCore::FloatSize videoDimensions, float hostingScaleFactor, WebCore::HTMLMediaElementEnums::VideoFullscreenMode videoFullscreenMode, bool allowsPictureInPicture, bool standby, bool blocksReturnToFullscreenFromPictureInPicture)
+    SetupFullscreenWithID(WebKit::PlaybackSessionContextIdentifier contextId, WebKit::LayerHostingContextID videoLayerID, WebCore::FloatRect initialRect, WebCore::FloatSize videoDimensions, float hostingScaleFactor, WebCore::HTMLMediaElementEnums::VideoFullscreenMode videoFullscreenMode, bool allowsPictureInPicture, bool standby, bool blocksReturnToFullscreenFromPictureInPicture)
 #if !PLATFORM(IOS_FAMILY)
     EnterFullscreen(WebKit::PlaybackSessionContextIdentifier contextId)
 #endif
-    ExitFullscreen(WebKit::PlaybackSessionContextIdentifier contextId, WebCore::IntRect finalRect) -> (bool success) Async
-    SetInlineRect(WebKit::PlaybackSessionContextIdentifier contextId, WebCore::IntRect inlineRect, bool visible)
+    ExitFullscreen(WebKit::PlaybackSessionContextIdentifier contextId, WebCore::FloatRect finalRect) -> (bool success) Async
+    SetInlineRect(WebKit::PlaybackSessionContextIdentifier contextId, WebCore::FloatRect inlineRect, bool visible)
     SetHasVideoContentLayer(WebKit::PlaybackSessionContextIdentifier contextId, bool value)
     CleanupFullscreen(WebKit::PlaybackSessionContextIdentifier contextId)
-    PreparedToReturnToInline(WebKit::PlaybackSessionContextIdentifier contextId, bool visible, WebCore::IntRect inlineRect)
+    PreparedToReturnToInline(WebKit::PlaybackSessionContextIdentifier contextId, bool visible, WebCore::FloatRect inlineRect)
     PreparedToExitFullscreen(WebKit::PlaybackSessionContextIdentifier contextId)
     ExitFullscreenWithoutAnimationToMode(WebKit::PlaybackSessionContextIdentifier contextId, WebCore::HTMLMediaElementEnums::VideoFullscreenMode videoFullscreenMode)
 }

Modified: trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm (277241 => 277242)


--- trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebKit/UIProcess/Cocoa/VideoFullscreenManagerProxy.mm	2021-05-09 04:53:33 UTC (rev 277242)
@@ -520,7 +520,7 @@
 
 #pragma mark Messages from VideoFullscreenManager
 
-void VideoFullscreenManagerProxy::setupFullscreenWithID(PlaybackSessionContextIdentifier contextId, WebKit::LayerHostingContextID videoLayerID, const WebCore::IntRect& initialRect, const WebCore::FloatSize& videoDimensions, float hostingDeviceScaleFactor, HTMLMediaElementEnums::VideoFullscreenMode videoFullscreenMode, bool allowsPictureInPicture, bool standby, bool blocksReturnToFullscreenFromPictureInPicture)
+void VideoFullscreenManagerProxy::setupFullscreenWithID(PlaybackSessionContextIdentifier contextId, WebKit::LayerHostingContextID videoLayerID, const WebCore::FloatRect& initialRect, const WebCore::FloatSize& videoDimensions, float hostingDeviceScaleFactor, HTMLMediaElementEnums::VideoFullscreenMode videoFullscreenMode, bool allowsPictureInPicture, bool standby, bool blocksReturnToFullscreenFromPictureInPicture)
 {
     MESSAGE_CHECK(videoLayerID);
 
@@ -561,7 +561,7 @@
     UNUSED_PARAM(videoDimensions);
     UNUSED_PARAM(blocksReturnToFullscreenFromPictureInPicture);
     IntRect initialWindowRect;
-    m_page->rootViewToWindow(initialRect, initialWindowRect);
+    m_page->rootViewToWindow(enclosingIntRect(initialRect), initialWindowRect);
     interface->setupFullscreen(*model->layerHostView(), initialWindowRect, m_page->platformWindow(), videoFullscreenMode, allowsPictureInPicture);
 #endif
 }
@@ -614,7 +614,7 @@
     }
 }
 
-void VideoFullscreenManagerProxy::exitFullscreen(PlaybackSessionContextIdentifier contextId, WebCore::IntRect finalRect, CompletionHandler<void(bool)>&& completionHandler)
+void VideoFullscreenManagerProxy::exitFullscreen(PlaybackSessionContextIdentifier contextId, WebCore::FloatRect finalRect, CompletionHandler<void(bool)>&& completionHandler)
 {
     ASSERT(m_contextMap.contains(contextId));
     if (!m_contextMap.contains(contextId)) {
@@ -624,7 +624,7 @@
 
 #if !PLATFORM(IOS_FAMILY)
     IntRect finalWindowRect;
-    m_page->rootViewToWindow(finalRect, finalWindowRect);
+    m_page->rootViewToWindow(enclosingIntRect(finalRect), finalWindowRect);
 #endif
 
     if (m_mockVideoPresentationModeEnabled) {
@@ -664,7 +664,7 @@
 
 #if PLATFORM(IOS_FAMILY)
 
-void VideoFullscreenManagerProxy::setInlineRect(PlaybackSessionContextIdentifier contextId, const WebCore::IntRect& inlineRect, bool visible)
+void VideoFullscreenManagerProxy::setInlineRect(PlaybackSessionContextIdentifier contextId, const WebCore::FloatRect& inlineRect, bool visible)
 {
     if (m_mockVideoPresentationModeEnabled)
         return;
@@ -688,7 +688,7 @@
 
 #else
 
-NO_RETURN_DUE_TO_ASSERT void VideoFullscreenManagerProxy::setInlineRect(PlaybackSessionContextIdentifier, const WebCore::IntRect&, bool)
+NO_RETURN_DUE_TO_ASSERT void VideoFullscreenManagerProxy::setInlineRect(PlaybackSessionContextIdentifier, const WebCore::FloatRect&, bool)
 {
     ASSERT_NOT_REACHED();
 }
@@ -710,13 +710,13 @@
     ensureInterface(contextId).cleanupFullscreen();
 }
 
-void VideoFullscreenManagerProxy::preparedToReturnToInline(PlaybackSessionContextIdentifier contextId, bool visible, WebCore::IntRect inlineRect)
+void VideoFullscreenManagerProxy::preparedToReturnToInline(PlaybackSessionContextIdentifier contextId, bool visible, WebCore::FloatRect inlineRect)
 {
     m_page->fullscreenMayReturnToInline();
 
 #if !PLATFORM(IOS_FAMILY)
     IntRect inlineWindowRect;
-    m_page->rootViewToWindow(inlineRect, inlineWindowRect);
+    m_page->rootViewToWindow(enclosingIntRect(inlineRect), inlineWindowRect);
 #endif
 
     if (m_mockVideoPresentationModeEnabled)

Modified: trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp (277241 => 277242)


--- trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp	2021-05-09 04:53:33 UTC (rev 277242)
@@ -871,7 +871,7 @@
 }
 
 #if PLATFORM(COCOA)
-void MediaPlayerPrivateRemote::setVideoInlineSizeFenced(const IntSize& size, const WTF::MachSendRight& machSendRight)
+void MediaPlayerPrivateRemote::setVideoInlineSizeFenced(const FloatSize& size, const WTF::MachSendRight& machSendRight)
 {
     connection().send(Messages::RemoteMediaPlayerProxy::SetVideoInlineSizeFenced(size, machSendRight), m_id);
 }
@@ -1212,6 +1212,17 @@
     connection().send(Messages::RemoteMediaPlayerProxy::NotifyActiveSourceBuffersChanged(), m_id);
 }
 
+#if PLATFORM(COCOA)
+bool MediaPlayerPrivateRemote::inVideoFullscreenOrPictureInPicture() const
+{
+#if ENABLE(VIDEO_PRESENTATION_MODE)
+    return !!m_videoLayerManager->videoFullscreenLayer();
+#else
+    return false;
+#endif
+}
+#endif
+
 void MediaPlayerPrivateRemote::applicationWillResignActive()
 {
     connection().send(Messages::RemoteMediaPlayerProxy::ApplicationWillResignActive(), m_id);

Modified: trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h (277241 => 277242)


--- trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h	2021-05-09 04:53:33 UTC (rev 277242)
@@ -107,7 +107,7 @@
     void firstVideoFrameAvailable();
     void renderingModeChanged();
 #if PLATFORM(COCOA)
-    void setVideoInlineSizeFenced(const WebCore::IntSize&, const WTF::MachSendRight&);
+    void setVideoInlineSizeFenced(const WebCore::FloatSize&, const WTF::MachSendRight&);
 #endif
 
     void currentTimeChanged(const MediaTime&, const MonotonicTime&);
@@ -146,6 +146,10 @@
 
     void activeSourceBuffersChanged();
 
+#if PLATFORM(COCOA)
+    bool inVideoFullscreenOrPictureInPicture() const;
+#endif
+
 #if ENABLE(ENCRYPTED_MEDIA)
     void waitingForKeyChanged(bool);
     void initializationDataEncountered(const String&, IPC::DataReference&&);

Modified: trunk/Source/WebKit/WebProcess/GPU/media/cocoa/VideoLayerRemoteCocoa.mm (277241 => 277242)


--- trunk/Source/WebKit/WebProcess/GPU/media/cocoa/VideoLayerRemoteCocoa.mm	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebKit/WebProcess/GPU/media/cocoa/VideoLayerRemoteCocoa.mm	2021-05-09 04:53:33 UTC (rev 277242)
@@ -91,7 +91,14 @@
 
     WebCore::FloatRect sourceVideoFrame = self.videoLayerFrame;
     WebCore::FloatRect targetVideoFrame = self.bounds;
-    CGAffineTransform transform = CGAffineTransformMakeScale(targetVideoFrame.width() / sourceVideoFrame.width(), targetVideoFrame.height() / sourceVideoFrame.height());
+    CGAffineTransform transform = CGAffineTransformIdentity;
+    if (!sourceVideoFrame.isEmpty()) {
+        if (auto* mediaPlayerPrivateRemote = self.mediaPlayerPrivateRemote; mediaPlayerPrivateRemote && mediaPlayerPrivateRemote->inVideoFullscreenOrPictureInPicture()) {
+            auto scale = std::fmax(targetVideoFrame.width() / sourceVideoFrame.width(), targetVideoFrame.height() / sourceVideoFrame.height());
+            transform = CGAffineTransformMakeScale(scale, scale);
+        } else
+            transform = CGAffineTransformMakeScale(targetVideoFrame.width() / sourceVideoFrame.width(), targetVideoFrame.height() / sourceVideoFrame.height());
+    }
 
     auto* videoSublayer = [sublayers objectAtIndex:0];
     [CATransaction begin];
@@ -136,7 +143,7 @@
         self.videoLayerFrame = self.bounds;
         if (auto* mediaPlayerPrivateRemote = self.mediaPlayerPrivateRemote) {
             MachSendRight fenceSendRight = MachSendRight::adopt([_context createFencePort]);
-            mediaPlayerPrivateRemote->setVideoInlineSizeFenced(WebCore::IntSize(self.videoLayerFrame.size), fenceSendRight);
+            mediaPlayerPrivateRemote->setVideoInlineSizeFenced(WebCore::FloatSize(self.videoLayerFrame.size), fenceSendRight);
         }
     }
 

Modified: trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm (277241 => 277242)


--- trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm	2021-05-09 04:31:43 UTC (rev 277241)
+++ trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm	2021-05-09 04:53:33 UTC (rev 277242)
@@ -59,7 +59,7 @@
 namespace WebKit {
 using namespace WebCore;
 
-static IntRect inlineVideoFrame(HTMLVideoElement& element)
+static FloatRect inlineVideoFrame(HTMLVideoElement& element)
 {
     auto& document = element.document();
     if (!document.hasLivingRenderTree() || document.activeDOMObjectsAreStopped())
@@ -73,7 +73,7 @@
     if (renderer->hasLayer() && renderer->enclosingLayer()->isComposited()) {
         FloatQuad contentsBox = static_cast<FloatRect>(renderer->enclosingLayer()->backing()->contentsBox());
         contentsBox = renderer->localToAbsoluteQuad(contentsBox);
-        return element.document().view()->contentsToRootView(contentsBox.enclosingBoundingBox());
+        return element.document().view()->contentsToRootView(contentsBox.boundingBox());
     }
 
     auto rect = renderer->videoBox();
@@ -393,7 +393,7 @@
         return;
 
     auto& model = ensureModel(contextId);
-    IntRect inlineRect = inlineVideoFrame(*model.videoElement());
+    auto inlineRect = inlineVideoFrame(*model.videoElement());
     m_page->send(Messages::VideoFullscreenManagerProxy::SetInlineRect(contextId, inlineRect, inlineRect != IntRect(0, 0, 0, 0)));
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to