Changeset 271737 in webkit


Ignore:
Timestamp:
Jan 21, 2021 10:11:21 PM (18 months ago)
Author:
Peng Liu
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):

Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r271714 r271737  
     12021-01-21  Peng Liu  <peng.liu6@apple.com>
     2
     3        PiP video subtitles stop updating when Safari is backgrounded
     4        https://bugs.webkit.org/show_bug.cgi?id=220660
     5
     6        Reviewed by Darin Adler.
     7
     8        Subtitles in the picture-in-picture window will stop updating when the browser is
     9        in the background because we freeze the layer tree when a browser is in the background.
     10        This patch fixes this issue by avoiding freezing the layer tree if a video is playing
     11        in picture-in-picture when the browser is in the background.
     12
     13        * WebProcess/WebPage/WebPage.cpp:
     14        (WebKit::WebPage::updateDrawingAreaLayerTreeFreezeState):
     15        * WebProcess/cocoa/VideoFullscreenManager.h:
     16        * WebProcess/cocoa/VideoFullscreenManager.mm:
     17        (WebKit::VideoFullscreenManager::videoInPictureInPicture const):
     18        (WebKit::VideoFullscreenManager::enterVideoFullscreenForVideoElement):
     19        (WebKit::VideoFullscreenManager::exitVideoFullscreenForVideoElement):
     20        (WebKit::VideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation):
     21
    1222021-01-21  Alex Christensen  <achristensen@webkit.org>
    223
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r271713 r271737  
    26442644    if (!m_drawingArea)
    26452645        return;
     2646
     2647#if ENABLE(VIDEO_PRESENTATION_MODE)
     2648    // When the browser is in the background, we should not freeze the layer tree
     2649    // if the page has a video playing in picture-in-picture.
     2650    if (m_videoFullscreenManager && m_videoFullscreenManager->hasVideoPlayingInPictureInPicture() && m_layerTreeFreezeReasons.hasExactlyOneBitSet() && m_layerTreeFreezeReasons.contains(LayerTreeFreezeReason::BackgroundApplication)) {
     2651        m_drawingArea->setLayerTreeStateIsFrozen(false);
     2652        return;
     2653    }
     2654#endif
     2655
    26462656    m_drawingArea->setLayerTreeStateIsFrozen(!!m_layerTreeFreezeReasons);
    26472657}
  • trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.h

    r269557 r271737  
    118118   
    119119    void invalidate();
    120    
     120
     121    bool hasVideoPlayingInPictureInPicture() const;
     122
    121123    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
    122124
     
    170172    PlaybackSessionContextIdentifier m_controlsManagerContextId;
    171173    HashMap<PlaybackSessionContextIdentifier, int> m_clientCounts;
     174    WeakPtr<WebCore::HTMLVideoElement> m_videoElementInPictureInPicture;
    172175};
    173176
  • trunk/Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm

    r271503 r271737  
    149149}
    150150
     151bool VideoFullscreenManager::hasVideoPlayingInPictureInPicture() const
     152{
     153    return !!m_videoElementInPictureInPicture;
     154}
     155
    151156VideoFullscreenManager::ModelInterfaceTuple VideoFullscreenManager::createModelAndInterface(PlaybackSessionContextIdentifier contextId)
    152157{
     
    266271        interface->setTargetIsFullscreen(false);
    267272
     273    if (mode == HTMLMediaElementEnums::VideoFullscreenModePictureInPicture)
     274        m_videoElementInPictureInPicture = makeWeakPtr(videoElement);
     275
    268276    interface->setFullscreenMode(mode);
    269277    interface->setFullscreenStandby(standby);
     
    296304}
    297305
    298 void VideoFullscreenManager::exitVideoFullscreenForVideoElement(WebCore::HTMLVideoElement& videoElement, CompletionHandler<void(bool)>&& completionHandler)
     306void VideoFullscreenManager::exitVideoFullscreenForVideoElement(HTMLVideoElement& videoElement, CompletionHandler<void(bool)>&& completionHandler)
    299307{
    300308    LOG(Fullscreen, "VideoFullscreenManager::exitVideoFullscreenForVideoElement(%p)", this);
     
    309317    }
    310318
    311     m_page->sendWithAsyncReply(Messages::VideoFullscreenManagerProxy::ExitFullscreen(contextId, inlineVideoFrame(videoElement)), [protectedThis = makeRefPtr(this), this, contextId, completionHandler = WTFMove(completionHandler)](auto success) mutable {
     319    m_page->sendWithAsyncReply(Messages::VideoFullscreenManagerProxy::ExitFullscreen(contextId, inlineVideoFrame(videoElement)), [protectedThis = makeRefPtr(this), this, contextId, videoElementPtr = &videoElement, completionHandler = WTFMove(completionHandler)](auto success) mutable {
    312320        if (!success) {
    313321            completionHandler(false);
     
    315323        }
    316324
     325        if (m_videoElementInPictureInPicture == videoElementPtr)
     326            m_videoElementInPictureInPicture = nullptr;
     327
    317328        auto& interface = ensureInterface(contextId);
    318329        interface.setTargetIsFullscreen(false);
     
    322333}
    323334
    324 void VideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation(WebCore::HTMLVideoElement& videoElement, WebCore::HTMLMediaElementEnums::VideoFullscreenMode targetMode)
     335void VideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation(HTMLVideoElement& videoElement, WebCore::HTMLMediaElementEnums::VideoFullscreenMode targetMode)
    325336{
    326337    LOG(Fullscreen, "VideoFullscreenManager::exitVideoFullscreenToModeWithoutAnimation(%p)", this);
     
    328339    ASSERT(m_page);
    329340    ASSERT(m_videoElements.contains(&videoElement));
     341
     342    if (m_videoElementInPictureInPicture == &videoElement)
     343        m_videoElementInPictureInPicture = nullptr;
    330344
    331345    auto contextId = m_videoElements.get(&videoElement);
Note: See TracChangeset for help on using the changeset viewer.