Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[GTK] Drop coordinated surfaces from the compositing thread as soon a…
…s possible

https://bugs.webkit.org/show_bug.cgi?id=171544

Reviewed by Žan Doberšek.

Source/WebCore:

* platform/graphics/texmap/coordinated/CoordinatedGraphicsState.h:
Remove atlasesToRemove from the GraphicsState. It is not a commit
state anymore.

Source/WebKit2:

Released coordinated surface from the main thread didn't be freed until
next commit message because the deletion of coordinated surfaces is
considered as a part of scene state.  We need to release corresponding
surfaces whenever the compositing coordinator drops update atlases to
reduce memory usages.

No new tests, only an optimization.

* Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:
Remove atlasesToRemove from the GraphicsState. it is not a commit
state anymore.
* Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
(WebKit::CoordinatedGraphicsScene::syncUpdateAtlases):
(WebKit::CoordinatedGraphicsScene::releaseUpdateAtlases):
* Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h:
* Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:
(WebKit::CompositingCoordinator::releaseAtlases): Pass the list of
released update atlases to the compositing thread right after cleaning
up deactivated update atlases.
* Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:
* WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp:
(WebKit::CompositingCoordinator::clearPendingStateChanges):
(WebKit::CompositingCoordinator::removeUpdateAtlas):
(WebKit::CompositingCoordinator::releaseAtlases):
* WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h:
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:
* WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp:
(WebKit::ThreadedCoordinatedLayerTreeHost::releaseUpdateAtlases):
* WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h:


Canonical link: https://commits.webkit.org/188488@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@216101 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
ryumiel committed May 2, 2017
1 parent 4273984 commit 752c41c
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 10 deletions.
11 changes: 11 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,14 @@
2017-05-02 Gwang Yoon Hwang <yoon@igalia.com>

[GTK] Drop coordinated surfaces from the compositing thread as soon as possible
https://bugs.webkit.org/show_bug.cgi?id=171544

Reviewed by Žan Doberšek.

* platform/graphics/texmap/coordinated/CoordinatedGraphicsState.h:
Remove atlasesToRemove from the GraphicsState. It is not a commit
state anymore.

2017-05-02 Gwang Yoon Hwang <yoon@igalia.com>

[GTK] Recycle textures while handling tiles
Expand Down
Expand Up @@ -186,7 +186,6 @@ struct CoordinatedGraphicsState {
Vector<CoordinatedImageBackingID> imagesToClear;

Vector<std::pair<uint32_t /* atlasID */, RefPtr<CoordinatedSurface> > > updateAtlasesToCreate;
Vector<uint32_t /* atlasID */> updateAtlasesToRemove;
};

} // namespace WebCore
Expand Down
37 changes: 37 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -1,3 +1,40 @@
2017-05-02 Gwang Yoon Hwang <yoon@igalia.com>

[GTK] Drop coordinated surfaces from the compositing thread as soon as possible
https://bugs.webkit.org/show_bug.cgi?id=171544

Reviewed by Žan Doberšek.

Released coordinated surface from the main thread didn't be freed until
next commit message because the deletion of coordinated surfaces is
considered as a part of scene state. We need to release corresponding
surfaces whenever the compositing coordinator drops update atlases to
reduce memory usages.

No new tests, only an optimization.

* Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:
Remove atlasesToRemove from the GraphicsState. it is not a commit
state anymore.
* Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
(WebKit::CoordinatedGraphicsScene::syncUpdateAtlases):
(WebKit::CoordinatedGraphicsScene::releaseUpdateAtlases):
* Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h:
* Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:
(WebKit::CompositingCoordinator::releaseAtlases): Pass the list of
released update atlases to the compositing thread right after cleaning
up deactivated update atlases.
* Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:
* WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp:
(WebKit::CompositingCoordinator::clearPendingStateChanges):
(WebKit::CompositingCoordinator::removeUpdateAtlas):
(WebKit::CompositingCoordinator::releaseAtlases):
* WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h:
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:
* WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp:
(WebKit::ThreadedCoordinatedLayerTreeHost::releaseUpdateAtlases):
* WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h:

2017-05-02 Timothy Horton <timothy_horton@apple.com>

Inform clients when viewport-fit state changes, so they can recompute insets
Expand Down
Expand Up @@ -846,7 +846,6 @@ void ArgumentCoder<CoordinatedGraphicsState>::encode(Encoder& encoder, const Coo
encoder << state.updateAtlasesToCreate[i].first;
encodeCoordinatedSurface(encoder, state.updateAtlasesToCreate[i].second);
}
encoder << state.updateAtlasesToRemove;
}

bool ArgumentCoder<CoordinatedGraphicsState>::decode(Decoder& decoder, CoordinatedGraphicsState& state)
Expand Down Expand Up @@ -913,9 +912,6 @@ bool ArgumentCoder<CoordinatedGraphicsState>::decode(Decoder& decoder, Coordinat
state.updateAtlasesToCreate.append(std::make_pair(atlasID, surface.release()));
}

if (!decoder.decode(state.updateAtlasesToRemove))
return false;

return true;
}

Expand Down
Expand Up @@ -424,9 +424,6 @@ void CoordinatedGraphicsScene::syncUpdateAtlases(const CoordinatedGraphicsState&
{
for (auto& atlas : state.updateAtlasesToCreate)
createUpdateAtlas(atlas.first, atlas.second);

for (auto& atlas : state.updateAtlasesToRemove)
removeUpdateAtlas(atlas);
}

void CoordinatedGraphicsScene::createUpdateAtlas(uint32_t atlasID, PassRefPtr<CoordinatedSurface> surface)
Expand All @@ -441,6 +438,12 @@ void CoordinatedGraphicsScene::removeUpdateAtlas(uint32_t atlasID)
m_surfaces.remove(atlasID);
}

void CoordinatedGraphicsScene::releaseUpdateAtlases(const Vector<uint32_t>& atlasesToRemove)
{
for (auto& atlas : atlasesToRemove)
removeUpdateAtlas(atlas);
}

void CoordinatedGraphicsScene::syncImageBackings(const CoordinatedGraphicsState& state)
{
for (auto& image : state.imagesToRemove)
Expand Down
Expand Up @@ -85,6 +85,8 @@ class CoordinatedGraphicsScene : public ThreadSafeRefCounted<CoordinatedGraphics
void setViewBackgroundColor(const WebCore::Color& color) { m_viewBackgroundColor = color; }
WebCore::Color viewBackgroundColor() const { return m_viewBackgroundColor; }

void releaseUpdateAtlases(const Vector<uint32_t>&);

private:
void setRootLayerID(WebCore::CoordinatedLayerID);
void createLayers(const Vector<WebCore::CoordinatedLayerID>&);
Expand Down
Expand Up @@ -244,6 +244,14 @@ void ThreadedCompositor::updateSceneState(const CoordinatedGraphicsState& state)
m_compositingRunLoop->scheduleUpdate();
}

void ThreadedCompositor::releaseUpdateAtlases(Vector<uint32_t>&& atlasesToRemove)
{
ASSERT(isMainThread());
m_compositingRunLoop->performTask([scene = makeRef(*m_scene), atlasesToRemove = WTFMove(atlasesToRemove)] {
scene->releaseUpdateAtlases(atlasesToRemove);
});
}

#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
RefPtr<WebCore::DisplayRefreshMonitor> ThreadedCompositor::displayRefreshMonitor(PlatformDisplayID)
{
Expand Down
Expand Up @@ -74,6 +74,7 @@ class ThreadedCompositor : public CoordinatedGraphicsSceneClient, public ThreadS
void setDrawsBackground(bool);

void updateSceneState(const WebCore::CoordinatedGraphicsState&);
void releaseUpdateAtlases(Vector<uint32_t>&&);

void invalidate();

Expand Down
Expand Up @@ -181,7 +181,6 @@ void CompositingCoordinator::clearPendingStateChanges()
m_state.imagesToClear.clear();

m_state.updateAtlasesToCreate.clear();
m_state.updateAtlasesToRemove.clear();
}

void CompositingCoordinator::initializeRootCompositingLayerIfNeeded()
Expand Down Expand Up @@ -304,7 +303,7 @@ void CompositingCoordinator::removeUpdateAtlas(uint32_t atlasID)
{
if (m_isPurging)
return;
m_state.updateAtlasesToRemove.append(atlasID);
m_atlasesToRemove.append(atlasID);
}

FloatRect CompositingCoordinator::visibleContentsRect() const
Expand Down Expand Up @@ -443,6 +442,9 @@ void CompositingCoordinator::releaseAtlases(ReleaseAtlasPolicy policy)

if (m_updateAtlases.size() <= 1)
m_releaseInactiveAtlasesTimer.stop();

if (!m_atlasesToRemove.isEmpty())
m_client.releaseUpdateAtlases(WTFMove(m_atlasesToRemove));
}

} // namespace WebKit
Expand Down
Expand Up @@ -60,6 +60,7 @@ class CompositingCoordinator final : public WebCore::GraphicsLayerClient
virtual void notifyFlushRequired() = 0;
virtual void commitSceneState(const WebCore::CoordinatedGraphicsState&) = 0;
virtual void paintLayerContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, const WebCore::IntRect& clipRect) = 0;
virtual void releaseUpdateAtlases(Vector<uint32_t>&&) = 0;
};

CompositingCoordinator(WebCore::Page*, CompositingCoordinator::Client&);
Expand Down Expand Up @@ -148,6 +149,7 @@ class CompositingCoordinator final : public WebCore::GraphicsLayerClient
typedef HashMap<WebCore::CoordinatedImageBackingID, RefPtr<WebCore::CoordinatedImageBacking> > ImageBackingMap;
ImageBackingMap m_imageBackings;
Vector<std::unique_ptr<UpdateAtlas>> m_updateAtlases;
Vector<uint32_t> m_atlasesToRemove;

// We don't send the messages related to releasing resources to renderer during purging, because renderer already had removed all resources.
bool m_isDestructing { false };
Expand Down
Expand Up @@ -72,6 +72,7 @@ class CoordinatedLayerTreeHost : public LayerTreeHost, public CompositingCoordin
void notifyFlushRequired() override { scheduleLayerFlush(); };
void commitSceneState(const WebCore::CoordinatedGraphicsState&) override;
void paintLayerContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, const WebCore::IntRect& clipRect) override;
void releaseUpdateAtlases(Vector<uint32_t>&&) override { };

private:
void layerFlushTimerFired();
Expand Down
Expand Up @@ -220,6 +220,11 @@ void ThreadedCoordinatedLayerTreeHost::commitSceneState(const CoordinatedGraphic
m_compositor->updateSceneState(state);
}

void ThreadedCoordinatedLayerTreeHost::releaseUpdateAtlases(Vector<uint32_t>&& atlasesToRemove)
{
m_compositor->releaseUpdateAtlases(WTFMove(atlasesToRemove));
}

void ThreadedCoordinatedLayerTreeHost::setIsDiscardable(bool discardable)
{
m_isDiscardable = discardable;
Expand Down
Expand Up @@ -100,6 +100,7 @@ class ThreadedCoordinatedLayerTreeHost final : public CoordinatedLayerTreeHost {
// CompositingCoordinator::Client
void didFlushRootLayer(const WebCore::FloatRect&) override { }
void commitSceneState(const WebCore::CoordinatedGraphicsState&) override;
void releaseUpdateAtlases(Vector<uint32_t>&&) override;

#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID) override;
Expand Down

0 comments on commit 752c41c

Please sign in to comment.