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

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

Issue 2189583004: [not for review - epic CL] Adding Elastic+Momentum+Layered scrolling to views::ScrollView Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Combined rebase Created 4 years, 4 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>
11 #include <limits> 11 #include <limits>
12 #include <set> 12 #include <set>
13 13
14 #include "base/containers/adapters.h" 14 #include "base/containers/adapters.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/timer/elapsed_timer.h" 16 #include "base/timer/elapsed_timer.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 #include "base/trace_event/trace_event_argument.h" 18 #include "base/trace_event/trace_event_argument.h"
19 #include "cc/animation/animation_host.h" 19 #include "cc/animation/animation_host.h"
20 #include "cc/base/histograms.h" 20 #include "cc/base/histograms.h"
21 #include "cc/base/math_util.h" 21 #include "cc/base/math_util.h"
22 #include "cc/base/synced_property.h" 22 #include "cc/base/synced_property.h"
23 #include "cc/debug/devtools_instrumentation.h" 23 #include "cc/debug/devtools_instrumentation.h"
24 #include "cc/debug/traced_value.h" 24 #include "cc/debug/traced_value.h"
25 #include "cc/input/page_scale_animation.h" 25 #include "cc/input/page_scale_animation.h"
26 #include "cc/input/scroll_elasticity_helper.h"
26 #include "cc/input/scrollbar_animation_controller.h" 27 #include "cc/input/scrollbar_animation_controller.h"
27 #include "cc/input/scrollbar_animation_controller_linear_fade.h" 28 #include "cc/input/scrollbar_animation_controller_linear_fade.h"
28 #include "cc/input/scrollbar_animation_controller_thinning.h" 29 #include "cc/input/scrollbar_animation_controller_thinning.h"
29 #include "cc/layers/heads_up_display_layer_impl.h" 30 #include "cc/layers/heads_up_display_layer_impl.h"
30 #include "cc/layers/layer.h" 31 #include "cc/layers/layer.h"
31 #include "cc/layers/layer_iterator.h" 32 #include "cc/layers/layer_iterator.h"
32 #include "cc/layers/layer_list_iterator.h" 33 #include "cc/layers/layer_list_iterator.h"
33 #include "cc/layers/render_surface_impl.h" 34 #include "cc/layers/render_surface_impl.h"
34 #include "cc/layers/scrollbar_layer_impl_base.h" 35 #include "cc/layers/scrollbar_layer_impl_base.h"
35 #include "cc/resources/ui_resource_request.h" 36 #include "cc/resources/ui_resource_request.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // trees, use the transform_id parameter instead of looking for indices from 147 // trees, use the transform_id parameter instead of looking for indices from
147 // LayerImpls. 148 // LayerImpls.
148 void LayerTreeImpl::DidUpdateScrollOffset(int layer_id, int transform_id) { 149 void LayerTreeImpl::DidUpdateScrollOffset(int layer_id, int transform_id) {
149 DidUpdateScrollState(layer_id); 150 DidUpdateScrollState(layer_id);
150 TransformTree& transform_tree = property_trees()->transform_tree; 151 TransformTree& transform_tree = property_trees()->transform_tree;
151 ScrollTree& scroll_tree = property_trees()->scroll_tree; 152 ScrollTree& scroll_tree = property_trees()->scroll_tree;
152 153
153 // If pending tree topology changed and we still want to notify the pending 154 // If pending tree topology changed and we still want to notify the pending
154 // tree about scroll offset in the active tree, we may not find the 155 // tree about scroll offset in the active tree, we may not find the
155 // corresponding pending layer. 156 // corresponding pending layer.
156 if (LayerById(layer_id)) { 157 if (LayerImpl* layer = LayerById(layer_id)) {
157 transform_id = LayerById(layer_id)->transform_tree_index(); 158 transform_id = layer->transform_tree_index();
158 } else { 159 } else {
159 DCHECK(!IsActiveTree()); 160 DCHECK(!IsActiveTree());
160 return; 161 return;
161 } 162 }
162 163
163 if (transform_id != -1) { 164 if (transform_id != -1) {
164 TransformNode* node = transform_tree.Node(transform_id); 165 TransformNode* node = transform_tree.Node(transform_id);
165 if (node->scroll_offset != scroll_tree.current_scroll_offset(layer_id)) { 166 gfx::ScrollOffset scroll_offset_with_overscroll =
166 node->scroll_offset = scroll_tree.current_scroll_offset(layer_id); 167 scroll_tree.current_scroll_offset(layer_id) +
168 scroll_tree.current_overscroll(layer_id);
169 if (node->scroll_offset_with_overscroll != scroll_offset_with_overscroll) {
170 node->scroll_offset_with_overscroll = scroll_offset_with_overscroll;
167 node->needs_local_transform_update = true; 171 node->needs_local_transform_update = true;
168 transform_tree.set_needs_update(true); 172 transform_tree.set_needs_update(true);
169 } 173 }
170 node->transform_changed = true; 174 node->transform_changed = true;
171 property_trees()->changed = true; 175 property_trees()->changed = true;
172 set_needs_update_draw_properties(); 176 set_needs_update_draw_properties();
173 } 177 }
174 178
175 if (IsActiveTree() && layer_tree_host_impl_->pending_tree()) 179 if (IsActiveTree() && layer_tree_host_impl_->pending_tree())
176 layer_tree_host_impl_->pending_tree()->DidUpdateScrollOffset(layer_id, 180 layer_tree_host_impl_->pending_tree()->DidUpdateScrollOffset(layer_id,
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 int new_id = layer ? layer->id() : Layer::INVALID_ID; 592 int new_id = layer ? layer->id() : Layer::INVALID_ID;
589 int new_scroll_node_id = layer ? layer->scroll_tree_index() : -1; 593 int new_scroll_node_id = layer ? layer->scroll_tree_index() : -1;
590 if (layer) 594 if (layer)
591 last_scrolled_layer_id_ = new_id; 595 last_scrolled_layer_id_ = new_id;
592 596
593 if (old_id == new_id) 597 if (old_id == new_id)
594 return; 598 return;
595 599
596 ScrollbarAnimationController* old_animation_controller = 600 ScrollbarAnimationController* old_animation_controller =
597 layer_tree_host_impl_->ScrollbarAnimationControllerForId(old_id); 601 layer_tree_host_impl_->ScrollbarAnimationControllerForId(old_id);
602 ScrollElasticityHelper* old_elasticity_helper =
603 layer_tree_host_impl_->ScrollElasticityHelperForId(old_id);
598 ScrollbarAnimationController* new_animation_controller = 604 ScrollbarAnimationController* new_animation_controller =
599 layer_tree_host_impl_->ScrollbarAnimationControllerForId(new_id); 605 layer_tree_host_impl_->ScrollbarAnimationControllerForId(new_id);
606 ScrollElasticityHelper* new_elasticity_helper =
607 layer_tree_host_impl_->ScrollElasticityHelperForId(new_id);
608 if (old_elasticity_helper == new_elasticity_helper)
609 old_elasticity_helper = new_elasticity_helper = nullptr;
600 610
601 if (old_animation_controller) 611 if (old_animation_controller)
602 old_animation_controller->DidScrollEnd(); 612 old_animation_controller->DidScrollEnd();
613
603 scroll_tree.set_currently_scrolling_node(new_scroll_node_id); 614 scroll_tree.set_currently_scrolling_node(new_scroll_node_id);
615
604 if (new_animation_controller) 616 if (new_animation_controller)
605 new_animation_controller->DidScrollBegin(); 617 new_animation_controller->DidScrollBegin();
606 } 618 }
607 619
608 void LayerTreeImpl::ClearCurrentlyScrollingLayer() { 620 void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
609 SetCurrentlyScrollingLayer(NULL); 621 SetCurrentlyScrollingLayer(NULL);
610 } 622 }
611 623
612 float LayerTreeImpl::ClampPageScaleFactorToLimits( 624 float LayerTreeImpl::ClampPageScaleFactorToLimits(
613 float page_scale_factor) const { 625 float page_scale_factor) const {
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 scroll_layer_id, layer_tree_host_impl_, delay, resize_delay, 1377 scroll_layer_id, layer_tree_host_impl_, delay, resize_delay,
1366 duration); 1378 duration);
1367 } 1379 }
1368 case LayerTreeSettings::NO_ANIMATOR: 1380 case LayerTreeSettings::NO_ANIMATOR:
1369 NOTREACHED(); 1381 NOTREACHED();
1370 break; 1382 break;
1371 } 1383 }
1372 return nullptr; 1384 return nullptr;
1373 } 1385 }
1374 1386
1387 std::unique_ptr<ScrollElasticityHelper>
1388 LayerTreeImpl::CreateScrollElasticityHelper(int scroll_layer_id) {
1389 DCHECK(settings().enable_elastic_overscroll);
1390 return ScrollElasticityHelper::CreateForLayer(scroll_layer_id,
1391 layer_tree_host_impl_);
1392 }
1393
1375 void LayerTreeImpl::DidAnimateScrollOffset() { 1394 void LayerTreeImpl::DidAnimateScrollOffset() {
1376 layer_tree_host_impl_->DidAnimateScrollOffset(); 1395 layer_tree_host_impl_->DidAnimateScrollOffset();
1377 } 1396 }
1378 1397
1379 bool LayerTreeImpl::use_gpu_rasterization() const { 1398 bool LayerTreeImpl::use_gpu_rasterization() const {
1380 return layer_tree_host_impl_->use_gpu_rasterization(); 1399 return layer_tree_host_impl_->use_gpu_rasterization();
1381 } 1400 }
1382 1401
1383 GpuRasterizationStatus LayerTreeImpl::GetGpuRasterizationStatus() const { 1402 GpuRasterizationStatus LayerTreeImpl::GetGpuRasterizationStatus() const {
1384 return layer_tree_host_impl_->gpu_rasterization_status(); 1403 return layer_tree_host_impl_->gpu_rasterization_status();
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 return scrollbars; 1618 return scrollbars;
1600 } 1619 }
1601 1620
1602 void LayerTreeImpl::RegisterScrollLayer(LayerImpl* layer) { 1621 void LayerTreeImpl::RegisterScrollLayer(LayerImpl* layer) {
1603 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) 1622 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID)
1604 return; 1623 return;
1605 1624
1606 clip_scroll_map_.insert( 1625 clip_scroll_map_.insert(
1607 std::pair<int, int>(layer->scroll_clip_layer_id(), layer->id())); 1626 std::pair<int, int>(layer->scroll_clip_layer_id(), layer->id()));
1608 1627
1628 bool can_overscroll = layer->can_overscroll();
1629 if (can_overscroll && settings().enable_elastic_overscroll &&
1630 (layer->user_scrollable_horizontal() ||
1631 layer->user_scrollable_vertical())) {
1632 layer_tree_host_impl_->RegisterScrollElasticityHelper(layer->id());
1633 }
1634
1609 DidUpdateScrollState(layer->id()); 1635 DidUpdateScrollState(layer->id());
1610 } 1636 }
1611 1637
1612 void LayerTreeImpl::UnregisterScrollLayer(LayerImpl* layer) { 1638 void LayerTreeImpl::UnregisterScrollLayer(LayerImpl* layer) {
1613 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) 1639 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID)
1614 return; 1640 return;
1615 1641
1642 layer_tree_host_impl_->UnregisterScrollElasticityHelper(layer->id());
1616 clip_scroll_map_.erase(layer->scroll_clip_layer_id()); 1643 clip_scroll_map_.erase(layer->scroll_clip_layer_id());
1617 } 1644 }
1618 1645
1619 void LayerTreeImpl::AddSurfaceLayer(LayerImpl* layer) { 1646 void LayerTreeImpl::AddSurfaceLayer(LayerImpl* layer) {
1620 DCHECK(std::find(surface_layers_.begin(), surface_layers_.end(), layer) == 1647 DCHECK(std::find(surface_layers_.begin(), surface_layers_.end(), layer) ==
1621 surface_layers_.end()); 1648 surface_layers_.end());
1622 surface_layers_.push_back(layer); 1649 surface_layers_.push_back(layer);
1623 } 1650 }
1624 1651
1625 void LayerTreeImpl::RemoveSurfaceLayer(LayerImpl* layer) { 1652 void LayerTreeImpl::RemoveSurfaceLayer(LayerImpl* layer) {
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 2060
2034 void LayerTreeImpl::ResetAllChangeTracking() { 2061 void LayerTreeImpl::ResetAllChangeTracking() {
2035 layers_that_should_push_properties_.clear(); 2062 layers_that_should_push_properties_.clear();
2036 // Iterate over all layers, including masks and replicas. 2063 // Iterate over all layers, including masks and replicas.
2037 for (auto& layer : *layers_) 2064 for (auto& layer : *layers_)
2038 layer->ResetChangeTracking(); 2065 layer->ResetChangeTracking();
2039 property_trees_.ResetAllChangeTracking(); 2066 property_trees_.ResetAllChangeTracking();
2040 } 2067 }
2041 2068
2042 } // namespace cc 2069 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698