blob: fdea6e2bb58449674a09d4d39a97fd32598efecf [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
5#include "config.h"
6
[email protected]a8461d82012-10-16 21:11:147#include "cc/tree_synchronizer.h"
[email protected]94f206c12012-08-25 00:09:148
9#include "CCLayerImpl.h"
10#include "CCScrollbarAnimationController.h"
11#include "CCScrollbarLayerImpl.h"
[email protected]a8461d82012-10-16 21:11:1412#include "cc/layer.h"
13#include "cc/scrollbar_layer.h"
[email protected]94f206c12012-08-25 00:09:1414
[email protected]9c88e562012-09-14 22:21:3015namespace cc {
[email protected]94f206c12012-08-25 00:09:1416
[email protected]e0bd43a2012-10-12 16:54:2117scoped_ptr<CCLayerImpl> TreeSynchronizer::synchronizeTrees(LayerChromium* layerChromiumRoot, scoped_ptr<CCLayerImpl> oldCCLayerImplRoot, CCLayerTreeHostImpl* hostImpl)
[email protected]94f206c12012-08-25 00:09:1418{
[email protected]e0bd43a2012-10-12 16:54:2119 ScopedPtrCCLayerImplMap oldLayers;
[email protected]94f206c12012-08-25 00:09:1420 RawPtrCCLayerImplMap newLayers;
21
[email protected]e0bd43a2012-10-12 16:54:2122 collectExistingCCLayerImplRecursive(oldLayers, oldCCLayerImplRoot.Pass());
[email protected]94f206c12012-08-25 00:09:1423
[email protected]e0bd43a2012-10-12 16:54:2124 scoped_ptr<CCLayerImpl> newTree = synchronizeTreeRecursive(newLayers, oldLayers, layerChromiumRoot, hostImpl);
[email protected]94f206c12012-08-25 00:09:1425
26 updateScrollbarLayerPointersRecursive(newLayers, layerChromiumRoot);
27
[email protected]e0bd43a2012-10-12 16:54:2128 return newTree.Pass();
[email protected]94f206c12012-08-25 00:09:1429}
30
[email protected]e0bd43a2012-10-12 16:54:2131void TreeSynchronizer::collectExistingCCLayerImplRecursive(ScopedPtrCCLayerImplMap& oldLayers, scoped_ptr<CCLayerImpl> ccLayerImpl)
[email protected]94f206c12012-08-25 00:09:1432{
[email protected]94f206c12012-08-25 00:09:1433 if (!ccLayerImpl)
34 return;
35
[email protected]e0bd43a2012-10-12 16:54:2136 ScopedPtrVector<CCLayerImpl>& children = ccLayerImpl->m_children;
[email protected]94f206c12012-08-25 00:09:1437 for (size_t i = 0; i < children.size(); ++i)
[email protected]0920e24f2012-09-20 03:34:0338 collectExistingCCLayerImplRecursive(oldLayers, children.take(i));
[email protected]94f206c12012-08-25 00:09:1439
[email protected]e0bd43a2012-10-12 16:54:2140 collectExistingCCLayerImplRecursive(oldLayers, ccLayerImpl->m_maskLayer.Pass());
41 collectExistingCCLayerImplRecursive(oldLayers, ccLayerImpl->m_replicaLayer.Pass());
[email protected]94f206c12012-08-25 00:09:1442
43 int id = ccLayerImpl->id();
[email protected]e0bd43a2012-10-12 16:54:2144 oldLayers.set(id, ccLayerImpl.Pass());
[email protected]94f206c12012-08-25 00:09:1445}
46
[email protected]e0bd43a2012-10-12 16:54:2147scoped_ptr<CCLayerImpl> TreeSynchronizer::reuseOrCreateCCLayerImpl(RawPtrCCLayerImplMap& newLayers, ScopedPtrCCLayerImplMap& oldLayers, LayerChromium* layer)
[email protected]94f206c12012-08-25 00:09:1448{
[email protected]e0bd43a2012-10-12 16:54:2149 scoped_ptr<CCLayerImpl> ccLayerImpl = oldLayers.take(layer->id());
[email protected]94f206c12012-08-25 00:09:1450
51 if (!ccLayerImpl)
52 ccLayerImpl = layer->createCCLayerImpl();
53
[email protected]e0bd43a2012-10-12 16:54:2154 newLayers[layer->id()] = ccLayerImpl.get();
55 return ccLayerImpl.Pass();
[email protected]94f206c12012-08-25 00:09:1456}
57
[email protected]e0bd43a2012-10-12 16:54:2158scoped_ptr<CCLayerImpl> TreeSynchronizer::synchronizeTreeRecursive(RawPtrCCLayerImplMap& newLayers, ScopedPtrCCLayerImplMap& oldLayers, LayerChromium* layer, CCLayerTreeHostImpl* hostImpl)
[email protected]94f206c12012-08-25 00:09:1459{
60 if (!layer)
[email protected]e0bd43a2012-10-12 16:54:2161 return scoped_ptr<CCLayerImpl>();
[email protected]94f206c12012-08-25 00:09:1462
[email protected]e0bd43a2012-10-12 16:54:2163 scoped_ptr<CCLayerImpl> ccLayerImpl = reuseOrCreateCCLayerImpl(newLayers, oldLayers, layer);
[email protected]94f206c12012-08-25 00:09:1464
65 ccLayerImpl->clearChildList();
[email protected]d58499a2012-10-09 22:27:4766 const std::vector<scoped_refptr<LayerChromium> >& children = layer->children();
[email protected]94f206c12012-08-25 00:09:1467 for (size_t i = 0; i < children.size(); ++i)
68 ccLayerImpl->addChild(synchronizeTreeRecursive(newLayers, oldLayers, children[i].get(), hostImpl));
69
70 ccLayerImpl->setMaskLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer->maskLayer(), hostImpl));
71 ccLayerImpl->setReplicaLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer->replicaLayer(), hostImpl));
72
73 layer->pushPropertiesTo(ccLayerImpl.get());
74 ccLayerImpl->setLayerTreeHostImpl(hostImpl);
75
76 // Remove all dangling pointers. The pointers will be setup later in updateScrollbarLayerPointersRecursive phase
77 if (CCScrollbarAnimationController* scrollbarController = ccLayerImpl->scrollbarAnimationController()) {
78 scrollbarController->setHorizontalScrollbarLayer(0);
79 scrollbarController->setVerticalScrollbarLayer(0);
80 }
81
[email protected]e0bd43a2012-10-12 16:54:2182 return ccLayerImpl.Pass();
[email protected]94f206c12012-08-25 00:09:1483}
84
85void TreeSynchronizer::updateScrollbarLayerPointersRecursive(const RawPtrCCLayerImplMap& newLayers, LayerChromium* layer)
86{
87 if (!layer)
88 return;
89
[email protected]d58499a2012-10-09 22:27:4790 const std::vector<scoped_refptr<LayerChromium> >& children = layer->children();
[email protected]94f206c12012-08-25 00:09:1491 for (size_t i = 0; i < children.size(); ++i)
92 updateScrollbarLayerPointersRecursive(newLayers, children[i].get());
93
94 ScrollbarLayerChromium* scrollbarLayer = layer->toScrollbarLayerChromium();
95 if (!scrollbarLayer)
96 return;
97
[email protected]e0bd43a2012-10-12 16:54:2198 RawPtrCCLayerImplMap::const_iterator iter = newLayers.find(scrollbarLayer->id());
99 CCScrollbarLayerImpl* ccScrollbarLayerImpl = iter != newLayers.end() ? static_cast<CCScrollbarLayerImpl*>(iter->second) : NULL;
100 iter = newLayers.find(scrollbarLayer->scrollLayerId());
101 CCLayerImpl* ccScrollLayerImpl = iter != newLayers.end() ? iter->second : NULL;
102
[email protected]94f206c12012-08-25 00:09:14103 ASSERT(ccScrollbarLayerImpl);
[email protected]94f206c12012-08-25 00:09:14104 ASSERT(ccScrollLayerImpl);
105
106 if (ccScrollbarLayerImpl->orientation() == WebKit::WebScrollbar::Horizontal)
107 ccScrollLayerImpl->setHorizontalScrollbarLayer(ccScrollbarLayerImpl);
108 else
109 ccScrollLayerImpl->setVerticalScrollbarLayer(ccScrollbarLayerImpl);
110}
111
[email protected]9c88e562012-09-14 22:21:30112} // namespace cc