| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 if (!settings_.impl_side_painting && output_surface_) | 298 if (!settings_.impl_side_painting && output_surface_) |
| 299 output_surface_->ForceReclaimResources(); | 299 output_surface_->ForceReclaimResources(); |
| 300 | 300 |
| 301 if (UsePendingTreeForSync()) | 301 if (UsePendingTreeForSync()) |
| 302 CreatePendingTree(); | 302 CreatePendingTree(); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void LayerTreeHostImpl::CommitComplete() { | 305 void LayerTreeHostImpl::CommitComplete() { |
| 306 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); | 306 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); |
| 307 | 307 |
| 308 if (pending_tree_) | |
| 309 pending_tree_->ApplyScrollDeltasSinceBeginMainFrame(); | |
| 310 sync_tree()->set_needs_update_draw_properties(); | 308 sync_tree()->set_needs_update_draw_properties(); |
| 311 | 309 |
| 312 if (settings_.impl_side_painting) { | 310 if (settings_.impl_side_painting) { |
| 313 // Impl-side painting needs an update immediately post-commit to have the | 311 // Impl-side painting needs an update immediately post-commit to have the |
| 314 // opportunity to create tilings. Other paths can call UpdateDrawProperties | 312 // opportunity to create tilings. Other paths can call UpdateDrawProperties |
| 315 // more lazily when needed prior to drawing. | 313 // more lazily when needed prior to drawing. |
| 316 sync_tree()->UpdateDrawProperties(); | 314 sync_tree()->UpdateDrawProperties(); |
| 317 // Start working on newly created tiles immediately if needed. | 315 // Start working on newly created tiles immediately if needed. |
| 318 if (tile_manager_ && tile_priorities_dirty_) | 316 if (tile_manager_ && tile_priorities_dirty_) |
| 319 PrepareTiles(); | 317 PrepareTiles(); |
| (...skipping 2079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2399 // behavior as ScrollBy to determine which layer to animate, but we do not | 2397 // behavior as ScrollBy to determine which layer to animate, but we do not |
| 2400 // do the Android-specific things in ScrollBy like showing top controls. | 2398 // do the Android-specific things in ScrollBy like showing top controls. |
| 2401 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); | 2399 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); |
| 2402 if (scroll_status == ScrollStarted) { | 2400 if (scroll_status == ScrollStarted) { |
| 2403 gfx::Vector2dF pending_delta = scroll_delta; | 2401 gfx::Vector2dF pending_delta = scroll_delta; |
| 2404 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; | 2402 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; |
| 2405 layer_impl = layer_impl->parent()) { | 2403 layer_impl = layer_impl->parent()) { |
| 2406 if (!layer_impl->scrollable()) | 2404 if (!layer_impl->scrollable()) |
| 2407 continue; | 2405 continue; |
| 2408 | 2406 |
| 2409 gfx::ScrollOffset current_offset = layer_impl->TotalScrollOffset(); | 2407 gfx::ScrollOffset current_offset = layer_impl->CurrentScrollOffset(); |
| 2410 gfx::ScrollOffset target_offset = | 2408 gfx::ScrollOffset target_offset = |
| 2411 ScrollOffsetWithDelta(current_offset, pending_delta); | 2409 ScrollOffsetWithDelta(current_offset, pending_delta); |
| 2412 target_offset.SetToMax(gfx::ScrollOffset()); | 2410 target_offset.SetToMax(gfx::ScrollOffset()); |
| 2413 target_offset.SetToMin(layer_impl->MaxScrollOffset()); | 2411 target_offset.SetToMin(layer_impl->MaxScrollOffset()); |
| 2414 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); | 2412 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); |
| 2415 | 2413 |
| 2416 const float kEpsilon = 0.1f; | 2414 const float kEpsilon = 0.1f; |
| 2417 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || | 2415 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon || |
| 2418 std::abs(actual_delta.y()) > kEpsilon); | 2416 std::abs(actual_delta.y()) > kEpsilon); |
| 2419 | 2417 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2489 return gfx::Vector2dF(); | 2487 return gfx::Vector2dF(); |
| 2490 | 2488 |
| 2491 // local_start_point and local_end_point are in content space but we want to | 2489 // local_start_point and local_end_point are in content space but we want to |
| 2492 // move them to layer space for scrolling. | 2490 // move them to layer space for scrolling. |
| 2493 float width_scale = 1.f / layer_impl->contents_scale_x(); | 2491 float width_scale = 1.f / layer_impl->contents_scale_x(); |
| 2494 float height_scale = 1.f / layer_impl->contents_scale_y(); | 2492 float height_scale = 1.f / layer_impl->contents_scale_y(); |
| 2495 local_start_point.Scale(width_scale, height_scale); | 2493 local_start_point.Scale(width_scale, height_scale); |
| 2496 local_end_point.Scale(width_scale, height_scale); | 2494 local_end_point.Scale(width_scale, height_scale); |
| 2497 | 2495 |
| 2498 // Apply the scroll delta. | 2496 // Apply the scroll delta. |
| 2499 gfx::Vector2dF previous_delta = layer_impl->ScrollDelta(); | 2497 gfx::ScrollOffset previous_offset = layer_impl->CurrentScrollOffset(); |
| 2500 layer_impl->ScrollBy(local_end_point - local_start_point); | 2498 layer_impl->ScrollBy(local_end_point - local_start_point); |
| 2499 gfx::ScrollOffset scrolled = |
| 2500 layer_impl->CurrentScrollOffset() - previous_offset; |
| 2501 | 2501 |
| 2502 // Get the end point in the layer's content space so we can apply its | 2502 // Get the end point in the layer's content space so we can apply its |
| 2503 // ScreenSpaceTransform. | 2503 // ScreenSpaceTransform. |
| 2504 gfx::PointF actual_local_end_point = local_start_point + | 2504 gfx::PointF actual_local_end_point = |
| 2505 layer_impl->ScrollDelta() - | 2505 local_start_point + gfx::Vector2dF(scrolled.x(), scrolled.y()); |
| 2506 previous_delta; | |
| 2507 gfx::PointF actual_local_content_end_point = | 2506 gfx::PointF actual_local_content_end_point = |
| 2508 gfx::ScalePoint(actual_local_end_point, | 2507 gfx::ScalePoint(actual_local_end_point, |
| 2509 1.f / width_scale, | 2508 1.f / width_scale, |
| 2510 1.f / height_scale); | 2509 1.f / height_scale); |
| 2511 | 2510 |
| 2512 // Calculate the applied scroll delta in viewport space coordinates. | 2511 // Calculate the applied scroll delta in viewport space coordinates. |
| 2513 gfx::PointF actual_screen_space_end_point = | 2512 gfx::PointF actual_screen_space_end_point = |
| 2514 MathUtil::MapPoint(layer_impl->screen_space_transform(), | 2513 MathUtil::MapPoint(layer_impl->screen_space_transform(), |
| 2515 actual_local_content_end_point, | 2514 actual_local_content_end_point, |
| 2516 &end_clipped); | 2515 &end_clipped); |
| 2517 DCHECK(!end_clipped); | 2516 DCHECK(!end_clipped); |
| 2518 if (end_clipped) | 2517 if (end_clipped) |
| 2519 return gfx::Vector2dF(); | 2518 return gfx::Vector2dF(); |
| 2520 gfx::PointF actual_viewport_end_point = | 2519 gfx::PointF actual_viewport_end_point = |
| 2521 gfx::ScalePoint(actual_screen_space_end_point, | 2520 gfx::ScalePoint(actual_screen_space_end_point, |
| 2522 1.f / scale_from_viewport_to_screen_space); | 2521 1.f / scale_from_viewport_to_screen_space); |
| 2523 return actual_viewport_end_point - viewport_point; | 2522 return actual_viewport_end_point - viewport_point; |
| 2524 } | 2523 } |
| 2525 | 2524 |
| 2526 static gfx::Vector2dF ScrollLayerWithLocalDelta( | 2525 static gfx::Vector2dF ScrollLayerWithLocalDelta( |
| 2527 LayerImpl* layer_impl, | 2526 LayerImpl* layer_impl, |
| 2528 const gfx::Vector2dF& local_delta, | 2527 const gfx::Vector2dF& local_delta, |
| 2529 float page_scale_factor) { | 2528 float page_scale_factor) { |
| 2530 gfx::Vector2dF previous_delta(layer_impl->ScrollDelta()); | 2529 gfx::ScrollOffset previous_offset = layer_impl->CurrentScrollOffset(); |
| 2531 gfx::Vector2dF delta = local_delta; | 2530 gfx::Vector2dF delta = local_delta; |
| 2532 delta.Scale(1.f / page_scale_factor); | 2531 delta.Scale(1.f / page_scale_factor); |
| 2533 layer_impl->ScrollBy(delta); | 2532 layer_impl->ScrollBy(delta); |
| 2534 return layer_impl->ScrollDelta() - previous_delta; | 2533 gfx::ScrollOffset scrolled = |
| 2534 layer_impl->CurrentScrollOffset() - previous_offset; |
| 2535 return gfx::Vector2dF(scrolled.x(), scrolled.y()); |
| 2535 } | 2536 } |
| 2536 | 2537 |
| 2537 bool LayerTreeHostImpl::ShouldTopControlsConsumeScroll( | 2538 bool LayerTreeHostImpl::ShouldTopControlsConsumeScroll( |
| 2538 const gfx::Vector2dF& scroll_delta) const { | 2539 const gfx::Vector2dF& scroll_delta) const { |
| 2539 DCHECK(CurrentlyScrollingLayer()); | 2540 DCHECK(CurrentlyScrollingLayer()); |
| 2540 | 2541 |
| 2541 if (!top_controls_manager_) | 2542 if (!top_controls_manager_) |
| 2542 return false; | 2543 return false; |
| 2543 | 2544 |
| 2544 // Always consume if it's in the direction to show the top controls. | 2545 // 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... |
| 2974 // scales that we want when we're not inside a pinch. | 2975 // scales that we want when we're not inside a pinch. |
| 2975 active_tree_->set_needs_update_draw_properties(); | 2976 active_tree_->set_needs_update_draw_properties(); |
| 2976 SetNeedsRedraw(); | 2977 SetNeedsRedraw(); |
| 2977 } | 2978 } |
| 2978 | 2979 |
| 2979 static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, | 2980 static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, |
| 2980 LayerImpl* layer_impl) { | 2981 LayerImpl* layer_impl) { |
| 2981 if (!layer_impl) | 2982 if (!layer_impl) |
| 2982 return; | 2983 return; |
| 2983 | 2984 |
| 2984 gfx::Vector2d scroll_delta = | 2985 gfx::ScrollOffset scroll_delta = layer_impl->PullDeltaForMainThread(); |
| 2985 gfx::ToFlooredVector2d(layer_impl->ScrollDelta()); | 2986 |
| 2986 if (!scroll_delta.IsZero()) { | 2987 if (!scroll_delta.IsZero()) { |
| 2987 LayerTreeHostCommon::ScrollUpdateInfo scroll; | 2988 LayerTreeHostCommon::ScrollUpdateInfo scroll; |
| 2988 scroll.layer_id = layer_impl->id(); | 2989 scroll.layer_id = layer_impl->id(); |
| 2989 scroll.scroll_delta = scroll_delta; | 2990 scroll.scroll_delta = gfx::Vector2d(scroll_delta.x(), scroll_delta.y()); |
| 2990 scroll_info->scrolls.push_back(scroll); | 2991 scroll_info->scrolls.push_back(scroll); |
| 2991 layer_impl->SetSentScrollDelta(scroll_delta); | |
| 2992 } | 2992 } |
| 2993 | 2993 |
| 2994 for (size_t i = 0; i < layer_impl->children().size(); ++i) | 2994 for (size_t i = 0; i < layer_impl->children().size(); ++i) |
| 2995 CollectScrollDeltas(scroll_info, layer_impl->children()[i]); | 2995 CollectScrollDeltas(scroll_info, layer_impl->children()[i]); |
| 2996 } | 2996 } |
| 2997 | 2997 |
| 2998 scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() { | 2998 scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() { |
| 2999 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); | 2999 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); |
| 3000 | 3000 |
| 3001 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); | 3001 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3458 } | 3458 } |
| 3459 | 3459 |
| 3460 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3460 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 3461 std::vector<PictureLayerImpl*>::iterator it = | 3461 std::vector<PictureLayerImpl*>::iterator it = |
| 3462 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3462 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
| 3463 DCHECK(it != picture_layers_.end()); | 3463 DCHECK(it != picture_layers_.end()); |
| 3464 picture_layers_.erase(it); | 3464 picture_layers_.erase(it); |
| 3465 } | 3465 } |
| 3466 | 3466 |
| 3467 } // namespace cc | 3467 } // namespace cc |
| OLD | NEW |