Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 93297c8fc1f654c10a126c5b7a6aeeef295072ba
      
https://github.com/WebKit/WebKit/commit/93297c8fc1f654c10a126c5b7a6aeeef295072ba
  Author: Jer Noble <[email protected]>
  Date:   2026-04-16 (Thu, 16 Apr 2026)

  Changed paths:
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/dom/Document.cpp
    M Source/WebCore/dom/Document.h
    M Source/WebCore/html/HTMLMediaElement.cpp
    M Source/WebCore/html/HTMLMediaElement.h
    M Source/WebCore/html/HTMLVideoElement.cpp
    M Source/WebCore/html/HTMLVideoElement.h
    A Source/WebCore/html/LazyLoadVideoObserver.cpp
    A Source/WebCore/html/LazyLoadVideoObserver.h
    M Source/WebCore/html/parser/HTMLParserOptions.cpp
    M Source/WebCore/platform/graphics/MediaPlayer.cpp
    M Source/WebCore/platform/graphics/MediaPlayer.h
    M Source/WebCore/platform/graphics/MediaPlayerEnums.h
    M Source/WebCore/platform/graphics/MediaPlayerPrivate.h
    M Source/WebCore/platform/graphics/avfoundation/AudioVideoRendererAVFObjC.mm
    M 
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp
    M 
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h
    M 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
    M 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
    M 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h
    M 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm
    M 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h
    M 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm
    M Source/WebCore/platform/graphics/cocoa/VideoMediaSampleRenderer.mm
    M Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
    M Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h
    M Source/WebCore/testing/Internals.cpp
    M Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp
    M Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h
    M Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.messages.in
    M Source/WebKit/Scripts/webkit/messages.py
    M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
    M Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp
    M Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h

  Log Message:
  -----------
  [Cocoa] Inifite scrolling video websites can cause window server jetsams
rdar://162452658
https://bugs.webkit.org/show_bug.cgi?id=312390

Reviewed by Jean-Yves Avenard.

When infinitely scrolling on a website, a video element may become abandoned
very far away from the viewport. This element is still using memory resources
in the window server or compositor, even though it will be clipped out of the
resulting viewport. After enough scrolling, so many clipped video elements may
exist in the compositor as to cause that compositor to be killed by the system
for using too much memory.

To avoid this, install a viewport listener in HTMLMediaElement. In the future,
this listener could be use to implement a lazy load algorithm. But for now, it
just notifies the MediaPlayer that the media element is visible in the viewport,
close to or intersecting the viewport, or not visible.

Support this visibility enum by turning off the layer of 
MediaPlayerPrivateAVFoundationObjC
and MediaPlayerPrivateMediaSourceAVFObjC when the visibility drops to "none", 
and
re-creating the layer when the visibility rises to "intersecting" or "visible".
This behavior also occurs when switching tabs in a browser, when the page's own
visibility state drops to "not visible".

* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::lazyLoadVideoObserver):
* Source/WebCore/dom/Document.h:
* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::isVisibleInViewportChanged):
(WebCore::HTMLMediaElement::viewportVisibility const):
(WebCore::HTMLMediaElement::updateMediaPlayer):
* Source/WebCore/html/HTMLMediaElement.h:
(WebCore::HTMLMediaElement::isIntersectingViewport const):
* Source/WebCore/html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::~HTMLVideoElement):
(WebCore::HTMLVideoElement::create):
(WebCore::HTMLVideoElement::computeAcceleratedRenderingStateAndUpdateMediaPlayer):
(WebCore::HTMLVideoElement::viewportIntersectionChanged):
* Source/WebCore/html/HTMLVideoElement.h:
* Source/WebCore/html/parser/HTMLParserOptions.cpp:
* Source/WebCore/platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::loadWithNextMediaEngine):
(WebCore::MediaPlayer::setViewportVisibility):
(WebCore::convertEnumerationToString):
(WebCore::MediaPlayer::setVisibleInViewport): Deleted.
* Source/WebCore/platform/graphics/MediaPlayer.h:
* Source/WebCore/platform/graphics/MediaPlayerEnums.h:
(WTF::LogArgument<WebCore::MediaPlayerEnums::ViewportVisibility>::toString):
* Source/WebCore/platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::setViewportVisibility):
(WebCore::MediaPlayerPrivateInterface::setVisibleInViewport): Deleted.
* Source/WebCore/platform/graphics/avfoundation/AudioVideoRendererAVFObjC.mm:
(WebCore::AudioVideoRendererAVFObjC::renderingCanBeAcceleratedChanged):
* 
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation):
(WebCore::MediaPlayerPrivateAVFoundation::isReadyForVideoSetup const):
(WebCore::MediaPlayerPrivateAVFoundation::setPageIsVisible):
(WebCore::MediaPlayerPrivateAVFoundation::setViewportVisibility):
* 
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:
(WebCore::MediaPlayerPrivateAVFoundation::pageIsVisible const):
(WebCore::MediaPlayerPrivateAVFoundation::viewportVisibility const):
(WebCore::MediaPlayerPrivateAVFoundation::isVisible const): Deleted.
* 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerLayer):
(WebCore::MediaPlayerPrivateAVFoundationObjC::platformPageIsVisibleChanged):
(WebCore::MediaPlayerPrivateAVFoundationObjC::platformViewportVisibilityChanged):
(WebCore::MediaPlayerPrivateAVFoundationObjC::updateSpatialTrackingLabel):
(WebCore::MediaPlayerPrivateAVFoundationObjC::setVideoTarget):
(WebCore::MediaPlayerPrivateAVFoundationObjC::isInFullscreenOrPictureInPictureChanged):
(WebCore::MediaPlayerPrivateAVFoundationObjC::updateLayerAttachment):
(WebCore::MediaPlayerPrivateAVFoundationObjC::shouldAttachLayerToPlayer):
(WebCore::MediaPlayerPrivateAVFoundationObjC::platformSetVisible): Deleted.
* 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::WTF_GUARDED_BY_CAPABILITY):
* 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::MediaPlayerPrivateMediaSourceAVFObjC):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::setPageIsVisible):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::setViewportVisibility):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::updateRendererVisibility):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::acceleratedRenderingStateChanged):
* 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h:
* 
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::setViewportVisibility):
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::setVisibleInViewport): Deleted.
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::setViewportVisibility):
(WebCore::MediaPlayerPrivateGStreamer::setVisibleInViewport): Deleted.
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:
* Source/WebCore/testing/Internals.cpp:
(WebCore::Internals::isPlayerVisibleInViewport const):
* Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:
(WebKit::RemoteMediaPlayerProxy::setViewportVisibility):
* Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h:
* Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.messages.in:
* Source/WebKit/Scripts/webkit/messages.py:
(headers_for_type):
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
(WebKit::MediaPlayerPrivateRemote::setViewportVisibility):
* Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h:

Canonical link: https://commits.webkit.org/311380@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to