Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stdint.h> | |
| 8 | |
| 9 #include "cc/animation/animation_curve.h" | 7 #include "cc/animation/animation_curve.h" |
| 10 #include "cc/animation/animation_host.h" | 8 #include "cc/animation/animation_host.h" |
| 11 #include "cc/animation/animation_id_provider.h" | 9 #include "cc/animation/animation_id_provider.h" |
| 12 #include "cc/animation/animation_player.h" | 10 #include "cc/animation/animation_player.h" |
| 13 #include "cc/animation/animation_registrar.h" | |
| 14 #include "cc/animation/animation_timeline.h" | 11 #include "cc/animation/animation_timeline.h" |
| 15 #include "cc/animation/element_animations.h" | 12 #include "cc/animation/element_animations.h" |
| 16 #include "cc/animation/layer_animation_controller.h" | 13 #include "cc/animation/layer_animation_controller.h" |
| 17 #include "cc/animation/scroll_offset_animation_curve.h" | 14 #include "cc/animation/scroll_offset_animation_curve.h" |
| 18 #include "cc/animation/timing_function.h" | 15 #include "cc/animation/timing_function.h" |
| 19 #include "cc/animation/transform_operations.h" | |
| 20 #include "cc/base/completion_event.h" | 16 #include "cc/base/completion_event.h" |
| 21 #include "cc/base/time_util.h" | 17 #include "cc/base/time_util.h" |
| 22 #include "cc/layers/layer.h" | 18 #include "cc/layers/layer.h" |
| 23 #include "cc/layers/layer_impl.h" | 19 #include "cc/layers/layer_impl.h" |
| 24 #include "cc/test/animation_test_common.h" | 20 #include "cc/test/animation_test_common.h" |
| 25 #include "cc/test/fake_content_layer_client.h" | 21 #include "cc/test/fake_content_layer_client.h" |
| 26 #include "cc/test/fake_picture_layer.h" | 22 #include "cc/test/fake_picture_layer.h" |
| 27 #include "cc/test/layer_tree_test.h" | 23 #include "cc/test/layer_tree_test.h" |
| 28 #include "cc/trees/layer_tree_impl.h" | 24 #include "cc/trees/layer_tree_impl.h" |
| 29 | 25 |
| 30 namespace cc { | 26 namespace cc { |
| 31 namespace { | 27 namespace { |
| 32 | 28 |
| 33 class LayerTreeHostAnimationTest : public LayerTreeTest { | 29 class LayerTreeHostTimelinesTest : public LayerTreeTest { |
| 34 public: | 30 public: |
| 35 LayerTreeHostAnimationTest() | 31 LayerTreeHostTimelinesTest() |
| 36 : timeline_id_(AnimationIdProvider::NextTimelineId()), | 32 : timeline_id_(AnimationIdProvider::NextTimelineId()), |
| 37 player_id_(AnimationIdProvider::NextPlayerId()), | 33 player_id_(AnimationIdProvider::NextPlayerId()), |
| 38 player_child_id_(AnimationIdProvider::NextPlayerId()) { | 34 player_child_id_(AnimationIdProvider::NextPlayerId()) { |
| 39 timeline_ = AnimationTimeline::Create(timeline_id_); | 35 timeline_ = AnimationTimeline::Create(timeline_id_); |
| 40 player_ = AnimationPlayer::Create(player_id_); | 36 player_ = AnimationPlayer::Create(player_id_); |
| 41 player_child_ = AnimationPlayer::Create(player_child_id_); | 37 player_child_ = AnimationPlayer::Create(player_child_id_); |
| 42 | 38 |
| 43 player_->set_layer_animation_delegate(this); | 39 player_->set_layer_animation_delegate(this); |
| 44 } | 40 } |
| 45 | 41 |
| 42 void InitializeSettings(LayerTreeSettings* settings) override { | |
| 43 settings->use_compositor_animation_timelines = true; | |
| 44 } | |
| 45 | |
| 46 void InitializeLayerSettings(LayerSettings* layer_settings) override { | |
| 47 layer_settings->use_compositor_animation_timelines = true; | |
| 48 } | |
| 49 | |
| 50 void SetupTree() override { LayerTreeTest::SetupTree(); } | |
| 51 | |
| 46 void AttachPlayersToTimeline() { | 52 void AttachPlayersToTimeline() { |
| 47 layer_tree_host()->animation_host()->AddAnimationTimeline(timeline_.get()); | 53 layer_tree_host()->animation_host()->AddAnimationTimeline(timeline_.get()); |
| 48 timeline_->AttachPlayer(player_.get()); | 54 timeline_->AttachPlayer(player_.get()); |
| 49 timeline_->AttachPlayer(player_child_.get()); | 55 timeline_->AttachPlayer(player_child_.get()); |
| 50 } | 56 } |
| 51 | 57 |
| 52 protected: | 58 protected: |
| 53 scoped_refptr<AnimationTimeline> timeline_; | 59 scoped_refptr<AnimationTimeline> timeline_; |
| 54 scoped_refptr<AnimationPlayer> player_; | 60 scoped_refptr<AnimationPlayer> player_; |
| 55 scoped_refptr<AnimationPlayer> player_child_; | 61 scoped_refptr<AnimationPlayer> player_child_; |
| 56 | 62 |
| 57 const int timeline_id_; | 63 const int timeline_id_; |
| 58 const int player_id_; | 64 const int player_id_; |
| 59 const int player_child_id_; | 65 const int player_child_id_; |
| 60 }; | 66 }; |
| 61 | 67 |
| 62 // Makes sure that SetNeedsAnimate does not cause the CommitRequested() state to | |
|
ajuma
2016/03/18 22:09:21
The changes in this file seem mostly unrelated to
Ian Vollick
2016/03/19 03:05:22
Yep, definitely rebasing weirdness. Shouldn't have
| |
| 63 // be set. | |
| 64 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested | |
| 65 : public LayerTreeHostAnimationTest { | |
| 66 public: | |
| 67 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested() | |
| 68 : num_commits_(0) {} | |
| 69 | |
| 70 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 71 | |
| 72 void BeginMainFrame(const BeginFrameArgs& args) override { | |
| 73 // We skip the first commit because its the commit that populates the | |
| 74 // impl thread with a tree. After the second commit, the test is done. | |
| 75 if (num_commits_ != 1) | |
| 76 return; | |
| 77 | |
| 78 layer_tree_host()->SetNeedsAnimate(); | |
| 79 // Right now, CommitRequested is going to be true, because during | |
| 80 // BeginFrame, we force CommitRequested to true to prevent requests from | |
| 81 // hitting the impl thread. But, when the next DidCommit happens, we should | |
| 82 // verify that CommitRequested has gone back to false. | |
| 83 } | |
| 84 | |
| 85 void DidCommit() override { | |
| 86 if (!num_commits_) { | |
| 87 EXPECT_FALSE(layer_tree_host()->CommitRequested()); | |
| 88 layer_tree_host()->SetNeedsAnimate(); | |
| 89 EXPECT_FALSE(layer_tree_host()->CommitRequested()); | |
| 90 } | |
| 91 | |
| 92 // Verifies that the SetNeedsAnimate we made in ::Animate did not | |
| 93 // trigger CommitRequested. | |
| 94 EXPECT_FALSE(layer_tree_host()->CommitRequested()); | |
| 95 EndTest(); | |
| 96 num_commits_++; | |
| 97 } | |
| 98 | |
| 99 void AfterTest() override {} | |
| 100 | |
| 101 private: | |
| 102 int num_commits_; | |
| 103 }; | |
| 104 | |
| 105 MULTI_THREAD_TEST_F( | |
| 106 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested); | |
| 107 | |
| 108 // Trigger a frame with SetNeedsCommit. Then, inside the resulting animate | |
| 109 // callback, request another frame using SetNeedsAnimate. End the test when | |
| 110 // animate gets called yet-again, indicating that the proxy is correctly | |
| 111 // handling the case where SetNeedsAnimate() is called inside the BeginFrame | |
| 112 // flow. | |
| 113 class LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback | |
| 114 : public LayerTreeHostAnimationTest { | |
| 115 public: | |
| 116 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback() | |
| 117 : num_begin_frames_(0) {} | |
| 118 | |
| 119 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 120 | |
| 121 void BeginMainFrame(const BeginFrameArgs& args) override { | |
| 122 if (!num_begin_frames_) { | |
| 123 layer_tree_host()->SetNeedsAnimate(); | |
| 124 num_begin_frames_++; | |
| 125 return; | |
| 126 } | |
| 127 EndTest(); | |
| 128 } | |
| 129 | |
| 130 void AfterTest() override {} | |
| 131 | |
| 132 private: | |
| 133 int num_begin_frames_; | |
| 134 }; | |
| 135 | |
| 136 SINGLE_AND_MULTI_THREAD_TEST_F( | |
| 137 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback); | |
| 138 | |
| 139 // Add a layer animation and confirm that | 68 // Add a layer animation and confirm that |
| 140 // LayerTreeHostImpl::UpdateAnimationState does get called. | 69 // LayerTreeHostImpl::UpdateAnimationState does get called. |
| 141 class LayerTreeHostAnimationTestAddAnimation | 70 // Evolved from LayerTreeHostAnimationTestAddAnimation |
| 142 : public LayerTreeHostAnimationTest { | 71 class LayerTreeHostTimelinesTestAddAnimation |
| 72 : public LayerTreeHostTimelinesTest { | |
| 143 public: | 73 public: |
| 144 LayerTreeHostAnimationTestAddAnimation() | 74 LayerTreeHostTimelinesTestAddAnimation() |
| 145 : update_animation_state_was_called_(false) {} | 75 : update_animation_state_was_called_(false) {} |
| 146 | 76 |
| 147 void BeginTest() override { | 77 void BeginTest() override { |
| 148 AttachPlayersToTimeline(); | 78 AttachPlayersToTimeline(); |
| 149 player_->AttachLayer(layer_tree_host()->root_layer()->id()); | 79 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 150 PostAddInstantAnimationToMainThreadPlayer(player_.get()); | 80 PostAddInstantAnimationToMainThreadPlayer(player_.get()); |
| 151 } | 81 } |
| 152 | 82 |
| 153 void UpdateAnimationState(LayerTreeHostImpl* host_impl, | 83 void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
| 154 bool has_unfinished_animation) override { | 84 bool has_unfinished_animation) override { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 169 | 99 |
| 170 EndTest(); | 100 EndTest(); |
| 171 } | 101 } |
| 172 | 102 |
| 173 void AfterTest() override { EXPECT_TRUE(update_animation_state_was_called_); } | 103 void AfterTest() override { EXPECT_TRUE(update_animation_state_was_called_); } |
| 174 | 104 |
| 175 private: | 105 private: |
| 176 bool update_animation_state_was_called_; | 106 bool update_animation_state_was_called_; |
| 177 }; | 107 }; |
| 178 | 108 |
| 179 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation); | 109 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestAddAnimation); |
| 180 | 110 |
| 181 // Add a layer animation to a layer, but continually fail to draw. Confirm that | 111 // Add a layer animation to a layer, but continually fail to draw. Confirm that |
| 182 // after a while, we do eventually force a draw. | 112 // after a while, we do eventually force a draw. |
| 183 class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws | 113 // Evolved from LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws. |
| 184 : public LayerTreeHostAnimationTest { | 114 class LayerTreeHostTimelinesTestCheckerboardDoesNotStarveDraws |
| 115 : public LayerTreeHostTimelinesTest { | |
| 185 public: | 116 public: |
| 186 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() | 117 LayerTreeHostTimelinesTestCheckerboardDoesNotStarveDraws() |
| 187 : started_animating_(false) {} | 118 : started_animating_(false) {} |
| 188 | 119 |
| 189 void BeginTest() override { | 120 void BeginTest() override { |
| 190 AttachPlayersToTimeline(); | 121 AttachPlayersToTimeline(); |
| 191 player_->AttachLayer(layer_tree_host()->root_layer()->id()); | 122 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 192 PostAddAnimationToMainThreadPlayer(player_.get()); | 123 PostAddAnimationToMainThreadPlayer(player_.get()); |
| 193 } | 124 } |
| 194 | 125 |
| 195 void AnimateLayers(LayerTreeHostImpl* host_impl, | 126 void AnimateLayers(LayerTreeHostImpl* host_impl, |
| 196 base::TimeTicks monotonic_time) override { | 127 base::TimeTicks monotonic_time) override { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 208 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 139 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
| 209 } | 140 } |
| 210 | 141 |
| 211 void AfterTest() override {} | 142 void AfterTest() override {} |
| 212 | 143 |
| 213 private: | 144 private: |
| 214 bool started_animating_; | 145 bool started_animating_; |
| 215 }; | 146 }; |
| 216 | 147 |
| 217 // Starvation can only be an issue with the MT compositor. | 148 // Starvation can only be an issue with the MT compositor. |
| 218 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws); | 149 MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestCheckerboardDoesNotStarveDraws); |
| 219 | 150 |
| 220 // Ensures that animations eventually get deleted. | 151 // Ensures that animations eventually get deleted. |
| 221 class LayerTreeHostAnimationTestAnimationsGetDeleted | 152 // Evolved from LayerTreeHostAnimationTestAnimationsGetDeleted. |
| 222 : public LayerTreeHostAnimationTest { | 153 class LayerTreeHostTimelinesTestAnimationsGetDeleted |
| 154 : public LayerTreeHostTimelinesTest { | |
| 223 public: | 155 public: |
| 224 LayerTreeHostAnimationTestAnimationsGetDeleted() | 156 LayerTreeHostTimelinesTestAnimationsGetDeleted() |
| 225 : started_animating_(false) {} | 157 : started_animating_(false) {} |
| 226 | 158 |
| 227 void BeginTest() override { | 159 void BeginTest() override { |
| 228 AttachPlayersToTimeline(); | 160 AttachPlayersToTimeline(); |
| 229 player_->AttachLayer(layer_tree_host()->root_layer()->id()); | 161 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 230 PostAddAnimationToMainThreadPlayer(player_.get()); | 162 PostAddAnimationToMainThreadPlayer(player_.get()); |
| 231 } | 163 } |
| 232 | 164 |
| 233 void AnimateLayers(LayerTreeHostImpl* host_impl, | 165 void AnimateLayers(LayerTreeHostImpl* host_impl, |
| 234 base::TimeTicks monotonic_time) override { | 166 base::TimeTicks monotonic_time) override { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 252 // so we need to schedule a commit. | 184 // so we need to schedule a commit. |
| 253 layer_tree_host()->SetNeedsCommit(); | 185 layer_tree_host()->SetNeedsCommit(); |
| 254 } | 186 } |
| 255 | 187 |
| 256 void AfterTest() override {} | 188 void AfterTest() override {} |
| 257 | 189 |
| 258 private: | 190 private: |
| 259 bool started_animating_; | 191 bool started_animating_; |
| 260 }; | 192 }; |
| 261 | 193 |
| 262 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimationsGetDeleted); | 194 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestAnimationsGetDeleted); |
| 263 | 195 |
| 264 // Ensure that an animation's timing function is respected. | 196 // Ensure that an animation's timing function is respected. |
| 265 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction | 197 // Evolved from LayerTreeHostAnimationTestAddAnimationWithTimingFunction. |
| 266 : public LayerTreeHostAnimationTest { | 198 class LayerTreeHostTimelinesTestAddAnimationWithTimingFunction |
| 199 : public LayerTreeHostTimelinesTest { | |
| 267 public: | 200 public: |
| 201 LayerTreeHostTimelinesTestAddAnimationWithTimingFunction() {} | |
| 202 | |
| 268 void SetupTree() override { | 203 void SetupTree() override { |
| 269 LayerTreeHostAnimationTest::SetupTree(); | 204 LayerTreeHostTimelinesTest::SetupTree(); |
| 270 picture_ = FakePictureLayer::Create(&client_); | 205 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 271 picture_->SetBounds(gfx::Size(4, 4)); | 206 picture_->SetBounds(gfx::Size(4, 4)); |
| 272 client_.set_bounds(picture_->bounds()); | 207 client_.set_bounds(picture_->bounds()); |
| 273 layer_tree_host()->root_layer()->AddChild(picture_); | 208 layer_tree_host()->root_layer()->AddChild(picture_); |
| 274 | 209 |
| 275 AttachPlayersToTimeline(); | 210 AttachPlayersToTimeline(); |
| 276 player_child_->AttachLayer(picture_->id()); | 211 player_child_->AttachLayer(picture_->id()); |
| 277 } | 212 } |
| 278 | 213 |
| 279 void BeginTest() override { | 214 void BeginTest() override { |
| 280 PostAddAnimationToMainThreadPlayer(player_child_.get()); | 215 PostAddAnimationToMainThreadPlayer(player_child_.get()); |
| 281 } | 216 } |
| 282 | 217 |
| 283 void AnimateLayers(LayerTreeHostImpl* host_impl, | 218 void AnimateLayers(LayerTreeHostImpl* host_impl, |
| 284 base::TimeTicks monotonic_time) override { | 219 base::TimeTicks monotonic_time) override { |
| 285 // TODO(ajuma): This test only checks the active tree. Add checks for | |
| 286 // pending tree too. | |
| 287 if (!host_impl->active_tree()->root_layer()) | |
| 288 return; | |
| 289 | |
| 290 // Wait for the commit with the animation to happen. | 220 // Wait for the commit with the animation to happen. |
| 291 if (host_impl->sync_tree()->source_frame_number() != 0) | 221 if (host_impl->sync_tree()->source_frame_number() != 0) |
| 292 return; | 222 return; |
| 293 | 223 |
| 294 scoped_refptr<AnimationTimeline> timeline_impl = | 224 scoped_refptr<AnimationTimeline> timeline_impl = |
| 295 host_impl->animation_host()->GetTimelineById(timeline_id_); | 225 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 296 scoped_refptr<AnimationPlayer> player_child_impl = | 226 scoped_refptr<AnimationPlayer> player_child_impl = |
| 297 timeline_impl->GetPlayerById(player_child_id_); | 227 timeline_impl->GetPlayerById(player_child_id_); |
| 298 | 228 |
| 299 LayerAnimationController* controller_impl = | 229 LayerAnimationController* controller_impl = |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 316 EndTest(); | 246 EndTest(); |
| 317 } | 247 } |
| 318 | 248 |
| 319 void AfterTest() override {} | 249 void AfterTest() override {} |
| 320 | 250 |
| 321 FakeContentLayerClient client_; | 251 FakeContentLayerClient client_; |
| 322 scoped_refptr<FakePictureLayer> picture_; | 252 scoped_refptr<FakePictureLayer> picture_; |
| 323 }; | 253 }; |
| 324 | 254 |
| 325 SINGLE_AND_MULTI_THREAD_TEST_F( | 255 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 326 LayerTreeHostAnimationTestAddAnimationWithTimingFunction); | 256 LayerTreeHostTimelinesTestAddAnimationWithTimingFunction); |
| 327 | 257 |
| 328 // Ensures that main thread animations have their start times synchronized with | 258 // Ensures that main thread animations have their start times synchronized with |
| 329 // impl thread animations. | 259 // impl thread animations. |
| 330 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes | 260 // Evolved from LayerTreeHostAnimationTestSynchronizeAnimationStartTimes. |
| 331 : public LayerTreeHostAnimationTest { | 261 class LayerTreeHostTimelinesTestSynchronizeAnimationStartTimes |
| 262 : public LayerTreeHostTimelinesTest { | |
| 332 public: | 263 public: |
| 264 LayerTreeHostTimelinesTestSynchronizeAnimationStartTimes() {} | |
| 265 | |
| 333 void SetupTree() override { | 266 void SetupTree() override { |
| 334 LayerTreeHostAnimationTest::SetupTree(); | 267 LayerTreeHostTimelinesTest::SetupTree(); |
| 335 picture_ = FakePictureLayer::Create(&client_); | 268 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 336 picture_->SetBounds(gfx::Size(4, 4)); | 269 picture_->SetBounds(gfx::Size(4, 4)); |
| 337 client_.set_bounds(picture_->bounds()); | 270 client_.set_bounds(picture_->bounds()); |
| 338 | 271 |
| 339 layer_tree_host()->root_layer()->AddChild(picture_); | 272 layer_tree_host()->root_layer()->AddChild(picture_); |
| 340 | 273 |
| 341 AttachPlayersToTimeline(); | 274 AttachPlayersToTimeline(); |
| 342 player_child_->set_layer_animation_delegate(this); | 275 player_child_->set_layer_animation_delegate(this); |
| 343 player_child_->AttachLayer(picture_->id()); | 276 player_child_->AttachLayer(picture_->id()); |
| 344 } | 277 } |
| 345 | 278 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 } | 313 } |
| 381 | 314 |
| 382 private: | 315 private: |
| 383 base::TimeTicks main_start_time_; | 316 base::TimeTicks main_start_time_; |
| 384 base::TimeTicks impl_start_time_; | 317 base::TimeTicks impl_start_time_; |
| 385 FakeContentLayerClient client_; | 318 FakeContentLayerClient client_; |
| 386 scoped_refptr<FakePictureLayer> picture_; | 319 scoped_refptr<FakePictureLayer> picture_; |
| 387 }; | 320 }; |
| 388 | 321 |
| 389 SINGLE_AND_MULTI_THREAD_TEST_F( | 322 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 390 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); | 323 LayerTreeHostTimelinesTestSynchronizeAnimationStartTimes); |
| 391 | 324 |
| 392 // Ensures that notify animation finished is called. | 325 // Ensures that notify animation finished is called. |
| 393 class LayerTreeHostAnimationTestAnimationFinishedEvents | 326 // Evolved from LayerTreeHostAnimationTestAnimationFinishedEvents. |
| 394 : public LayerTreeHostAnimationTest { | 327 class LayerTreeHostTimelinesTestAnimationFinishedEvents |
| 328 : public LayerTreeHostTimelinesTest { | |
| 395 public: | 329 public: |
| 330 LayerTreeHostTimelinesTestAnimationFinishedEvents() {} | |
| 331 | |
| 396 void BeginTest() override { | 332 void BeginTest() override { |
| 397 AttachPlayersToTimeline(); | 333 AttachPlayersToTimeline(); |
| 398 player_->AttachLayer(layer_tree_host()->root_layer()->id()); | 334 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 399 PostAddInstantAnimationToMainThreadPlayer(player_.get()); | 335 PostAddInstantAnimationToMainThreadPlayer(player_.get()); |
| 400 } | 336 } |
| 401 | 337 |
| 402 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 338 void NotifyAnimationFinished(base::TimeTicks monotonic_time, |
| 403 TargetProperty::Type target_property, | 339 TargetProperty::Type target_property, |
| 404 int group) override { | 340 int group) override { |
| 405 LayerAnimationController* controller = | 341 LayerAnimationController* controller = |
| 406 player_->element_animations()->layer_animation_controller(); | 342 player_->element_animations()->layer_animation_controller(); |
| 407 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); | 343 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); |
| 408 if (animation) | 344 if (animation) |
| 409 controller->RemoveAnimation(animation->id()); | 345 controller->RemoveAnimation(animation->id()); |
| 410 EndTest(); | 346 EndTest(); |
| 411 } | 347 } |
| 412 | 348 |
| 413 void AfterTest() override {} | 349 void AfterTest() override {} |
| 414 }; | 350 }; |
| 415 | 351 |
| 416 SINGLE_AND_MULTI_THREAD_TEST_F( | 352 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 417 LayerTreeHostAnimationTestAnimationFinishedEvents); | 353 LayerTreeHostTimelinesTestAnimationFinishedEvents); |
| 418 | 354 |
| 419 // Ensures that when opacity is being animated, this value does not cause the | 355 // Ensures that when opacity is being animated, this value does not cause the |
| 420 // subtree to be skipped. | 356 // subtree to be skipped. |
| 421 class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity | 357 // Evolved from LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity. |
| 422 : public LayerTreeHostAnimationTest { | 358 class LayerTreeHostTimelinesTestDoNotSkipLayersWithAnimatedOpacity |
| 359 : public LayerTreeHostTimelinesTest { | |
| 423 public: | 360 public: |
| 424 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity() | 361 LayerTreeHostTimelinesTestDoNotSkipLayersWithAnimatedOpacity() |
| 425 : update_check_layer_() {} | 362 : update_check_layer_( |
| 363 FakePictureLayer::Create(layer_settings(), &client_)) {} | |
| 426 | 364 |
| 427 void SetupTree() override { | 365 void SetupTree() override { |
| 428 update_check_layer_ = FakePictureLayer::Create(&client_); | |
| 429 update_check_layer_->SetOpacity(0.f); | 366 update_check_layer_->SetOpacity(0.f); |
| 430 layer_tree_host()->SetRootLayer(update_check_layer_); | 367 layer_tree_host()->SetRootLayer(update_check_layer_); |
| 431 client_.set_bounds(update_check_layer_->bounds()); | 368 client_.set_bounds(update_check_layer_->bounds()); |
| 432 LayerTreeHostAnimationTest::SetupTree(); | 369 LayerTreeHostTimelinesTest::SetupTree(); |
| 433 | 370 |
| 434 AttachPlayersToTimeline(); | 371 AttachPlayersToTimeline(); |
| 435 player_->AttachLayer(update_check_layer_->id()); | 372 player_->AttachLayer(update_check_layer_->id()); |
| 436 } | 373 } |
| 437 | 374 |
| 438 void BeginTest() override { | 375 void BeginTest() override { |
| 439 PostAddAnimationToMainThreadPlayer(player_.get()); | 376 PostAddAnimationToMainThreadPlayer(player_.get()); |
| 440 } | 377 } |
| 441 | 378 |
| 442 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 379 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 461 // clear update_check_layer_ so LayerTreeHost dies. | 398 // clear update_check_layer_ so LayerTreeHost dies. |
| 462 update_check_layer_ = NULL; | 399 update_check_layer_ = NULL; |
| 463 } | 400 } |
| 464 | 401 |
| 465 private: | 402 private: |
| 466 FakeContentLayerClient client_; | 403 FakeContentLayerClient client_; |
| 467 scoped_refptr<FakePictureLayer> update_check_layer_; | 404 scoped_refptr<FakePictureLayer> update_check_layer_; |
| 468 }; | 405 }; |
| 469 | 406 |
| 470 SINGLE_AND_MULTI_THREAD_TEST_F( | 407 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 471 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity); | 408 LayerTreeHostTimelinesTestDoNotSkipLayersWithAnimatedOpacity); |
| 472 | 409 |
| 473 // Layers added to tree with existing active animations should have the | 410 // Layers added to tree with existing active animations should have the |
| 474 // animation correctly recognized. | 411 // animation correctly recognized. |
| 475 class LayerTreeHostAnimationTestLayerAddedWithAnimation | 412 // Evolved from LayerTreeHostAnimationTestLayerAddedWithAnimation. |
| 476 : public LayerTreeHostAnimationTest { | 413 class LayerTreeHostTimelinesTestLayerAddedWithAnimation |
| 414 : public LayerTreeHostTimelinesTest { | |
| 477 public: | 415 public: |
| 416 LayerTreeHostTimelinesTestLayerAddedWithAnimation() {} | |
| 417 | |
| 478 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 418 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 479 | 419 |
| 480 void DidCommit() override { | 420 void DidCommit() override { |
| 481 if (layer_tree_host()->source_frame_number() == 1) { | 421 if (layer_tree_host()->source_frame_number() == 1) { |
| 482 AttachPlayersToTimeline(); | 422 AttachPlayersToTimeline(); |
| 483 | 423 |
| 484 scoped_refptr<Layer> layer = Layer::Create(); | 424 scoped_refptr<Layer> layer = Layer::Create(layer_settings()); |
| 485 player_->AttachLayer(layer->id()); | 425 player_->AttachLayer(layer->id()); |
| 486 player_->set_layer_animation_delegate(this); | 426 player_->set_layer_animation_delegate(this); |
| 487 | 427 |
| 488 // Any valid AnimationCurve will do here. | 428 // Any valid AnimationCurve will do here. |
| 489 scoped_ptr<AnimationCurve> curve(new FakeFloatAnimationCurve()); | 429 scoped_ptr<AnimationCurve> curve(new FakeFloatAnimationCurve()); |
| 490 scoped_ptr<Animation> animation( | 430 scoped_ptr<Animation> animation( |
| 491 Animation::Create(std::move(curve), 1, 1, TargetProperty::OPACITY)); | 431 Animation::Create(std::move(curve), 1, 1, TargetProperty::OPACITY)); |
| 492 player_->AddAnimation(std::move(animation)); | 432 player_->AddAnimation(std::move(animation)); |
| 493 | 433 |
| 494 // We add the animation *before* attaching the layer to the tree. | 434 // We add the animation *before* attaching the layer to the tree. |
| 495 layer_tree_host()->root_layer()->AddChild(layer); | 435 layer_tree_host()->root_layer()->AddChild(layer); |
| 496 } | 436 } |
| 497 } | 437 } |
| 498 | 438 |
| 499 void AnimateLayers(LayerTreeHostImpl* impl_host, | 439 void AnimateLayers(LayerTreeHostImpl* impl_host, |
| 500 base::TimeTicks monotonic_time) override { | 440 base::TimeTicks monotonic_time) override { |
| 501 EndTest(); | 441 EndTest(); |
| 502 } | 442 } |
| 503 | 443 |
| 504 void AfterTest() override {} | 444 void AfterTest() override {} |
| 505 }; | 445 }; |
| 506 | 446 |
| 507 SINGLE_AND_MULTI_THREAD_TEST_F( | 447 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 508 LayerTreeHostAnimationTestLayerAddedWithAnimation); | 448 LayerTreeHostTimelinesTestLayerAddedWithAnimation); |
| 509 | |
| 510 class LayerTreeHostAnimationTestCancelAnimateCommit | |
| 511 : public LayerTreeHostAnimationTest { | |
| 512 public: | |
| 513 LayerTreeHostAnimationTestCancelAnimateCommit() | |
| 514 : num_begin_frames_(0), num_commit_calls_(0), num_draw_calls_(0) {} | |
| 515 | |
| 516 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 517 | |
| 518 void BeginMainFrame(const BeginFrameArgs& args) override { | |
| 519 num_begin_frames_++; | |
| 520 // No-op animate will cancel the commit. | |
| 521 if (layer_tree_host()->source_frame_number() == 1) { | |
| 522 EndTest(); | |
| 523 return; | |
| 524 } | |
| 525 layer_tree_host()->SetNeedsAnimate(); | |
| 526 } | |
| 527 | |
| 528 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { | |
| 529 num_commit_calls_++; | |
| 530 if (impl->active_tree()->source_frame_number() > 1) | |
| 531 FAIL() << "Commit should have been canceled."; | |
| 532 } | |
| 533 | |
| 534 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | |
| 535 num_draw_calls_++; | |
| 536 if (impl->active_tree()->source_frame_number() > 1) | |
| 537 FAIL() << "Draw should have been canceled."; | |
| 538 } | |
| 539 | |
| 540 void AfterTest() override { | |
| 541 EXPECT_EQ(2, num_begin_frames_); | |
| 542 EXPECT_EQ(1, num_commit_calls_); | |
| 543 EXPECT_EQ(1, num_draw_calls_); | |
| 544 } | |
| 545 | |
| 546 private: | |
| 547 int num_begin_frames_; | |
| 548 int num_commit_calls_; | |
| 549 int num_draw_calls_; | |
| 550 }; | |
| 551 | |
| 552 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCancelAnimateCommit); | |
| 553 | |
| 554 class LayerTreeHostAnimationTestForceRedraw | |
| 555 : public LayerTreeHostAnimationTest { | |
| 556 public: | |
| 557 LayerTreeHostAnimationTestForceRedraw() | |
| 558 : num_animate_(0), num_draw_layers_(0) {} | |
| 559 | |
| 560 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 561 | |
| 562 void BeginMainFrame(const BeginFrameArgs& args) override { | |
| 563 if (++num_animate_ < 2) | |
| 564 layer_tree_host()->SetNeedsAnimate(); | |
| 565 } | |
| 566 | |
| 567 void UpdateLayerTreeHost() override { | |
| 568 layer_tree_host()->SetNextCommitForcesRedraw(); | |
| 569 } | |
| 570 | |
| 571 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | |
| 572 if (++num_draw_layers_ == 2) | |
| 573 EndTest(); | |
| 574 } | |
| 575 | |
| 576 void AfterTest() override { | |
| 577 // The first commit will always draw; make sure the second draw triggered | |
| 578 // by the animation was not cancelled. | |
| 579 EXPECT_EQ(2, num_draw_layers_); | |
| 580 EXPECT_EQ(2, num_animate_); | |
| 581 } | |
| 582 | |
| 583 private: | |
| 584 int num_animate_; | |
| 585 int num_draw_layers_; | |
| 586 }; | |
| 587 | |
| 588 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestForceRedraw); | |
| 589 | |
| 590 class LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit | |
| 591 : public LayerTreeHostAnimationTest { | |
| 592 public: | |
| 593 LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit() | |
| 594 : num_animate_(0), num_draw_layers_(0) {} | |
| 595 | |
| 596 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 597 | |
| 598 void BeginMainFrame(const BeginFrameArgs& args) override { | |
| 599 if (++num_animate_ <= 2) { | |
| 600 layer_tree_host()->SetNeedsCommit(); | |
| 601 layer_tree_host()->SetNeedsAnimate(); | |
| 602 } | |
| 603 } | |
| 604 | |
| 605 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | |
| 606 if (++num_draw_layers_ == 2) | |
| 607 EndTest(); | |
| 608 } | |
| 609 | |
| 610 void AfterTest() override { | |
| 611 // The first commit will always draw; make sure the second draw triggered | |
| 612 // by the SetNeedsCommit was not cancelled. | |
| 613 EXPECT_EQ(2, num_draw_layers_); | |
| 614 EXPECT_GE(num_animate_, 2); | |
| 615 } | |
| 616 | |
| 617 private: | |
| 618 int num_animate_; | |
| 619 int num_draw_layers_; | |
| 620 }; | |
| 621 | |
| 622 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit); | |
| 623 | 449 |
| 624 // Animations should not be started when frames are being skipped due to | 450 // Animations should not be started when frames are being skipped due to |
| 625 // checkerboard. | 451 // checkerboard. |
| 626 class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations | 452 // Evolved from LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations. |
| 627 : public LayerTreeHostAnimationTest { | 453 class LayerTreeHostTimelinesTestCheckerboardDoesntStartAnimations |
| 454 : public LayerTreeHostTimelinesTest { | |
| 628 void SetupTree() override { | 455 void SetupTree() override { |
| 629 LayerTreeHostAnimationTest::SetupTree(); | 456 LayerTreeHostTimelinesTest::SetupTree(); |
| 630 picture_ = FakePictureLayer::Create(&client_); | 457 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 631 picture_->SetBounds(gfx::Size(4, 4)); | 458 picture_->SetBounds(gfx::Size(4, 4)); |
| 632 client_.set_bounds(picture_->bounds()); | 459 client_.set_bounds(picture_->bounds()); |
| 633 layer_tree_host()->root_layer()->AddChild(picture_); | 460 layer_tree_host()->root_layer()->AddChild(picture_); |
| 634 | 461 |
| 635 AttachPlayersToTimeline(); | 462 AttachPlayersToTimeline(); |
| 636 player_child_->AttachLayer(picture_->id()); | 463 player_child_->AttachLayer(picture_->id()); |
| 637 player_child_->set_layer_animation_delegate(this); | 464 player_child_->set_layer_animation_delegate(this); |
| 638 } | 465 } |
| 639 | 466 |
| 640 void InitializeSettings(LayerTreeSettings* settings) override { | 467 void InitializeSettings(LayerTreeSettings* settings) override { |
| 641 // Make sure that drawing many times doesn't cause a checkerboarded | 468 // Make sure that drawing many times doesn't cause a checkerboarded |
| 642 // animation to start so we avoid flake in this test. | 469 // animation to start so we avoid flake in this test. |
| 643 settings->timeout_and_draw_when_animation_checkerboards = false; | 470 settings->timeout_and_draw_when_animation_checkerboards = false; |
| 644 LayerTreeHostAnimationTest::InitializeSettings(settings); | 471 LayerTreeHostTimelinesTest::InitializeSettings(settings); |
| 645 } | 472 } |
| 646 | 473 |
| 647 void BeginTest() override { | 474 void BeginTest() override { |
| 648 prevented_draw_ = 0; | 475 prevented_draw_ = 0; |
| 649 started_times_ = 0; | 476 started_times_ = 0; |
| 650 | 477 |
| 651 PostSetNeedsCommitToMainThread(); | 478 PostSetNeedsCommitToMainThread(); |
| 652 } | 479 } |
| 653 | 480 |
| 654 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 481 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 EXPECT_EQ(1, started_times_); | 523 EXPECT_EQ(1, started_times_); |
| 697 } | 524 } |
| 698 | 525 |
| 699 int prevented_draw_; | 526 int prevented_draw_; |
| 700 int started_times_; | 527 int started_times_; |
| 701 FakeContentLayerClient client_; | 528 FakeContentLayerClient client_; |
| 702 scoped_refptr<FakePictureLayer> picture_; | 529 scoped_refptr<FakePictureLayer> picture_; |
| 703 }; | 530 }; |
| 704 | 531 |
| 705 MULTI_THREAD_TEST_F( | 532 MULTI_THREAD_TEST_F( |
| 706 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); | 533 LayerTreeHostTimelinesTestCheckerboardDoesntStartAnimations); |
| 707 | 534 |
| 708 // Verifies that scroll offset animations are only accepted when impl-scrolling | 535 // Verifies that scroll offset animations are only accepted when impl-scrolling |
| 709 // is supported, and that when scroll offset animations are accepted, | 536 // is supported, and that when scroll offset animations are accepted, |
| 710 // scroll offset updates are sent back to the main thread. | 537 // scroll offset updates are sent back to the main thread. |
| 711 class LayerTreeHostAnimationTestScrollOffsetChangesArePropagated | 538 // Evolved from LayerTreeHostAnimationTestScrollOffsetChangesArePropagated |
| 712 : public LayerTreeHostAnimationTest { | 539 class LayerTreeHostTimelinesTestScrollOffsetChangesArePropagated |
| 540 : public LayerTreeHostTimelinesTest { | |
| 713 public: | 541 public: |
| 542 LayerTreeHostTimelinesTestScrollOffsetChangesArePropagated() {} | |
| 543 | |
| 714 void SetupTree() override { | 544 void SetupTree() override { |
| 715 LayerTreeHostAnimationTest::SetupTree(); | 545 LayerTreeHostTimelinesTest::SetupTree(); |
| 716 | 546 |
| 717 scroll_layer_ = FakePictureLayer::Create(&client_); | 547 scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 718 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); | 548 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); |
| 719 scroll_layer_->SetBounds(gfx::Size(1000, 1000)); | 549 scroll_layer_->SetBounds(gfx::Size(1000, 1000)); |
| 720 client_.set_bounds(scroll_layer_->bounds()); | 550 client_.set_bounds(scroll_layer_->bounds()); |
| 721 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); | 551 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 722 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | 552 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 723 | 553 |
| 724 AttachPlayersToTimeline(); | 554 AttachPlayersToTimeline(); |
| 725 player_child_->AttachLayer(scroll_layer_->id()); | 555 player_child_->AttachLayer(scroll_layer_->id()); |
| 726 } | 556 } |
| 727 | 557 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 753 } | 583 } |
| 754 | 584 |
| 755 void AfterTest() override {} | 585 void AfterTest() override {} |
| 756 | 586 |
| 757 private: | 587 private: |
| 758 FakeContentLayerClient client_; | 588 FakeContentLayerClient client_; |
| 759 scoped_refptr<FakePictureLayer> scroll_layer_; | 589 scoped_refptr<FakePictureLayer> scroll_layer_; |
| 760 }; | 590 }; |
| 761 | 591 |
| 762 SINGLE_AND_MULTI_THREAD_TEST_F( | 592 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 763 LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); | 593 LayerTreeHostTimelinesTestScrollOffsetChangesArePropagated); |
| 764 | 594 |
| 765 // Verifies that when the main thread removes a scroll animation and sets a new | 595 // Verifies that when the main thread removes a scroll animation and sets a new |
| 766 // scroll position, the active tree takes on exactly this new scroll position | 596 // scroll position, the active tree takes on exactly this new scroll position |
| 767 // after activation, and the main thread doesn't receive a spurious scroll | 597 // after activation, and the main thread doesn't receive a spurious scroll |
| 768 // delta. | 598 // delta. |
| 769 class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval | 599 // Evolved from LayerTreeHostAnimationTestScrollOffsetAnimationRemoval |
| 770 : public LayerTreeHostAnimationTest { | 600 class LayerTreeHostTimelinesTestScrollOffsetAnimationRemoval |
| 601 : public LayerTreeHostTimelinesTest { | |
| 771 public: | 602 public: |
| 772 LayerTreeHostAnimationTestScrollOffsetAnimationRemoval() | 603 LayerTreeHostTimelinesTestScrollOffsetAnimationRemoval() |
| 773 : final_postion_(50.0, 100.0) {} | 604 : final_postion_(50.0, 100.0) {} |
| 774 | 605 |
| 775 void SetupTree() override { | 606 void SetupTree() override { |
| 776 LayerTreeHostAnimationTest::SetupTree(); | 607 LayerTreeHostTimelinesTest::SetupTree(); |
| 777 | 608 |
| 778 scroll_layer_ = FakePictureLayer::Create(&client_); | 609 scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 779 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); | 610 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); |
| 780 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); | 611 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); |
| 781 client_.set_bounds(scroll_layer_->bounds()); | 612 client_.set_bounds(scroll_layer_->bounds()); |
| 782 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(100.0, 200.0)); | 613 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(100.0, 200.0)); |
| 783 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | 614 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 784 | 615 |
| 785 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 616 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| 786 ScrollOffsetAnimationCurve::Create(gfx::ScrollOffset(6500.f, 7500.f), | 617 ScrollOffsetAnimationCurve::Create(gfx::ScrollOffset(6500.f, 7500.f), |
| 787 EaseInOutTimingFunction::Create())); | 618 EaseInOutTimingFunction::Create())); |
| 788 scoped_ptr<Animation> animation(Animation::Create( | 619 scoped_ptr<Animation> animation(Animation::Create( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 827 host_impl->BlockNotifyReadyToActivateForTesting(false); | 658 host_impl->BlockNotifyReadyToActivateForTesting(false); |
| 828 return; | 659 return; |
| 829 } | 660 } |
| 830 | 661 |
| 831 scoped_refptr<AnimationTimeline> timeline_impl = | 662 scoped_refptr<AnimationTimeline> timeline_impl = |
| 832 host_impl->animation_host()->GetTimelineById(timeline_id_); | 663 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 833 scoped_refptr<AnimationPlayer> player_impl = | 664 scoped_refptr<AnimationPlayer> player_impl = |
| 834 timeline_impl->GetPlayerById(player_child_id_); | 665 timeline_impl->GetPlayerById(player_child_id_); |
| 835 | 666 |
| 836 LayerImpl* scroll_layer_impl = | 667 LayerImpl* scroll_layer_impl = |
| 837 host_impl->active_tree()->root_layer()->children()[0].get(); | 668 host_impl->active_tree()->root_layer()->children()[0]; |
| 838 Animation* animation = player_impl->element_animations() | 669 Animation* animation = player_impl->element_animations() |
| 839 ->layer_animation_controller() | 670 ->layer_animation_controller() |
| 840 ->GetAnimation(TargetProperty::SCROLL_OFFSET); | 671 ->GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 841 | 672 |
| 842 if (!animation || animation->run_state() != Animation::RUNNING) { | 673 if (!animation || animation->run_state() != Animation::RUNNING) { |
| 843 host_impl->BlockNotifyReadyToActivateForTesting(false); | 674 host_impl->BlockNotifyReadyToActivateForTesting(false); |
| 844 return; | 675 return; |
| 845 } | 676 } |
| 846 | 677 |
| 847 // Block activation until the running animation has a chance to produce a | 678 // Block activation until the running animation has a chance to produce a |
| 848 // scroll delta. | 679 // scroll delta. |
| 849 gfx::Vector2dF scroll_delta = ScrollDelta(scroll_layer_impl); | 680 gfx::Vector2dF scroll_delta = scroll_layer_impl->ScrollDelta(); |
| 850 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) | 681 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) |
| 851 return; | 682 return; |
| 852 | 683 |
| 853 host_impl->BlockNotifyReadyToActivateForTesting(false); | 684 host_impl->BlockNotifyReadyToActivateForTesting(false); |
| 854 } | 685 } |
| 855 | 686 |
| 856 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 687 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 857 if (host_impl->pending_tree()->source_frame_number() != 1) | 688 if (host_impl->pending_tree()->source_frame_number() != 1) |
| 858 return; | 689 return; |
| 859 LayerImpl* scroll_layer_impl = | 690 LayerImpl* scroll_layer_impl = |
| 860 host_impl->pending_tree()->root_layer()->children()[0].get(); | 691 host_impl->pending_tree()->root_layer()->children()[0]; |
| 861 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); | 692 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); |
| 862 } | 693 } |
| 863 | 694 |
| 864 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 695 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 865 if (host_impl->active_tree()->source_frame_number() != 1) | 696 if (host_impl->active_tree()->source_frame_number() != 1) |
| 866 return; | 697 return; |
| 867 LayerImpl* scroll_layer_impl = | 698 LayerImpl* scroll_layer_impl = |
| 868 host_impl->active_tree()->root_layer()->children()[0].get(); | 699 host_impl->active_tree()->root_layer()->children()[0]; |
| 869 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); | 700 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); |
| 870 EndTest(); | 701 EndTest(); |
| 871 } | 702 } |
| 872 | 703 |
| 873 void AfterTest() override { | 704 void AfterTest() override { |
| 874 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); | 705 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); |
| 875 } | 706 } |
| 876 | 707 |
| 877 private: | 708 private: |
| 878 FakeContentLayerClient client_; | 709 FakeContentLayerClient client_; |
| 879 scoped_refptr<FakePictureLayer> scroll_layer_; | 710 scoped_refptr<FakePictureLayer> scroll_layer_; |
| 880 const gfx::ScrollOffset final_postion_; | 711 const gfx::ScrollOffset final_postion_; |
| 881 }; | 712 }; |
| 882 | 713 |
| 883 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationRemoval); | 714 MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestScrollOffsetAnimationRemoval); |
| 884 | 715 |
| 885 // When animations are simultaneously added to an existing layer and to a new | 716 // When animations are simultaneously added to an existing layer and to a new |
| 886 // layer, they should start at the same time, even when there's already a | 717 // layer, they should start at the same time, even when there's already a |
| 887 // running animation on the existing layer. | 718 // running animation on the existing layer. |
| 888 class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers | 719 // Evolved from LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers. |
| 889 : public LayerTreeHostAnimationTest { | 720 class LayerTreeHostTimelinesTestAnimationsAddedToNewAndExistingLayers |
| 721 : public LayerTreeHostTimelinesTest { | |
| 890 public: | 722 public: |
| 891 LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers() | 723 LayerTreeHostTimelinesTestAnimationsAddedToNewAndExistingLayers() |
| 892 : frame_count_with_pending_tree_(0) {} | 724 : frame_count_with_pending_tree_(0) {} |
| 893 | 725 |
| 894 void BeginTest() override { | 726 void BeginTest() override { |
| 895 AttachPlayersToTimeline(); | 727 AttachPlayersToTimeline(); |
| 896 PostSetNeedsCommitToMainThread(); | 728 PostSetNeedsCommitToMainThread(); |
| 897 } | 729 } |
| 898 | 730 |
| 899 void DidCommit() override { | 731 void DidCommit() override { |
| 900 if (layer_tree_host()->source_frame_number() == 1) { | 732 if (layer_tree_host()->source_frame_number() == 1) { |
| 901 player_->AttachLayer(layer_tree_host()->root_layer()->id()); | 733 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 902 AddAnimatedTransformToPlayer(player_.get(), 4, 1, 1); | 734 AddAnimatedTransformToPlayer(player_.get(), 4, 1, 1); |
| 903 } else if (layer_tree_host()->source_frame_number() == 2) { | 735 } else if (layer_tree_host()->source_frame_number() == 2) { |
| 904 AddOpacityTransitionToPlayer(player_.get(), 1, 0.f, 0.5f, true); | 736 AddOpacityTransitionToPlayer(player_.get(), 1, 0.f, 0.5f, true); |
| 905 | 737 |
| 906 scoped_refptr<Layer> layer = Layer::Create(); | 738 scoped_refptr<Layer> layer = Layer::Create(layer_settings()); |
| 907 layer_tree_host()->root_layer()->AddChild(layer); | 739 layer_tree_host()->root_layer()->AddChild(layer); |
| 908 layer->SetBounds(gfx::Size(4, 4)); | 740 layer->SetBounds(gfx::Size(4, 4)); |
| 909 | 741 |
| 910 player_child_->AttachLayer(layer->id()); | 742 player_child_->AttachLayer(layer->id()); |
| 911 player_child_->set_layer_animation_delegate(this); | 743 player_child_->set_layer_animation_delegate(this); |
| 912 AddOpacityTransitionToPlayer(player_child_.get(), 1, 0.f, 0.5f, true); | 744 AddOpacityTransitionToPlayer(player_child_.get(), 1, 0.f, 0.5f, true); |
| 913 } | 745 } |
| 914 } | 746 } |
| 915 | 747 |
| 916 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { | 748 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 972 } | 804 } |
| 973 | 805 |
| 974 void AfterTest() override {} | 806 void AfterTest() override {} |
| 975 | 807 |
| 976 private: | 808 private: |
| 977 int frame_count_with_pending_tree_; | 809 int frame_count_with_pending_tree_; |
| 978 }; | 810 }; |
| 979 | 811 |
| 980 // This test blocks activation which is not supported for single thread mode. | 812 // This test blocks activation which is not supported for single thread mode. |
| 981 MULTI_THREAD_BLOCKNOTIFY_TEST_F( | 813 MULTI_THREAD_BLOCKNOTIFY_TEST_F( |
| 982 LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers); | 814 LayerTreeHostTimelinesTestAnimationsAddedToNewAndExistingLayers); |
| 983 | 815 |
| 984 class LayerTreeHostAnimationTestPendingTreeAnimatesFirstCommit | 816 // Evolved from LayerTreeHostAnimationTestAddAnimationAfterAnimating. |
| 985 : public LayerTreeHostAnimationTest { | 817 class LayerTreeHostTimelinesTestAddAnimationAfterAnimating |
| 818 : public LayerTreeHostTimelinesTest { | |
| 986 public: | 819 public: |
| 987 void SetupTree() override { | 820 void SetupTree() override { |
| 988 LayerTreeHostAnimationTest::SetupTree(); | 821 LayerTreeHostTimelinesTest::SetupTree(); |
| 989 | 822 content_ = Layer::Create(layer_settings()); |
| 990 layer_ = FakePictureLayer::Create(&client_); | 823 content_->SetBounds(gfx::Size(4, 4)); |
| 991 layer_->SetBounds(gfx::Size(2, 2)); | 824 layer_tree_host()->root_layer()->AddChild(content_); |
| 992 client_.set_bounds(layer_->bounds()); | |
| 993 // Transform the layer to 4,4 to start. | |
| 994 gfx::Transform start_transform; | |
| 995 start_transform.Translate(4.0, 4.0); | |
| 996 layer_->SetTransform(start_transform); | |
| 997 | |
| 998 layer_tree_host()->root_layer()->AddChild(layer_); | |
| 999 player_->AttachLayer(layer_->id()); | |
| 1000 | 825 |
| 1001 AttachPlayersToTimeline(); | 826 AttachPlayersToTimeline(); |
| 1002 } | |
| 1003 | 827 |
| 1004 void BeginTest() override { | 828 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 1005 // Add a translate from 6,7 to 8,9. | 829 player_child_->AttachLayer(content_->id()); |
| 1006 TransformOperations start; | |
| 1007 start.AppendTranslate(6.f, 7.f, 0.f); | |
| 1008 TransformOperations end; | |
| 1009 end.AppendTranslate(8.f, 9.f, 0.f); | |
| 1010 AddAnimatedTransformToPlayer(player_.get(), 4.0, start, end); | |
| 1011 | |
| 1012 PostSetNeedsCommitToMainThread(); | |
| 1013 } | |
| 1014 | |
| 1015 void WillPrepareTiles(LayerTreeHostImpl* host_impl) override { | |
| 1016 if (host_impl->sync_tree()->source_frame_number() != 0) | |
| 1017 return; | |
| 1018 | |
| 1019 // After checking this on the sync tree, we will activate, which will cause | |
| 1020 // PrepareTiles to happen again (which races with the test exiting). | |
| 1021 if (TestEnded()) | |
| 1022 return; | |
| 1023 | |
| 1024 scoped_refptr<AnimationTimeline> timeline_impl = | |
| 1025 host_impl->animation_host()->GetTimelineById(timeline_id_); | |
| 1026 scoped_refptr<AnimationPlayer> player_impl = | |
| 1027 timeline_impl->GetPlayerById(player_id_); | |
| 1028 | |
| 1029 LayerAnimationController* controller_impl = | |
| 1030 player_impl->element_animations()->layer_animation_controller(); | |
| 1031 | |
| 1032 LayerImpl* root = host_impl->sync_tree()->root_layer(); | |
| 1033 LayerImpl* child = root->children()[0].get(); | |
| 1034 Animation* animation = | |
| 1035 controller_impl->GetAnimation(TargetProperty::TRANSFORM); | |
| 1036 | |
| 1037 // The animation should be starting for the first frame. | |
| 1038 EXPECT_EQ(Animation::STARTING, animation->run_state()); | |
| 1039 | |
| 1040 // And the transform should be propogated to the sync tree layer, at its | |
| 1041 // starting state which is 6,7. | |
| 1042 gfx::Transform expected_transform; | |
| 1043 expected_transform.Translate(6.0, 7.0); | |
| 1044 EXPECT_EQ(expected_transform, child->DrawTransform()); | |
| 1045 // And the sync tree layer should know it is animating. | |
| 1046 EXPECT_TRUE(child->screen_space_transform_is_animating()); | |
| 1047 | |
| 1048 controller_impl->AbortAnimations(TargetProperty::TRANSFORM); | |
| 1049 EndTest(); | |
| 1050 } | |
| 1051 | |
| 1052 void AfterTest() override {} | |
| 1053 | |
| 1054 FakeContentLayerClient client_; | |
| 1055 scoped_refptr<Layer> layer_; | |
| 1056 }; | |
| 1057 | |
| 1058 SINGLE_AND_MULTI_THREAD_TEST_F( | |
| 1059 LayerTreeHostAnimationTestPendingTreeAnimatesFirstCommit); | |
| 1060 | |
| 1061 // When a layer with an animation is removed from the tree and later re-added, | |
| 1062 // the animation should resume. | |
| 1063 class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded | |
| 1064 : public LayerTreeHostAnimationTest { | |
| 1065 public: | |
| 1066 void SetupTree() override { | |
| 1067 LayerTreeHostAnimationTest::SetupTree(); | |
| 1068 layer_ = Layer::Create(); | |
| 1069 layer_->SetBounds(gfx::Size(4, 4)); | |
| 1070 layer_tree_host()->root_layer()->AddChild(layer_); | |
| 1071 | |
| 1072 layer_tree_host()->animation_host()->AddAnimationTimeline(timeline_.get()); | |
| 1073 timeline_->AttachPlayer(player_.get()); | |
| 1074 player_->AttachLayer(layer_->id()); | |
| 1075 DCHECK(player_->element_animations()); | |
| 1076 | |
| 1077 AddOpacityTransitionToPlayer(player_.get(), 10000.0, 0.1f, 0.9f, true); | |
| 1078 } | 830 } |
| 1079 | 831 |
| 1080 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 832 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1081 | 833 |
| 1082 void DidCommit() override { | 834 void DidCommit() override { |
| 1083 switch (layer_tree_host()->source_frame_number()) { | 835 switch (layer_tree_host()->source_frame_number()) { |
| 1084 case 0: | |
| 1085 EXPECT_TRUE(player_->element_animations() | |
| 1086 ->has_active_value_observer_for_testing()); | |
| 1087 EXPECT_FALSE(player_->element_animations() | |
| 1088 ->has_pending_value_observer_for_testing()); | |
| 1089 EXPECT_TRUE(layer_tree_host() | |
| 1090 ->animation_host() | |
| 1091 ->animation_registrar() | |
| 1092 ->needs_animate_layers()); | |
| 1093 break; | |
| 1094 case 1: | 836 case 1: |
| 1095 layer_->RemoveFromParent(); | 837 // First frame: add an animation to the root layer. |
| 1096 EXPECT_FALSE(player_->element_animations() | 838 AddAnimatedTransformToPlayer(player_.get(), 0.1, 5, 5); |
| 1097 ->has_active_value_observer_for_testing()); | |
| 1098 EXPECT_FALSE(player_->element_animations() | |
| 1099 ->has_pending_value_observer_for_testing()); | |
| 1100 EXPECT_TRUE(layer_tree_host() | |
| 1101 ->animation_host() | |
| 1102 ->animation_registrar() | |
| 1103 ->needs_animate_layers()); | |
| 1104 break; | 839 break; |
| 1105 case 2: | 840 case 2: |
| 1106 layer_tree_host()->root_layer()->AddChild(layer_); | 841 // Second frame: add an animation to the content layer. The root layer |
| 1107 EXPECT_TRUE(player_->element_animations() | 842 // animation has caused us to animate already during this frame. |
| 1108 ->has_active_value_observer_for_testing()); | 843 AddOpacityTransitionToPlayer(player_child_.get(), 0.1, 5, 5, false); |
| 1109 EXPECT_FALSE(player_->element_animations() | |
| 1110 ->has_pending_value_observer_for_testing()); | |
| 1111 EXPECT_TRUE(layer_tree_host() | |
| 1112 ->animation_host() | |
| 1113 ->animation_registrar() | |
| 1114 ->needs_animate_layers()); | |
| 1115 break; | 844 break; |
| 1116 } | 845 } |
| 1117 } | 846 } |
| 1118 | 847 |
| 1119 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 848 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
| 1120 scoped_refptr<AnimationTimeline> timeline_impl = | 849 // After both animations have started, verify that they have valid |
| 1121 host_impl->animation_host()->GetTimelineById(timeline_id_); | 850 // start times. |
| 1122 scoped_refptr<AnimationPlayer> player_impl = | 851 if (host_impl->active_tree()->source_frame_number() < 2) |
| 1123 timeline_impl->GetPlayerById(player_id_); | 852 return; |
| 1124 | 853 AnimationRegistrar::AnimationControllerMap controllers_copy = |
| 1125 switch (host_impl->active_tree()->source_frame_number()) { | 854 host_impl->animation_host() |
| 1126 case 0: | 855 ->animation_registrar() |
| 1127 EXPECT_TRUE(player_impl->element_animations() | 856 ->active_animation_controllers_for_testing(); |
| 1128 ->has_active_value_observer_for_testing()); | 857 EXPECT_EQ(2u, controllers_copy.size()); |
| 1129 EXPECT_TRUE(host_impl->animation_host() | 858 for (auto& it : controllers_copy) { |
| 1130 ->animation_registrar() | 859 int id = it.first; |
| 1131 ->needs_animate_layers()); | 860 if (id == host_impl->RootLayer()->id()) { |
| 1132 break; | 861 Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM); |
| 1133 case 1: | 862 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| 1134 EXPECT_FALSE(player_impl->element_animations() | 863 } else if (id == host_impl->RootLayer()->children()[0]->id()) { |
| 1135 ->has_active_value_observer_for_testing()); | 864 Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY); |
| 1136 EXPECT_TRUE(host_impl->animation_host() | 865 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| 1137 ->animation_registrar() | 866 } |
| 1138 ->needs_animate_layers()); | 867 EndTest(); |
| 1139 break; | |
| 1140 case 2: | |
| 1141 EXPECT_TRUE(player_impl->element_animations() | |
| 1142 ->has_active_value_observer_for_testing()); | |
| 1143 EXPECT_TRUE(host_impl->animation_host() | |
| 1144 ->animation_registrar() | |
| 1145 ->needs_animate_layers()); | |
| 1146 EndTest(); | |
| 1147 break; | |
| 1148 } | 868 } |
| 1149 } | 869 } |
| 1150 | 870 |
| 1151 void AfterTest() override {} | 871 void AfterTest() override {} |
| 1152 | 872 |
| 1153 private: | 873 private: |
| 1154 scoped_refptr<Layer> layer_; | 874 scoped_refptr<Layer> content_; |
| 1155 }; | 875 }; |
| 1156 | 876 |
| 1157 SINGLE_AND_MULTI_THREAD_TEST_F( | 877 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1158 LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded); | 878 LayerTreeHostTimelinesTestAddAnimationAfterAnimating); |
| 1159 | 879 |
| 1160 class LayerTreeHostAnimationTestAddAnimationAfterAnimating | 880 class LayerTreeHostTimelinesTestRemoveAnimation |
| 1161 : public LayerTreeHostAnimationTest { | 881 : public LayerTreeHostTimelinesTest { |
| 1162 public: | 882 public: |
| 1163 void SetupTree() override { | 883 void SetupTree() override { |
| 1164 LayerTreeHostAnimationTest::SetupTree(); | 884 LayerTreeHostTimelinesTest::SetupTree(); |
| 1165 layer_ = Layer::Create(); | 885 layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 1166 layer_->SetBounds(gfx::Size(4, 4)); | 886 layer_->SetBounds(gfx::Size(4, 4)); |
| 887 client_.set_bounds(layer_->bounds()); | |
| 1167 layer_tree_host()->root_layer()->AddChild(layer_); | 888 layer_tree_host()->root_layer()->AddChild(layer_); |
| 1168 | 889 |
| 1169 AttachPlayersToTimeline(); | 890 AttachPlayersToTimeline(); |
| 891 | |
| 892 player_->AttachLayer(layer_tree_host()->root_layer()->id()); | |
| 893 player_child_->AttachLayer(layer_->id()); | |
| 894 } | |
| 895 | |
| 896 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 897 | |
| 898 void DidCommit() override { | |
| 899 switch (layer_tree_host()->source_frame_number()) { | |
| 900 case 1: | |
| 901 AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); | |
| 902 break; | |
| 903 case 2: | |
| 904 LayerAnimationController* controller = | |
| 905 player_child_->element_animations()->layer_animation_controller(); | |
| 906 Animation* animation = | |
| 907 controller->GetAnimation(TargetProperty::TRANSFORM); | |
| 908 player_child_->RemoveAnimation(animation->id()); | |
| 909 gfx::Transform transform; | |
| 910 transform.Translate(10.f, 10.f); | |
| 911 layer_->SetTransform(transform); | |
| 912 | |
| 913 // Do something that causes property trees to get rebuilt. | |
| 914 layer_->AddChild(Layer::Create(layer_settings())); | |
| 915 break; | |
| 916 } | |
| 917 } | |
| 918 | |
| 919 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | |
| 920 if (host_impl->active_tree()->source_frame_number() < 2) | |
| 921 return; | |
| 922 gfx::Transform expected_transform; | |
| 923 expected_transform.Translate(10.f, 10.f); | |
| 924 EXPECT_EQ( | |
| 925 expected_transform, | |
| 926 host_impl->active_tree()->root_layer()->children()[0]->DrawTransform()); | |
| 927 EndTest(); | |
| 928 } | |
| 929 | |
| 930 void AfterTest() override {} | |
| 931 | |
| 932 private: | |
| 933 scoped_refptr<Layer> layer_; | |
| 934 FakeContentLayerClient client_; | |
| 935 }; | |
| 936 | |
| 937 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestRemoveAnimation); | |
| 938 | |
| 939 class LayerTreeHostTimelinesTestAnimationFinishesDuringCommit | |
| 940 : public LayerTreeHostTimelinesTest { | |
| 941 public: | |
| 942 void SetupTree() override { | |
| 943 LayerTreeHostTimelinesTest::SetupTree(); | |
| 944 layer_ = FakePictureLayer::Create(layer_settings(), &client_); | |
| 945 layer_->SetBounds(gfx::Size(4, 4)); | |
| 946 client_.set_bounds(layer_->bounds()); | |
| 947 layer_tree_host()->root_layer()->AddChild(layer_); | |
| 948 | |
| 949 AttachPlayersToTimeline(); | |
| 1170 | 950 |
| 1171 player_->AttachLayer(layer_tree_host()->root_layer()->id()); | 951 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 1172 player_child_->AttachLayer(layer_->id()); | 952 player_child_->AttachLayer(layer_->id()); |
| 1173 } | 953 } |
| 1174 | 954 |
| 1175 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 955 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1176 | 956 |
| 1177 void DidCommit() override { | 957 void DidCommit() override { |
| 1178 switch (layer_tree_host()->source_frame_number()) { | 958 if (layer_tree_host()->source_frame_number() == 1) |
| 959 AddAnimatedTransformToPlayer(player_child_.get(), 0.04, 5, 5); | |
| 960 } | |
| 961 | |
| 962 void WillCommit() override { | |
| 963 if (layer_tree_host()->source_frame_number() == 2) { | |
| 964 // Block until the animation finishes on the compositor thread. Since | |
| 965 // animations have already been ticked on the main thread, when the commit | |
| 966 // happens the state on the main thread will be consistent with having a | |
| 967 // running animation but the state on the compositor thread will be | |
| 968 // consistent with having only a finished animation. | |
| 969 completion_.Wait(); | |
| 970 } | |
| 971 } | |
| 972 | |
| 973 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | |
| 974 switch (host_impl->sync_tree()->source_frame_number()) { | |
| 1179 case 1: | 975 case 1: |
| 1180 // First frame: add an animation to the root layer. | 976 PostSetNeedsCommitToMainThread(); |
| 1181 AddAnimatedTransformToPlayer(player_.get(), 0.1, 5, 5); | |
| 1182 break; | 977 break; |
| 1183 case 2: | 978 case 2: |
| 1184 // Second frame: add an animation to the content layer. The root layer | 979 gfx::Transform expected_transform; |
| 1185 // animation has caused us to animate already during this frame. | 980 expected_transform.Translate(5.f, 5.f); |
| 1186 AddOpacityTransitionToPlayer(player_child_.get(), 0.1, 5, 5, false); | 981 LayerImpl* layer_impl = |
| 982 host_impl->sync_tree()->root_layer()->children()[0]; | |
| 983 EXPECT_EQ(expected_transform, layer_impl->DrawTransform()); | |
| 984 EndTest(); | |
| 1187 break; | 985 break; |
| 1188 } | 986 } |
| 1189 } | 987 } |
| 1190 | 988 |
| 1191 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { | 989 void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
| 1192 // After both animations have started, verify that they have valid | 990 bool has_unfinished_animation) override { |
| 1193 // start times. | 991 if (host_impl->active_tree()->source_frame_number() == 1 && |
| 1194 if (host_impl->active_tree()->source_frame_number() < 2) | 992 !has_unfinished_animation) { |
| 1195 return; | 993 // The animation has finished, so allow the main thread to commit. |
| 1196 AnimationRegistrar::AnimationControllerMap controllers_copy = | 994 completion_.Signal(); |
| 1197 host_impl->animation_host() | |
| 1198 ->animation_registrar() | |
| 1199 ->active_animation_controllers_for_testing(); | |
| 1200 EXPECT_EQ(2u, controllers_copy.size()); | |
| 1201 for (auto& it : controllers_copy) { | |
| 1202 int id = it.first; | |
| 1203 if (id == host_impl->RootLayer()->id()) { | |
| 1204 Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM); | |
| 1205 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | |
| 1206 } else if (id == host_impl->RootLayer()->children()[0]->id()) { | |
| 1207 Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY); | |
| 1208 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | |
| 1209 } | |
| 1210 EndTest(); | |
| 1211 } | 995 } |
| 1212 } | 996 } |
| 1213 | 997 |
| 1214 void AfterTest() override {} | 998 void AfterTest() override {} |
| 1215 | 999 |
| 1216 private: | 1000 private: |
| 1217 scoped_refptr<Layer> layer_; | 1001 scoped_refptr<Layer> layer_; |
| 1002 FakeContentLayerClient client_; | |
| 1003 CompletionEvent completion_; | |
| 1218 }; | 1004 }; |
| 1219 | 1005 |
| 1220 SINGLE_AND_MULTI_THREAD_TEST_F( | 1006 // An animation finishing during commit can only happen when we have a separate |
| 1221 LayerTreeHostAnimationTestAddAnimationAfterAnimating); | 1007 // compositor thread. |
| 1008 MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestAnimationFinishesDuringCommit); | |
| 1222 | 1009 |
| 1223 class LayerTreeHostAnimationTestRemoveAnimation | 1010 // Check that SetTransformIsPotentiallyAnimatingChanged is called |
| 1224 : public LayerTreeHostAnimationTest { | 1011 // if we destroy LayerAnimationController and ElementAnimations. |
| 1012 class LayerTreeHostTimelinesTestSetPotentiallyAnimatingOnLacDestruction | |
| 1013 : public LayerTreeHostTimelinesTest { | |
| 1225 public: | 1014 public: |
| 1226 void SetupTree() override { | 1015 void SetupTree() override { |
| 1227 LayerTreeHostAnimationTest::SetupTree(); | 1016 prev_screen_space_transform_is_animating_ = true; |
| 1228 layer_ = FakePictureLayer::Create(&client_); | 1017 screen_space_transform_animation_stopped_ = false; |
| 1018 | |
| 1019 LayerTreeHostTimelinesTest::SetupTree(); | |
| 1020 AttachPlayersToTimeline(); | |
| 1021 player_->AttachLayer(layer_tree_host()->root_layer()->id()); | |
| 1022 AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5); | |
| 1023 } | |
| 1024 | |
| 1025 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 1026 | |
| 1027 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | |
| 1028 if (host_impl->pending_tree()->source_frame_number() <= 1) { | |
| 1029 EXPECT_TRUE(host_impl->pending_tree() | |
| 1030 ->root_layer() | |
| 1031 ->screen_space_transform_is_animating()); | |
| 1032 } else { | |
| 1033 EXPECT_FALSE(host_impl->pending_tree() | |
| 1034 ->root_layer() | |
| 1035 ->screen_space_transform_is_animating()); | |
| 1036 } | |
| 1037 } | |
| 1038 | |
| 1039 void DidCommit() override { PostSetNeedsCommitToMainThread(); } | |
| 1040 | |
| 1041 void UpdateLayerTreeHost() override { | |
| 1042 if (layer_tree_host()->source_frame_number() == 2) { | |
| 1043 // Destroy player. | |
| 1044 timeline_->DetachPlayer(player_.get()); | |
| 1045 player_ = nullptr; | |
| 1046 } | |
| 1047 } | |
| 1048 | |
| 1049 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | |
| 1050 LayerTreeHostImpl::FrameData* frame_data, | |
| 1051 DrawResult draw_result) override { | |
| 1052 const bool screen_space_transform_is_animating = | |
| 1053 host_impl->active_tree() | |
| 1054 ->root_layer() | |
| 1055 ->screen_space_transform_is_animating(); | |
| 1056 | |
| 1057 // Check that screen_space_transform_is_animating changes only once. | |
| 1058 if (screen_space_transform_is_animating && | |
| 1059 prev_screen_space_transform_is_animating_) | |
| 1060 EXPECT_FALSE(screen_space_transform_animation_stopped_); | |
| 1061 if (!screen_space_transform_is_animating && | |
| 1062 prev_screen_space_transform_is_animating_) { | |
| 1063 EXPECT_FALSE(screen_space_transform_animation_stopped_); | |
| 1064 screen_space_transform_animation_stopped_ = true; | |
| 1065 } | |
| 1066 if (!screen_space_transform_is_animating && | |
| 1067 !prev_screen_space_transform_is_animating_) | |
| 1068 EXPECT_TRUE(screen_space_transform_animation_stopped_); | |
| 1069 | |
| 1070 prev_screen_space_transform_is_animating_ = | |
| 1071 screen_space_transform_is_animating; | |
| 1072 | |
| 1073 return draw_result; | |
| 1074 } | |
| 1075 | |
| 1076 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | |
| 1077 if (host_impl->active_tree()->source_frame_number() >= 2) | |
| 1078 EndTest(); | |
| 1079 } | |
| 1080 | |
| 1081 void AfterTest() override { | |
| 1082 EXPECT_TRUE(screen_space_transform_animation_stopped_); | |
| 1083 } | |
| 1084 | |
| 1085 bool prev_screen_space_transform_is_animating_; | |
| 1086 bool screen_space_transform_animation_stopped_; | |
| 1087 }; | |
| 1088 | |
| 1089 MULTI_THREAD_TEST_F( | |
| 1090 LayerTreeHostTimelinesTestSetPotentiallyAnimatingOnLacDestruction); | |
| 1091 | |
| 1092 // Check that we invalidate property trees on AnimationPlayer::SetNeedsCommit. | |
| 1093 class LayerTreeHostTimelinesTestRebuildPropertyTreesOnAnimationSetNeedsCommit | |
| 1094 : public LayerTreeHostTimelinesTest { | |
| 1095 public: | |
| 1096 void SetupTree() override { | |
| 1097 LayerTreeHostTimelinesTest::SetupTree(); | |
| 1098 layer_ = FakePictureLayer::Create(layer_settings(), &client_); | |
| 1229 layer_->SetBounds(gfx::Size(4, 4)); | 1099 layer_->SetBounds(gfx::Size(4, 4)); |
| 1230 client_.set_bounds(layer_->bounds()); | 1100 client_.set_bounds(layer_->bounds()); |
| 1231 layer_tree_host()->root_layer()->AddChild(layer_); | 1101 layer_tree_host()->root_layer()->AddChild(layer_); |
| 1232 | 1102 |
| 1233 AttachPlayersToTimeline(); | 1103 AttachPlayersToTimeline(); |
| 1234 | 1104 |
| 1235 player_->AttachLayer(layer_tree_host()->root_layer()->id()); | 1105 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 1236 player_child_->AttachLayer(layer_->id()); | 1106 player_child_->AttachLayer(layer_->id()); |
| 1237 } | 1107 } |
| 1238 | 1108 |
| 1239 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1109 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1240 | 1110 |
| 1241 void DidCommit() override { | 1111 void DidCommit() override { |
| 1112 if (layer_tree_host()->source_frame_number() == 1 || | |
| 1113 layer_tree_host()->source_frame_number() == 2) | |
| 1114 PostSetNeedsCommitToMainThread(); | |
| 1115 } | |
| 1116 | |
| 1117 void UpdateLayerTreeHost() override { | |
| 1118 if (layer_tree_host()->source_frame_number() == 1) { | |
| 1119 EXPECT_FALSE(layer_tree_host()->property_trees()->needs_rebuild); | |
| 1120 AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); | |
| 1121 } | |
| 1122 | |
| 1123 EXPECT_TRUE(layer_tree_host()->property_trees()->needs_rebuild); | |
| 1124 } | |
| 1125 | |
| 1126 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | |
| 1127 if (host_impl->active_tree()->source_frame_number() >= 2) | |
| 1128 EndTest(); | |
| 1129 } | |
| 1130 | |
| 1131 void AfterTest() override {} | |
| 1132 | |
| 1133 private: | |
| 1134 scoped_refptr<Layer> layer_; | |
| 1135 FakeContentLayerClient client_; | |
| 1136 }; | |
| 1137 | |
| 1138 MULTI_THREAD_TEST_F( | |
| 1139 LayerTreeHostTimelinesTestRebuildPropertyTreesOnAnimationSetNeedsCommit); | |
| 1140 | |
| 1141 class LayerTreeHostTimelinesTestPendingTreeAnimatesFirstCommit | |
| 1142 : public LayerTreeHostTimelinesTest { | |
| 1143 public: | |
| 1144 void SetupTree() override { | |
| 1145 LayerTreeHostTimelinesTest::SetupTree(); | |
| 1146 | |
| 1147 layer_ = FakePictureLayer::Create(layer_settings(), &client_); | |
| 1148 layer_->SetBounds(gfx::Size(2, 2)); | |
| 1149 client_.set_bounds(layer_->bounds()); | |
| 1150 // Transform the layer to 4,4 to start. | |
| 1151 gfx::Transform start_transform; | |
| 1152 start_transform.Translate(4.0, 4.0); | |
| 1153 layer_->SetTransform(start_transform); | |
| 1154 | |
| 1155 layer_tree_host()->root_layer()->AddChild(layer_); | |
| 1156 player_->AttachLayer(layer_->id()); | |
| 1157 | |
| 1158 AttachPlayersToTimeline(); | |
| 1159 } | |
| 1160 | |
| 1161 void BeginTest() override { | |
| 1162 // Add a translate from 6,7 to 8,9. | |
| 1163 TransformOperations start; | |
| 1164 start.AppendTranslate(6.f, 7.f, 0.f); | |
| 1165 TransformOperations end; | |
| 1166 end.AppendTranslate(8.f, 9.f, 0.f); | |
| 1167 AddAnimatedTransformToPlayer(player_.get(), 4.0, start, end); | |
| 1168 | |
| 1169 PostSetNeedsCommitToMainThread(); | |
| 1170 } | |
| 1171 | |
| 1172 void WillPrepareTiles(LayerTreeHostImpl* host_impl) override { | |
| 1173 if (host_impl->sync_tree()->source_frame_number() != 0) | |
| 1174 return; | |
| 1175 | |
| 1176 // After checking this on the sync tree, we will activate, which will cause | |
| 1177 // PrepareTiles to happen again (which races with the test exiting). | |
| 1178 if (TestEnded()) | |
| 1179 return; | |
| 1180 | |
| 1181 scoped_refptr<AnimationTimeline> timeline_impl = | |
| 1182 host_impl->animation_host()->GetTimelineById(timeline_id_); | |
| 1183 scoped_refptr<AnimationPlayer> player_impl = | |
| 1184 timeline_impl->GetPlayerById(player_id_); | |
| 1185 | |
| 1186 LayerAnimationController* controller_impl = | |
| 1187 player_impl->element_animations()->layer_animation_controller(); | |
| 1188 | |
| 1189 LayerImpl* root = host_impl->sync_tree()->root_layer(); | |
| 1190 LayerImpl* child = root->children()[0]; | |
| 1191 Animation* animation = | |
| 1192 controller_impl->GetAnimation(TargetProperty::TRANSFORM); | |
| 1193 | |
| 1194 // The animation should be starting for the first frame. | |
| 1195 EXPECT_EQ(Animation::STARTING, animation->run_state()); | |
| 1196 | |
| 1197 // And the transform should be propogated to the sync tree layer, at its | |
| 1198 // starting state which is 6,7. | |
| 1199 gfx::Transform expected_transform; | |
| 1200 expected_transform.Translate(6.0, 7.0); | |
| 1201 EXPECT_EQ(expected_transform, child->DrawTransform()); | |
| 1202 // And the sync tree layer should know it is animating. | |
| 1203 EXPECT_TRUE(child->screen_space_transform_is_animating()); | |
| 1204 | |
| 1205 controller_impl->AbortAnimations(TargetProperty::TRANSFORM); | |
| 1206 EndTest(); | |
| 1207 } | |
| 1208 | |
| 1209 void AfterTest() override {} | |
| 1210 | |
| 1211 FakeContentLayerClient client_; | |
| 1212 scoped_refptr<Layer> layer_; | |
| 1213 }; | |
| 1214 | |
| 1215 SINGLE_AND_MULTI_THREAD_TEST_F( | |
| 1216 LayerTreeHostTimelinesTestPendingTreeAnimatesFirstCommit); | |
| 1217 | |
| 1218 // When a layer with an animation is removed from the tree and later re-added, | |
| 1219 // the animation should resume. | |
| 1220 class LayerTreeHostTimelinesTestAnimatedLayerRemovedAndAdded | |
| 1221 : public LayerTreeHostTimelinesTest { | |
| 1222 public: | |
| 1223 void SetupTree() override { | |
| 1224 LayerTreeHostTimelinesTest::SetupTree(); | |
| 1225 layer_ = Layer::Create(layer_settings()); | |
| 1226 layer_->SetBounds(gfx::Size(4, 4)); | |
| 1227 layer_tree_host()->root_layer()->AddChild(layer_); | |
| 1228 | |
| 1229 layer_tree_host()->animation_host()->AddAnimationTimeline(timeline_.get()); | |
| 1230 timeline_->AttachPlayer(player_.get()); | |
| 1231 player_->AttachLayer(layer_->id()); | |
| 1232 DCHECK(player_->element_animations()); | |
| 1233 | |
| 1234 AddOpacityTransitionToPlayer(player_.get(), 10000.0, 0.1f, 0.9f, true); | |
| 1235 } | |
| 1236 | |
| 1237 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 1238 | |
| 1239 void DidCommit() override { | |
| 1242 switch (layer_tree_host()->source_frame_number()) { | 1240 switch (layer_tree_host()->source_frame_number()) { |
| 1241 case 0: | |
| 1242 EXPECT_TRUE(player_->element_animations() | |
| 1243 ->has_active_value_observer_for_testing()); | |
| 1244 EXPECT_FALSE(player_->element_animations() | |
| 1245 ->has_pending_value_observer_for_testing()); | |
| 1246 EXPECT_TRUE(layer_tree_host() | |
| 1247 ->animation_host() | |
| 1248 ->animation_registrar() | |
| 1249 ->needs_animate_layers()); | |
| 1250 break; | |
| 1243 case 1: | 1251 case 1: |
| 1244 AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); | 1252 layer_->RemoveFromParent(); |
| 1253 EXPECT_FALSE(player_->element_animations() | |
| 1254 ->has_active_value_observer_for_testing()); | |
| 1255 EXPECT_FALSE(player_->element_animations() | |
| 1256 ->has_pending_value_observer_for_testing()); | |
| 1257 EXPECT_TRUE(layer_tree_host() | |
| 1258 ->animation_host() | |
| 1259 ->animation_registrar() | |
| 1260 ->needs_animate_layers()); | |
| 1245 break; | 1261 break; |
| 1246 case 2: | 1262 case 2: |
| 1247 LayerAnimationController* controller = | 1263 layer_tree_host()->root_layer()->AddChild(layer_); |
| 1248 player_child_->element_animations()->layer_animation_controller(); | 1264 EXPECT_TRUE(player_->element_animations() |
| 1249 Animation* animation = | 1265 ->has_active_value_observer_for_testing()); |
| 1250 controller->GetAnimation(TargetProperty::TRANSFORM); | 1266 EXPECT_FALSE(player_->element_animations() |
| 1251 player_child_->RemoveAnimation(animation->id()); | 1267 ->has_pending_value_observer_for_testing()); |
| 1252 gfx::Transform transform; | 1268 EXPECT_TRUE(layer_tree_host() |
| 1253 transform.Translate(10.f, 10.f); | 1269 ->animation_host() |
| 1254 layer_->SetTransform(transform); | 1270 ->animation_registrar() |
| 1255 | 1271 ->needs_animate_layers()); |
| 1256 // Do something that causes property trees to get rebuilt. This is | |
| 1257 // intended to simulate the conditions that caused the bug whose fix | |
| 1258 // this is testing (the test will pass without it but won't test what | |
| 1259 // we want it to). We were updating the wrong transform node at the end | |
| 1260 // of an animation (we were assuming the layer with the finished | |
| 1261 // animation still had its own transform node). But nodes can only get | |
| 1262 // added/deleted when something triggers a rebuild. Adding a layer | |
| 1263 // triggers a rebuild, and since the layer that had an animation before | |
| 1264 // no longer has one, it doesn't get a transform node in the rebuild. | |
| 1265 layer_->AddChild(Layer::Create()); | |
| 1266 break; | 1272 break; |
| 1267 } | 1273 } |
| 1268 } | 1274 } |
| 1269 | 1275 |
| 1270 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 1276 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 1271 LayerImpl* root = host_impl->active_tree()->root_layer(); | 1277 scoped_refptr<AnimationTimeline> timeline_impl = |
| 1272 LayerImpl* child = root->children()[0].get(); | 1278 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 1279 scoped_refptr<AnimationPlayer> player_impl = | |
| 1280 timeline_impl->GetPlayerById(player_id_); | |
| 1281 | |
| 1273 switch (host_impl->active_tree()->source_frame_number()) { | 1282 switch (host_impl->active_tree()->source_frame_number()) { |
| 1274 case 0: | 1283 case 0: |
| 1275 // No animation yet. | 1284 EXPECT_TRUE(player_impl->element_animations() |
| 1285 ->has_active_value_observer_for_testing()); | |
| 1286 EXPECT_TRUE(host_impl->animation_host() | |
| 1287 ->animation_registrar() | |
| 1288 ->needs_animate_layers()); | |
| 1276 break; | 1289 break; |
| 1277 case 1: | 1290 case 1: |
| 1278 // Animation is started. | 1291 EXPECT_FALSE(player_impl->element_animations() |
| 1279 EXPECT_TRUE(child->screen_space_transform_is_animating()); | 1292 ->has_active_value_observer_for_testing()); |
| 1293 EXPECT_TRUE(host_impl->animation_host() | |
| 1294 ->animation_registrar() | |
| 1295 ->needs_animate_layers()); | |
| 1280 break; | 1296 break; |
| 1281 case 2: { | 1297 case 2: |
| 1282 // The animation is removed, the transform that was set afterward is | 1298 EXPECT_TRUE(player_impl->element_animations() |
| 1283 // applied. | 1299 ->has_active_value_observer_for_testing()); |
| 1284 gfx::Transform expected_transform; | 1300 EXPECT_TRUE(host_impl->animation_host() |
| 1285 expected_transform.Translate(10.f, 10.f); | 1301 ->animation_registrar() |
| 1286 EXPECT_EQ(expected_transform, child->DrawTransform()); | 1302 ->needs_animate_layers()); |
| 1287 EXPECT_FALSE(child->screen_space_transform_is_animating()); | |
| 1288 EndTest(); | 1303 EndTest(); |
| 1289 break; | 1304 break; |
| 1290 } | |
| 1291 default: | |
| 1292 NOTREACHED(); | |
| 1293 } | 1305 } |
| 1294 } | 1306 } |
| 1295 | 1307 |
| 1296 void AfterTest() override {} | 1308 void AfterTest() override {} |
| 1297 | 1309 |
| 1298 private: | 1310 private: |
| 1299 scoped_refptr<Layer> layer_; | 1311 scoped_refptr<Layer> layer_; |
| 1300 FakeContentLayerClient client_; | |
| 1301 }; | 1312 }; |
| 1302 | 1313 |
| 1303 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestRemoveAnimation); | 1314 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1315 LayerTreeHostTimelinesTestAnimatedLayerRemovedAndAdded); | |
| 1304 | 1316 |
| 1305 class LayerTreeHostAnimationTestIsAnimating | 1317 class LayerTreeHostTimelinesTestIsAnimating |
| 1306 : public LayerTreeHostAnimationTest { | 1318 : public LayerTreeHostTimelinesTest { |
| 1307 public: | 1319 public: |
| 1308 void SetupTree() override { | 1320 void SetupTree() override { |
| 1309 LayerTreeHostAnimationTest::SetupTree(); | 1321 LayerTreeHostTimelinesTest::SetupTree(); |
| 1310 layer_ = FakePictureLayer::Create(&client_); | 1322 layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 1311 layer_->SetBounds(gfx::Size(4, 4)); | 1323 layer_->SetBounds(gfx::Size(4, 4)); |
| 1312 client_.set_bounds(layer_->bounds()); | 1324 client_.set_bounds(layer_->bounds()); |
| 1313 layer_tree_host()->root_layer()->AddChild(layer_); | 1325 layer_tree_host()->root_layer()->AddChild(layer_); |
| 1314 | 1326 |
| 1315 AttachPlayersToTimeline(); | 1327 AttachPlayersToTimeline(); |
| 1316 player_->AttachLayer(layer_->id()); | 1328 player_->AttachLayer(layer_->id()); |
| 1317 } | 1329 } |
| 1318 | 1330 |
| 1319 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1331 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1320 | 1332 |
| 1321 void DidCommit() override { | 1333 void DidCommit() override { |
| 1322 switch (layer_tree_host()->source_frame_number()) { | 1334 switch (layer_tree_host()->source_frame_number()) { |
| 1323 case 1: | 1335 case 1: |
| 1324 AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5); | 1336 AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5); |
| 1325 break; | 1337 break; |
| 1326 case 2: | 1338 case 2: |
| 1327 LayerAnimationController* controller = | 1339 LayerAnimationController* controller = |
| 1328 player_->element_animations()->layer_animation_controller(); | 1340 player_->element_animations()->layer_animation_controller(); |
| 1329 Animation* animation = | 1341 Animation* animation = |
| 1330 controller->GetAnimation(TargetProperty::TRANSFORM); | 1342 controller->GetAnimation(TargetProperty::TRANSFORM); |
| 1331 player_->RemoveAnimation(animation->id()); | 1343 player_->RemoveAnimation(animation->id()); |
| 1332 break; | 1344 break; |
| 1333 } | 1345 } |
| 1334 } | 1346 } |
| 1335 | 1347 |
| 1336 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 1348 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 1337 LayerImpl* root = host_impl->sync_tree()->root_layer(); | 1349 LayerImpl* root = host_impl->sync_tree()->root_layer(); |
| 1338 LayerImpl* child = root->children()[0].get(); | 1350 LayerImpl* child = root->children()[0]; |
| 1339 switch (host_impl->sync_tree()->source_frame_number()) { | 1351 switch (host_impl->sync_tree()->source_frame_number()) { |
| 1340 case 0: | 1352 case 0: |
| 1341 // No animation yet. | 1353 // No animation yet. |
| 1342 break; | 1354 break; |
| 1343 case 1: | 1355 case 1: |
| 1344 // Animation is started. | 1356 // Animation is started. |
| 1345 EXPECT_TRUE(child->screen_space_transform_is_animating()); | 1357 EXPECT_TRUE(child->screen_space_transform_is_animating()); |
| 1346 break; | 1358 break; |
| 1347 case 2: | 1359 case 2: |
| 1348 // The animation is removed/stopped. | 1360 // The animation is removed/stopped. |
| 1349 EXPECT_FALSE(child->screen_space_transform_is_animating()); | 1361 EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 1350 EndTest(); | 1362 EndTest(); |
| 1351 break; | 1363 break; |
| 1352 default: | 1364 default: |
| 1353 NOTREACHED(); | 1365 NOTREACHED(); |
| 1354 } | 1366 } |
| 1355 } | 1367 } |
| 1356 | 1368 |
| 1357 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 1369 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 1358 LayerImpl* root = host_impl->active_tree()->root_layer(); | 1370 LayerImpl* root = host_impl->active_tree()->root_layer(); |
| 1359 LayerImpl* child = root->children()[0].get(); | 1371 LayerImpl* child = root->children()[0]; |
| 1360 switch (host_impl->active_tree()->source_frame_number()) { | 1372 switch (host_impl->active_tree()->source_frame_number()) { |
| 1361 case 0: | 1373 case 0: |
| 1362 // No animation yet. | 1374 // No animation yet. |
| 1363 break; | 1375 break; |
| 1364 case 1: | 1376 case 1: |
| 1365 // Animation is started. | 1377 // Animation is started. |
| 1366 EXPECT_TRUE(child->screen_space_transform_is_animating()); | 1378 EXPECT_TRUE(child->screen_space_transform_is_animating()); |
| 1367 break; | 1379 break; |
| 1368 case 2: | 1380 case 2: |
| 1369 // The animation is removed/stopped. | 1381 // The animation is removed/stopped. |
| 1370 EXPECT_FALSE(child->screen_space_transform_is_animating()); | 1382 EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 1371 EndTest(); | 1383 EndTest(); |
| 1372 break; | 1384 break; |
| 1373 default: | 1385 default: |
| 1374 NOTREACHED(); | 1386 NOTREACHED(); |
| 1375 } | 1387 } |
| 1376 } | 1388 } |
| 1377 | 1389 |
| 1378 void AfterTest() override {} | 1390 void AfterTest() override {} |
| 1379 | 1391 |
| 1380 private: | 1392 private: |
| 1381 scoped_refptr<Layer> layer_; | 1393 scoped_refptr<Layer> layer_; |
| 1382 FakeContentLayerClient client_; | 1394 FakeContentLayerClient client_; |
| 1383 }; | 1395 }; |
| 1384 | 1396 |
| 1385 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestIsAnimating); | 1397 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestIsAnimating); |
| 1386 | 1398 |
| 1387 class LayerTreeHostAnimationTestAnimationFinishesDuringCommit | 1399 class LayerTreeHostTimelinesTestNotifyAnimationFinished |
| 1388 : public LayerTreeHostAnimationTest { | 1400 : public LayerTreeHostTimelinesTest { |
| 1389 public: | 1401 public: |
| 1390 LayerTreeHostAnimationTestAnimationFinishesDuringCommit() | 1402 LayerTreeHostTimelinesTestNotifyAnimationFinished() |
| 1391 : signalled_(false) {} | |
| 1392 | |
| 1393 void SetupTree() override { | |
| 1394 LayerTreeHostAnimationTest::SetupTree(); | |
| 1395 layer_ = FakePictureLayer::Create(&client_); | |
| 1396 layer_->SetBounds(gfx::Size(4, 4)); | |
| 1397 client_.set_bounds(layer_->bounds()); | |
| 1398 layer_tree_host()->root_layer()->AddChild(layer_); | |
| 1399 | |
| 1400 AttachPlayersToTimeline(); | |
| 1401 | |
| 1402 player_->AttachLayer(layer_tree_host()->root_layer()->id()); | |
| 1403 player_child_->AttachLayer(layer_->id()); | |
| 1404 } | |
| 1405 | |
| 1406 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 1407 | |
| 1408 void DidCommit() override { | |
| 1409 if (layer_tree_host()->source_frame_number() == 1) | |
| 1410 AddAnimatedTransformToPlayer(player_child_.get(), 0.04, 5, 5); | |
| 1411 } | |
| 1412 | |
| 1413 void WillCommit() override { | |
| 1414 if (layer_tree_host()->source_frame_number() == 2) { | |
| 1415 // Block until the animation finishes on the compositor thread. Since | |
| 1416 // animations have already been ticked on the main thread, when the commit | |
| 1417 // happens the state on the main thread will be consistent with having a | |
| 1418 // running animation but the state on the compositor thread will be | |
| 1419 // consistent with having only a finished animation. | |
| 1420 completion_.Wait(); | |
| 1421 } | |
| 1422 } | |
| 1423 | |
| 1424 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | |
| 1425 switch (host_impl->sync_tree()->source_frame_number()) { | |
| 1426 case 1: | |
| 1427 PostSetNeedsCommitToMainThread(); | |
| 1428 break; | |
| 1429 case 2: | |
| 1430 gfx::Transform expected_transform; | |
| 1431 expected_transform.Translate(5.f, 5.f); | |
| 1432 LayerImpl* layer_impl = | |
| 1433 host_impl->sync_tree()->root_layer()->children()[0].get(); | |
| 1434 EXPECT_EQ(expected_transform, layer_impl->DrawTransform()); | |
| 1435 EndTest(); | |
| 1436 break; | |
| 1437 } | |
| 1438 } | |
| 1439 | |
| 1440 void UpdateAnimationState(LayerTreeHostImpl* host_impl, | |
| 1441 bool has_unfinished_animation) override { | |
| 1442 if (host_impl->active_tree()->source_frame_number() == 1 && | |
| 1443 !has_unfinished_animation && !signalled_) { | |
| 1444 // The animation has finished, so allow the main thread to commit. | |
| 1445 completion_.Signal(); | |
| 1446 signalled_ = true; | |
| 1447 } | |
| 1448 } | |
| 1449 | |
| 1450 void AfterTest() override {} | |
| 1451 | |
| 1452 private: | |
| 1453 scoped_refptr<Layer> layer_; | |
| 1454 FakeContentLayerClient client_; | |
| 1455 CompletionEvent completion_; | |
| 1456 bool signalled_; | |
| 1457 }; | |
| 1458 | |
| 1459 // An animation finishing during commit can only happen when we have a separate | |
| 1460 // compositor thread. | |
| 1461 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimationFinishesDuringCommit); | |
| 1462 | |
| 1463 class LayerTreeHostAnimationTestNotifyAnimationFinished | |
| 1464 : public LayerTreeHostAnimationTest { | |
| 1465 public: | |
| 1466 LayerTreeHostAnimationTestNotifyAnimationFinished() | |
| 1467 : called_animation_started_(false), called_animation_finished_(false) {} | 1403 : called_animation_started_(false), called_animation_finished_(false) {} |
| 1468 | 1404 |
| 1469 void SetupTree() override { | 1405 void SetupTree() override { |
| 1470 LayerTreeHostAnimationTest::SetupTree(); | 1406 LayerTreeHostTimelinesTest::SetupTree(); |
| 1471 picture_ = FakePictureLayer::Create(&client_); | 1407 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 1472 picture_->SetBounds(gfx::Size(4, 4)); | 1408 picture_->SetBounds(gfx::Size(4, 4)); |
| 1473 client_.set_bounds(picture_->bounds()); | 1409 client_.set_bounds(picture_->bounds()); |
| 1474 layer_tree_host()->root_layer()->AddChild(picture_); | 1410 layer_tree_host()->root_layer()->AddChild(picture_); |
| 1475 | 1411 |
| 1476 AttachPlayersToTimeline(); | 1412 AttachPlayersToTimeline(); |
| 1477 player_->AttachLayer(picture_->id()); | 1413 player_->AttachLayer(picture_->id()); |
| 1478 player_->set_layer_animation_delegate(this); | 1414 player_->set_layer_animation_delegate(this); |
| 1479 } | 1415 } |
| 1480 | 1416 |
| 1481 void BeginTest() override { | 1417 void BeginTest() override { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1504 } | 1440 } |
| 1505 | 1441 |
| 1506 private: | 1442 private: |
| 1507 bool called_animation_started_; | 1443 bool called_animation_started_; |
| 1508 bool called_animation_finished_; | 1444 bool called_animation_finished_; |
| 1509 FakeContentLayerClient client_; | 1445 FakeContentLayerClient client_; |
| 1510 scoped_refptr<FakePictureLayer> picture_; | 1446 scoped_refptr<FakePictureLayer> picture_; |
| 1511 }; | 1447 }; |
| 1512 | 1448 |
| 1513 SINGLE_AND_MULTI_THREAD_TEST_F( | 1449 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1514 LayerTreeHostAnimationTestNotifyAnimationFinished); | 1450 LayerTreeHostTimelinesTestNotifyAnimationFinished); |
| 1515 | |
| 1516 // Check that SetTransformIsPotentiallyAnimatingChanged is called | |
| 1517 // if we destroy LayerAnimationController and ElementAnimations. | |
| 1518 class LayerTreeHostAnimationTestSetPotentiallyAnimatingOnLacDestruction | |
| 1519 : public LayerTreeHostAnimationTest { | |
| 1520 public: | |
| 1521 void SetupTree() override { | |
| 1522 prev_screen_space_transform_is_animating_ = true; | |
| 1523 screen_space_transform_animation_stopped_ = false; | |
| 1524 | |
| 1525 LayerTreeHostAnimationTest::SetupTree(); | |
| 1526 AttachPlayersToTimeline(); | |
| 1527 player_->AttachLayer(layer_tree_host()->root_layer()->id()); | |
| 1528 AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5); | |
| 1529 } | |
| 1530 | |
| 1531 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 1532 | |
| 1533 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | |
| 1534 if (host_impl->pending_tree()->source_frame_number() <= 1) { | |
| 1535 EXPECT_TRUE(host_impl->pending_tree() | |
| 1536 ->root_layer() | |
| 1537 ->screen_space_transform_is_animating()); | |
| 1538 } else { | |
| 1539 EXPECT_FALSE(host_impl->pending_tree() | |
| 1540 ->root_layer() | |
| 1541 ->screen_space_transform_is_animating()); | |
| 1542 } | |
| 1543 } | |
| 1544 | |
| 1545 void DidCommit() override { PostSetNeedsCommitToMainThread(); } | |
| 1546 | |
| 1547 void UpdateLayerTreeHost() override { | |
| 1548 if (layer_tree_host()->source_frame_number() == 2) { | |
| 1549 // Destroy player. | |
| 1550 timeline_->DetachPlayer(player_.get()); | |
| 1551 player_ = nullptr; | |
| 1552 } | |
| 1553 } | |
| 1554 | |
| 1555 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | |
| 1556 LayerTreeHostImpl::FrameData* frame_data, | |
| 1557 DrawResult draw_result) override { | |
| 1558 const bool screen_space_transform_is_animating = | |
| 1559 host_impl->active_tree() | |
| 1560 ->root_layer() | |
| 1561 ->screen_space_transform_is_animating(); | |
| 1562 | |
| 1563 // Check that screen_space_transform_is_animating changes only once. | |
| 1564 if (screen_space_transform_is_animating && | |
| 1565 prev_screen_space_transform_is_animating_) | |
| 1566 EXPECT_FALSE(screen_space_transform_animation_stopped_); | |
| 1567 if (!screen_space_transform_is_animating && | |
| 1568 prev_screen_space_transform_is_animating_) { | |
| 1569 EXPECT_FALSE(screen_space_transform_animation_stopped_); | |
| 1570 screen_space_transform_animation_stopped_ = true; | |
| 1571 } | |
| 1572 if (!screen_space_transform_is_animating && | |
| 1573 !prev_screen_space_transform_is_animating_) | |
| 1574 EXPECT_TRUE(screen_space_transform_animation_stopped_); | |
| 1575 | |
| 1576 prev_screen_space_transform_is_animating_ = | |
| 1577 screen_space_transform_is_animating; | |
| 1578 | |
| 1579 return draw_result; | |
| 1580 } | |
| 1581 | |
| 1582 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | |
| 1583 if (host_impl->active_tree()->source_frame_number() >= 2) | |
| 1584 EndTest(); | |
| 1585 } | |
| 1586 | |
| 1587 void AfterTest() override { | |
| 1588 EXPECT_TRUE(screen_space_transform_animation_stopped_); | |
| 1589 } | |
| 1590 | |
| 1591 bool prev_screen_space_transform_is_animating_; | |
| 1592 bool screen_space_transform_animation_stopped_; | |
| 1593 }; | |
| 1594 | |
| 1595 MULTI_THREAD_TEST_F( | |
| 1596 LayerTreeHostAnimationTestSetPotentiallyAnimatingOnLacDestruction); | |
| 1597 | |
| 1598 // Check that we invalidate property trees on AnimationPlayer::SetNeedsCommit. | |
| 1599 class LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit | |
| 1600 : public LayerTreeHostAnimationTest { | |
| 1601 public: | |
| 1602 void SetupTree() override { | |
| 1603 LayerTreeHostAnimationTest::SetupTree(); | |
| 1604 layer_ = FakePictureLayer::Create(&client_); | |
| 1605 layer_->SetBounds(gfx::Size(4, 4)); | |
| 1606 client_.set_bounds(layer_->bounds()); | |
| 1607 layer_tree_host()->root_layer()->AddChild(layer_); | |
| 1608 | |
| 1609 AttachPlayersToTimeline(); | |
| 1610 | |
| 1611 player_->AttachLayer(layer_tree_host()->root_layer()->id()); | |
| 1612 player_child_->AttachLayer(layer_->id()); | |
| 1613 } | |
| 1614 | |
| 1615 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 1616 | |
| 1617 void DidCommit() override { | |
| 1618 if (layer_tree_host()->source_frame_number() == 1 || | |
| 1619 layer_tree_host()->source_frame_number() == 2) | |
| 1620 PostSetNeedsCommitToMainThread(); | |
| 1621 } | |
| 1622 | |
| 1623 void UpdateLayerTreeHost() override { | |
| 1624 if (layer_tree_host()->source_frame_number() == 1) { | |
| 1625 EXPECT_FALSE(layer_tree_host()->property_trees()->needs_rebuild); | |
| 1626 AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); | |
| 1627 } | |
| 1628 | |
| 1629 EXPECT_TRUE(layer_tree_host()->property_trees()->needs_rebuild); | |
| 1630 } | |
| 1631 | |
| 1632 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | |
| 1633 if (host_impl->active_tree()->source_frame_number() >= 2) | |
| 1634 EndTest(); | |
| 1635 } | |
| 1636 | |
| 1637 void AfterTest() override {} | |
| 1638 | |
| 1639 private: | |
| 1640 scoped_refptr<Layer> layer_; | |
| 1641 FakeContentLayerClient client_; | |
| 1642 }; | |
| 1643 | |
| 1644 MULTI_THREAD_TEST_F( | |
| 1645 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); | |
| 1646 | 1451 |
| 1647 } // namespace | 1452 } // namespace |
| 1648 } // namespace cc | 1453 } // namespace cc |
| OLD | NEW |