Skip to content

Commit

Permalink
[GTK] Remove the code to keep previous layer tree host alive
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=261672

Reviewed by Alejandro G. Castro.

This was used for the ondemand mode when we allowed to exit accelerated compositing mode,
but now we force always compositing the first time we enter accelerated compositing mode.
The only way to exit accelerated compositing is by setting the policy to never, in which
case we don't want to keep the previous layer tree host since it's unlikely we enter it
again soon.

* Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp:
(WebKit::DrawingAreaCoordinatedGraphics::DrawingAreaCoordinatedGraphics):
(WebKit::DrawingAreaCoordinatedGraphics::scroll):
(WebKit::DrawingAreaCoordinatedGraphics::mainFrameContentSizeChanged):
(WebKit::DrawingAreaCoordinatedGraphics::deviceOrPageScaleFactorChanged):
(WebKit::DrawingAreaCoordinatedGraphics::didChangeViewportAttributes):
(WebKit::DrawingAreaCoordinatedGraphics::attachViewOverlayGraphicsLayer):
(WebKit::DrawingAreaCoordinatedGraphics::updateGeometry):
(WebKit::DrawingAreaCoordinatedGraphics::enterAcceleratedCompositingMode):
(WebKit::DrawingAreaCoordinatedGraphics::exitAcceleratedCompositingMode):
(WebKit::DrawingAreaCoordinatedGraphics::discardPreviousLayerTreeHost): Deleted.
* Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.h:
* Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.cpp:
(WebKit::LayerTreeHost::scrollNonCompositedContents):
(WebKit::LayerTreeHost::sizeDidChange):
(WebKit::LayerTreeHost::contentsSizeChanged):
(WebKit::LayerTreeHost::didChangeViewportAttributes):
(WebKit::LayerTreeHost::deviceOrPageScaleFactorChanged):
(WebKit::LayerTreeHost::setIsDiscardable): Deleted.
* Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.h:
(WebKit::LayerTreeHost::didChangeViewportAttributes):
(WebKit::LayerTreeHost::setIsDiscardable): Deleted.

Canonical link: https://commits.webkit.org/269463@main
  • Loading branch information
carlosgcampos committed Oct 18, 2023
1 parent e20b694 commit 825a7cc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,10 @@ DrawingAreaCoordinatedGraphics::DrawingAreaCoordinatedGraphics(WebPage& webPage,
: DrawingArea(DrawingAreaType::CoordinatedGraphics, parameters.drawingAreaIdentifier, webPage)
, m_isPaintingSuspended(!(parameters.activityState & ActivityState::IsVisible))
, m_exitCompositingTimer(RunLoop::main(), this, &DrawingAreaCoordinatedGraphics::exitAcceleratedCompositingMode)
, m_discardPreviousLayerTreeHostTimer(RunLoop::main(), this, &DrawingAreaCoordinatedGraphics::discardPreviousLayerTreeHost)
, m_displayTimer(RunLoop::main(), this, &DrawingAreaCoordinatedGraphics::displayTimerFired)
{
#if USE(GLIB_EVENT_LOOP)
m_discardPreviousLayerTreeHostTimer.setPriority(RunLoopSourcePriority::ReleaseUnusedResourcesTimer);
#if !PLATFORM(WPE)
#if USE(GLIB_EVENT_LOOP) && !PLATFORM(WPE)
m_displayTimer.setPriority(RunLoopSourcePriority::NonAcceleratedDrawingTimer);
#endif
#endif

updatePreferences(parameters.store);
Expand Down Expand Up @@ -116,9 +112,6 @@ void DrawingAreaCoordinatedGraphics::scroll(const IntRect& scrollRect, const Int
if (scrollRect.isEmpty())
return;

if (m_previousLayerTreeHost)
m_previousLayerTreeHost->scrollNonCompositedContents(scrollRect);

if (!m_scrollRect.isEmpty() && scrollRect != m_scrollRect) {
unsigned scrollArea = scrollRect.width() * scrollRect.height();
unsigned currentScrollArea = m_scrollRect.width() * m_scrollRect.height();
Expand Down Expand Up @@ -264,25 +257,19 @@ void DrawingAreaCoordinatedGraphics::mainFrameContentSizeChanged(WebCore::FrameI
{
if (m_layerTreeHost)
m_layerTreeHost->contentsSizeChanged(size);
else if (m_previousLayerTreeHost)
m_previousLayerTreeHost->contentsSizeChanged(size);
}

#if USE(COORDINATED_GRAPHICS) || USE(TEXTURE_MAPPER)
void DrawingAreaCoordinatedGraphics::deviceOrPageScaleFactorChanged()
{
if (m_layerTreeHost)
m_layerTreeHost->deviceOrPageScaleFactorChanged();
else if (m_previousLayerTreeHost)
m_previousLayerTreeHost->deviceOrPageScaleFactorChanged();
}

void DrawingAreaCoordinatedGraphics::didChangeViewportAttributes(ViewportAttributes&& attrs)
{
if (m_layerTreeHost)
m_layerTreeHost->didChangeViewportAttributes(WTFMove(attrs));
else if (m_previousLayerTreeHost)
m_previousLayerTreeHost->didChangeViewportAttributes(WTFMove(attrs));
}

bool DrawingAreaCoordinatedGraphics::enterAcceleratedCompositingModeIfNeeded()
Expand Down Expand Up @@ -409,8 +396,6 @@ void DrawingAreaCoordinatedGraphics::attachViewOverlayGraphicsLayer(WebCore::Fra
{
if (m_layerTreeHost)
m_layerTreeHost->setViewOverlayRootLayer(viewOverlayRootLayer);
else if (m_previousLayerTreeHost)
m_previousLayerTreeHost->setViewOverlayRootLayer(viewOverlayRootLayer);
}

void DrawingAreaCoordinatedGraphics::updateGeometry(const IntSize& size, CompletionHandler<void()>&& completionHandler)
Expand All @@ -427,8 +412,7 @@ void DrawingAreaCoordinatedGraphics::updateGeometry(const IntSize& size, Complet
if (m_layerTreeHost) {
previousLayerTreeContext = m_layerTreeHost->layerTreeContext();
m_layerTreeHost->sizeDidChange(webPage->size());
} else if (m_previousLayerTreeHost)
m_previousLayerTreeHost->sizeDidChange(m_webPage->size());
}

if (m_layerTreeHost) {
auto layerTreeContext = m_layerTreeHost->layerTreeContext();
Expand Down Expand Up @@ -522,12 +506,6 @@ void DrawingAreaCoordinatedGraphics::exitAcceleratedCompositingModeSoon()
m_exitCompositingTimer.startOneShot(0_s);
}

void DrawingAreaCoordinatedGraphics::discardPreviousLayerTreeHost()
{
m_discardPreviousLayerTreeHostTimer.stop();
m_previousLayerTreeHost = nullptr;
}

void DrawingAreaCoordinatedGraphics::suspendPainting()
{
ASSERT(!m_isPaintingSuspended);
Expand Down Expand Up @@ -569,7 +547,6 @@ void DrawingAreaCoordinatedGraphics::enterAcceleratedCompositingMode(GraphicsLay
m_alwaysUseCompositing = true;
}
#endif
m_discardPreviousLayerTreeHostTimer.stop();

m_exitCompositingTimer.stop();
m_wantsToExitAcceleratedCompositingMode = false;
Expand All @@ -583,33 +560,22 @@ void DrawingAreaCoordinatedGraphics::enterAcceleratedCompositingMode(GraphicsLay
#endif

ASSERT(!m_layerTreeHost);
if (m_previousLayerTreeHost) {
m_layerTreeHost = WTFMove(m_previousLayerTreeHost);
#if !HAVE(DISPLAY_LINK)
changeWindowScreen();
#endif
m_layerTreeHost->setIsDiscardable(false);
m_layerTreeHost->resumeRendering();
if (!m_layerTreeStateIsFrozen)
m_layerTreeHost->setLayerFlushSchedulingEnabled(true);
} else {
#if USE(GRAPHICS_LAYER_TEXTURE_MAPPER) || HAVE(DISPLAY_LINK)
m_layerTreeHost = makeUnique<LayerTreeHost>(m_webPage);
m_layerTreeHost = makeUnique<LayerTreeHost>(m_webPage);
#elif USE(COORDINATED_GRAPHICS)
m_layerTreeHost = makeUnique<LayerTreeHost>(m_webPage, std::numeric_limits<uint32_t>::max() - m_identifier.toUInt64());
m_layerTreeHost = makeUnique<LayerTreeHost>(m_webPage, std::numeric_limits<uint32_t>::max() - m_identifier.toUInt64());
#else
m_layerTreeHost = nullptr;
return;
m_layerTreeHost = nullptr;
return;
#endif

#if !HAVE(DISPLAY_LINK)
changeWindowScreen();
changeWindowScreen();
#endif
if (m_layerTreeStateIsFrozen)
m_layerTreeHost->setLayerFlushSchedulingEnabled(false);
if (m_isPaintingSuspended)
m_layerTreeHost->pauseRendering();
}

if (m_layerTreeStateIsFrozen)
m_layerTreeHost->setLayerFlushSchedulingEnabled(false);
if (m_isPaintingSuspended)
m_layerTreeHost->pauseRendering();
if (!m_inUpdateGeometry)
m_layerTreeHost->setShouldNotifyAfterNextScheduledLayerFlush(true);

Expand Down Expand Up @@ -651,11 +617,7 @@ void DrawingAreaCoordinatedGraphics::exitAcceleratedCompositingMode()
m_wantsToExitAcceleratedCompositingMode = false;

ASSERT(m_layerTreeHost);
m_previousLayerTreeHost = WTFMove(m_layerTreeHost);
m_previousLayerTreeHost->setIsDiscardable(true);
m_previousLayerTreeHost->pauseRendering();
m_previousLayerTreeHost->setLayerFlushSchedulingEnabled(false);
m_discardPreviousLayerTreeHostTimer.startOneShot(5_s);
m_layerTreeHost = nullptr;

Ref webPage = m_webPage.get();
#if !HAVE(DISPLAY_LINK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class DrawingAreaCoordinatedGraphics final : public DrawingArea {

void exitAcceleratedCompositingModeSoon();
bool exitAcceleratedCompositingModePending() const { return m_exitCompositingTimer.isActive(); }
void discardPreviousLayerTreeHost();

void suspendPainting();
void resumePainting();
Expand Down Expand Up @@ -133,9 +132,6 @@ class DrawingAreaCoordinatedGraphics final : public DrawingArea {
// The layer tree host that handles accelerated compositing.
std::unique_ptr<LayerTreeHost> m_layerTreeHost;

std::unique_ptr<LayerTreeHost> m_previousLayerTreeHost;
RunLoop::Timer m_discardPreviousLayerTreeHostTimer;

WebCore::Region m_dirtyRegion;
WebCore::IntRect m_scrollRect;
WebCore::IntSize m_scrollOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,7 @@ void LayerTreeHost::scrollNonCompositedContents(const IntRect& rect)
return;

m_viewportController.didScroll(rect.location());
if (m_isDiscardable)
m_discardableSyncActions.add(DiscardableSyncActions::UpdateViewport);
else
didChangeViewport();
didChangeViewport();
}

void LayerTreeHost::forceRepaint()
Expand Down Expand Up @@ -256,12 +253,6 @@ void LayerTreeHost::forceRepaintAsync(CompletionHandler<void()>&& callback)

void LayerTreeHost::sizeDidChange(const IntSize& size)
{
if (m_isDiscardable) {
m_discardableSyncActions.add(DiscardableSyncActions::UpdateSize);
m_viewportController.didChangeViewportSize(size);
return;
}

if (m_surface->hostResize(size))
m_layerTreeContext.contextID = m_surface->surfaceID();

Expand Down Expand Up @@ -296,19 +287,13 @@ GraphicsLayerFactory* LayerTreeHost::graphicsLayerFactory()
void LayerTreeHost::contentsSizeChanged(const IntSize& newSize)
{
m_viewportController.didChangeContentsSize(newSize);
if (m_isDiscardable)
m_discardableSyncActions.add(DiscardableSyncActions::UpdateViewport);
else
didChangeViewport();
didChangeViewport();
}

void LayerTreeHost::didChangeViewportAttributes(ViewportAttributes&& attr)
{
m_viewportController.didChangeViewportAttributes(WTFMove(attr));
if (m_isDiscardable)
m_discardableSyncActions.add(DiscardableSyncActions::UpdateViewport);
else
didChangeViewport();
didChangeViewport();
}

void LayerTreeHost::didChangeViewport()
Expand Down Expand Up @@ -350,37 +335,8 @@ void LayerTreeHost::didChangeViewport()
}
}

void LayerTreeHost::setIsDiscardable(bool discardable)
{
m_isDiscardable = discardable;
if (m_isDiscardable) {
m_discardableSyncActions = OptionSet<DiscardableSyncActions>();
return;
}

if (m_discardableSyncActions.isEmpty())
return;

if (m_discardableSyncActions.contains(DiscardableSyncActions::UpdateSize)) {
// Size changes already sets the scale factor and updates the viewport.
sizeDidChange(m_webPage.size());
return;
}

if (m_discardableSyncActions.contains(DiscardableSyncActions::UpdateScale))
deviceOrPageScaleFactorChanged();

if (m_discardableSyncActions.contains(DiscardableSyncActions::UpdateViewport))
didChangeViewport();
}

void LayerTreeHost::deviceOrPageScaleFactorChanged()
{
if (m_isDiscardable) {
m_discardableSyncActions.add(DiscardableSyncActions::UpdateScale);
return;
}

if (m_surface->hostResize(m_webPage.size()))
m_layerTreeContext.contextID = m_surface->surfaceID();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ class LayerTreeHost
void contentsSizeChanged(const WebCore::IntSize&);
void didChangeViewportAttributes(WebCore::ViewportAttributes&&);

void setIsDiscardable(bool);

void deviceOrPageScaleFactorChanged();

#if !HAVE(DISPLAY_LINK)
Expand Down Expand Up @@ -153,11 +151,6 @@ class LayerTreeHost
void applyTransientZoomToLayers(double, WebCore::FloatPoint);
#endif

enum class DiscardableSyncActions {
UpdateSize = 1 << 1,
UpdateViewport = 1 << 2,
UpdateScale = 1 << 3
};
#endif // USE(COORDINATED_GRAPHICS)

WebPage& m_webPage;
Expand All @@ -170,8 +163,6 @@ class LayerTreeHost
bool m_scheduledWhileWaitingForRenderer { false };
float m_lastPageScaleFactor { 1 };
WebCore::IntPoint m_lastScrollPosition;
bool m_isDiscardable { false };
OptionSet<DiscardableSyncActions> m_discardableSyncActions;
WebCore::GraphicsLayer* m_viewOverlayRootLayer { nullptr };
std::unique_ptr<AcceleratedSurface> m_surface;
RefPtr<ThreadedCompositor> m_compositor;
Expand Down Expand Up @@ -219,7 +210,6 @@ inline void LayerTreeHost::resumeRendering() { }
inline WebCore::GraphicsLayerFactory* LayerTreeHost::graphicsLayerFactory() { return nullptr; }
inline void LayerTreeHost::contentsSizeChanged(const WebCore::IntSize&) { }
inline void LayerTreeHost::didChangeViewportAttributes(WebCore::ViewportAttributes&&) { }
inline void LayerTreeHost::setIsDiscardable(bool) { }
inline void LayerTreeHost::deviceOrPageScaleFactorChanged() { }
#if PLATFORM(GTK)
inline void LayerTreeHost::adjustTransientZoom(double, WebCore::FloatPoint) { }
Expand Down

0 comments on commit 825a7cc

Please sign in to comment.