| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "cc/animation/animation_host.h" | 11 #include "cc/animation/animation_host.h" |
| 12 #include "cc/input/main_thread_scrolling_reason.h" | 12 #include "cc/input/main_thread_scrolling_reason.h" |
| 13 #include "cc/input/scroll_elasticity_helper.h" | 13 #include "cc/input/scroll_elasticity_helper.h" |
| 14 #include "cc/layers/layer.h" | 14 #include "cc/layers/layer.h" |
| 15 #include "cc/layers/layer_impl.h" | 15 #include "cc/layers/layer_impl.h" |
| 16 #include "cc/layers/picture_layer.h" | 16 #include "cc/layers/picture_layer.h" |
| 17 #include "cc/scheduler/begin_frame_source.h" | 17 #include "cc/scheduler/begin_frame_source.h" |
| 18 #include "cc/test/fake_content_layer_client.h" | 18 #include "cc/test/fake_content_layer_client.h" |
| 19 #include "cc/test/fake_layer_tree_host_client.h" | 19 #include "cc/test/fake_layer_tree_host_client.h" |
| 20 #include "cc/test/fake_picture_layer.h" | 20 #include "cc/test/fake_picture_layer.h" |
| 21 #include "cc/test/fake_picture_layer_impl.h" | 21 #include "cc/test/fake_picture_layer_impl.h" |
| 22 #include "cc/test/geometry_test_utils.h" | 22 #include "cc/test/geometry_test_utils.h" |
| 23 #include "cc/test/layer_tree_test.h" | 23 #include "cc/test/layer_tree_test.h" |
| 24 #include "cc/test/test_shared_bitmap_manager.h" | 24 #include "cc/test/test_shared_bitmap_manager.h" |
| 25 #include "cc/test/test_task_graph_runner.h" | 25 #include "cc/test/test_task_graph_runner.h" |
| 26 #include "cc/trees/layer_tree_impl.h" | 26 #include "cc/trees/layer_tree_impl.h" |
| 27 #include "cc/trees/scroll_node.h" | 27 #include "cc/trees/scroll_node.h" |
| 28 #include "cc/trees/transform_node.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "ui/gfx/geometry/point_conversions.h" | 30 #include "ui/gfx/geometry/point_conversions.h" |
| 30 #include "ui/gfx/geometry/size_conversions.h" | 31 #include "ui/gfx/geometry/size_conversions.h" |
| 31 #include "ui/gfx/geometry/vector2d_conversions.h" | 32 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 32 | 33 |
| 33 using ::testing::Mock; | 34 using ::testing::Mock; |
| 34 | 35 |
| 35 namespace cc { | 36 namespace cc { |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| (...skipping 1933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1971 int num_begin_main_frames_main_thread_; | 1972 int num_begin_main_frames_main_thread_; |
| 1972 gfx::Vector2dF current_elastic_overscroll_; | 1973 gfx::Vector2dF current_elastic_overscroll_; |
| 1973 | 1974 |
| 1974 const gfx::Vector2dF elastic_overscroll_test_cases_[5] = { | 1975 const gfx::Vector2dF elastic_overscroll_test_cases_[5] = { |
| 1975 gfx::Vector2dF(0, 0), gfx::Vector2dF(5, 10), gfx::Vector2dF(5, 5), | 1976 gfx::Vector2dF(0, 0), gfx::Vector2dF(5, 10), gfx::Vector2dF(5, 5), |
| 1976 gfx::Vector2dF(-4, -5), gfx::Vector2dF(0, 0)}; | 1977 gfx::Vector2dF(-4, -5), gfx::Vector2dF(0, 0)}; |
| 1977 }; | 1978 }; |
| 1978 | 1979 |
| 1979 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestElasticOverscroll); | 1980 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestElasticOverscroll); |
| 1980 | 1981 |
| 1982 class LayerTreeHostScrollTestPropertyTreeUpdate |
| 1983 : public LayerTreeHostScrollTest { |
| 1984 public: |
| 1985 LayerTreeHostScrollTestPropertyTreeUpdate() |
| 1986 : initial_scroll_(10, 20), second_scroll_(0, 0) {} |
| 1987 |
| 1988 void BeginTest() override { |
| 1989 layer_tree()->inner_viewport_scroll_layer()->SetScrollOffset( |
| 1990 initial_scroll_); |
| 1991 layer_tree()->inner_viewport_scroll_layer()->SetBounds(gfx::Size(100, 100)); |
| 1992 PostSetNeedsCommitToMainThread(); |
| 1993 } |
| 1994 |
| 1995 void UpdateLayerTreeHost() override { |
| 1996 Layer* scroll_layer = layer_tree()->inner_viewport_scroll_layer(); |
| 1997 if (layer_tree_host()->SourceFrameNumber() == 0) { |
| 1998 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); |
| 1999 } else { |
| 2000 EXPECT_VECTOR_EQ( |
| 2001 gfx::ScrollOffsetWithDelta(initial_scroll_, scroll_amount_), |
| 2002 scroll_layer->scroll_offset()); |
| 2003 scroll_layer->SetScrollOffset(second_scroll_); |
| 2004 scroll_layer->SetOpacity(0.5f); |
| 2005 } |
| 2006 } |
| 2007 |
| 2008 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 2009 LayerImpl* scroll_layer = impl->InnerViewportScrollLayer(); |
| 2010 |
| 2011 switch (impl->active_tree()->source_frame_number()) { |
| 2012 case 0: |
| 2013 EXPECT_VECTOR_EQ(initial_scroll_, ScrollTreeForLayer(scroll_layer) |
| 2014 ->GetScrollOffsetBaseForTesting( |
| 2015 scroll_layer->id())); |
| 2016 EXPECT_VECTOR_EQ( |
| 2017 initial_scroll_, |
| 2018 scroll_layer->layer_tree_impl() |
| 2019 ->property_trees() |
| 2020 ->transform_tree.Node(scroll_layer->transform_tree_index()) |
| 2021 ->scroll_offset); |
| 2022 PostSetNeedsCommitToMainThread(); |
| 2023 break; |
| 2024 case 1: |
| 2025 EXPECT_VECTOR_EQ(second_scroll_, ScrollTreeForLayer(scroll_layer) |
| 2026 ->GetScrollOffsetBaseForTesting( |
| 2027 scroll_layer->id())); |
| 2028 EXPECT_VECTOR_EQ( |
| 2029 second_scroll_, |
| 2030 scroll_layer->layer_tree_impl() |
| 2031 ->property_trees() |
| 2032 ->transform_tree.Node(scroll_layer->transform_tree_index()) |
| 2033 ->scroll_offset); |
| 2034 EndTest(); |
| 2035 break; |
| 2036 } |
| 2037 } |
| 2038 |
| 2039 void AfterTest() override {} |
| 2040 |
| 2041 private: |
| 2042 gfx::ScrollOffset initial_scroll_; |
| 2043 gfx::ScrollOffset second_scroll_; |
| 2044 gfx::Vector2dF scroll_amount_; |
| 2045 }; |
| 2046 |
| 2047 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostScrollTestPropertyTreeUpdate); |
| 2048 |
| 1981 } // namespace | 2049 } // namespace |
| 1982 } // namespace cc | 2050 } // namespace cc |
| OLD | NEW |