[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | // 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] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame^] | 7 | #include "cc/tree_synchronizer.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 8 | |
| 9 | #include "CCLayerImpl.h" |
| 10 | #include "CCScrollbarAnimationController.h" |
| 11 | #include "CCScrollbarLayerImpl.h" |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame^] | 12 | #include "cc/layer.h" |
| 13 | #include "cc/scrollbar_layer.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 14 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 15 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 16 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 17 | scoped_ptr<CCLayerImpl> TreeSynchronizer::synchronizeTrees(LayerChromium* layerChromiumRoot, scoped_ptr<CCLayerImpl> oldCCLayerImplRoot, CCLayerTreeHostImpl* hostImpl) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 18 | { |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 19 | ScopedPtrCCLayerImplMap oldLayers; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 20 | RawPtrCCLayerImplMap newLayers; |
| 21 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 22 | collectExistingCCLayerImplRecursive(oldLayers, oldCCLayerImplRoot.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 23 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 24 | scoped_ptr<CCLayerImpl> newTree = synchronizeTreeRecursive(newLayers, oldLayers, layerChromiumRoot, hostImpl); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 25 | |
| 26 | updateScrollbarLayerPointersRecursive(newLayers, layerChromiumRoot); |
| 27 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 28 | return newTree.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 29 | } |
| 30 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 31 | void TreeSynchronizer::collectExistingCCLayerImplRecursive(ScopedPtrCCLayerImplMap& oldLayers, scoped_ptr<CCLayerImpl> ccLayerImpl) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 32 | { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 33 | if (!ccLayerImpl) |
| 34 | return; |
| 35 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 36 | ScopedPtrVector<CCLayerImpl>& children = ccLayerImpl->m_children; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 37 | for (size_t i = 0; i < children.size(); ++i) |
[email protected] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 38 | collectExistingCCLayerImplRecursive(oldLayers, children.take(i)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 39 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 40 | collectExistingCCLayerImplRecursive(oldLayers, ccLayerImpl->m_maskLayer.Pass()); |
| 41 | collectExistingCCLayerImplRecursive(oldLayers, ccLayerImpl->m_replicaLayer.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 42 | |
| 43 | int id = ccLayerImpl->id(); |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 44 | oldLayers.set(id, ccLayerImpl.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 45 | } |
| 46 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 47 | scoped_ptr<CCLayerImpl> TreeSynchronizer::reuseOrCreateCCLayerImpl(RawPtrCCLayerImplMap& newLayers, ScopedPtrCCLayerImplMap& oldLayers, LayerChromium* layer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 48 | { |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 49 | scoped_ptr<CCLayerImpl> ccLayerImpl = oldLayers.take(layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 50 | |
| 51 | if (!ccLayerImpl) |
| 52 | ccLayerImpl = layer->createCCLayerImpl(); |
| 53 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 54 | newLayers[layer->id()] = ccLayerImpl.get(); |
| 55 | return ccLayerImpl.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 56 | } |
| 57 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 58 | scoped_ptr<CCLayerImpl> TreeSynchronizer::synchronizeTreeRecursive(RawPtrCCLayerImplMap& newLayers, ScopedPtrCCLayerImplMap& oldLayers, LayerChromium* layer, CCLayerTreeHostImpl* hostImpl) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 59 | { |
| 60 | if (!layer) |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 61 | return scoped_ptr<CCLayerImpl>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 62 | |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 63 | scoped_ptr<CCLayerImpl> ccLayerImpl = reuseOrCreateCCLayerImpl(newLayers, oldLayers, layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 64 | |
| 65 | ccLayerImpl->clearChildList(); |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 66 | const std::vector<scoped_refptr<LayerChromium> >& children = layer->children(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 67 | 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] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 82 | return ccLayerImpl.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void TreeSynchronizer::updateScrollbarLayerPointersRecursive(const RawPtrCCLayerImplMap& newLayers, LayerChromium* layer) |
| 86 | { |
| 87 | if (!layer) |
| 88 | return; |
| 89 | |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 90 | const std::vector<scoped_refptr<LayerChromium> >& children = layer->children(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 91 | 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] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 98 | 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] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 103 | ASSERT(ccScrollbarLayerImpl); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 104 | ASSERT(ccScrollLayerImpl); |
| 105 | |
| 106 | if (ccScrollbarLayerImpl->orientation() == WebKit::WebScrollbar::Horizontal) |
| 107 | ccScrollLayerImpl->setHorizontalScrollbarLayer(ccScrollbarLayerImpl); |
| 108 | else |
| 109 | ccScrollLayerImpl->setVerticalScrollbarLayer(ccScrollbarLayerImpl); |
| 110 | } |
| 111 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 112 | } // namespace cc |