OLD | NEW |
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_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 namespace cc { | 81 namespace cc { |
82 namespace { | 82 namespace { |
83 | 83 |
84 // Small helper class that saves the current viewport location as the user sees | 84 // Small helper class that saves the current viewport location as the user sees |
85 // it and resets to the same location. | 85 // it and resets to the same location. |
86 class ViewportAnchor { | 86 class ViewportAnchor { |
87 public: | 87 public: |
88 ViewportAnchor(LayerImpl* inner_scroll, LayerImpl* outer_scroll) | 88 ViewportAnchor(LayerImpl* inner_scroll, LayerImpl* outer_scroll) |
89 : inner_(inner_scroll), | 89 : inner_(inner_scroll), |
90 outer_(outer_scroll) { | 90 outer_(outer_scroll) { |
91 viewport_in_content_coordinates_ = inner_->TotalScrollOffset(); | 91 viewport_in_content_coordinates_ = inner_->CurrentScrollOffset(); |
92 | 92 |
93 if (outer_) | 93 if (outer_) |
94 viewport_in_content_coordinates_ += outer_->TotalScrollOffset(); | 94 viewport_in_content_coordinates_ += outer_->CurrentScrollOffset(); |
95 } | 95 } |
96 | 96 |
97 void ResetViewportToAnchoredPosition() { | 97 void ResetViewportToAnchoredPosition() { |
98 DCHECK(outer_); | 98 DCHECK(outer_); |
99 | 99 |
100 inner_->ClampScrollToMaxScrollOffset(); | 100 inner_->ClampScrollToMaxScrollOffset(); |
101 outer_->ClampScrollToMaxScrollOffset(); | 101 outer_->ClampScrollToMaxScrollOffset(); |
102 | 102 |
103 gfx::ScrollOffset viewport_location = inner_->TotalScrollOffset() + | 103 gfx::ScrollOffset viewport_location = |
104 outer_->TotalScrollOffset(); | 104 inner_->CurrentScrollOffset() + outer_->CurrentScrollOffset(); |
105 | 105 |
106 gfx::Vector2dF delta = | 106 gfx::Vector2dF delta = |
107 viewport_in_content_coordinates_.DeltaFrom(viewport_location); | 107 viewport_in_content_coordinates_.DeltaFrom(viewport_location); |
108 | 108 |
109 delta = outer_->ScrollBy(delta); | 109 delta = outer_->ScrollBy(delta); |
110 inner_->ScrollBy(delta); | 110 inner_->ScrollBy(delta); |
111 } | 111 } |
112 | 112 |
113 private: | 113 private: |
114 LayerImpl* inner_; | 114 LayerImpl* inner_; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 void LayerTreeHostImpl::BeginCommit() { | 293 void LayerTreeHostImpl::BeginCommit() { |
294 TRACE_EVENT0("cc", "LayerTreeHostImpl::BeginCommit"); | 294 TRACE_EVENT0("cc", "LayerTreeHostImpl::BeginCommit"); |
295 | 295 |
296 if (UsePendingTreeForSync()) | 296 if (UsePendingTreeForSync()) |
297 CreatePendingTree(); | 297 CreatePendingTree(); |
298 } | 298 } |
299 | 299 |
300 void LayerTreeHostImpl::CommitComplete() { | 300 void LayerTreeHostImpl::CommitComplete() { |
301 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); | 301 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); |
302 | 302 |
303 if (pending_tree_) | |
304 pending_tree_->ApplyScrollDeltasSinceBeginMainFrame(); | |
305 sync_tree()->set_needs_update_draw_properties(); | 303 sync_tree()->set_needs_update_draw_properties(); |
306 | 304 |
307 if (settings_.impl_side_painting) { | 305 if (settings_.impl_side_painting) { |
308 // Impl-side painting needs an update immediately post-commit to have the | 306 // Impl-side painting needs an update immediately post-commit to have the |
309 // opportunity to create tilings. Other paths can call UpdateDrawProperties | 307 // opportunity to create tilings. Other paths can call UpdateDrawProperties |
310 // more lazily when needed prior to drawing. | 308 // more lazily when needed prior to drawing. |
311 sync_tree()->UpdateDrawProperties(); | 309 sync_tree()->UpdateDrawProperties(); |
312 // Start working on newly created tiles immediately if needed. | 310 // Start working on newly created tiles immediately if needed. |
313 if (tile_manager_ && tile_priorities_dirty_) | 311 if (tile_manager_ && tile_priorities_dirty_) |
314 PrepareTiles(); | 312 PrepareTiles(); |
(...skipping 2127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2442 // behavior as ScrollBy to determine which layer to animate, but we do not | 2440 // behavior as ScrollBy to determine which layer to animate, but we do not |
2443 // do the Android-specific things in ScrollBy like showing top controls. | 2441 // do the Android-specific things in ScrollBy like showing top controls. |
2444 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); | 2442 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); |
2445 if (scroll_status == ScrollStarted) { | 2443 if (scroll_status == ScrollStarted) { |
2446 gfx::Vector2dF pending_delta = scroll_delta; | 2444 gfx::Vector2dF pending_delta = scroll_delta; |
2447 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; | 2445 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; |
2448 layer_impl = layer_impl->parent()) { | 2446 layer_impl = layer_impl->parent()) { |
2449 if (!layer_impl->scrollable()) | 2447 if (!layer_impl->scrollable()) |
2450 continue; | 2448 continue; |
2451 | 2449 |
2452 gfx::ScrollOffset current_offset = layer_impl->TotalScrollOffset(); | 2450 gfx::ScrollOffset current_offset = layer_impl->CurrentScrollOffset(); |
2453 gfx::ScrollOffset target_offset = | 2451 gfx::ScrollOffset target_offset = |
2454 ScrollOffsetWithDelta(current_offset, pending_delta); | 2452 ScrollOffsetWithDelta(current_offset, pending_delta); |
2455 target_offset.SetToMax(gfx::ScrollOffset()); | 2453 target_offset.SetToMax(gfx::ScrollOffset()); |
2456 target_offset.SetToMin(layer_impl->MaxScrollOffset()); | 2454 target_offset.SetToMin(layer_impl->MaxScrollOffset()); |
2457 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); | 2455 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); |
2458 | 2456 |
2459 const float kEpsilon = 0.1f; | 2457 const float kEpsilon = 0.1f; |
2460 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || | 2458 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || |
2461 std::abs(actual_delta.y()) > kEpsilon); | 2459 std::abs(actual_delta.y()) > kEpsilon); |
2462 | 2460 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2532 return gfx::Vector2dF(); | 2530 return gfx::Vector2dF(); |
2533 | 2531 |
2534 // local_start_point and local_end_point are in content space but we want to | 2532 // local_start_point and local_end_point are in content space but we want to |
2535 // move them to layer space for scrolling. | 2533 // move them to layer space for scrolling. |
2536 float width_scale = 1.f / layer_impl->contents_scale_x(); | 2534 float width_scale = 1.f / layer_impl->contents_scale_x(); |
2537 float height_scale = 1.f / layer_impl->contents_scale_y(); | 2535 float height_scale = 1.f / layer_impl->contents_scale_y(); |
2538 local_start_point.Scale(width_scale, height_scale); | 2536 local_start_point.Scale(width_scale, height_scale); |
2539 local_end_point.Scale(width_scale, height_scale); | 2537 local_end_point.Scale(width_scale, height_scale); |
2540 | 2538 |
2541 // Apply the scroll delta. | 2539 // Apply the scroll delta. |
2542 gfx::Vector2dF previous_delta = layer_impl->ScrollDelta(); | 2540 gfx::ScrollOffset previous_offset = layer_impl->CurrentScrollOffset(); |
2543 layer_impl->ScrollBy(local_end_point - local_start_point); | 2541 layer_impl->ScrollBy(local_end_point - local_start_point); |
| 2542 gfx::ScrollOffset scrolled = |
| 2543 layer_impl->CurrentScrollOffset() - previous_offset; |
2544 | 2544 |
2545 // Get the end point in the layer's content space so we can apply its | 2545 // Get the end point in the layer's content space so we can apply its |
2546 // ScreenSpaceTransform. | 2546 // ScreenSpaceTransform. |
2547 gfx::PointF actual_local_end_point = local_start_point + | 2547 gfx::PointF actual_local_end_point = |
2548 layer_impl->ScrollDelta() - | 2548 local_start_point + gfx::Vector2dF(scrolled.x(), scrolled.y()); |
2549 previous_delta; | |
2550 gfx::PointF actual_local_content_end_point = | 2549 gfx::PointF actual_local_content_end_point = |
2551 gfx::ScalePoint(actual_local_end_point, | 2550 gfx::ScalePoint(actual_local_end_point, |
2552 1.f / width_scale, | 2551 1.f / width_scale, |
2553 1.f / height_scale); | 2552 1.f / height_scale); |
2554 | 2553 |
2555 // Calculate the applied scroll delta in viewport space coordinates. | 2554 // Calculate the applied scroll delta in viewport space coordinates. |
2556 gfx::PointF actual_screen_space_end_point = | 2555 gfx::PointF actual_screen_space_end_point = |
2557 MathUtil::MapPoint(layer_impl->screen_space_transform(), | 2556 MathUtil::MapPoint(layer_impl->screen_space_transform(), |
2558 actual_local_content_end_point, | 2557 actual_local_content_end_point, |
2559 &end_clipped); | 2558 &end_clipped); |
2560 DCHECK(!end_clipped); | 2559 DCHECK(!end_clipped); |
2561 if (end_clipped) | 2560 if (end_clipped) |
2562 return gfx::Vector2dF(); | 2561 return gfx::Vector2dF(); |
2563 gfx::PointF actual_viewport_end_point = | 2562 gfx::PointF actual_viewport_end_point = |
2564 gfx::ScalePoint(actual_screen_space_end_point, | 2563 gfx::ScalePoint(actual_screen_space_end_point, |
2565 1.f / scale_from_viewport_to_screen_space); | 2564 1.f / scale_from_viewport_to_screen_space); |
2566 return actual_viewport_end_point - viewport_point; | 2565 return actual_viewport_end_point - viewport_point; |
2567 } | 2566 } |
2568 | 2567 |
2569 static gfx::Vector2dF ScrollLayerWithLocalDelta( | 2568 static gfx::Vector2dF ScrollLayerWithLocalDelta( |
2570 LayerImpl* layer_impl, | 2569 LayerImpl* layer_impl, |
2571 const gfx::Vector2dF& local_delta, | 2570 const gfx::Vector2dF& local_delta, |
2572 float page_scale_factor) { | 2571 float page_scale_factor) { |
2573 gfx::Vector2dF previous_delta(layer_impl->ScrollDelta()); | 2572 gfx::ScrollOffset previous_offset = layer_impl->CurrentScrollOffset(); |
2574 gfx::Vector2dF delta = local_delta; | 2573 gfx::Vector2dF delta = local_delta; |
2575 delta.Scale(1.f / page_scale_factor); | 2574 delta.Scale(1.f / page_scale_factor); |
2576 layer_impl->ScrollBy(delta); | 2575 layer_impl->ScrollBy(delta); |
2577 return layer_impl->ScrollDelta() - previous_delta; | 2576 gfx::ScrollOffset scrolled = |
| 2577 layer_impl->CurrentScrollOffset() - previous_offset; |
| 2578 return gfx::Vector2dF(scrolled.x(), scrolled.y()); |
2578 } | 2579 } |
2579 | 2580 |
2580 bool LayerTreeHostImpl::ShouldTopControlsConsumeScroll( | 2581 bool LayerTreeHostImpl::ShouldTopControlsConsumeScroll( |
2581 const gfx::Vector2dF& scroll_delta) const { | 2582 const gfx::Vector2dF& scroll_delta) const { |
2582 DCHECK(CurrentlyScrollingLayer()); | 2583 DCHECK(CurrentlyScrollingLayer()); |
2583 | 2584 |
2584 if (!top_controls_manager_) | 2585 if (!top_controls_manager_) |
2585 return false; | 2586 return false; |
2586 | 2587 |
2587 // Always consume if it's in the direction to show the top controls. | 2588 // Always consume if it's in the direction to show the top controls. |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3017 // scales that we want when we're not inside a pinch. | 3018 // scales that we want when we're not inside a pinch. |
3018 active_tree_->set_needs_update_draw_properties(); | 3019 active_tree_->set_needs_update_draw_properties(); |
3019 SetNeedsRedraw(); | 3020 SetNeedsRedraw(); |
3020 } | 3021 } |
3021 | 3022 |
3022 static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, | 3023 static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, |
3023 LayerImpl* layer_impl) { | 3024 LayerImpl* layer_impl) { |
3024 if (!layer_impl) | 3025 if (!layer_impl) |
3025 return; | 3026 return; |
3026 | 3027 |
3027 gfx::Vector2d scroll_delta = | 3028 layer_impl->RefreshScrollDelegate(); |
3028 gfx::ToFlooredVector2d(layer_impl->ScrollDelta()); | 3029 gfx::ScrollOffset scroll_delta = |
| 3030 layer_impl->scroll_offset()->PullDeltaForMainThread(); |
| 3031 |
3029 if (!scroll_delta.IsZero()) { | 3032 if (!scroll_delta.IsZero()) { |
3030 LayerTreeHostCommon::ScrollUpdateInfo scroll; | 3033 LayerTreeHostCommon::ScrollUpdateInfo scroll; |
3031 scroll.layer_id = layer_impl->id(); | 3034 scroll.layer_id = layer_impl->id(); |
3032 scroll.scroll_delta = scroll_delta; | 3035 scroll.scroll_delta = gfx::Vector2d(scroll_delta.x(), scroll_delta.y()); |
3033 scroll_info->scrolls.push_back(scroll); | 3036 scroll_info->scrolls.push_back(scroll); |
3034 layer_impl->SetSentScrollDelta(scroll_delta); | |
3035 } | 3037 } |
3036 | 3038 |
3037 for (size_t i = 0; i < layer_impl->children().size(); ++i) | 3039 for (size_t i = 0; i < layer_impl->children().size(); ++i) |
3038 CollectScrollDeltas(scroll_info, layer_impl->children()[i]); | 3040 CollectScrollDeltas(scroll_info, layer_impl->children()[i]); |
3039 } | 3041 } |
3040 | 3042 |
3041 scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() { | 3043 scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() { |
3042 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); | 3044 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); |
3043 | 3045 |
3044 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); | 3046 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3501 } | 3503 } |
3502 | 3504 |
3503 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3505 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
3504 std::vector<PictureLayerImpl*>::iterator it = | 3506 std::vector<PictureLayerImpl*>::iterator it = |
3505 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3507 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
3506 DCHECK(it != picture_layers_.end()); | 3508 DCHECK(it != picture_layers_.end()); |
3507 picture_layers_.erase(it); | 3509 picture_layers_.erase(it); |
3508 } | 3510 } |
3509 | 3511 |
3510 } // namespace cc | 3512 } // namespace cc |
OLD | NEW |