Title: [271737] trunk/Source/WebKit
Revision
271737
Author
peng.l...@apple.com
Date
2021-01-21 22:11:21 -0800 (Thu, 21 Jan 2021)

Log Message

PiP video subtitles stop updating when Safari is backgrounded
https://bugs.webkit.org/show_bug.cgi?id=220660

Reviewed by Darin Adler.

Subtitles in the picture-in-picture window will stop updating when the browser is
in the background because we freeze the layer tree when a browser is in the background.
This patch fixes this issue by avoiding freezing the layer tree if a video is playing
in picture-in-picture when the browser is in the background.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updateDrawingAreaLayerTreeFreezeState):
* WebProcess/cocoa/VideoFullscreenManager.h:
* WebProcess/cocoa/VideoFullscreenManager.mm:
(WebKit::VideoFullscreenManager::videoInPictureInPicture const):
(WebKit::VideoFullscreenManager::enterVideoFullscreenForVideoElement):
(WebKit::VideoFullscreenManager::exitVideoFullscreenForVideoElement):
(WebKit::VideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (271736 => 271737)


--- trunk/Source/WebKit/ChangeLog	2021-01-22 06:08:18 UTC (rev 271736)
+++ trunk/Source/WebKit/ChangeLog	2021-01-22 06:11:21 UTC (rev 271737)
@@ -1,3 +1,24 @@
+2021-01-21  Peng Liu  <peng.l...@apple.com>
+
+        PiP video subtitles stop updating when Safari is backgrounded
+        https://bugs.webkit.org/show_bug.cgi?id=220660
+
+        Reviewed by Darin Adler.
+
+        Subtitles in the picture-in-picture window will stop updating when the browser is
+        in the background because we freeze the layer tree when a browser is in the background.
+        This patch fixes this issue by avoiding freezing the layer tree if a video is playing
+        in picture-in-picture when the browser is in the background.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::updateDrawingAreaLayerTreeFreezeState):
+        * WebProcess/cocoa/VideoFullscreenManager.h:
+        * WebProcess/cocoa/VideoFullscreenManager.mm:
+        (WebKit::VideoFullscreenManager::videoInPictureInPicture const):
+        (WebKit::VideoFullscreenManager::enterVideoFullscreenForVideoElement):
+        (WebKit::VideoFullscreenManager::exitVideoFullscreenForVideoElement):
+        (WebKit::VideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation):
+
 2021-01-21  Alex Christensen  <achristen...@webkit.org>
 
         Add experimental feature to use network loader

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (271736 => 271737)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-01-22 06:08:18 UTC (rev 271736)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-01-22 06:11:21 UTC (rev 271737)
@@ -2643,6 +2643,16 @@
 {
     if (!m_drawingArea)
         return;
+
+#if ENABLE(VIDEO_PRESENTATION_MODE)
+    // When the browser is in the background, we should not freeze the layer tree
+    // if the page has a video playing in picture-in-picture.
+    if (m_videoFullscreenManager && m_videoFullscreenManager->hasVideoPlayingInPictureInPicture() && m_layerTreeFreezeReasons.hasExactlyOneBitSet() && m_layerTreeFreezeReasons.contains(LayerTreeFreezeReason::BackgroundApplication)) {
+        m_drawingArea->setLayerTreeStateIsFrozen(false);
+        return;
+    }
+#endif
+
     m_drawingArea->setLayerTreeStateIsFrozen(!!m_layerTreeFreezeReasons);
 }
 

Modified: trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h (271736 => 271737)


--- trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h	2021-01-22 06:08:18 UTC (rev 271736)
+++ trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h	2021-01-22 06:11:21 UTC (rev 271737)
@@ -117,7 +117,9 @@
     virtual ~VideoFullscreenManager();
     
     void invalidate();
-    
+
+    bool hasVideoPlayingInPictureInPicture() const;
+
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
 
     // Interface to WebChromeClient
@@ -169,6 +171,7 @@
     HashMap<PlaybackSessionContextIdentifier, ModelInterfaceTuple> m_contextMap;
     PlaybackSessionContextIdentifier m_controlsManagerContextId;
     HashMap<PlaybackSessionContextIdentifier, int> m_clientCounts;
+    WeakPtr<WebCore::HTMLVideoElement> m_videoElementInPictureInPicture;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm (271736 => 271737)


--- trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm	2021-01-22 06:08:18 UTC (rev 271736)
+++ trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm	2021-01-22 06:11:21 UTC (rev 271737)
@@ -148,6 +148,11 @@
     m_page = nullptr;
 }
 
+bool VideoFullscreenManager::hasVideoPlayingInPictureInPicture() const
+{
+    return !!m_videoElementInPictureInPicture;
+}
+
 VideoFullscreenManager::ModelInterfaceTuple VideoFullscreenManager::createModelAndInterface(PlaybackSessionContextIdentifier contextId)
 {
     auto model = VideoFullscreenModelVideoElement::create();
@@ -265,6 +270,9 @@
     else
         interface->setTargetIsFullscreen(false);
 
+    if (mode == HTMLMediaElementEnums::VideoFullscreenModePictureInPicture)
+        m_videoElementInPictureInPicture = makeWeakPtr(videoElement);
+
     interface->setFullscreenMode(mode);
     interface->setFullscreenStandby(standby);
     model->setVideoElement(&videoElement);
@@ -295,7 +303,7 @@
     m_page->send(Messages::VideoFullscreenManagerProxy::SetupFullscreenWithID(contextId, interface->layerHostingContext()->contextID(), videoRect, FloatSize(videoElement.videoWidth(), videoElement.videoHeight()), m_page->deviceScaleFactor(), interface->fullscreenMode(), allowsPictureInPicture, standby, videoElement.document().quirks().blocksReturnToFullscreenFromPictureInPictureQuirk()));
 }
 
-void VideoFullscreenManager::exitVideoFullscreenForVideoElement(WebCore::HTMLVideoElement& videoElement, CompletionHandler<void(bool)>&& completionHandler)
+void VideoFullscreenManager::exitVideoFullscreenForVideoElement(HTMLVideoElement& videoElement, CompletionHandler<void(bool)>&& completionHandler)
 {
     LOG(Fullscreen, "VideoFullscreenManager::exitVideoFullscreenForVideoElement(%p)", this);
     ASSERT(m_page);
@@ -308,12 +316,15 @@
         return;
     }
 
-    m_page->sendWithAsyncReply(Messages::VideoFullscreenManagerProxy::ExitFullscreen(contextId, inlineVideoFrame(videoElement)), [protectedThis = makeRefPtr(this), this, contextId, completionHandler = WTFMove(completionHandler)](auto success) mutable {
+    m_page->sendWithAsyncReply(Messages::VideoFullscreenManagerProxy::ExitFullscreen(contextId, inlineVideoFrame(videoElement)), [protectedThis = makeRefPtr(this), this, contextId, videoElementPtr = &videoElement, completionHandler = WTFMove(completionHandler)](auto success) mutable {
         if (!success) {
             completionHandler(false);
             return;
         }
 
+        if (m_videoElementInPictureInPicture == videoElementPtr)
+            m_videoElementInPictureInPicture = nullptr;
+
         auto& interface = ensureInterface(contextId);
         interface.setTargetIsFullscreen(false);
         interface.setAnimationState(VideoFullscreenInterfaceContext::AnimationType::FromFullscreen);
@@ -321,7 +332,7 @@
     });
 }
 
-void VideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation(WebCore::HTMLVideoElement& videoElement, WebCore::HTMLMediaElementEnums::VideoFullscreenMode targetMode)
+void VideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation(HTMLVideoElement& videoElement, WebCore::HTMLMediaElementEnums::VideoFullscreenMode targetMode)
 {
     LOG(Fullscreen, "VideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation(%p)", this);
 
@@ -328,6 +339,9 @@
     ASSERT(m_page);
     ASSERT(m_videoElements.contains(&videoElement));
 
+    if (m_videoElementInPictureInPicture == &videoElement)
+        m_videoElementInPictureInPicture = nullptr;
+
     auto contextId = m_videoElements.get(&videoElement);
     auto& interface = ensureInterface(contextId);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to