Title: [272253] branches/safari-611-branch/Source/WebKit
Revision
272253
Author
[email protected]
Date
2021-02-02 17:39:35 -0800 (Tue, 02 Feb 2021)

Log Message

Cherry-pick r271737. rdar://problem/73890706

    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):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271737 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-611-branch/Source/WebKit/ChangeLog (272252 => 272253)


--- branches/safari-611-branch/Source/WebKit/ChangeLog	2021-02-03 01:39:32 UTC (rev 272252)
+++ branches/safari-611-branch/Source/WebKit/ChangeLog	2021-02-03 01:39:35 UTC (rev 272253)
@@ -1,5 +1,52 @@
 2021-02-02  Alan Coon  <[email protected]>
 
+        Cherry-pick r271737. rdar://problem/73890706
+
+    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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271737 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-01-21  Peng Liu  <[email protected]>
+
+            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-02-02  Alan Coon  <[email protected]>
+
         Cherry-pick r271656. rdar://problem/73890220
 
     [Mac] Netflix controls do not fade out after entering fullscreen

Modified: branches/safari-611-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp (272252 => 272253)


--- branches/safari-611-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-02-03 01:39:32 UTC (rev 272252)
+++ branches/safari-611-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-02-03 01:39:35 UTC (rev 272253)
@@ -2644,6 +2644,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: branches/safari-611-branch/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h (272252 => 272253)


--- branches/safari-611-branch/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h	2021-02-03 01:39:32 UTC (rev 272252)
+++ branches/safari-611-branch/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h	2021-02-03 01:39:35 UTC (rev 272253)
@@ -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: branches/safari-611-branch/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm (272252 => 272253)


--- branches/safari-611-branch/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm	2021-02-03 01:39:32 UTC (rev 272252)
+++ branches/safari-611-branch/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm	2021-02-03 01:39:35 UTC (rev 272253)
@@ -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
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to