Commit 0bf94724 authored by jamesr@chromium.org's avatar jamesr@chromium.org

Only do full tree sync if tree is actually changed, otherwise just push properties

We only have to run the complete tree synchronization algorithm if the cc::Layer tree's
structure is actually changed, otherwise we can just push properties over since the
cc::LayerImpl tree structure is never changed outside of commit.

Since scroll offset updates are tied into the tree synchronization algorithm, we currently
have to do a full tree sync for scroll updates. Fixing this will speed up scroll operations
but requires a bit more work.

Speeds up cc_perftests tenTenSingleThread by 7.3%

BUG=161166


Review URL: https://chromiumcodereview.appspot.com/11316297

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170881 0039d316-1c4b-4281-b951-d872f2087c98
parent 9ec9dcf8
......@@ -116,6 +116,12 @@ void Layer::setNeedsCommit()
m_layerTreeHost->setNeedsCommit();
}
void Layer::setNeedsFullTreeSync()
{
if (m_layerTreeHost)
m_layerTreeHost->setNeedsFullTreeSync();
}
gfx::Rect Layer::layerRectToContentRect(const gfx::RectF& layerRect) const
{
gfx::RectF contentRect = gfx::ScaleRect(layerRect, contentsScaleX(), contentsScaleY());
......@@ -157,7 +163,7 @@ void Layer::insertChild(scoped_refptr<Layer> child, size_t index)
index = min(index, m_children.size());
LayerList::iterator iter = m_children.begin();
m_children.insert(iter + index, child);
setNeedsCommit();
setNeedsFullTreeSync();
}
void Layer::removeFromParent()
......@@ -175,7 +181,7 @@ void Layer::removeChild(Layer* child)
child->setParent(0);
m_children.erase(iter);
setNeedsCommit();
setNeedsFullTreeSync();
return;
}
}
......@@ -302,7 +308,7 @@ void Layer::setMaskLayer(Layer* maskLayer)
m_maskLayer->setLayerTreeHost(m_layerTreeHost);
m_maskLayer->setIsMask(true);
}
setNeedsCommit();
setNeedsFullTreeSync();
}
void Layer::setReplicaLayer(Layer* layer)
......@@ -314,7 +320,7 @@ void Layer::setReplicaLayer(Layer* layer)
m_replicaLayer = layer;
if (m_replicaLayer)
m_replicaLayer->setLayerTreeHost(m_layerTreeHost);
setNeedsCommit();
setNeedsFullTreeSync();
}
void Layer::setFilters(const WebKit::WebFilterOperations& filters)
......@@ -411,7 +417,7 @@ void Layer::setScrollOffset(gfx::Vector2d scrollOffset)
m_scrollOffset = scrollOffset;
if (m_layerScrollClient)
m_layerScrollClient->didScroll();
setNeedsCommit();
setNeedsFullTreeSync();
}
void Layer::setMaxScrollOffset(gfx::Vector2d maxScrollOffset)
......
......@@ -309,6 +309,7 @@ protected:
Layer();
void setNeedsCommit();
void setNeedsFullTreeSync();
// This flag is set when layer need repainting/updating.
bool m_needsDisplay;
......
......@@ -161,6 +161,7 @@ scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, con
LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSettings& settings)
: m_animating(false)
, m_needsAnimateLayers(false)
, m_needsFullTreeSync(true)
, m_client(client)
, m_commitNumber(0)
, m_renderingStats()
......@@ -310,6 +311,28 @@ void LayerTreeHost::beginCommitOnImplThread(LayerTreeHostImpl* hostImpl)
TRACE_EVENT0("cc", "LayerTreeHost::commitTo");
}
static void pushPropertiesRecursive(Layer* layer, LayerImpl* layerImpl)
{
if (!layer) {
DCHECK(!layerImpl);
return;
}
DCHECK_EQ(layer->id(), layerImpl->id());
layer->pushPropertiesTo(layerImpl);
pushPropertiesRecursive(layer->maskLayer(), layerImpl->maskLayer());
pushPropertiesRecursive(layer->replicaLayer(), layerImpl->replicaLayer());
const std::vector<scoped_refptr<Layer> >& children = layer->children();
const ScopedPtrVector<LayerImpl>& implChildren = layerImpl->children();
DCHECK_EQ(children.size(), implChildren.size());
for (size_t i = 0; i < children.size(); ++i) {
pushPropertiesRecursive(children[i].get(), implChildren[i]);
}
}
// This function commits the LayerTreeHost to an impl tree. When modifying
// this function, keep in mind that the function *runs* on the impl thread! Any
// code that is logically a main thread operation, e.g. deletion of a Layer,
......@@ -322,7 +345,13 @@ void LayerTreeHost::finishCommitOnImplThread(LayerTreeHostImpl* hostImpl)
m_contentsTextureManager->updateBackingsInDrawingImplTree();
m_contentsTextureManager->reduceMemory(hostImpl->resourceProvider());
if (m_needsFullTreeSync) {
hostImpl->setRootLayer(TreeSynchronizer::synchronizeTrees(rootLayer(), hostImpl->detachLayerTree(), hostImpl));
} else {
TRACE_EVENT0("cc", "LayerTreeHost::pushPropertiesRecursive");
pushPropertiesRecursive(rootLayer(), hostImpl->rootLayer());
}
m_needsFullTreeSync = false;
if (m_rootLayer && m_hudLayer)
hostImpl->setHudLayer(static_cast<HeadsUpDisplayLayerImpl*>(LayerTreeHostCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->id())));
......@@ -443,6 +472,12 @@ void LayerTreeHost::setNeedsCommit()
m_proxy->setNeedsCommit();
}
void LayerTreeHost::setNeedsFullTreeSync()
{
m_needsFullTreeSync = true;
setNeedsCommit();
}
void LayerTreeHost::setNeedsRedraw()
{
m_proxy->setNeedsRedraw();
......@@ -481,7 +516,7 @@ void LayerTreeHost::setRootLayer(scoped_refptr<Layer> rootLayer)
if (m_hudLayer)
m_hudLayer->removeFromParent();
setNeedsCommit();
setNeedsFullTreeSync();
}
void LayerTreeHost::setDebugState(const LayerTreeDebugState& debugState)
......
......@@ -184,6 +184,7 @@ public:
void setNeedsAnimate();
// virtual for testing
virtual void setNeedsCommit();
virtual void setNeedsFullTreeSync();
void setNeedsRedraw();
bool commitRequested() const;
......@@ -268,6 +269,7 @@ private:
bool m_animating;
bool m_needsAnimateLayers;
bool m_needsFullTreeSync;
base::CancelableClosure m_prepaintCallback;
......
This diff is collapsed.
......@@ -40,6 +40,15 @@ ScrollbarLayer::~ScrollbarLayer()
{
}
void ScrollbarLayer::setScrollLayerId(int id)
{
if (id == m_scrollLayerId)
return;
m_scrollLayerId = id;
setNeedsFullTreeSync();
}
int ScrollbarLayer::maxTextureSize() {
DCHECK(layerTreeHost());
return layerTreeHost()->rendererCapabilities().maxTextureSize;
......
......@@ -25,6 +25,9 @@ public:
static scoped_refptr<ScrollbarLayer> create(scoped_ptr<WebKit::WebScrollbar>, WebKit::WebScrollbarThemePainter, scoped_ptr<WebKit::WebScrollbarThemeGeometry>, int scrollLayerId);
int scrollLayerId() const { return m_scrollLayerId; }
void setScrollLayerId(int id);
// Layer interface
virtual void setTexturePriorities(const PriorityCalculator&) OVERRIDE;
virtual void update(ResourceUpdateQueue&, const OcclusionTracker*, RenderingStats&) OVERRIDE;
......@@ -32,9 +35,6 @@ public:
virtual void pushPropertiesTo(LayerImpl*) OVERRIDE;
virtual void setContentsScale(float contentsScale) OVERRIDE;
int scrollLayerId() const { return m_scrollLayerId; }
void setScrollLayerId(int id) { m_scrollLayerId = id; }
virtual ScrollbarLayer* toScrollbarLayer() OVERRIDE;
protected:
......
......@@ -4,6 +4,7 @@
#include "cc/tree_synchronizer.h"
#include "base/debug/trace_event.h"
#include "cc/layer.h"
#include "cc/layer_impl.h"
#include "cc/scrollbar_animation_controller.h"
......@@ -14,6 +15,7 @@ namespace cc {
scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTrees(Layer* layerRoot, scoped_ptr<LayerImpl> oldLayerImplRoot, LayerTreeHostImpl* hostImpl)
{
TRACE_EVENT0("cc", "TreeSynchronizer::synchronizeTrees");
ScopedPtrLayerImplMap oldLayers;
RawPtrLayerImplMap newLayers;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment