[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 | |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 5 | #include "cc/tree_synchronizer.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
[email protected] | 0bf94724 | 2012-12-04 04:25:11 | [diff] [blame] | 7 | #include "base/debug/trace_event.h" |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 8 | #include "cc/layer.h" |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 9 | #include "cc/layer_impl.h" |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 10 | #include "cc/scrollbar_animation_controller.h" |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 11 | #include "cc/scrollbar_layer.h" |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 12 | #include "cc/scrollbar_layer_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 13 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 14 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 15 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 16 | scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTrees(Layer* layerRoot, scoped_ptr<LayerImpl> oldLayerImplRoot, LayerTreeHostImpl* hostImpl) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 17 | { |
[email protected] | 0bf94724 | 2012-12-04 04:25:11 | [diff] [blame] | 18 | TRACE_EVENT0("cc", "TreeSynchronizer::synchronizeTrees"); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 19 | ScopedPtrLayerImplMap oldLayers; |
| 20 | RawPtrLayerImplMap newLayers; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 21 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 22 | collectExistingLayerImplRecursive(oldLayers, oldLayerImplRoot.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 23 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 24 | scoped_ptr<LayerImpl> newTree = synchronizeTreeRecursive(newLayers, oldLayers, layerRoot, hostImpl); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 25 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 26 | updateScrollbarLayerPointersRecursive(newLayers, layerRoot); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 31 | void TreeSynchronizer::collectExistingLayerImplRecursive(ScopedPtrLayerImplMap& oldLayers, scoped_ptr<LayerImpl> layerImpl) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 32 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 33 | if (!layerImpl) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 34 | return; |
| 35 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 36 | ScopedPtrVector<LayerImpl>& children = layerImpl->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] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 38 | collectExistingLayerImplRecursive(oldLayers, children.take(i)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 39 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 40 | collectExistingLayerImplRecursive(oldLayers, layerImpl->m_maskLayer.Pass()); |
| 41 | collectExistingLayerImplRecursive(oldLayers, layerImpl->m_replicaLayer.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 42 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 43 | int id = layerImpl->id(); |
| 44 | oldLayers.set(id, layerImpl.Pass()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 45 | } |
| 46 | |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 47 | scoped_ptr<LayerImpl> TreeSynchronizer::reuseOrCreateLayerImpl(RawPtrLayerImplMap& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeHostImpl* hostImpl) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 48 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 49 | scoped_ptr<LayerImpl> layerImpl = oldLayers.take(layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 50 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 51 | if (!layerImpl) |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 52 | layerImpl = layer->createLayerImpl(hostImpl); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 53 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 54 | newLayers[layer->id()] = layerImpl.get(); |
| 55 | return layerImpl.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 56 | } |
| 57 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 58 | scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTreeRecursive(RawPtrLayerImplMap& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeHostImpl* hostImpl) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 59 | { |
| 60 | if (!layer) |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 61 | return scoped_ptr<LayerImpl>(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 62 | |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 63 | scoped_ptr<LayerImpl> layerImpl = reuseOrCreateLayerImpl(newLayers, oldLayers, layer, hostImpl); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 64 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 65 | layerImpl->clearChildList(); |
| 66 | const std::vector<scoped_refptr<Layer> >& children = layer->children(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 67 | for (size_t i = 0; i < children.size(); ++i) |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 68 | layerImpl->addChild(synchronizeTreeRecursive(newLayers, oldLayers, children[i].get(), hostImpl)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 69 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 70 | layerImpl->setMaskLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer->maskLayer(), hostImpl)); |
| 71 | layerImpl->setReplicaLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer->replicaLayer(), hostImpl)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 72 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 73 | layer->pushPropertiesTo(layerImpl.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 74 | |
| 75 | // Remove all dangling pointers. The pointers will be setup later in updateScrollbarLayerPointersRecursive phase |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 76 | if (ScrollbarAnimationController* scrollbarController = layerImpl->scrollbarAnimationController()) { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 77 | scrollbarController->setHorizontalScrollbarLayer(0); |
| 78 | scrollbarController->setVerticalScrollbarLayer(0); |
| 79 | } |
| 80 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 81 | return layerImpl.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 82 | } |
| 83 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 84 | void TreeSynchronizer::updateScrollbarLayerPointersRecursive(const RawPtrLayerImplMap& newLayers, Layer* layer) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 85 | { |
| 86 | if (!layer) |
| 87 | return; |
| 88 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 89 | const std::vector<scoped_refptr<Layer> >& children = layer->children(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 90 | for (size_t i = 0; i < children.size(); ++i) |
| 91 | updateScrollbarLayerPointersRecursive(newLayers, children[i].get()); |
| 92 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 93 | ScrollbarLayer* scrollbarLayer = layer->toScrollbarLayer(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 94 | if (!scrollbarLayer) |
| 95 | return; |
| 96 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 97 | RawPtrLayerImplMap::const_iterator iter = newLayers.find(scrollbarLayer->id()); |
| 98 | ScrollbarLayerImpl* scrollbarLayerImpl = iter != newLayers.end() ? static_cast<ScrollbarLayerImpl*>(iter->second) : NULL; |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 99 | iter = newLayers.find(scrollbarLayer->scrollLayerId()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 100 | LayerImpl* scrollLayerImpl = iter != newLayers.end() ? iter->second : NULL; |
[email protected] | e0bd43a | 2012-10-12 16:54:21 | [diff] [blame] | 101 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 102 | DCHECK(scrollbarLayerImpl); |
| 103 | DCHECK(scrollLayerImpl); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 104 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 105 | if (scrollbarLayerImpl->orientation() == WebKit::WebScrollbar::Horizontal) |
| 106 | scrollLayerImpl->setHorizontalScrollbarLayer(scrollbarLayerImpl); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 107 | else |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 108 | scrollLayerImpl->setVerticalScrollbarLayer(scrollbarLayerImpl); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 109 | } |
| 110 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 111 | } // namespace cc |