Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: cc/trees/layer_tree_impl.cc

Issue 2816063003: Replace layer id with Element id for tracking scrollbar animation controllers (Closed)
Patch Set: Address reviewer comments, pull element_id.h change to another patch Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_impl.h" 5 #include "cc/trees/layer_tree_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 267
268 scrollbar_needs_animation |= 268 scrollbar_needs_animation |=
269 (clip_layer_size_did_change || scroll_layer_size_did_change); 269 (clip_layer_size_did_change || scroll_layer_size_did_change);
270 270
271 if (y_offset_did_change && IsViewportLayerId(scroll_layer_id)) 271 if (y_offset_did_change && IsViewportLayerId(scroll_layer_id))
272 TRACE_COUNTER_ID1("cc", "scroll_offset_y", scroll_layer->id(), 272 TRACE_COUNTER_ID1("cc", "scroll_offset_y", scroll_layer->id(),
273 current_offset.y()); 273 current_offset.y());
274 274
275 if (scrollbar_needs_animation) { 275 if (scrollbar_needs_animation) {
276 ScrollbarAnimationController* controller = 276 ScrollbarAnimationController* controller =
277 layer_tree_host_impl_->ScrollbarAnimationControllerForId( 277 layer_tree_host_impl_->ScrollbarAnimationControllerForElementId(
278 scroll_layer_id); 278 scroll_layer->element_id());
279 if (!controller) 279 if (!controller)
280 return; 280 return;
281 281
282 // TODO(chaopeng) clip_layer_size_did_change should call DidResize after 282 // TODO(chaopeng) clip_layer_size_did_change should call DidResize after
283 // crbug.com/701810 got fixed. 283 // crbug.com/701810 got fixed.
284 if (scroll_layer_size_did_change) { 284 if (scroll_layer_size_did_change) {
285 controller->DidResize(); 285 controller->DidResize();
286 } else { 286 } else {
287 controller->DidScrollUpdate(); 287 controller->DidScrollUpdate();
288 } 288 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 // Note: this needs to happen after SetPropertyTrees. 545 // Note: this needs to happen after SetPropertyTrees.
546 target_tree->ShowScrollbars(); 546 target_tree->ShowScrollbars();
547 } 547 }
548 548
549 void LayerTreeImpl::ShowScrollbars() { 549 void LayerTreeImpl::ShowScrollbars() {
550 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [this]( 550 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [this](
551 LayerImpl* layer) { 551 LayerImpl* layer) {
552 if (!layer->needs_show_scrollbars()) 552 if (!layer->needs_show_scrollbars())
553 return; 553 return;
554 ScrollbarAnimationController* controller = 554 ScrollbarAnimationController* controller =
555 layer_tree_host_impl_->ScrollbarAnimationControllerForId(layer->id()); 555 layer_tree_host_impl_->ScrollbarAnimationControllerForElementId(
556 layer->element_id());
556 if (controller) { 557 if (controller) {
557 controller->DidRequestShowFromMainThread(); 558 controller->DidRequestShowFromMainThread();
558 layer->set_needs_show_scrollbars(false); 559 layer->set_needs_show_scrollbars(false);
559 } 560 }
560 }); 561 });
561 } 562 }
562 563
563 void LayerTreeImpl::MoveChangeTrackingToLayers() { 564 void LayerTreeImpl::MoveChangeTrackingToLayers() {
564 // We need to update the change tracking on property trees before we move it 565 // We need to update the change tracking on property trees before we move it
565 // onto the layers. 566 // onto the layers.
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 #if DCHECK_IS_ON() 730 #if DCHECK_IS_ON()
730 int old_layer_id = old_node ? old_node->owning_layer_id : Layer::INVALID_ID; 731 int old_layer_id = old_node ? old_node->owning_layer_id : Layer::INVALID_ID;
731 int new_layer_id = node ? node->owning_layer_id : Layer::INVALID_ID; 732 int new_layer_id = node ? node->owning_layer_id : Layer::INVALID_ID;
732 DCHECK(old_layer_id == LayerIdByElementId(old_element_id)); 733 DCHECK(old_layer_id == LayerIdByElementId(old_element_id));
733 DCHECK(new_layer_id == LayerIdByElementId(new_element_id)); 734 DCHECK(new_layer_id == LayerIdByElementId(new_element_id));
734 #endif 735 #endif
735 736
736 if (old_element_id == new_element_id) 737 if (old_element_id == new_element_id)
737 return; 738 return;
738 739
739 // TODO(pdr): Make the scrollbar animation controller lookup based on
740 // element ids instead of layer ids.
741 ScrollbarAnimationController* old_animation_controller = 740 ScrollbarAnimationController* old_animation_controller =
742 layer_tree_host_impl_->ScrollbarAnimationControllerForId( 741 layer_tree_host_impl_->ScrollbarAnimationControllerForElementId(
743 LayerIdByElementId(old_element_id)); 742 old_element_id);
744 ScrollbarAnimationController* new_animation_controller = 743 ScrollbarAnimationController* new_animation_controller =
745 layer_tree_host_impl_->ScrollbarAnimationControllerForId( 744 layer_tree_host_impl_->ScrollbarAnimationControllerForElementId(
746 LayerIdByElementId(new_element_id)); 745 new_element_id);
747 746
748 if (old_animation_controller) 747 if (old_animation_controller)
749 old_animation_controller->DidScrollEnd(); 748 old_animation_controller->DidScrollEnd();
750 scroll_tree.set_currently_scrolling_node(node ? node->id 749 scroll_tree.set_currently_scrolling_node(node ? node->id
751 : ScrollTree::kInvalidNodeId); 750 : ScrollTree::kInvalidNodeId);
752 if (new_animation_controller) 751 if (new_animation_controller)
753 new_animation_controller->DidScrollBegin(); 752 new_animation_controller->DidScrollBegin();
754 } 753 }
755 754
756 void LayerTreeImpl::ClearCurrentlyScrollingNode() { 755 void LayerTreeImpl::ClearCurrentlyScrollingNode() {
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 DCHECK(it != picture_layers_.end()); 1718 DCHECK(it != picture_layers_.end());
1720 picture_layers_.erase(it); 1719 picture_layers_.erase(it);
1721 } 1720 }
1722 1721
1723 void LayerTreeImpl::RegisterScrollbar(ScrollbarLayerImplBase* scrollbar_layer) { 1722 void LayerTreeImpl::RegisterScrollbar(ScrollbarLayerImplBase* scrollbar_layer) {
1724 if (scrollbar_layer->ScrollLayerId() == Layer::INVALID_ID) 1723 if (scrollbar_layer->ScrollLayerId() == Layer::INVALID_ID)
1725 return; 1724 return;
1726 1725
1727 scrollbar_map_.insert(std::pair<int, int>(scrollbar_layer->ScrollLayerId(), 1726 scrollbar_map_.insert(std::pair<int, int>(scrollbar_layer->ScrollLayerId(),
1728 scrollbar_layer->id())); 1727 scrollbar_layer->id()));
1729 if (IsActiveTree() && scrollbar_layer->is_overlay_scrollbar()) 1728 if (IsActiveTree() && scrollbar_layer->is_overlay_scrollbar()) {
1729 auto scroll_layer_id = scrollbar_layer->ScrollLayerId();
1730 layer_tree_host_impl_->RegisterScrollbarAnimationController( 1730 layer_tree_host_impl_->RegisterScrollbarAnimationController(
1731 scrollbar_layer->ScrollLayerId()); 1731 scroll_layer_id, scrollbar_layer->scroll_element_id());
1732 }
1732 1733
1733 DidUpdateScrollState(scrollbar_layer->ScrollLayerId()); 1734 DidUpdateScrollState(scrollbar_layer->ScrollLayerId());
1734 } 1735 }
1735 1736
1736 void LayerTreeImpl::UnregisterScrollbar( 1737 void LayerTreeImpl::UnregisterScrollbar(
1737 ScrollbarLayerImplBase* scrollbar_layer) { 1738 ScrollbarLayerImplBase* scrollbar_layer) {
1738 int scroll_layer_id = scrollbar_layer->ScrollLayerId(); 1739 int scroll_layer_id = scrollbar_layer->ScrollLayerId();
1739 if (scroll_layer_id == Layer::INVALID_ID) 1740 if (scroll_layer_id == Layer::INVALID_ID)
1740 return; 1741 return;
1741 1742
1742 auto scrollbar_range = scrollbar_map_.equal_range(scroll_layer_id); 1743 auto scrollbar_range = scrollbar_map_.equal_range(scroll_layer_id);
1743 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i) 1744 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i)
1744 if (i->second == scrollbar_layer->id()) { 1745 if (i->second == scrollbar_layer->id()) {
1745 scrollbar_map_.erase(i); 1746 scrollbar_map_.erase(i);
1746 break; 1747 break;
1747 } 1748 }
1748 1749
1749 if (IsActiveTree() && scrollbar_map_.count(scroll_layer_id) == 0) 1750 if (IsActiveTree() && scrollbar_map_.count(scroll_layer_id) == 0) {
1750 layer_tree_host_impl_->UnregisterScrollbarAnimationController( 1751 layer_tree_host_impl_->UnregisterScrollbarAnimationController(
1751 scroll_layer_id); 1752 scrollbar_layer->scroll_element_id());
1753 }
1752 } 1754 }
1753 1755
1754 ScrollbarSet LayerTreeImpl::ScrollbarsFor(int scroll_layer_id) const { 1756 ScrollbarSet LayerTreeImpl::ScrollbarsFor(int scroll_layer_id) const {
1755 ScrollbarSet scrollbars; 1757 ScrollbarSet scrollbars;
1756 auto scrollbar_range = scrollbar_map_.equal_range(scroll_layer_id); 1758 auto scrollbar_range = scrollbar_map_.equal_range(scroll_layer_id);
1757 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i) 1759 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i)
1758 scrollbars.insert(LayerById(i->second)->ToScrollbarLayer()); 1760 scrollbars.insert(LayerById(i->second)->ToScrollbarLayer());
1759 return scrollbars; 1761 return scrollbars;
1760 } 1762 }
1761 1763
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
2179 2181
2180 void LayerTreeImpl::ResetAllChangeTracking() { 2182 void LayerTreeImpl::ResetAllChangeTracking() {
2181 layers_that_should_push_properties_.clear(); 2183 layers_that_should_push_properties_.clear();
2182 // Iterate over all layers, including masks. 2184 // Iterate over all layers, including masks.
2183 for (auto& layer : *layers_) 2185 for (auto& layer : *layers_)
2184 layer->ResetChangeTracking(); 2186 layer->ResetChangeTracking();
2185 property_trees_.ResetAllChangeTracking(); 2187 property_trees_.ResetAllChangeTracking();
2186 } 2188 }
2187 2189
2188 } // namespace cc 2190 } // namespace cc
OLDNEW
« cc/layers/scrollbar_layer_impl_base.cc ('K') | « cc/trees/layer_tree_host_unittest_damage.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698