blob: 863edef53e95afd0635e89e934a8ebcf18615a3c [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// Copyright 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]a8461d82012-10-16 21:11:145#include "cc/tree_synchronizer.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]0bf947242012-12-04 04:25:117#include "base/debug/trace_event.h"
[email protected]a8461d82012-10-16 21:11:148#include "cc/layer.h"
[email protected]d50c6862012-10-23 02:08:319#include "cc/layer_impl.h"
[email protected]c4040a522012-10-21 15:01:4010#include "cc/scrollbar_animation_controller.h"
[email protected]a8461d82012-10-16 21:11:1411#include "cc/scrollbar_layer.h"
[email protected]c4040a522012-10-21 15:01:4012#include "cc/scrollbar_layer_impl.h"
[email protected]94f206c12012-08-25 00:09:1413
[email protected]9c88e562012-09-14 22:21:3014namespace cc {
[email protected]94f206c12012-08-25 00:09:1415
[email protected]96baf3e2012-10-22 23:09:5516scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTrees(Layer* layerRoot, scoped_ptr<LayerImpl> oldLayerImplRoot, LayerTreeHostImpl* hostImpl)
[email protected]94f206c12012-08-25 00:09:1417{
[email protected]0bf947242012-12-04 04:25:1118 TRACE_EVENT0("cc", "TreeSynchronizer::synchronizeTrees");
[email protected]96baf3e2012-10-22 23:09:5519 ScopedPtrLayerImplMap oldLayers;
20 RawPtrLayerImplMap newLayers;
[email protected]94f206c12012-08-25 00:09:1421
[email protected]96baf3e2012-10-22 23:09:5522 collectExistingLayerImplRecursive(oldLayers, oldLayerImplRoot.Pass());
[email protected]94f206c12012-08-25 00:09:1423
[email protected]96baf3e2012-10-22 23:09:5524 scoped_ptr<LayerImpl> newTree = synchronizeTreeRecursive(newLayers, oldLayers, layerRoot, hostImpl);
[email protected]94f206c12012-08-25 00:09:1425
[email protected]96baf3e2012-10-22 23:09:5526 updateScrollbarLayerPointersRecursive(newLayers, layerRoot);
[email protected]94f206c12012-08-25 00:09:1427
[email protected]e0bd43a2012-10-12 16:54:2128 return newTree.Pass();
[email protected]94f206c12012-08-25 00:09:1429}
30
[email protected]96baf3e2012-10-22 23:09:5531void TreeSynchronizer::collectExistingLayerImplRecursive(ScopedPtrLayerImplMap& oldLayers, scoped_ptr<LayerImpl> layerImpl)
[email protected]94f206c12012-08-25 00:09:1432{
[email protected]96baf3e2012-10-22 23:09:5533 if (!layerImpl)
[email protected]94f206c12012-08-25 00:09:1434 return;
35
[email protected]96baf3e2012-10-22 23:09:5536 ScopedPtrVector<LayerImpl>& children = layerImpl->m_children;
[email protected]94f206c12012-08-25 00:09:1437 for (size_t i = 0; i < children.size(); ++i)
[email protected]96baf3e2012-10-22 23:09:5538 collectExistingLayerImplRecursive(oldLayers, children.take(i));
[email protected]94f206c12012-08-25 00:09:1439
[email protected]96baf3e2012-10-22 23:09:5540 collectExistingLayerImplRecursive(oldLayers, layerImpl->m_maskLayer.Pass());
41 collectExistingLayerImplRecursive(oldLayers, layerImpl->m_replicaLayer.Pass());
[email protected]94f206c12012-08-25 00:09:1442
[email protected]96baf3e2012-10-22 23:09:5543 int id = layerImpl->id();
44 oldLayers.set(id, layerImpl.Pass());
[email protected]94f206c12012-08-25 00:09:1445}
46
[email protected]586d51ed2012-12-07 20:31:4547scoped_ptr<LayerImpl> TreeSynchronizer::reuseOrCreateLayerImpl(RawPtrLayerImplMap& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeHostImpl* hostImpl)
[email protected]94f206c12012-08-25 00:09:1448{
[email protected]96baf3e2012-10-22 23:09:5549 scoped_ptr<LayerImpl> layerImpl = oldLayers.take(layer->id());
[email protected]94f206c12012-08-25 00:09:1450
[email protected]96baf3e2012-10-22 23:09:5551 if (!layerImpl)
[email protected]586d51ed2012-12-07 20:31:4552 layerImpl = layer->createLayerImpl(hostImpl);
[email protected]94f206c12012-08-25 00:09:1453
[email protected]96baf3e2012-10-22 23:09:5554 newLayers[layer->id()] = layerImpl.get();
55 return layerImpl.Pass();
[email protected]94f206c12012-08-25 00:09:1456}
57
[email protected]96baf3e2012-10-22 23:09:5558scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTreeRecursive(RawPtrLayerImplMap& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeHostImpl* hostImpl)
[email protected]94f206c12012-08-25 00:09:1459{
60 if (!layer)
[email protected]96baf3e2012-10-22 23:09:5561 return scoped_ptr<LayerImpl>();
[email protected]94f206c12012-08-25 00:09:1462
[email protected]586d51ed2012-12-07 20:31:4563 scoped_ptr<LayerImpl> layerImpl = reuseOrCreateLayerImpl(newLayers, oldLayers, layer, hostImpl);
[email protected]94f206c12012-08-25 00:09:1464
[email protected]96baf3e2012-10-22 23:09:5565 layerImpl->clearChildList();
66 const std::vector<scoped_refptr<Layer> >& children = layer->children();
[email protected]94f206c12012-08-25 00:09:1467 for (size_t i = 0; i < children.size(); ++i)
[email protected]96baf3e2012-10-22 23:09:5568 layerImpl->addChild(synchronizeTreeRecursive(newLayers, oldLayers, children[i].get(), hostImpl));
[email protected]94f206c12012-08-25 00:09:1469
[email protected]96baf3e2012-10-22 23:09:5570 layerImpl->setMaskLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer->maskLayer(), hostImpl));
71 layerImpl->setReplicaLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer->replicaLayer(), hostImpl));
[email protected]94f206c12012-08-25 00:09:1472
[email protected]96baf3e2012-10-22 23:09:5573 layer->pushPropertiesTo(layerImpl.get());
[email protected]94f206c12012-08-25 00:09:1474
75 // Remove all dangling pointers. The pointers will be setup later in updateScrollbarLayerPointersRecursive phase
[email protected]96baf3e2012-10-22 23:09:5576 if (ScrollbarAnimationController* scrollbarController = layerImpl->scrollbarAnimationController()) {
[email protected]94f206c12012-08-25 00:09:1477 scrollbarController->setHorizontalScrollbarLayer(0);
78 scrollbarController->setVerticalScrollbarLayer(0);
79 }
80
[email protected]96baf3e2012-10-22 23:09:5581 return layerImpl.Pass();
[email protected]94f206c12012-08-25 00:09:1482}
83
[email protected]96baf3e2012-10-22 23:09:5584void TreeSynchronizer::updateScrollbarLayerPointersRecursive(const RawPtrLayerImplMap& newLayers, Layer* layer)
[email protected]94f206c12012-08-25 00:09:1485{
86 if (!layer)
87 return;
88
[email protected]96baf3e2012-10-22 23:09:5589 const std::vector<scoped_refptr<Layer> >& children = layer->children();
[email protected]94f206c12012-08-25 00:09:1490 for (size_t i = 0; i < children.size(); ++i)
91 updateScrollbarLayerPointersRecursive(newLayers, children[i].get());
92
[email protected]96baf3e2012-10-22 23:09:5593 ScrollbarLayer* scrollbarLayer = layer->toScrollbarLayer();
[email protected]94f206c12012-08-25 00:09:1494 if (!scrollbarLayer)
95 return;
96
[email protected]96baf3e2012-10-22 23:09:5597 RawPtrLayerImplMap::const_iterator iter = newLayers.find(scrollbarLayer->id());
98 ScrollbarLayerImpl* scrollbarLayerImpl = iter != newLayers.end() ? static_cast<ScrollbarLayerImpl*>(iter->second) : NULL;
[email protected]e0bd43a2012-10-12 16:54:2199 iter = newLayers.find(scrollbarLayer->scrollLayerId());
[email protected]96baf3e2012-10-22 23:09:55100 LayerImpl* scrollLayerImpl = iter != newLayers.end() ? iter->second : NULL;
[email protected]e0bd43a2012-10-12 16:54:21101
[email protected]96baf3e2012-10-22 23:09:55102 DCHECK(scrollbarLayerImpl);
103 DCHECK(scrollLayerImpl);
[email protected]94f206c12012-08-25 00:09:14104
[email protected]96baf3e2012-10-22 23:09:55105 if (scrollbarLayerImpl->orientation() == WebKit::WebScrollbar::Horizontal)
106 scrollLayerImpl->setHorizontalScrollbarLayer(scrollbarLayerImpl);
[email protected]94f206c12012-08-25 00:09:14107 else
[email protected]96baf3e2012-10-22 23:09:55108 scrollLayerImpl->setVerticalScrollbarLayer(scrollbarLayerImpl);
[email protected]94f206c12012-08-25 00:09:14109}
110
[email protected]bc5e77c2012-11-05 20:00:49111} // namespace cc