Skip to content

Commit db503ac

Browse files
committed
[PageLifecycle] Implement hide event for normal and nonCompositedWebGL.
1 parent 38f0080 commit db503ac

6 files changed

Lines changed: 54 additions & 29 deletions

File tree

Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,8 +1211,11 @@ void WebGLRenderingContextBase::addActivityStateChangeObserverIfNecessary()
12111211

12121212
// We are only interested in visibility changes for contexts
12131213
// that are using the high-performance GPU.
1214+
// We also use the activityState changes when nonCompositedWebGL is enabled, but not
1215+
// if we're using PageLifecycle, as we don't hide to transparent there.
12141216
m_nonCompositedWebGLEnabled = canvas->document().frame()->settings().nonCompositedWebGLEnabled();
1215-
if (!isHighPerformanceContext(m_context) && !m_nonCompositedWebGLEnabled)
1217+
m_usingPageLifecycle = canvas->document().frame()->settings().pageLifecycleAPIEnabled();
1218+
if (!isHighPerformanceContext(m_context) && (!m_nonCompositedWebGLEnabled || m_usingPageLifecycle))
12161219
return;
12171220

12181221
auto* page = canvas->document().page();

Source/WebCore/html/canvas/WebGLRenderingContextBase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,7 @@ class WebGLRenderingContextBase : public GraphicsContextGL::Client, public GPUBa
12061206
Timer m_checkForContextLossHandlingTimer;
12071207
bool m_isSuspended { false };
12081208
bool m_nonCompositedWebGLEnabled { false };
1209+
bool m_usingPageLifecycle { false };
12091210

12101211
#if ENABLE(WEBXR)
12111212
bool m_isXRCompatible { false };

Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

399400
void 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

Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ class DrawingAreaCoordinatedGraphics final : public DrawingArea {
165165
bool m_transientZoom { false };
166166
WebCore::FloatPoint m_transientZoomInitialOrigin;
167167
#endif
168+
169+
bool m_usingPageLifecycle { false };
168170
};
169171

170172
} // namespace WebKit

Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,13 @@ void LayerTreeHost::targetRefreshRateDidChange(uint32_t rate)
257257
m_compositor->targetRefreshRateDidChange(rate);
258258
}
259259

260-
void LayerTreeHost::pauseRendering()
260+
void LayerTreeHost::pauseRendering(bool toTransparent)
261261
{
262262
m_isSuspended = true;
263-
m_compositor->suspendToTransparent();
263+
if (toTransparent)
264+
m_compositor->suspendToTransparent();
265+
else
266+
m_compositor->suspend();
264267
}
265268

266269
void LayerTreeHost::resumeRendering()

Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class LayerTreeHost
8383
void sizeDidChange(const WebCore::IntSize& newSize);
8484
void targetRefreshRateDidChange(unsigned);
8585

86-
void pauseRendering();
86+
void pauseRendering(bool toTransparent = false);
8787
void resumeRendering();
8888

8989
WebCore::GraphicsLayerFactory* graphicsLayerFactory();

0 commit comments

Comments
 (0)