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

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: Fix flaky LayerTreeHostImplTestScrollbarOpacity.Android 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_->ScrollbarAnimationControllerForId(
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_->ScrollbarAnimationControllerForId(
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_->ScrollbarAnimationControllerForId(old_element_id);
wkorman 2017/04/14 18:17:30 Future change -- suggest renaming this method to q
pdr. 2017/04/15 06:02:00 +1, going to include that in this change since we
743 LayerIdByElementId(old_element_id));
744 ScrollbarAnimationController* new_animation_controller = 742 ScrollbarAnimationController* new_animation_controller =
745 layer_tree_host_impl_->ScrollbarAnimationControllerForId( 743 layer_tree_host_impl_->ScrollbarAnimationControllerForId(new_element_id);
746 LayerIdByElementId(new_element_id));
747 744
748 if (old_animation_controller) 745 if (old_animation_controller)
749 old_animation_controller->DidScrollEnd(); 746 old_animation_controller->DidScrollEnd();
750 scroll_tree.set_currently_scrolling_node(node ? node->id 747 scroll_tree.set_currently_scrolling_node(node ? node->id
751 : ScrollTree::kInvalidNodeId); 748 : ScrollTree::kInvalidNodeId);
752 if (new_animation_controller) 749 if (new_animation_controller)
753 new_animation_controller->DidScrollBegin(); 750 new_animation_controller->DidScrollBegin();
754 } 751 }
755 752
756 void LayerTreeImpl::ClearCurrentlyScrollingNode() { 753 void LayerTreeImpl::ClearCurrentlyScrollingNode() {
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 DCHECK(it != picture_layers_.end()); 1717 DCHECK(it != picture_layers_.end());
1721 picture_layers_.erase(it); 1718 picture_layers_.erase(it);
1722 } 1719 }
1723 1720
1724 void LayerTreeImpl::RegisterScrollbar(ScrollbarLayerImplBase* scrollbar_layer) { 1721 void LayerTreeImpl::RegisterScrollbar(ScrollbarLayerImplBase* scrollbar_layer) {
1725 if (scrollbar_layer->ScrollLayerId() == Layer::INVALID_ID) 1722 if (scrollbar_layer->ScrollLayerId() == Layer::INVALID_ID)
1726 return; 1723 return;
1727 1724
1728 scrollbar_map_.insert(std::pair<int, int>(scrollbar_layer->ScrollLayerId(), 1725 scrollbar_map_.insert(std::pair<int, int>(scrollbar_layer->ScrollLayerId(),
1729 scrollbar_layer->id())); 1726 scrollbar_layer->id()));
1730 if (IsActiveTree() && scrollbar_layer->is_overlay_scrollbar()) 1727 if (IsActiveTree() && scrollbar_layer->is_overlay_scrollbar()) {
1728 auto scroll_layer_id = scrollbar_layer->ScrollLayerId();
1731 layer_tree_host_impl_->RegisterScrollbarAnimationController( 1729 layer_tree_host_impl_->RegisterScrollbarAnimationController(
1732 scrollbar_layer->ScrollLayerId()); 1730 scroll_layer_id, scrollbar_layer->ScrollElementId());
1731 }
1733 1732
1734 DidUpdateScrollState(scrollbar_layer->ScrollLayerId()); 1733 DidUpdateScrollState(scrollbar_layer->ScrollLayerId());
1735 } 1734 }
1736 1735
1737 void LayerTreeImpl::UnregisterScrollbar( 1736 void LayerTreeImpl::UnregisterScrollbar(
1738 ScrollbarLayerImplBase* scrollbar_layer) { 1737 ScrollbarLayerImplBase* scrollbar_layer) {
1739 int scroll_layer_id = scrollbar_layer->ScrollLayerId(); 1738 int scroll_layer_id = scrollbar_layer->ScrollLayerId();
1740 if (scroll_layer_id == Layer::INVALID_ID) 1739 if (scroll_layer_id == Layer::INVALID_ID)
1741 return; 1740 return;
1742 1741
1743 auto scrollbar_range = scrollbar_map_.equal_range(scroll_layer_id); 1742 auto scrollbar_range = scrollbar_map_.equal_range(scroll_layer_id);
1744 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i) 1743 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i)
1745 if (i->second == scrollbar_layer->id()) { 1744 if (i->second == scrollbar_layer->id()) {
1746 scrollbar_map_.erase(i); 1745 scrollbar_map_.erase(i);
1747 break; 1746 break;
1748 } 1747 }
1749 1748
1750 if (IsActiveTree() && scrollbar_map_.count(scroll_layer_id) == 0) 1749 if (IsActiveTree() && scrollbar_map_.count(scroll_layer_id) == 0) {
1751 layer_tree_host_impl_->UnregisterScrollbarAnimationController( 1750 layer_tree_host_impl_->UnregisterScrollbarAnimationController(
1752 scroll_layer_id); 1751 scrollbar_layer->ScrollElementId());
1752 }
1753 } 1753 }
1754 1754
1755 ScrollbarSet LayerTreeImpl::ScrollbarsFor(int scroll_layer_id) const { 1755 ScrollbarSet LayerTreeImpl::ScrollbarsFor(int scroll_layer_id) const {
1756 ScrollbarSet scrollbars; 1756 ScrollbarSet scrollbars;
1757 auto scrollbar_range = scrollbar_map_.equal_range(scroll_layer_id); 1757 auto scrollbar_range = scrollbar_map_.equal_range(scroll_layer_id);
1758 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i) 1758 for (auto i = scrollbar_range.first; i != scrollbar_range.second; ++i)
1759 scrollbars.insert(LayerById(i->second)->ToScrollbarLayer()); 1759 scrollbars.insert(LayerById(i->second)->ToScrollbarLayer());
1760 return scrollbars; 1760 return scrollbars;
1761 } 1761 }
1762 1762
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 2180
2181 void LayerTreeImpl::ResetAllChangeTracking() { 2181 void LayerTreeImpl::ResetAllChangeTracking() {
2182 layers_that_should_push_properties_.clear(); 2182 layers_that_should_push_properties_.clear();
2183 // Iterate over all layers, including masks. 2183 // Iterate over all layers, including masks.
2184 for (auto& layer : *layers_) 2184 for (auto& layer : *layers_)
2185 layer->ResetChangeTracking(); 2185 layer->ResetChangeTracking();
2186 property_trees_.ResetAllChangeTracking(); 2186 property_trees_.ResetAllChangeTracking();
2187 } 2187 }
2188 2188
2189 } // namespace cc 2189 } // namespace cc
OLDNEW
« cc/layers/scrollbar_layer_interface.h ('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