| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 10027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10038 host_impl_->DidFinishImplFrame(); | 10038 host_impl_->DidFinishImplFrame(); |
| 10039 | 10039 |
| 10040 LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); | 10040 LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10041 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), scrolling_layer); | 10041 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), scrolling_layer); |
| 10042 | 10042 |
| 10043 // Verify no jump. | 10043 // Verify no jump. |
| 10044 float y = scrolling_layer->CurrentScrollOffset().y(); | 10044 float y = scrolling_layer->CurrentScrollOffset().y(); |
| 10045 EXPECT_TRUE(y > 1 && y < 49); | 10045 EXPECT_TRUE(y > 1 && y < 49); |
| 10046 } | 10046 } |
| 10047 | 10047 |
| 10048 TEST_F(LayerTreeHostImplTest, ScrollAnimatedWithDelay) { |
| 10049 const gfx::Size content_size(1000, 1000); |
| 10050 const gfx::Size viewport_size(50, 100); |
| 10051 CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10052 |
| 10053 DrawFrame(); |
| 10054 |
| 10055 base::TimeTicks start_time = |
| 10056 base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10057 BeginFrameArgs begin_frame_args = |
| 10058 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10059 |
| 10060 // Create animation with a 100ms delay. |
| 10061 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10062 host_impl_ |
| 10063 ->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 100), |
| 10064 base::TimeDelta::FromMilliseconds(100)) |
| 10065 .thread); |
| 10066 LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10067 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), scrolling_layer); |
| 10068 |
| 10069 // First tick, animation is started. |
| 10070 begin_frame_args.frame_time = start_time; |
| 10071 host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10072 host_impl_->UpdateAnimationState(true); |
| 10073 EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
| 10074 host_impl_->DidFinishImplFrame(); |
| 10075 |
| 10076 // Second tick after 50ms, animation should be half way done since |
| 10077 // the duration due to delay is 100ms. |
| 10078 begin_frame_args.frame_time = |
| 10079 start_time + base::TimeDelta::FromMilliseconds(50); |
| 10080 host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10081 host_impl_->UpdateAnimationState(true); |
| 10082 EXPECT_EQ(50, scrolling_layer->CurrentScrollOffset().y()); |
| 10083 host_impl_->DidFinishImplFrame(); |
| 10084 |
| 10085 // Update target. |
| 10086 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10087 host_impl_ |
| 10088 ->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 100), |
| 10089 base::TimeDelta::FromMilliseconds(150)) |
| 10090 .thread); |
| 10091 |
| 10092 // Third tick after 100ms, should be at the target position since update |
| 10093 // target was called with a large value of jank. |
| 10094 begin_frame_args.frame_time = |
| 10095 start_time + base::TimeDelta::FromMilliseconds(100); |
| 10096 host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10097 host_impl_->UpdateAnimationState(true); |
| 10098 EXPECT_EQ(200, scrolling_layer->CurrentScrollOffset().y()); |
| 10099 } |
| 10100 |
| 10048 // Test that a smooth scroll offset animation is aborted when followed by a | 10101 // Test that a smooth scroll offset animation is aborted when followed by a |
| 10049 // non-smooth scroll offset animation. | 10102 // non-smooth scroll offset animation. |
| 10050 TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimatedAborted) { | 10103 TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimatedAborted) { |
| 10051 const gfx::Size content_size(1000, 1000); | 10104 const gfx::Size content_size(1000, 1000); |
| 10052 const gfx::Size viewport_size(500, 500); | 10105 const gfx::Size viewport_size(500, 500); |
| 10053 CreateBasicVirtualViewportLayers(viewport_size, content_size); | 10106 CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10054 | 10107 |
| 10055 DrawFrame(); | 10108 DrawFrame(); |
| 10056 | 10109 |
| 10057 base::TimeTicks start_time = | 10110 base::TimeTicks start_time = |
| (...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11138 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); | 11191 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 11139 | 11192 |
| 11140 // Re-initialize with a software output surface. | 11193 // Re-initialize with a software output surface. |
| 11141 output_surface_ = FakeOutputSurface::CreateDelegatingSoftware(); | 11194 output_surface_ = FakeOutputSurface::CreateDelegatingSoftware(); |
| 11142 host_impl_->InitializeRenderer(output_surface_.get()); | 11195 host_impl_->InitializeRenderer(output_surface_.get()); |
| 11143 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); | 11196 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 11144 } | 11197 } |
| 11145 | 11198 |
| 11146 } // namespace | 11199 } // namespace |
| 11147 } // namespace cc | 11200 } // namespace cc |
| OLD | NEW |