@@ -57,6 +57,7 @@ DrawingAreaCoordinatedGraphics::DrawingAreaCoordinatedGraphics(WebPage& webPage,
5757 , m_discardPreviousLayerTreeHostTimer(RunLoop::main(), this , &DrawingAreaCoordinatedGraphics::discardPreviousLayerTreeHost)
5858 , m_supportsAsyncScrolling(parameters.store.getBoolValueForKey(WebPreferencesKey::threadedScrollingEnabledKey()))
5959 , m_displayTimer(RunLoop::main(), this , &DrawingAreaCoordinatedGraphics::displayTimerFired)
60+ , m_usingPageLifecycle(parameters.store.getBoolValueForKey(WebPreferencesKey::pageLifecycleAPIEnabledKey()))
6061{
6162#if USE(GLIB_EVENT_LOOP)
6263 m_discardPreviousLayerTreeHostTimer.setPriority (RunLoopSourcePriority::ReleaseUnusedResourcesTimer);
@@ -398,34 +399,49 @@ RefPtr<DisplayRefreshMonitor> DrawingAreaCoordinatedGraphics::createDisplayRefre
398399
399400void DrawingAreaCoordinatedGraphics::activityStateDidChange (OptionSet<ActivityState::Flag> changed, ActivityStateChangeID, CompletionHandler<void ()>&& completionHandler)
400401{
401- // We use calls to suspendPainting() and resumePainting() to stop the compositor loop and paint the content transparent
402- // so nothing gets rendered. There are 2 exceptions to this that need to be handled separately:
403- // - WebGL in nonCompositedWebGL: we're not using the compositor in this case. WebGLRenderingContextBase will observe the activity
404- // state changes and paint the content transparent when the view is suspended or hidden.
405- // - MediaPlayer videoSink window when using the GStreamer holepunch: HTMLMediaElement will perform calls to the MediaPlayer
406- // to set an empty rectangle when it detects that the view has become hidden or suspended.
402+ if (m_usingPageLifecycle) {
403+ // Implementation for the Page Lifecycle events.
407404
408- // Handle hide/show functionality.
409- if (changed & ActivityState::IsVisible && !m_isViewSuspended ) {
410- if (m_webPage.corePage ()->isVisible ())
411- resumePainting ();
412- else
413- suspendPainting ();
414- }
405+ // Handle hide/show functionality.
406+ if (changed & ActivityState::IsVisible) {
407+ if (m_webPage.corePage ()->isVisible ())
408+ resumePainting ();
409+ else
410+ suspendPainting ();
411+ }
415412
416- // Handle suspend/resume functionality. Besides stopping the rendering, we stop active DOM objects and media playback.
417- if (changed & ActivityState::IsInWindow) {
418- if (m_isViewSuspended) {
419- m_webPage.corePage ()->resumeActiveDOMObjectsAndAnimations ();
420- m_webPage.corePage ()->resumeAllMediaPlayback ();
413+ } else {
414+ // Implementation for the old suspend/resume/hide/show functionality
415+
416+ // We use calls to suspendPainting() and resumePainting() to stop the compositor loop and paint the content transparent
417+ // so nothing gets rendered. There are 2 exceptions to this that need to be handled separately:
418+ // - WebGL in nonCompositedWebGL: we're not using the compositor in this case. WebGLRenderingContextBase will observe the activity
419+ // state changes and paint the content transparent when the view is suspended or hidden.
420+ // - MediaPlayer videoSink window when using the GStreamer holepunch: HTMLMediaElement will perform calls to the MediaPlayer
421+ // to set an empty rectangle when it detects that the view has become hidden or suspended.
422+
423+ // Handle hide/show functionality.
424+ if (changed & ActivityState::IsVisible && !m_isViewSuspended) {
421425 if (m_webPage.corePage ()->isVisible ())
422426 resumePainting ();
423- m_isViewSuspended = false ;
424- } else {
425- suspendPainting ();
426- m_webPage.corePage ()->suspendAllMediaPlayback ();
427- m_webPage.corePage ()->suspendActiveDOMObjectsAndAnimations ();
428- m_isViewSuspended = true ;
427+ else
428+ suspendPainting ();
429+ }
430+
431+ // Handle suspend/resume functionality. Besides stopping the rendering, we stop active DOM objects and media playback.
432+ if (changed & ActivityState::IsInWindow) {
433+ if (m_isViewSuspended) {
434+ m_webPage.corePage ()->resumeActiveDOMObjectsAndAnimations ();
435+ m_webPage.corePage ()->resumeAllMediaPlayback ();
436+ if (m_webPage.corePage ()->isVisible ())
437+ resumePainting ();
438+ m_isViewSuspended = false ;
439+ } else {
440+ suspendPainting ();
441+ m_webPage.corePage ()->suspendAllMediaPlayback ();
442+ m_webPage.corePage ()->suspendActiveDOMObjectsAndAnimations ();
443+ m_isViewSuspended = true ;
444+ }
429445 }
430446 }
431447
@@ -632,7 +648,7 @@ void DrawingAreaCoordinatedGraphics::suspendPainting()
632648 return ;
633649
634650 if (m_layerTreeHost)
635- m_layerTreeHost->pauseRendering ();
651+ m_layerTreeHost->pauseRendering (!m_usingPageLifecycle );
636652 else
637653 m_displayTimer.stop ();
638654
0 commit comments