Diff
Modified: trunk/Source/WebKit2/ChangeLog (203775 => 203776)
--- trunk/Source/WebKit2/ChangeLog 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/ChangeLog 2016-07-27 15:58:08 UTC (rev 203776)
@@ -1,5 +1,51 @@
2016-07-27 Carlos Garcia Campos <[email protected]>
+ [Coordinated Graphics] Improve scheduling of tasks between threads in CoordinatedGraphicsScene
+ https://bugs.webkit.org/show_bug.cgi?id=160238
+
+ Reviewed by Michael Catanzaro.
+
+ This patch makes the following improvements:
+
+ - Avoid scheduling tasks to the main thread if the scene is detached.
+ - Do not take references when not actually sending tasks to another threads.
+ - Use Function instead of std::function on dispatch methods.
+ - Remove purgeBackingStores that is actually never called. It's only scheduled from purgeGLResources() that
+ is always called after detach.
+
+ * Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
+ (WebKit::CoordinatedGraphicsScene::dispatchOnMainThread):
+ (WebKit::CoordinatedGraphicsScene::dispatchOnClientRunLoop):
+ (WebKit::CoordinatedGraphicsScene::paintToCurrentGLContext):
+ (WebKit::CoordinatedGraphicsScene::updateViewport):
+ (WebKit::CoordinatedGraphicsScene::onNewBufferAvailable):
+ (WebKit::CoordinatedGraphicsScene::commitSceneState):
+ (WebKit::CoordinatedGraphicsScene::renderNextFrame):
+ (WebKit::CoordinatedGraphicsScene::purgeGLResources):
+ (WebKit::CoordinatedGraphicsScene::commitScrollOffset):
+ (WebKit::CoordinatedGraphicsScene::detach):
+ (WebKit::CoordinatedGraphicsScene::setActive):
+ (WebKit::CoordinatedGraphicsScene::dispatchCommitScrollOffset): Deleted.
+ (WebKit::CoordinatedGraphicsScene::purgeBackingStores): Deleted.
+ * Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h:
+ * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:
+ (WebKit::ThreadedCompositor::purgeBackingStores): Deleted.
+ * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:
+ * UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp:
+ (WebKit::CoordinatedLayerTreeHostProxy::purgeBackingStores): Deleted.
+ * UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h:
+ * WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp:
+ (WebKit::CompositingCoordinator::invalidate):
+ * WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h:
+ * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp:
+ (WebKit::CoordinatedLayerTreeHost::invalidate):
+ (WebKit::CoordinatedLayerTreeHost::purgeBackingStores): Deleted.
+ * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:
+ * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.messages.in:
+ * WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h:
+
+2016-07-27 Carlos Garcia Campos <[email protected]>
+
[GTK] Remove network setup from web process
https://bugs.webkit.org/show_bug.cgi?id=160236
Modified: trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp (203775 => 203776)
--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp 2016-07-27 15:58:08 UTC (rev 203776)
@@ -34,20 +34,28 @@
namespace WebKit {
-void CoordinatedGraphicsScene::dispatchOnMainThread(std::function<void()>&& function)
+void CoordinatedGraphicsScene::dispatchOnMainThread(Function<void()>&& function)
{
- if (isMainThread())
+ if (isMainThread()) {
function();
- else
- RunLoop::main().dispatch(WTFMove(function));
+ return;
+ }
+
+ RunLoop::main().dispatch([protectedThis = makeRef(*this), function = WTFMove(function)] {
+ function();
+ });
}
-void CoordinatedGraphicsScene::dispatchOnClientRunLoop(std::function<void()>&& function)
+void CoordinatedGraphicsScene::dispatchOnClientRunLoop(Function<void()>&& function)
{
- if (&m_clientRunLoop == &RunLoop::current())
+ if (&m_clientRunLoop == &RunLoop::current()) {
function();
- else
- m_clientRunLoop.dispatch(WTFMove(function));
+ return;
+ }
+
+ m_clientRunLoop.dispatch([protectedThis = makeRef(*this), function = WTFMove(function)] {
+ function();
+ });
}
static bool layerShouldHaveBackingStore(TextureMapperLayer* layer)
@@ -113,12 +121,8 @@
m_textureMapper->endClip();
m_textureMapper->endPainting();
- if (currentRootLayer->descendantsOrSelfHaveRunningAnimations()) {
- RefPtr<CoordinatedGraphicsScene> protector(this);
- dispatchOnClientRunLoop([protector] {
- protector->updateViewport();
- });
- }
+ if (currentRootLayer->descendantsOrSelfHaveRunningAnimations())
+ updateViewport();
}
void CoordinatedGraphicsScene::paintToGraphicsContext(PlatformGraphicsContext* platformContext, const Color& backgroundColor, bool drawsBackground)
@@ -149,9 +153,12 @@
void CoordinatedGraphicsScene::updateViewport()
{
- ASSERT(&m_clientRunLoop == &RunLoop::current());
- if (m_client)
- m_client->updateViewport();
+ if (!m_client)
+ return;
+ dispatchOnClientRunLoop([this] {
+ if (m_client)
+ m_client->updateViewport();
+ });
}
void CoordinatedGraphicsScene::adjustPositionForFixedLayers(const FloatPoint& contentPosition)
@@ -202,10 +209,7 @@
#if USE(COORDINATED_GRAPHICS_THREADED)
void CoordinatedGraphicsScene::onNewBufferAvailable()
{
- RefPtr<CoordinatedGraphicsScene> protector(this);
- dispatchOnClientRunLoop([protector] {
- protector->updateViewport();
- });
+ updateViewport();
}
#endif
@@ -608,16 +612,17 @@
removeReleasedImageBackingsIfNeeded();
// The pending tiles state is on its way for the screen, tell the web process to render the next one.
- RefPtr<CoordinatedGraphicsScene> protector(this);
- dispatchOnMainThread([protector] {
- protector->renderNextFrame();
- });
+ renderNextFrame();
}
void CoordinatedGraphicsScene::renderNextFrame()
{
- if (m_client)
- m_client->renderNextFrame();
+ if (!m_client)
+ return;
+ dispatchOnMainThread([this] {
+ if (m_client)
+ m_client->renderNextFrame();
+ });
}
void CoordinatedGraphicsScene::ensureRootLayer()
@@ -656,6 +661,8 @@
void CoordinatedGraphicsScene::purgeGLResources()
{
+ ASSERT(!m_client);
+
m_imageBackings.clear();
m_releasedImageBackings.clear();
#if USE(GRAPHICS_SURFACE)
@@ -673,34 +680,18 @@
m_textureMapper = nullptr;
m_backingStores.clear();
m_backingStoresWithPendingBuffers.clear();
-
- setActive(false);
-
- RefPtr<CoordinatedGraphicsScene> protector(this);
- dispatchOnMainThread([protector] {
- protector->purgeBackingStores();
- });
}
-void CoordinatedGraphicsScene::dispatchCommitScrollOffset(uint32_t layerID, const IntSize& offset)
-{
- m_client->commitScrollOffset(layerID, offset);
-}
-
void CoordinatedGraphicsScene::commitScrollOffset(uint32_t layerID, const IntSize& offset)
{
- RefPtr<CoordinatedGraphicsScene> protector(this);
- dispatchOnMainThread([protector, layerID, offset] {
- protector->dispatchCommitScrollOffset(layerID, offset);
+ if (!m_client)
+ return;
+ dispatchOnMainThread([this, layerID, offset] {
+ if (m_client)
+ m_client->commitScrollOffset(layerID, offset);
});
}
-void CoordinatedGraphicsScene::purgeBackingStores()
-{
- if (m_client)
- m_client->purgeBackingStores();
-}
-
void CoordinatedGraphicsScene::setLayerAnimationsIfNeeded(TextureMapperLayer* layer, const CoordinatedGraphicsLayerState& state)
{
if (!state.animationsChanged)
@@ -713,7 +704,8 @@
{
ASSERT(isMainThread());
m_renderQueue.clear();
- m_client = 0;
+ m_isActive = false;
+ m_client = nullptr;
}
void CoordinatedGraphicsScene::appendUpdate(std::function<void()>&& function)
@@ -728,6 +720,9 @@
void CoordinatedGraphicsScene::setActive(bool active)
{
+ if (!m_client)
+ return;
+
if (m_isActive == active)
return;
@@ -736,12 +731,8 @@
// and cannot be applied to the newly created instance.
m_renderQueue.clear();
m_isActive = active;
- if (m_isActive) {
- RefPtr<CoordinatedGraphicsScene> protector(this);
- dispatchOnMainThread([protector] {
- protector->renderNextFrame();
- });
- }
+ if (m_isActive)
+ renderNextFrame();
}
TextureMapperLayer* CoordinatedGraphicsScene::findScrollableContentsLayerAt(const FloatPoint& point)
Modified: trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h (203775 => 203776)
--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h 2016-07-27 15:58:08 UTC (rev 203776)
@@ -33,7 +33,7 @@
#include <WebCore/TextureMapperFPSCounter.h>
#include <WebCore/TextureMapperLayer.h>
#include <WebCore/Timer.h>
-#include <functional>
+#include <wtf/Function.h>
#include <wtf/HashSet.h>
#include <wtf/Lock.h>
#include <wtf/RunLoop.h>
@@ -56,7 +56,6 @@
class CoordinatedGraphicsSceneClient {
public:
virtual ~CoordinatedGraphicsSceneClient() { }
- virtual void purgeBackingStores() = 0;
virtual void renderNextFrame() = 0;
virtual void updateViewport() = 0;
virtual void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset) = 0;
@@ -131,11 +130,10 @@
void syncRemoteContent();
void adjustPositionForFixedLayers(const WebCore::FloatPoint& contentPosition);
- void dispatchOnMainThread(std::function<void()>&&);
- void dispatchOnClientRunLoop(std::function<void()>&&);
+ void dispatchOnMainThread(Function<void()>&&);
+ void dispatchOnClientRunLoop(Function<void()>&&);
void updateViewport();
void renderNextFrame();
- void purgeBackingStores();
void createLayer(WebCore::CoordinatedLayerID);
void deleteLayer(WebCore::CoordinatedLayerID);
@@ -150,8 +148,6 @@
void removeBackingStoreIfNeeded(WebCore::TextureMapperLayer*);
void resetBackingStoreSizeToLayerSize(WebCore::TextureMapperLayer*);
- void dispatchCommitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset);
-
#if USE(COORDINATED_GRAPHICS_THREADED)
void onNewBufferAvailable() override;
#endif
Modified: trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp (203775 => 203776)
--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp 2016-07-27 15:58:08 UTC (rev 203776)
@@ -140,12 +140,6 @@
});
}
-void ThreadedCompositor::purgeBackingStores()
-{
- ASSERT(isMainThread());
- m_client->purgeBackingStores();
-}
-
void ThreadedCompositor::renderNextFrame()
{
ASSERT(isMainThread());
Modified: trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h (203775 => 203776)
--- trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h 2016-07-27 15:58:08 UTC (rev 203776)
@@ -53,7 +53,6 @@
class Client {
public:
virtual void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&, float) = 0;
- virtual void purgeBackingStores() = 0;
virtual void renderNextFrame() = 0;
virtual void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset) = 0;
};
@@ -81,7 +80,6 @@
ThreadedCompositor(Client*);
// CoordinatedGraphicsSceneClient
- void purgeBackingStores() override;
void renderNextFrame() override;
void updateViewport() override;
void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset) override;
Modified: trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp (203775 => 203776)
--- trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp 2016-07-27 15:58:08 UTC (rev 203776)
@@ -85,11 +85,6 @@
m_drawingAreaProxy->page().process().send(Messages::CoordinatedLayerTreeHost::RenderNextFrame(), m_drawingAreaProxy->page().pageID());
}
-void CoordinatedLayerTreeHostProxy::purgeBackingStores()
-{
- m_drawingAreaProxy->page().process().send(Messages::CoordinatedLayerTreeHost::PurgeBackingStores(), m_drawingAreaProxy->page().pageID());
-}
-
void CoordinatedLayerTreeHostProxy::commitScrollOffset(uint32_t layerID, const IntSize& offset)
{
m_drawingAreaProxy->page().process().send(Messages::CoordinatedLayerTreeHost::CommitScrollOffset(layerID, offset), m_drawingAreaProxy->page().pageID());
Modified: trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h (203775 => 203776)
--- trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h 2016-07-27 15:58:08 UTC (rev 203776)
@@ -51,7 +51,6 @@
void updateViewport() override;
void renderNextFrame() override;
- void purgeBackingStores() override;
void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset) override;
Modified: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp (203775 => 203776)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp 2016-07-27 15:58:08 UTC (rev 203776)
@@ -59,6 +59,12 @@
registeredLayer->setCoordinator(nullptr);
}
+void CompositingCoordinator::invalidate()
+{
+ m_rootLayer = nullptr;
+ purgeBackingStores();
+}
+
void CompositingCoordinator::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
{
if (m_rootCompositingLayer == graphicsLayer)
Modified: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h (203775 => 203776)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h 2016-07-27 15:58:08 UTC (rev 203776)
@@ -66,6 +66,8 @@
CompositingCoordinator(WebCore::Page*, CompositingCoordinator::Client&);
virtual ~CompositingCoordinator();
+ void invalidate();
+
void setRootCompositingLayer(WebCore::GraphicsLayer*);
void setViewOverlayRootLayer(WebCore::GraphicsLayer*);
void sizeDidChange(const WebCore::IntSize&);
@@ -73,11 +75,9 @@
void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&);
void renderNextFrame();
- void purgeBackingStores();
void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset);
void createRootLayer(const WebCore::IntSize&);
- void clearRootLayer() { m_rootLayer = nullptr; }
WebCore::GraphicsLayer* rootLayer() const { return m_rootLayer.get(); }
WebCore::CoordinatedGraphicsLayer* mainContentsLayer();
@@ -123,6 +123,8 @@
void flushPendingImageBackingChanges();
void clearPendingStateChanges();
+ void purgeBackingStores();
+
void scheduleReleaseInactiveAtlases();
void releaseInactiveAtlasesTimerFired();
Modified: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp (203775 => 203776)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp 2016-07-27 15:58:08 UTC (rev 203776)
@@ -102,7 +102,7 @@
{
cancelPendingLayerFlush();
- m_coordinator.clearRootLayer();
+ m_coordinator.invalidate();
LayerTreeHost::invalidate();
}
@@ -150,11 +150,6 @@
m_coordinator.renderNextFrame();
}
-void CoordinatedLayerTreeHost::purgeBackingStores()
-{
- m_coordinator.purgeBackingStores();
-}
-
void CoordinatedLayerTreeHost::didFlushRootLayer(const FloatRect& visibleContentRect)
{
// Because our view-relative overlay root layer is not attached to the FrameView's GraphicsLayer tree, we need to flush it manually.
Modified: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h (203775 => 203776)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h 2016-07-27 15:58:08 UTC (rev 203776)
@@ -59,7 +59,6 @@
void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&);
void renderNextFrame();
- void purgeBackingStores();
void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset);
WebCore::GraphicsLayerFactory* graphicsLayerFactory() override;
Modified: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.messages.in (203775 => 203776)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.messages.in 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.messages.in 2016-07-27 15:58:08 UTC (rev 203776)
@@ -23,7 +23,6 @@
messages -> CoordinatedLayerTreeHost LegacyReceiver {
SetVisibleContentsRect(WebCore::FloatRect visibleContentsRect, WebCore::FloatPoint trajectoryVectory)
RenderNextFrame()
- PurgeBackingStores()
CommitScrollOffset(uint32_t layerID, WebCore::IntSize offset)
}
#endif
Modified: trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h (203775 => 203776)
--- trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h 2016-07-27 15:52:24 UTC (rev 203775)
+++ trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h 2016-07-27 15:58:08 UTC (rev 203776)
@@ -82,11 +82,6 @@
m_layerTreeHost.setVisibleContentsRect(rect, trajectoryVector, scale);
}
- void purgeBackingStores() override
- {
- m_layerTreeHost.purgeBackingStores();
- }
-
void renderNextFrame() override
{
m_layerTreeHost.renderNextFrame();