| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "cc/animation/animation_curve.h" | 9 #include "cc/animation/animation_curve.h" |
| 10 #include "cc/animation/animation_host.h" |
| 11 #include "cc/animation/animation_id_provider.h" |
| 12 #include "cc/animation/animation_player.h" |
| 13 #include "cc/animation/animation_timeline.h" |
| 14 #include "cc/animation/element_animations.h" |
| 10 #include "cc/animation/layer_animation_controller.h" | 15 #include "cc/animation/layer_animation_controller.h" |
| 11 #include "cc/animation/scroll_offset_animation_curve.h" | 16 #include "cc/animation/scroll_offset_animation_curve.h" |
| 12 #include "cc/animation/timing_function.h" | 17 #include "cc/animation/timing_function.h" |
| 13 #include "cc/animation/transform_operations.h" | 18 #include "cc/animation/transform_operations.h" |
| 14 #include "cc/base/completion_event.h" | 19 #include "cc/base/completion_event.h" |
| 15 #include "cc/base/time_util.h" | 20 #include "cc/base/time_util.h" |
| 16 #include "cc/layers/layer.h" | 21 #include "cc/layers/layer.h" |
| 17 #include "cc/layers/layer_impl.h" | 22 #include "cc/layers/layer_impl.h" |
| 18 #include "cc/test/animation_test_common.h" | 23 #include "cc/test/animation_test_common.h" |
| 19 #include "cc/test/fake_content_layer_client.h" | 24 #include "cc/test/fake_content_layer_client.h" |
| 20 #include "cc/test/fake_picture_layer.h" | 25 #include "cc/test/fake_picture_layer.h" |
| 21 #include "cc/test/layer_tree_test.h" | 26 #include "cc/test/layer_tree_test.h" |
| 22 #include "cc/trees/layer_tree_impl.h" | 27 #include "cc/trees/layer_tree_impl.h" |
| 23 | 28 |
| 24 namespace cc { | 29 namespace cc { |
| 25 namespace { | 30 namespace { |
| 26 | 31 |
| 27 class LayerTreeHostAnimationTest : public LayerTreeTest { | 32 class LayerTreeHostAnimationTest : public LayerTreeTest { |
| 28 public: | 33 public: |
| 34 LayerTreeHostAnimationTest() |
| 35 : timeline_id_(AnimationIdProvider::NextTimelineId()), |
| 36 player_id_(AnimationIdProvider::NextPlayerId()), |
| 37 player_child_id_(AnimationIdProvider::NextPlayerId()) { |
| 38 timeline_ = AnimationTimeline::Create(timeline_id_); |
| 39 player_ = AnimationPlayer::Create(player_id_); |
| 40 player_child_ = AnimationPlayer::Create(player_child_id_); |
| 41 |
| 42 player_->set_layer_animation_delegate(this); |
| 43 } |
| 44 |
| 29 void InitializeSettings(LayerTreeSettings* settings) override { | 45 void InitializeSettings(LayerTreeSettings* settings) override { |
| 30 settings->use_compositor_animation_timelines = false; | 46 settings->use_compositor_animation_timelines = true; |
| 31 } | 47 } |
| 32 | 48 |
| 33 void InitializeLayerSettings(LayerSettings* layer_settings) override { | 49 void InitializeLayerSettings(LayerSettings* layer_settings) override { |
| 34 layer_settings->use_compositor_animation_timelines = false; | 50 layer_settings->use_compositor_animation_timelines = true; |
| 35 } | 51 } |
| 36 | 52 |
| 37 void SetupTree() override { | 53 void AttachPlayersToTimeline() { |
| 38 LayerTreeTest::SetupTree(); | 54 layer_tree_host()->animation_host()->AddAnimationTimeline(timeline_.get()); |
| 39 layer_tree_host()->root_layer()->set_layer_animation_delegate(this); | 55 timeline_->AttachPlayer(player_.get()); |
| 56 timeline_->AttachPlayer(player_child_.get()); |
| 40 } | 57 } |
| 58 |
| 59 protected: |
| 60 scoped_refptr<AnimationTimeline> timeline_; |
| 61 scoped_refptr<AnimationPlayer> player_; |
| 62 scoped_refptr<AnimationPlayer> player_child_; |
| 63 |
| 64 const int timeline_id_; |
| 65 const int player_id_; |
| 66 const int player_child_id_; |
| 41 }; | 67 }; |
| 42 | 68 |
| 43 // Makes sure that SetNeedsAnimate does not cause the CommitRequested() state to | 69 // Makes sure that SetNeedsAnimate does not cause the CommitRequested() state to |
| 44 // be set. | 70 // be set. |
| 45 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested | 71 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested |
| 46 : public LayerTreeHostAnimationTest { | 72 : public LayerTreeHostAnimationTest { |
| 47 public: | 73 public: |
| 48 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested() | 74 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested() |
| 49 : num_commits_(0) {} | 75 : num_commits_(0) {} |
| 50 | 76 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 145 |
| 120 // Add a layer animation and confirm that | 146 // Add a layer animation and confirm that |
| 121 // LayerTreeHostImpl::UpdateAnimationState does get called. | 147 // LayerTreeHostImpl::UpdateAnimationState does get called. |
| 122 class LayerTreeHostAnimationTestAddAnimation | 148 class LayerTreeHostAnimationTestAddAnimation |
| 123 : public LayerTreeHostAnimationTest { | 149 : public LayerTreeHostAnimationTest { |
| 124 public: | 150 public: |
| 125 LayerTreeHostAnimationTestAddAnimation() | 151 LayerTreeHostAnimationTestAddAnimation() |
| 126 : update_animation_state_was_called_(false) {} | 152 : update_animation_state_was_called_(false) {} |
| 127 | 153 |
| 128 void BeginTest() override { | 154 void BeginTest() override { |
| 129 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); | 155 AttachPlayersToTimeline(); |
| 156 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 157 PostAddInstantAnimationToMainThreadPlayer(player_.get()); |
| 130 } | 158 } |
| 131 | 159 |
| 132 void UpdateAnimationState(LayerTreeHostImpl* host_impl, | 160 void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
| 133 bool has_unfinished_animation) override { | 161 bool has_unfinished_animation) override { |
| 134 EXPECT_FALSE(has_unfinished_animation); | 162 EXPECT_FALSE(has_unfinished_animation); |
| 135 update_animation_state_was_called_ = true; | 163 update_animation_state_was_called_ = true; |
| 136 } | 164 } |
| 137 | 165 |
| 138 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 166 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
| 139 TargetProperty::Type target_property, | 167 TargetProperty::Type target_property, |
| 140 int group) override { | 168 int group) override { |
| 141 EXPECT_LT(base::TimeTicks(), monotonic_time); | 169 EXPECT_LT(base::TimeTicks(), monotonic_time); |
| 142 | 170 |
| 143 LayerAnimationController* controller = | 171 LayerAnimationController* controller = |
| 144 layer_tree_host()->root_layer()->layer_animation_controller(); | 172 player_->element_animations()->layer_animation_controller(); |
| 145 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); | 173 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); |
| 146 if (animation) | 174 if (animation) |
| 147 controller->RemoveAnimation(animation->id()); | 175 player_->RemoveAnimation(animation->id()); |
| 148 | 176 |
| 149 EndTest(); | 177 EndTest(); |
| 150 } | 178 } |
| 151 | 179 |
| 152 void AfterTest() override { EXPECT_TRUE(update_animation_state_was_called_); } | 180 void AfterTest() override { EXPECT_TRUE(update_animation_state_was_called_); } |
| 153 | 181 |
| 154 private: | 182 private: |
| 155 bool update_animation_state_was_called_; | 183 bool update_animation_state_was_called_; |
| 156 }; | 184 }; |
| 157 | 185 |
| 158 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation); | 186 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation); |
| 159 | 187 |
| 160 // Add a layer animation to a layer, but continually fail to draw. Confirm that | 188 // Add a layer animation to a layer, but continually fail to draw. Confirm that |
| 161 // after a while, we do eventually force a draw. | 189 // after a while, we do eventually force a draw. |
| 162 class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws | 190 class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws |
| 163 : public LayerTreeHostAnimationTest { | 191 : public LayerTreeHostAnimationTest { |
| 164 public: | 192 public: |
| 165 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() | 193 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() |
| 166 : started_animating_(false) {} | 194 : started_animating_(false) {} |
| 167 | 195 |
| 168 void BeginTest() override { | 196 void BeginTest() override { |
| 169 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | 197 AttachPlayersToTimeline(); |
| 198 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 199 PostAddAnimationToMainThreadPlayer(player_.get()); |
| 170 } | 200 } |
| 171 | 201 |
| 172 void AnimateLayers(LayerTreeHostImpl* host_impl, | 202 void AnimateLayers(LayerTreeHostImpl* host_impl, |
| 173 base::TimeTicks monotonic_time) override { | 203 base::TimeTicks monotonic_time) override { |
| 174 started_animating_ = true; | 204 started_animating_ = true; |
| 175 } | 205 } |
| 176 | 206 |
| 177 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 207 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 178 if (started_animating_) | 208 if (started_animating_) |
| 179 EndTest(); | 209 EndTest(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 195 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws); | 225 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws); |
| 196 | 226 |
| 197 // Ensures that animations eventually get deleted. | 227 // Ensures that animations eventually get deleted. |
| 198 class LayerTreeHostAnimationTestAnimationsGetDeleted | 228 class LayerTreeHostAnimationTestAnimationsGetDeleted |
| 199 : public LayerTreeHostAnimationTest { | 229 : public LayerTreeHostAnimationTest { |
| 200 public: | 230 public: |
| 201 LayerTreeHostAnimationTestAnimationsGetDeleted() | 231 LayerTreeHostAnimationTestAnimationsGetDeleted() |
| 202 : started_animating_(false) {} | 232 : started_animating_(false) {} |
| 203 | 233 |
| 204 void BeginTest() override { | 234 void BeginTest() override { |
| 205 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | 235 AttachPlayersToTimeline(); |
| 236 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 237 PostAddAnimationToMainThreadPlayer(player_.get()); |
| 206 } | 238 } |
| 207 | 239 |
| 208 void AnimateLayers(LayerTreeHostImpl* host_impl, | 240 void AnimateLayers(LayerTreeHostImpl* host_impl, |
| 209 base::TimeTicks monotonic_time) override { | 241 base::TimeTicks monotonic_time) override { |
| 210 bool have_animations = !host_impl->animation_registrar() | 242 bool have_animations = !host_impl->animation_host() |
| 243 ->animation_registrar() |
| 211 ->active_animation_controllers_for_testing() | 244 ->active_animation_controllers_for_testing() |
| 212 .empty(); | 245 .empty(); |
| 213 if (!started_animating_ && have_animations) { | 246 if (!started_animating_ && have_animations) { |
| 214 started_animating_ = true; | 247 started_animating_ = true; |
| 215 return; | 248 return; |
| 216 } | 249 } |
| 217 | 250 |
| 218 if (started_animating_ && !have_animations) | 251 if (started_animating_ && !have_animations) |
| 219 EndTest(); | 252 EndTest(); |
| 220 } | 253 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 238 // Ensure that an animation's timing function is respected. | 271 // Ensure that an animation's timing function is respected. |
| 239 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction | 272 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction |
| 240 : public LayerTreeHostAnimationTest { | 273 : public LayerTreeHostAnimationTest { |
| 241 public: | 274 public: |
| 242 void SetupTree() override { | 275 void SetupTree() override { |
| 243 LayerTreeHostAnimationTest::SetupTree(); | 276 LayerTreeHostAnimationTest::SetupTree(); |
| 244 picture_ = FakePictureLayer::Create(layer_settings(), &client_); | 277 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 245 picture_->SetBounds(gfx::Size(4, 4)); | 278 picture_->SetBounds(gfx::Size(4, 4)); |
| 246 client_.set_bounds(picture_->bounds()); | 279 client_.set_bounds(picture_->bounds()); |
| 247 layer_tree_host()->root_layer()->AddChild(picture_); | 280 layer_tree_host()->root_layer()->AddChild(picture_); |
| 281 |
| 282 AttachPlayersToTimeline(); |
| 283 player_child_->AttachLayer(picture_->id()); |
| 248 } | 284 } |
| 249 | 285 |
| 250 void BeginTest() override { PostAddAnimationToMainThread(picture_.get()); } | 286 void BeginTest() override { |
| 287 PostAddAnimationToMainThreadPlayer(player_child_.get()); |
| 288 } |
| 251 | 289 |
| 252 void AnimateLayers(LayerTreeHostImpl* host_impl, | 290 void AnimateLayers(LayerTreeHostImpl* host_impl, |
| 253 base::TimeTicks monotonic_time) override { | 291 base::TimeTicks monotonic_time) override { |
| 254 // TODO(ajuma): This test only checks the active tree. Add checks for | 292 // TODO(ajuma): This test only checks the active tree. Add checks for |
| 255 // pending tree too. | 293 // pending tree too. |
| 256 if (!host_impl->active_tree()->root_layer()) | 294 if (!host_impl->active_tree()->root_layer()) |
| 257 return; | 295 return; |
| 296 |
| 297 // Wait for the commit with the animation to happen. |
| 298 if (host_impl->sync_tree()->source_frame_number() != 0) |
| 299 return; |
| 300 |
| 301 scoped_refptr<AnimationTimeline> timeline_impl = |
| 302 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 303 scoped_refptr<AnimationPlayer> player_child_impl = |
| 304 timeline_impl->GetPlayerById(player_child_id_); |
| 305 |
| 258 LayerAnimationController* controller_impl = | 306 LayerAnimationController* controller_impl = |
| 259 host_impl->active_tree()->root_layer()->children()[0]-> | 307 player_child_impl->element_animations()->layer_animation_controller(); |
| 260 layer_animation_controller(); | |
| 261 Animation* animation = | 308 Animation* animation = |
| 262 controller_impl->GetAnimation(TargetProperty::OPACITY); | 309 controller_impl->GetAnimation(TargetProperty::OPACITY); |
| 263 if (!animation) | |
| 264 return; | |
| 265 | 310 |
| 266 const FloatAnimationCurve* curve = | 311 const FloatAnimationCurve* curve = |
| 267 animation->curve()->ToFloatAnimationCurve(); | 312 animation->curve()->ToFloatAnimationCurve(); |
| 268 float start_opacity = curve->GetValue(base::TimeDelta()); | 313 float start_opacity = curve->GetValue(base::TimeDelta()); |
| 269 float end_opacity = curve->GetValue(curve->Duration()); | 314 float end_opacity = curve->GetValue(curve->Duration()); |
| 270 float linearly_interpolated_opacity = | 315 float linearly_interpolated_opacity = |
| 271 0.25f * end_opacity + 0.75f * start_opacity; | 316 0.25f * end_opacity + 0.75f * start_opacity; |
| 272 base::TimeDelta time = TimeUtil::Scale(curve->Duration(), 0.25f); | 317 base::TimeDelta time = TimeUtil::Scale(curve->Duration(), 0.25f); |
| 273 // If the linear timing function associated with this animation was not | 318 // If the linear timing function associated with this animation was not |
| 274 // picked up, then the linearly interpolated opacity would be different | 319 // picked up, then the linearly interpolated opacity would be different |
| (...skipping 15 matching lines...) Expand all Loading... |
| 290 // Ensures that main thread animations have their start times synchronized with | 335 // Ensures that main thread animations have their start times synchronized with |
| 291 // impl thread animations. | 336 // impl thread animations. |
| 292 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes | 337 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes |
| 293 : public LayerTreeHostAnimationTest { | 338 : public LayerTreeHostAnimationTest { |
| 294 public: | 339 public: |
| 295 void SetupTree() override { | 340 void SetupTree() override { |
| 296 LayerTreeHostAnimationTest::SetupTree(); | 341 LayerTreeHostAnimationTest::SetupTree(); |
| 297 picture_ = FakePictureLayer::Create(layer_settings(), &client_); | 342 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 298 picture_->SetBounds(gfx::Size(4, 4)); | 343 picture_->SetBounds(gfx::Size(4, 4)); |
| 299 client_.set_bounds(picture_->bounds()); | 344 client_.set_bounds(picture_->bounds()); |
| 300 picture_->set_layer_animation_delegate(this); | 345 |
| 301 layer_tree_host()->root_layer()->AddChild(picture_); | 346 layer_tree_host()->root_layer()->AddChild(picture_); |
| 347 |
| 348 AttachPlayersToTimeline(); |
| 349 player_child_->set_layer_animation_delegate(this); |
| 350 player_child_->AttachLayer(picture_->id()); |
| 302 } | 351 } |
| 303 | 352 |
| 304 void BeginTest() override { PostAddAnimationToMainThread(picture_.get()); } | 353 void BeginTest() override { |
| 354 PostAddAnimationToMainThreadPlayer(player_child_.get()); |
| 355 } |
| 305 | 356 |
| 306 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 357 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
| 307 TargetProperty::Type target_property, | 358 TargetProperty::Type target_property, |
| 308 int group) override { | 359 int group) override { |
| 309 LayerAnimationController* controller = | 360 LayerAnimationController* controller = |
| 310 layer_tree_host()->root_layer()->children()[0]-> | 361 player_child_->element_animations()->layer_animation_controller(); |
| 311 layer_animation_controller(); | |
| 312 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); | 362 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); |
| 313 main_start_time_ = animation->start_time(); | 363 main_start_time_ = animation->start_time(); |
| 314 controller->RemoveAnimation(animation->id()); | 364 controller->RemoveAnimation(animation->id()); |
| 315 EndTest(); | 365 EndTest(); |
| 316 } | 366 } |
| 317 | 367 |
| 318 void UpdateAnimationState(LayerTreeHostImpl* impl_host, | 368 void UpdateAnimationState(LayerTreeHostImpl* impl_host, |
| 319 bool has_unfinished_animation) override { | 369 bool has_unfinished_animation) override { |
| 370 scoped_refptr<AnimationTimeline> timeline_impl = |
| 371 impl_host->animation_host()->GetTimelineById(timeline_id_); |
| 372 scoped_refptr<AnimationPlayer> player_child_impl = |
| 373 timeline_impl->GetPlayerById(player_child_id_); |
| 374 |
| 320 LayerAnimationController* controller = | 375 LayerAnimationController* controller = |
| 321 impl_host->active_tree()->root_layer()->children()[0]-> | 376 player_child_impl->element_animations()->layer_animation_controller(); |
| 322 layer_animation_controller(); | |
| 323 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); | 377 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); |
| 324 if (!animation) | 378 if (!animation) |
| 325 return; | 379 return; |
| 326 | 380 |
| 327 impl_start_time_ = animation->start_time(); | 381 impl_start_time_ = animation->start_time(); |
| 328 } | 382 } |
| 329 | 383 |
| 330 void AfterTest() override { | 384 void AfterTest() override { |
| 331 EXPECT_EQ(impl_start_time_, main_start_time_); | 385 EXPECT_EQ(impl_start_time_, main_start_time_); |
| 332 EXPECT_LT(base::TimeTicks(), impl_start_time_); | 386 EXPECT_LT(base::TimeTicks(), impl_start_time_); |
| 333 } | 387 } |
| 334 | 388 |
| 335 private: | 389 private: |
| 336 base::TimeTicks main_start_time_; | 390 base::TimeTicks main_start_time_; |
| 337 base::TimeTicks impl_start_time_; | 391 base::TimeTicks impl_start_time_; |
| 338 FakeContentLayerClient client_; | 392 FakeContentLayerClient client_; |
| 339 scoped_refptr<FakePictureLayer> picture_; | 393 scoped_refptr<FakePictureLayer> picture_; |
| 340 }; | 394 }; |
| 341 | 395 |
| 342 SINGLE_AND_MULTI_THREAD_TEST_F( | 396 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 343 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); | 397 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); |
| 344 | 398 |
| 345 // Ensures that notify animation finished is called. | 399 // Ensures that notify animation finished is called. |
| 346 class LayerTreeHostAnimationTestAnimationFinishedEvents | 400 class LayerTreeHostAnimationTestAnimationFinishedEvents |
| 347 : public LayerTreeHostAnimationTest { | 401 : public LayerTreeHostAnimationTest { |
| 348 public: | 402 public: |
| 349 void BeginTest() override { | 403 void BeginTest() override { |
| 350 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); | 404 AttachPlayersToTimeline(); |
| 405 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 406 PostAddInstantAnimationToMainThreadPlayer(player_.get()); |
| 351 } | 407 } |
| 352 | 408 |
| 353 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 409 void NotifyAnimationFinished(base::TimeTicks monotonic_time, |
| 354 TargetProperty::Type target_property, | 410 TargetProperty::Type target_property, |
| 355 int group) override { | 411 int group) override { |
| 356 LayerAnimationController* controller = | 412 LayerAnimationController* controller = |
| 357 layer_tree_host()->root_layer()->layer_animation_controller(); | 413 player_->element_animations()->layer_animation_controller(); |
| 358 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); | 414 Animation* animation = controller->GetAnimation(TargetProperty::OPACITY); |
| 359 if (animation) | 415 if (animation) |
| 360 controller->RemoveAnimation(animation->id()); | 416 controller->RemoveAnimation(animation->id()); |
| 361 EndTest(); | 417 EndTest(); |
| 362 } | 418 } |
| 363 | 419 |
| 364 void AfterTest() override {} | 420 void AfterTest() override {} |
| 365 }; | 421 }; |
| 366 | 422 |
| 367 SINGLE_AND_MULTI_THREAD_TEST_F( | 423 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 368 LayerTreeHostAnimationTestAnimationFinishedEvents); | 424 LayerTreeHostAnimationTestAnimationFinishedEvents); |
| 369 | 425 |
| 370 // Ensures that when opacity is being animated, this value does not cause the | 426 // Ensures that when opacity is being animated, this value does not cause the |
| 371 // subtree to be skipped. | 427 // subtree to be skipped. |
| 372 class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity | 428 class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity |
| 373 : public LayerTreeHostAnimationTest { | 429 : public LayerTreeHostAnimationTest { |
| 374 public: | 430 public: |
| 375 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity() | 431 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity() |
| 376 : update_check_layer_() {} | 432 : update_check_layer_() {} |
| 377 | 433 |
| 378 void SetupTree() override { | 434 void SetupTree() override { |
| 379 update_check_layer_ = FakePictureLayer::Create(layer_settings(), &client_); | 435 update_check_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 380 update_check_layer_->SetOpacity(0.f); | 436 update_check_layer_->SetOpacity(0.f); |
| 381 layer_tree_host()->SetRootLayer(update_check_layer_); | 437 layer_tree_host()->SetRootLayer(update_check_layer_); |
| 382 client_.set_bounds(update_check_layer_->bounds()); | 438 client_.set_bounds(update_check_layer_->bounds()); |
| 383 LayerTreeHostAnimationTest::SetupTree(); | 439 LayerTreeHostAnimationTest::SetupTree(); |
| 440 |
| 441 AttachPlayersToTimeline(); |
| 442 player_->AttachLayer(update_check_layer_->id()); |
| 384 } | 443 } |
| 385 | 444 |
| 386 void BeginTest() override { | 445 void BeginTest() override { |
| 387 PostAddAnimationToMainThread(update_check_layer_.get()); | 446 PostAddAnimationToMainThreadPlayer(player_.get()); |
| 388 } | 447 } |
| 389 | 448 |
| 390 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 449 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 450 scoped_refptr<AnimationTimeline> timeline_impl = |
| 451 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 452 scoped_refptr<AnimationPlayer> player_impl = |
| 453 timeline_impl->GetPlayerById(player_id_); |
| 454 |
| 391 LayerAnimationController* controller_impl = | 455 LayerAnimationController* controller_impl = |
| 392 host_impl->active_tree()->root_layer()->layer_animation_controller(); | 456 player_impl->element_animations()->layer_animation_controller(); |
| 393 Animation* animation_impl = | 457 Animation* animation_impl = |
| 394 controller_impl->GetAnimation(TargetProperty::OPACITY); | 458 controller_impl->GetAnimation(TargetProperty::OPACITY); |
| 395 controller_impl->RemoveAnimation(animation_impl->id()); | 459 controller_impl->RemoveAnimation(animation_impl->id()); |
| 396 EndTest(); | 460 EndTest(); |
| 397 } | 461 } |
| 398 | 462 |
| 399 void AfterTest() override { | 463 void AfterTest() override { |
| 400 // Update() should have been called once, proving that the layer was not | 464 // Update() should have been called once, proving that the layer was not |
| 401 // skipped. | 465 // skipped. |
| 402 EXPECT_EQ(1, update_check_layer_->update_count()); | 466 EXPECT_EQ(1, update_check_layer_->update_count()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 415 | 479 |
| 416 // Layers added to tree with existing active animations should have the | 480 // Layers added to tree with existing active animations should have the |
| 417 // animation correctly recognized. | 481 // animation correctly recognized. |
| 418 class LayerTreeHostAnimationTestLayerAddedWithAnimation | 482 class LayerTreeHostAnimationTestLayerAddedWithAnimation |
| 419 : public LayerTreeHostAnimationTest { | 483 : public LayerTreeHostAnimationTest { |
| 420 public: | 484 public: |
| 421 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 485 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 422 | 486 |
| 423 void DidCommit() override { | 487 void DidCommit() override { |
| 424 if (layer_tree_host()->source_frame_number() == 1) { | 488 if (layer_tree_host()->source_frame_number() == 1) { |
| 489 AttachPlayersToTimeline(); |
| 490 |
| 425 scoped_refptr<Layer> layer = Layer::Create(layer_settings()); | 491 scoped_refptr<Layer> layer = Layer::Create(layer_settings()); |
| 426 layer->set_layer_animation_delegate(this); | 492 player_->AttachLayer(layer->id()); |
| 493 player_->set_layer_animation_delegate(this); |
| 427 | 494 |
| 428 // Any valid AnimationCurve will do here. | 495 // Any valid AnimationCurve will do here. |
| 429 scoped_ptr<AnimationCurve> curve(new FakeFloatAnimationCurve()); | 496 scoped_ptr<AnimationCurve> curve(new FakeFloatAnimationCurve()); |
| 430 scoped_ptr<Animation> animation( | 497 scoped_ptr<Animation> animation( |
| 431 Animation::Create(std::move(curve), 1, 1, TargetProperty::OPACITY)); | 498 Animation::Create(std::move(curve), 1, 1, TargetProperty::OPACITY)); |
| 432 layer->layer_animation_controller()->AddAnimation(std::move(animation)); | 499 player_->AddAnimation(std::move(animation)); |
| 433 | 500 |
| 434 // We add the animation *before* attaching the layer to the tree. | 501 // We add the animation *before* attaching the layer to the tree. |
| 435 layer_tree_host()->root_layer()->AddChild(layer); | 502 layer_tree_host()->root_layer()->AddChild(layer); |
| 436 } | 503 } |
| 437 } | 504 } |
| 438 | 505 |
| 439 void AnimateLayers(LayerTreeHostImpl* impl_host, | 506 void AnimateLayers(LayerTreeHostImpl* impl_host, |
| 440 base::TimeTicks monotonic_time) override { | 507 base::TimeTicks monotonic_time) override { |
| 441 EndTest(); | 508 EndTest(); |
| 442 } | 509 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 | 630 |
| 564 // Animations should not be started when frames are being skipped due to | 631 // Animations should not be started when frames are being skipped due to |
| 565 // checkerboard. | 632 // checkerboard. |
| 566 class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations | 633 class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations |
| 567 : public LayerTreeHostAnimationTest { | 634 : public LayerTreeHostAnimationTest { |
| 568 void SetupTree() override { | 635 void SetupTree() override { |
| 569 LayerTreeHostAnimationTest::SetupTree(); | 636 LayerTreeHostAnimationTest::SetupTree(); |
| 570 picture_ = FakePictureLayer::Create(layer_settings(), &client_); | 637 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 571 picture_->SetBounds(gfx::Size(4, 4)); | 638 picture_->SetBounds(gfx::Size(4, 4)); |
| 572 client_.set_bounds(picture_->bounds()); | 639 client_.set_bounds(picture_->bounds()); |
| 573 picture_->set_layer_animation_delegate(this); | |
| 574 layer_tree_host()->root_layer()->AddChild(picture_); | 640 layer_tree_host()->root_layer()->AddChild(picture_); |
| 641 |
| 642 AttachPlayersToTimeline(); |
| 643 player_child_->AttachLayer(picture_->id()); |
| 644 player_child_->set_layer_animation_delegate(this); |
| 575 } | 645 } |
| 576 | 646 |
| 577 void InitializeSettings(LayerTreeSettings* settings) override { | 647 void InitializeSettings(LayerTreeSettings* settings) override { |
| 578 LayerTreeHostAnimationTest::InitializeSettings(settings); | |
| 579 // Make sure that drawing many times doesn't cause a checkerboarded | 648 // Make sure that drawing many times doesn't cause a checkerboarded |
| 580 // animation to start so we avoid flake in this test. | 649 // animation to start so we avoid flake in this test. |
| 581 settings->timeout_and_draw_when_animation_checkerboards = false; | 650 settings->timeout_and_draw_when_animation_checkerboards = false; |
| 651 LayerTreeHostAnimationTest::InitializeSettings(settings); |
| 582 } | 652 } |
| 583 | 653 |
| 584 void BeginTest() override { | 654 void BeginTest() override { |
| 585 prevented_draw_ = 0; | 655 prevented_draw_ = 0; |
| 586 started_times_ = 0; | 656 started_times_ = 0; |
| 587 | 657 |
| 588 PostSetNeedsCommitToMainThread(); | 658 PostSetNeedsCommitToMainThread(); |
| 589 } | 659 } |
| 590 | 660 |
| 591 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 661 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 592 LayerTreeHostImpl::FrameData* frame_data, | 662 LayerTreeHostImpl::FrameData* frame_data, |
| 593 DrawResult draw_result) override { | 663 DrawResult draw_result) override { |
| 594 // Don't checkerboard when the first animation wants to start. | 664 // Don't checkerboard when the first animation wants to start. |
| 595 if (host_impl->active_tree()->source_frame_number() < 2) | 665 if (host_impl->active_tree()->source_frame_number() < 2) |
| 596 return draw_result; | 666 return draw_result; |
| 597 if (TestEnded()) | 667 if (TestEnded()) |
| 598 return draw_result; | 668 return draw_result; |
| 599 // Act like there is checkerboard when the second animation wants to draw. | 669 // Act like there is checkerboard when the second animation wants to draw. |
| 600 ++prevented_draw_; | 670 ++prevented_draw_; |
| 601 if (prevented_draw_ > 2) | 671 if (prevented_draw_ > 2) |
| 602 EndTest(); | 672 EndTest(); |
| 603 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 673 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
| 604 } | 674 } |
| 605 | 675 |
| 606 void DidCommitAndDrawFrame() override { | 676 void DidCommitAndDrawFrame() override { |
| 607 switch (layer_tree_host()->source_frame_number()) { | 677 switch (layer_tree_host()->source_frame_number()) { |
| 608 case 1: | 678 case 1: |
| 609 // The animation is longer than 1 BeginFrame interval. | 679 // The animation is longer than 1 BeginFrame interval. |
| 610 AddOpacityTransitionToLayer(picture_.get(), 0.1, 0.2f, 0.8f, false); | 680 AddOpacityTransitionToPlayer(player_child_.get(), 0.1, 0.2f, 0.8f, |
| 681 false); |
| 611 break; | 682 break; |
| 612 case 2: | 683 case 2: |
| 613 // This second animation will not be drawn so it should not start. | 684 // This second animation will not be drawn so it should not start. |
| 614 AddAnimatedTransformToLayer(picture_.get(), 0.1, 5, 5); | 685 AddAnimatedTransformToPlayer(player_child_.get(), 0.1, 5, 5); |
| 615 break; | 686 break; |
| 616 } | 687 } |
| 617 } | 688 } |
| 618 | 689 |
| 619 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 690 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
| 620 TargetProperty::Type target_property, | 691 TargetProperty::Type target_property, |
| 621 int group) override { | 692 int group) override { |
| 622 if (TestEnded()) | 693 if (TestEnded()) |
| 623 return; | 694 return; |
| 624 started_times_++; | 695 started_times_++; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 649 public: | 720 public: |
| 650 void SetupTree() override { | 721 void SetupTree() override { |
| 651 LayerTreeHostAnimationTest::SetupTree(); | 722 LayerTreeHostAnimationTest::SetupTree(); |
| 652 | 723 |
| 653 scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); | 724 scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 654 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); | 725 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); |
| 655 scroll_layer_->SetBounds(gfx::Size(1000, 1000)); | 726 scroll_layer_->SetBounds(gfx::Size(1000, 1000)); |
| 656 client_.set_bounds(scroll_layer_->bounds()); | 727 client_.set_bounds(scroll_layer_->bounds()); |
| 657 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); | 728 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 658 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | 729 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 730 |
| 731 AttachPlayersToTimeline(); |
| 732 player_child_->AttachLayer(scroll_layer_->id()); |
| 659 } | 733 } |
| 660 | 734 |
| 661 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 735 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 662 | 736 |
| 663 void DidCommit() override { | 737 void DidCommit() override { |
| 664 switch (layer_tree_host()->source_frame_number()) { | 738 switch (layer_tree_host()->source_frame_number()) { |
| 665 case 1: { | 739 case 1: { |
| 666 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 740 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| 667 ScrollOffsetAnimationCurve::Create( | 741 ScrollOffsetAnimationCurve::Create( |
| 668 gfx::ScrollOffset(500.f, 550.f), | 742 gfx::ScrollOffset(500.f, 550.f), |
| 669 EaseInOutTimingFunction::Create())); | 743 EaseInOutTimingFunction::Create())); |
| 670 scoped_ptr<Animation> animation(Animation::Create( | 744 scoped_ptr<Animation> animation(Animation::Create( |
| 671 std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | 745 std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
| 672 animation->set_needs_synchronized_start_time(true); | 746 animation->set_needs_synchronized_start_time(true); |
| 673 bool animation_added = | |
| 674 scroll_layer_->AddAnimation(std::move(animation)); | |
| 675 bool impl_scrolling_supported = | 747 bool impl_scrolling_supported = |
| 676 layer_tree_host()->proxy()->SupportsImplScrolling(); | 748 layer_tree_host()->proxy()->SupportsImplScrolling(); |
| 677 EXPECT_EQ(impl_scrolling_supported, animation_added); | 749 if (impl_scrolling_supported) |
| 678 if (!impl_scrolling_supported) | 750 player_child_->AddAnimation(std::move(animation)); |
| 751 else |
| 679 EndTest(); | 752 EndTest(); |
| 680 break; | 753 break; |
| 681 } | 754 } |
| 682 default: | 755 default: |
| 683 if (scroll_layer_->scroll_offset().x() > 10 && | 756 if (scroll_layer_->scroll_offset().x() > 10 && |
| 684 scroll_layer_->scroll_offset().y() > 20) | 757 scroll_layer_->scroll_offset().y() > 20) |
| 685 EndTest(); | 758 EndTest(); |
| 686 } | 759 } |
| 687 } | 760 } |
| 688 | 761 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 715 client_.set_bounds(scroll_layer_->bounds()); | 788 client_.set_bounds(scroll_layer_->bounds()); |
| 716 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(100.0, 200.0)); | 789 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(100.0, 200.0)); |
| 717 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | 790 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 718 | 791 |
| 719 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 792 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| 720 ScrollOffsetAnimationCurve::Create(gfx::ScrollOffset(6500.f, 7500.f), | 793 ScrollOffsetAnimationCurve::Create(gfx::ScrollOffset(6500.f, 7500.f), |
| 721 EaseInOutTimingFunction::Create())); | 794 EaseInOutTimingFunction::Create())); |
| 722 scoped_ptr<Animation> animation(Animation::Create( | 795 scoped_ptr<Animation> animation(Animation::Create( |
| 723 std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); | 796 std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
| 724 animation->set_needs_synchronized_start_time(true); | 797 animation->set_needs_synchronized_start_time(true); |
| 725 scroll_layer_->AddAnimation(std::move(animation)); | 798 |
| 799 AttachPlayersToTimeline(); |
| 800 player_child_->AttachLayer(scroll_layer_->id()); |
| 801 player_child_->AddAnimation(std::move(animation)); |
| 726 } | 802 } |
| 727 | 803 |
| 728 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 804 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 729 | 805 |
| 730 void BeginMainFrame(const BeginFrameArgs& args) override { | 806 void BeginMainFrame(const BeginFrameArgs& args) override { |
| 731 switch (layer_tree_host()->source_frame_number()) { | 807 switch (layer_tree_host()->source_frame_number()) { |
| 732 case 0: | 808 case 0: |
| 733 break; | 809 break; |
| 734 case 1: { | 810 case 1: { |
| 735 Animation* animation = | 811 Animation* animation = |
| 736 scroll_layer_->layer_animation_controller()->GetAnimation( | 812 player_child_->element_animations() |
| 737 TargetProperty::SCROLL_OFFSET); | 813 ->layer_animation_controller() |
| 738 scroll_layer_->layer_animation_controller()->RemoveAnimation( | 814 ->GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 739 animation->id()); | 815 player_child_->RemoveAnimation(animation->id()); |
| 740 scroll_layer_->SetScrollOffset(final_postion_); | 816 scroll_layer_->SetScrollOffset(final_postion_); |
| 741 break; | 817 break; |
| 742 } | 818 } |
| 743 default: | 819 default: |
| 744 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); | 820 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); |
| 745 } | 821 } |
| 746 } | 822 } |
| 747 | 823 |
| 748 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { | 824 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
| 749 host_impl->BlockNotifyReadyToActivateForTesting(true); | 825 host_impl->BlockNotifyReadyToActivateForTesting(true); |
| 750 } | 826 } |
| 751 | 827 |
| 752 void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, | 828 void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, |
| 753 const BeginFrameArgs& args) override { | 829 const BeginFrameArgs& args) override { |
| 754 if (!host_impl->pending_tree()) | 830 if (!host_impl->pending_tree()) |
| 755 return; | 831 return; |
| 756 | 832 |
| 757 if (!host_impl->active_tree()->root_layer()) { | 833 if (!host_impl->active_tree()->root_layer()) { |
| 758 host_impl->BlockNotifyReadyToActivateForTesting(false); | 834 host_impl->BlockNotifyReadyToActivateForTesting(false); |
| 759 return; | 835 return; |
| 760 } | 836 } |
| 761 | 837 |
| 838 scoped_refptr<AnimationTimeline> timeline_impl = |
| 839 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 840 scoped_refptr<AnimationPlayer> player_impl = |
| 841 timeline_impl->GetPlayerById(player_child_id_); |
| 842 |
| 762 LayerImpl* scroll_layer_impl = | 843 LayerImpl* scroll_layer_impl = |
| 763 host_impl->active_tree()->root_layer()->children()[0].get(); | 844 host_impl->active_tree()->root_layer()->children()[0].get(); |
| 764 Animation* animation = | 845 Animation* animation = player_impl->element_animations() |
| 765 scroll_layer_impl->layer_animation_controller()->GetAnimation( | 846 ->layer_animation_controller() |
| 766 TargetProperty::SCROLL_OFFSET); | 847 ->GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 767 | 848 |
| 768 if (!animation || animation->run_state() != Animation::RUNNING) { | 849 if (!animation || animation->run_state() != Animation::RUNNING) { |
| 769 host_impl->BlockNotifyReadyToActivateForTesting(false); | 850 host_impl->BlockNotifyReadyToActivateForTesting(false); |
| 770 return; | 851 return; |
| 771 } | 852 } |
| 772 | 853 |
| 773 // Block activation until the running animation has a chance to produce a | 854 // Block activation until the running animation has a chance to produce a |
| 774 // scroll delta. | 855 // scroll delta. |
| 775 gfx::Vector2dF scroll_delta = ScrollDelta(scroll_layer_impl); | 856 gfx::Vector2dF scroll_delta = ScrollDelta(scroll_layer_impl); |
| 776 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) | 857 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 | 891 |
| 811 // When animations are simultaneously added to an existing layer and to a new | 892 // When animations are simultaneously added to an existing layer and to a new |
| 812 // layer, they should start at the same time, even when there's already a | 893 // layer, they should start at the same time, even when there's already a |
| 813 // running animation on the existing layer. | 894 // running animation on the existing layer. |
| 814 class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers | 895 class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers |
| 815 : public LayerTreeHostAnimationTest { | 896 : public LayerTreeHostAnimationTest { |
| 816 public: | 897 public: |
| 817 LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers() | 898 LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers() |
| 818 : frame_count_with_pending_tree_(0) {} | 899 : frame_count_with_pending_tree_(0) {} |
| 819 | 900 |
| 820 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 901 void BeginTest() override { |
| 902 AttachPlayersToTimeline(); |
| 903 PostSetNeedsCommitToMainThread(); |
| 904 } |
| 821 | 905 |
| 822 void DidCommit() override { | 906 void DidCommit() override { |
| 823 if (layer_tree_host()->source_frame_number() == 1) { | 907 if (layer_tree_host()->source_frame_number() == 1) { |
| 824 AddAnimatedTransformToLayer(layer_tree_host()->root_layer(), 4, 1, 1); | 908 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 909 AddAnimatedTransformToPlayer(player_.get(), 4, 1, 1); |
| 825 } else if (layer_tree_host()->source_frame_number() == 2) { | 910 } else if (layer_tree_host()->source_frame_number() == 2) { |
| 826 AddOpacityTransitionToLayer( | 911 AddOpacityTransitionToPlayer(player_.get(), 1, 0.f, 0.5f, true); |
| 827 layer_tree_host()->root_layer(), 1, 0.f, 0.5f, true); | |
| 828 | 912 |
| 829 scoped_refptr<Layer> layer = Layer::Create(layer_settings()); | 913 scoped_refptr<Layer> layer = Layer::Create(layer_settings()); |
| 830 layer_tree_host()->root_layer()->AddChild(layer); | 914 layer_tree_host()->root_layer()->AddChild(layer); |
| 831 layer->set_layer_animation_delegate(this); | |
| 832 layer->SetBounds(gfx::Size(4, 4)); | 915 layer->SetBounds(gfx::Size(4, 4)); |
| 833 AddOpacityTransitionToLayer(layer.get(), 1, 0.f, 0.5f, true); | 916 |
| 917 player_child_->AttachLayer(layer->id()); |
| 918 player_child_->set_layer_animation_delegate(this); |
| 919 AddOpacityTransitionToPlayer(player_child_.get(), 1, 0.f, 0.5f, true); |
| 834 } | 920 } |
| 835 } | 921 } |
| 836 | 922 |
| 837 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { | 923 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
| 838 host_impl->BlockNotifyReadyToActivateForTesting(true); | 924 host_impl->BlockNotifyReadyToActivateForTesting(true); |
| 839 } | 925 } |
| 840 | 926 |
| 841 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 927 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 842 // For the commit that added animations to new and existing layers, keep | 928 // For the commit that added animations to new and existing layers, keep |
| 843 // blocking activation. We want to verify that even with activation blocked, | 929 // blocking activation. We want to verify that even with activation blocked, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 855 return; | 941 return; |
| 856 | 942 |
| 857 frame_count_with_pending_tree_++; | 943 frame_count_with_pending_tree_++; |
| 858 if (frame_count_with_pending_tree_ == 2) { | 944 if (frame_count_with_pending_tree_ == 2) { |
| 859 host_impl->BlockNotifyReadyToActivateForTesting(false); | 945 host_impl->BlockNotifyReadyToActivateForTesting(false); |
| 860 } | 946 } |
| 861 } | 947 } |
| 862 | 948 |
| 863 void UpdateAnimationState(LayerTreeHostImpl* host_impl, | 949 void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
| 864 bool has_unfinished_animation) override { | 950 bool has_unfinished_animation) override { |
| 951 scoped_refptr<AnimationTimeline> timeline_impl = |
| 952 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 953 scoped_refptr<AnimationPlayer> player_impl = |
| 954 timeline_impl->GetPlayerById(player_id_); |
| 955 scoped_refptr<AnimationPlayer> player_child_impl = |
| 956 timeline_impl->GetPlayerById(player_child_id_); |
| 957 |
| 958 // wait for tree activation. |
| 959 if (!player_impl->element_animations()) |
| 960 return; |
| 961 |
| 865 LayerAnimationController* root_controller_impl = | 962 LayerAnimationController* root_controller_impl = |
| 866 host_impl->active_tree()->root_layer()->layer_animation_controller(); | 963 player_impl->element_animations()->layer_animation_controller(); |
| 867 Animation* root_animation = | 964 Animation* root_animation = |
| 868 root_controller_impl->GetAnimation(TargetProperty::OPACITY); | 965 root_controller_impl->GetAnimation(TargetProperty::OPACITY); |
| 869 if (!root_animation || root_animation->run_state() != Animation::RUNNING) | 966 if (!root_animation || root_animation->run_state() != Animation::RUNNING) |
| 870 return; | 967 return; |
| 871 | 968 |
| 872 LayerAnimationController* child_controller_impl = | 969 LayerAnimationController* child_controller_impl = |
| 873 host_impl->active_tree()->root_layer()->children() | 970 player_child_impl->element_animations()->layer_animation_controller(); |
| 874 [0]->layer_animation_controller(); | |
| 875 Animation* child_animation = | 971 Animation* child_animation = |
| 876 child_controller_impl->GetAnimation(TargetProperty::OPACITY); | 972 child_controller_impl->GetAnimation(TargetProperty::OPACITY); |
| 877 EXPECT_EQ(Animation::RUNNING, child_animation->run_state()); | 973 EXPECT_EQ(Animation::RUNNING, child_animation->run_state()); |
| 878 EXPECT_EQ(root_animation->start_time(), child_animation->start_time()); | 974 EXPECT_EQ(root_animation->start_time(), child_animation->start_time()); |
| 879 root_controller_impl->AbortAnimations(TargetProperty::OPACITY); | 975 root_controller_impl->AbortAnimations(TargetProperty::OPACITY); |
| 880 root_controller_impl->AbortAnimations(TargetProperty::TRANSFORM); | 976 root_controller_impl->AbortAnimations(TargetProperty::TRANSFORM); |
| 881 child_controller_impl->AbortAnimations(TargetProperty::OPACITY); | 977 child_controller_impl->AbortAnimations(TargetProperty::OPACITY); |
| 882 EndTest(); | 978 EndTest(); |
| 883 } | 979 } |
| 884 | 980 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 900 | 996 |
| 901 layer_ = FakePictureLayer::Create(layer_settings(), &client_); | 997 layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 902 layer_->SetBounds(gfx::Size(2, 2)); | 998 layer_->SetBounds(gfx::Size(2, 2)); |
| 903 client_.set_bounds(layer_->bounds()); | 999 client_.set_bounds(layer_->bounds()); |
| 904 // Transform the layer to 4,4 to start. | 1000 // Transform the layer to 4,4 to start. |
| 905 gfx::Transform start_transform; | 1001 gfx::Transform start_transform; |
| 906 start_transform.Translate(4.0, 4.0); | 1002 start_transform.Translate(4.0, 4.0); |
| 907 layer_->SetTransform(start_transform); | 1003 layer_->SetTransform(start_transform); |
| 908 | 1004 |
| 909 layer_tree_host()->root_layer()->AddChild(layer_); | 1005 layer_tree_host()->root_layer()->AddChild(layer_); |
| 1006 player_->AttachLayer(layer_->id()); |
| 1007 |
| 1008 AttachPlayersToTimeline(); |
| 910 } | 1009 } |
| 911 | 1010 |
| 912 void BeginTest() override { | 1011 void BeginTest() override { |
| 913 // Add a translate from 6,7 to 8,9. | 1012 // Add a translate from 6,7 to 8,9. |
| 914 TransformOperations start; | 1013 TransformOperations start; |
| 915 start.AppendTranslate(6.f, 7.f, 0.f); | 1014 start.AppendTranslate(6.f, 7.f, 0.f); |
| 916 TransformOperations end; | 1015 TransformOperations end; |
| 917 end.AppendTranslate(8.f, 9.f, 0.f); | 1016 end.AppendTranslate(8.f, 9.f, 0.f); |
| 918 AddAnimatedTransformToLayer(layer_.get(), 4.0, start, end); | 1017 AddAnimatedTransformToPlayer(player_.get(), 4.0, start, end); |
| 919 | 1018 |
| 920 PostSetNeedsCommitToMainThread(); | 1019 PostSetNeedsCommitToMainThread(); |
| 921 } | 1020 } |
| 922 | 1021 |
| 923 void WillPrepareTiles(LayerTreeHostImpl* host_impl) override { | 1022 void WillPrepareTiles(LayerTreeHostImpl* host_impl) override { |
| 924 if (host_impl->sync_tree()->source_frame_number() != 0) | 1023 if (host_impl->sync_tree()->source_frame_number() != 0) |
| 925 return; | 1024 return; |
| 926 | 1025 |
| 927 // After checking this on the sync tree, we will activate, which will cause | 1026 // After checking this on the sync tree, we will activate, which will cause |
| 928 // PrepareTiles to happen again (which races with the test exiting). | 1027 // PrepareTiles to happen again (which races with the test exiting). |
| 929 if (TestEnded()) | 1028 if (TestEnded()) |
| 930 return; | 1029 return; |
| 931 | 1030 |
| 1031 scoped_refptr<AnimationTimeline> timeline_impl = |
| 1032 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 1033 scoped_refptr<AnimationPlayer> player_impl = |
| 1034 timeline_impl->GetPlayerById(player_id_); |
| 1035 |
| 1036 LayerAnimationController* controller_impl = |
| 1037 player_impl->element_animations()->layer_animation_controller(); |
| 1038 |
| 932 LayerImpl* root = host_impl->sync_tree()->root_layer(); | 1039 LayerImpl* root = host_impl->sync_tree()->root_layer(); |
| 933 LayerImpl* child = root->children()[0].get(); | 1040 LayerImpl* child = root->children()[0].get(); |
| 934 LayerAnimationController* controller_impl = | |
| 935 child->layer_animation_controller(); | |
| 936 Animation* animation = | 1041 Animation* animation = |
| 937 controller_impl->GetAnimation(TargetProperty::TRANSFORM); | 1042 controller_impl->GetAnimation(TargetProperty::TRANSFORM); |
| 938 | 1043 |
| 939 // The animation should be starting for the first frame. | 1044 // The animation should be starting for the first frame. |
| 940 EXPECT_EQ(Animation::STARTING, animation->run_state()); | 1045 EXPECT_EQ(Animation::STARTING, animation->run_state()); |
| 941 | 1046 |
| 942 // And the transform should be propogated to the sync tree layer, at its | 1047 // And the transform should be propogated to the sync tree layer, at its |
| 943 // starting state which is 6,7. | 1048 // starting state which is 6,7. |
| 944 gfx::Transform expected_transform; | 1049 gfx::Transform expected_transform; |
| 945 expected_transform.Translate(6.0, 7.0); | 1050 expected_transform.Translate(6.0, 7.0); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 963 // When a layer with an animation is removed from the tree and later re-added, | 1068 // When a layer with an animation is removed from the tree and later re-added, |
| 964 // the animation should resume. | 1069 // the animation should resume. |
| 965 class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded | 1070 class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded |
| 966 : public LayerTreeHostAnimationTest { | 1071 : public LayerTreeHostAnimationTest { |
| 967 public: | 1072 public: |
| 968 void SetupTree() override { | 1073 void SetupTree() override { |
| 969 LayerTreeHostAnimationTest::SetupTree(); | 1074 LayerTreeHostAnimationTest::SetupTree(); |
| 970 layer_ = Layer::Create(layer_settings()); | 1075 layer_ = Layer::Create(layer_settings()); |
| 971 layer_->SetBounds(gfx::Size(4, 4)); | 1076 layer_->SetBounds(gfx::Size(4, 4)); |
| 972 layer_tree_host()->root_layer()->AddChild(layer_); | 1077 layer_tree_host()->root_layer()->AddChild(layer_); |
| 973 AddOpacityTransitionToLayer(layer_.get(), 10000.0, 0.1f, 0.9f, true); | 1078 |
| 1079 layer_tree_host()->animation_host()->AddAnimationTimeline(timeline_.get()); |
| 1080 timeline_->AttachPlayer(player_.get()); |
| 1081 player_->AttachLayer(layer_->id()); |
| 1082 DCHECK(player_->element_animations()); |
| 1083 |
| 1084 AddOpacityTransitionToPlayer(player_.get(), 10000.0, 0.1f, 0.9f, true); |
| 974 } | 1085 } |
| 975 | 1086 |
| 976 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1087 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 977 | 1088 |
| 978 void DidCommit() override { | 1089 void DidCommit() override { |
| 979 switch (layer_tree_host()->source_frame_number()) { | 1090 switch (layer_tree_host()->source_frame_number()) { |
| 980 case 0: | 1091 case 0: |
| 981 EXPECT_TRUE( | 1092 EXPECT_TRUE(player_->element_animations() |
| 982 layer_tree_host()->animation_registrar()->needs_animate_layers()); | 1093 ->has_active_value_observer_for_testing()); |
| 1094 EXPECT_FALSE(player_->element_animations() |
| 1095 ->has_pending_value_observer_for_testing()); |
| 1096 EXPECT_TRUE(layer_tree_host() |
| 1097 ->animation_host() |
| 1098 ->animation_registrar() |
| 1099 ->needs_animate_layers()); |
| 983 break; | 1100 break; |
| 984 case 1: | 1101 case 1: |
| 985 layer_->RemoveFromParent(); | 1102 layer_->RemoveFromParent(); |
| 986 EXPECT_TRUE( | 1103 EXPECT_FALSE(player_->element_animations() |
| 987 layer_tree_host()->animation_registrar()->needs_animate_layers()); | 1104 ->has_active_value_observer_for_testing()); |
| 1105 EXPECT_FALSE(player_->element_animations() |
| 1106 ->has_pending_value_observer_for_testing()); |
| 1107 EXPECT_TRUE(layer_tree_host() |
| 1108 ->animation_host() |
| 1109 ->animation_registrar() |
| 1110 ->needs_animate_layers()); |
| 988 break; | 1111 break; |
| 989 case 2: | 1112 case 2: |
| 990 layer_tree_host()->root_layer()->AddChild(layer_); | 1113 layer_tree_host()->root_layer()->AddChild(layer_); |
| 991 EXPECT_TRUE( | 1114 EXPECT_TRUE(player_->element_animations() |
| 992 layer_tree_host()->animation_registrar()->needs_animate_layers()); | 1115 ->has_active_value_observer_for_testing()); |
| 1116 EXPECT_FALSE(player_->element_animations() |
| 1117 ->has_pending_value_observer_for_testing()); |
| 1118 EXPECT_TRUE(layer_tree_host() |
| 1119 ->animation_host() |
| 1120 ->animation_registrar() |
| 1121 ->needs_animate_layers()); |
| 993 break; | 1122 break; |
| 994 } | 1123 } |
| 995 } | 1124 } |
| 996 | 1125 |
| 997 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 1126 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 1127 scoped_refptr<AnimationTimeline> timeline_impl = |
| 1128 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 1129 scoped_refptr<AnimationPlayer> player_impl = |
| 1130 timeline_impl->GetPlayerById(player_id_); |
| 1131 |
| 998 switch (host_impl->active_tree()->source_frame_number()) { | 1132 switch (host_impl->active_tree()->source_frame_number()) { |
| 999 case 0: | 1133 case 0: |
| 1000 EXPECT_TRUE(host_impl->animation_registrar()->needs_animate_layers()); | 1134 EXPECT_TRUE(player_impl->element_animations() |
| 1135 ->has_active_value_observer_for_testing()); |
| 1136 EXPECT_TRUE(host_impl->animation_host() |
| 1137 ->animation_registrar() |
| 1138 ->needs_animate_layers()); |
| 1001 break; | 1139 break; |
| 1002 case 1: | 1140 case 1: |
| 1003 EXPECT_FALSE(host_impl->animation_registrar()->needs_animate_layers()); | 1141 EXPECT_FALSE(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()); |
| 1004 break; | 1146 break; |
| 1005 case 2: | 1147 case 2: |
| 1006 EXPECT_TRUE(host_impl->animation_registrar()->needs_animate_layers()); | 1148 EXPECT_TRUE(player_impl->element_animations() |
| 1149 ->has_active_value_observer_for_testing()); |
| 1150 EXPECT_TRUE(host_impl->animation_host() |
| 1151 ->animation_registrar() |
| 1152 ->needs_animate_layers()); |
| 1007 EndTest(); | 1153 EndTest(); |
| 1008 break; | 1154 break; |
| 1009 } | 1155 } |
| 1010 } | 1156 } |
| 1011 | 1157 |
| 1012 void AfterTest() override {} | 1158 void AfterTest() override {} |
| 1013 | 1159 |
| 1014 private: | 1160 private: |
| 1015 scoped_refptr<Layer> layer_; | 1161 scoped_refptr<Layer> layer_; |
| 1016 }; | 1162 }; |
| 1017 | 1163 |
| 1018 SINGLE_AND_MULTI_THREAD_TEST_F( | 1164 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1019 LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded); | 1165 LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded); |
| 1020 | 1166 |
| 1021 class LayerTreeHostAnimationTestAddAnimationAfterAnimating | 1167 class LayerTreeHostAnimationTestAddAnimationAfterAnimating |
| 1022 : public LayerTreeHostAnimationTest { | 1168 : public LayerTreeHostAnimationTest { |
| 1023 public: | 1169 public: |
| 1024 void SetupTree() override { | 1170 void SetupTree() override { |
| 1025 LayerTreeHostAnimationTest::SetupTree(); | 1171 LayerTreeHostAnimationTest::SetupTree(); |
| 1026 layer_ = Layer::Create(layer_settings()); | 1172 layer_ = Layer::Create(layer_settings()); |
| 1027 layer_->SetBounds(gfx::Size(4, 4)); | 1173 layer_->SetBounds(gfx::Size(4, 4)); |
| 1028 layer_tree_host()->root_layer()->AddChild(layer_); | 1174 layer_tree_host()->root_layer()->AddChild(layer_); |
| 1175 |
| 1176 AttachPlayersToTimeline(); |
| 1177 |
| 1178 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 1179 player_child_->AttachLayer(layer_->id()); |
| 1029 } | 1180 } |
| 1030 | 1181 |
| 1031 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1182 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1032 | 1183 |
| 1033 void DidCommit() override { | 1184 void DidCommit() override { |
| 1034 switch (layer_tree_host()->source_frame_number()) { | 1185 switch (layer_tree_host()->source_frame_number()) { |
| 1035 case 1: | 1186 case 1: |
| 1036 // First frame: add an animation to the root layer. | 1187 // First frame: add an animation to the root layer. |
| 1037 AddAnimatedTransformToLayer(layer_tree_host()->root_layer(), 0.1, 5, 5); | 1188 AddAnimatedTransformToPlayer(player_.get(), 0.1, 5, 5); |
| 1038 break; | 1189 break; |
| 1039 case 2: | 1190 case 2: |
| 1040 // Second frame: add an animation to the content layer. The root layer | 1191 // Second frame: add an animation to the content layer. The root layer |
| 1041 // animation has caused us to animate already during this frame. | 1192 // animation has caused us to animate already during this frame. |
| 1042 AddOpacityTransitionToLayer(layer_.get(), 0.1, 5, 5, false); | 1193 AddOpacityTransitionToPlayer(player_child_.get(), 0.1, 5, 5, false); |
| 1043 break; | 1194 break; |
| 1044 } | 1195 } |
| 1045 } | 1196 } |
| 1046 | 1197 |
| 1047 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { | 1198 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
| 1048 // After both animations have started, verify that they have valid | 1199 // After both animations have started, verify that they have valid |
| 1049 // start times. | 1200 // start times. |
| 1050 if (host_impl->active_tree()->source_frame_number() < 2) | 1201 if (host_impl->active_tree()->source_frame_number() < 2) |
| 1051 return; | 1202 return; |
| 1052 AnimationRegistrar::AnimationControllerMap controllers_copy = | 1203 AnimationRegistrar::AnimationControllerMap controllers_copy = |
| 1053 host_impl->animation_registrar() | 1204 host_impl->animation_host() |
| 1205 ->animation_registrar() |
| 1054 ->active_animation_controllers_for_testing(); | 1206 ->active_animation_controllers_for_testing(); |
| 1055 EXPECT_EQ(2u, controllers_copy.size()); | 1207 EXPECT_EQ(2u, controllers_copy.size()); |
| 1056 for (auto& it : controllers_copy) { | 1208 for (auto& it : controllers_copy) { |
| 1057 int id = it.first; | 1209 int id = it.first; |
| 1058 if (id == host_impl->RootLayer()->id()) { | 1210 if (id == host_impl->RootLayer()->id()) { |
| 1059 Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM); | 1211 Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM); |
| 1060 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1212 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| 1061 } else if (id == host_impl->RootLayer()->children()[0]->id()) { | 1213 } else if (id == host_impl->RootLayer()->children()[0]->id()) { |
| 1062 Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY); | 1214 Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY); |
| 1063 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1215 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1077 | 1229 |
| 1078 class LayerTreeHostAnimationTestRemoveAnimation | 1230 class LayerTreeHostAnimationTestRemoveAnimation |
| 1079 : public LayerTreeHostAnimationTest { | 1231 : public LayerTreeHostAnimationTest { |
| 1080 public: | 1232 public: |
| 1081 void SetupTree() override { | 1233 void SetupTree() override { |
| 1082 LayerTreeHostAnimationTest::SetupTree(); | 1234 LayerTreeHostAnimationTest::SetupTree(); |
| 1083 layer_ = FakePictureLayer::Create(layer_settings(), &client_); | 1235 layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 1084 layer_->SetBounds(gfx::Size(4, 4)); | 1236 layer_->SetBounds(gfx::Size(4, 4)); |
| 1085 client_.set_bounds(layer_->bounds()); | 1237 client_.set_bounds(layer_->bounds()); |
| 1086 layer_tree_host()->root_layer()->AddChild(layer_); | 1238 layer_tree_host()->root_layer()->AddChild(layer_); |
| 1239 |
| 1240 AttachPlayersToTimeline(); |
| 1241 |
| 1242 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 1243 player_child_->AttachLayer(layer_->id()); |
| 1087 } | 1244 } |
| 1088 | 1245 |
| 1089 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1246 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1090 | 1247 |
| 1091 void DidCommit() override { | 1248 void DidCommit() override { |
| 1092 switch (layer_tree_host()->source_frame_number()) { | 1249 switch (layer_tree_host()->source_frame_number()) { |
| 1093 case 1: | 1250 case 1: |
| 1094 AddAnimatedTransformToLayer(layer_.get(), 1.0, 5, 5); | 1251 AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); |
| 1095 break; | 1252 break; |
| 1096 case 2: | 1253 case 2: |
| 1097 LayerAnimationController* controller = | 1254 LayerAnimationController* controller = |
| 1098 layer_->layer_animation_controller(); | 1255 player_child_->element_animations()->layer_animation_controller(); |
| 1099 Animation* animation = | 1256 Animation* animation = |
| 1100 controller->GetAnimation(TargetProperty::TRANSFORM); | 1257 controller->GetAnimation(TargetProperty::TRANSFORM); |
| 1101 layer_->RemoveAnimation(animation->id()); | 1258 player_child_->RemoveAnimation(animation->id()); |
| 1102 gfx::Transform transform; | 1259 gfx::Transform transform; |
| 1103 transform.Translate(10.f, 10.f); | 1260 transform.Translate(10.f, 10.f); |
| 1104 layer_->SetTransform(transform); | 1261 layer_->SetTransform(transform); |
| 1105 | 1262 |
| 1106 // Do something that causes property trees to get rebuilt. This is | 1263 // Do something that causes property trees to get rebuilt. This is |
| 1107 // intended to simulate the conditions that caused the bug whose fix | 1264 // intended to simulate the conditions that caused the bug whose fix |
| 1108 // this is testing (the test will pass without it but won't test what | 1265 // this is testing (the test will pass without it but won't test what |
| 1109 // we want it to). We were updating the wrong transform node at the end | 1266 // we want it to). We were updating the wrong transform node at the end |
| 1110 // of an animation (we were assuming the layer with the finished | 1267 // of an animation (we were assuming the layer with the finished |
| 1111 // animation still had its own transform node). But nodes can only get | 1268 // animation still had its own transform node). But nodes can only get |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 | 1311 |
| 1155 class LayerTreeHostAnimationTestIsAnimating | 1312 class LayerTreeHostAnimationTestIsAnimating |
| 1156 : public LayerTreeHostAnimationTest { | 1313 : public LayerTreeHostAnimationTest { |
| 1157 public: | 1314 public: |
| 1158 void SetupTree() override { | 1315 void SetupTree() override { |
| 1159 LayerTreeHostAnimationTest::SetupTree(); | 1316 LayerTreeHostAnimationTest::SetupTree(); |
| 1160 layer_ = FakePictureLayer::Create(layer_settings(), &client_); | 1317 layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 1161 layer_->SetBounds(gfx::Size(4, 4)); | 1318 layer_->SetBounds(gfx::Size(4, 4)); |
| 1162 client_.set_bounds(layer_->bounds()); | 1319 client_.set_bounds(layer_->bounds()); |
| 1163 layer_tree_host()->root_layer()->AddChild(layer_); | 1320 layer_tree_host()->root_layer()->AddChild(layer_); |
| 1321 |
| 1322 AttachPlayersToTimeline(); |
| 1323 player_->AttachLayer(layer_->id()); |
| 1164 } | 1324 } |
| 1165 | 1325 |
| 1166 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1326 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1167 | 1327 |
| 1168 void DidCommit() override { | 1328 void DidCommit() override { |
| 1169 switch (layer_tree_host()->source_frame_number()) { | 1329 switch (layer_tree_host()->source_frame_number()) { |
| 1170 case 1: | 1330 case 1: |
| 1171 AddAnimatedTransformToLayer(layer_.get(), 1.0, 5, 5); | 1331 AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5); |
| 1172 break; | 1332 break; |
| 1173 case 2: | 1333 case 2: |
| 1174 LayerAnimationController* controller = | 1334 LayerAnimationController* controller = |
| 1175 layer_->layer_animation_controller(); | 1335 player_->element_animations()->layer_animation_controller(); |
| 1176 Animation* animation = | 1336 Animation* animation = |
| 1177 controller->GetAnimation(TargetProperty::TRANSFORM); | 1337 controller->GetAnimation(TargetProperty::TRANSFORM); |
| 1178 layer_->RemoveAnimation(animation->id()); | 1338 player_->RemoveAnimation(animation->id()); |
| 1179 break; | 1339 break; |
| 1180 } | 1340 } |
| 1181 } | 1341 } |
| 1182 | 1342 |
| 1183 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 1343 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 1184 LayerImpl* root = host_impl->sync_tree()->root_layer(); | 1344 LayerImpl* root = host_impl->sync_tree()->root_layer(); |
| 1185 LayerImpl* child = root->children()[0].get(); | 1345 LayerImpl* child = root->children()[0].get(); |
| 1186 switch (host_impl->sync_tree()->source_frame_number()) { | 1346 switch (host_impl->sync_tree()->source_frame_number()) { |
| 1187 case 0: | 1347 case 0: |
| 1188 // No animation yet. | 1348 // No animation yet. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 public: | 1396 public: |
| 1237 LayerTreeHostAnimationTestAnimationFinishesDuringCommit() | 1397 LayerTreeHostAnimationTestAnimationFinishesDuringCommit() |
| 1238 : signalled_(false) {} | 1398 : signalled_(false) {} |
| 1239 | 1399 |
| 1240 void SetupTree() override { | 1400 void SetupTree() override { |
| 1241 LayerTreeHostAnimationTest::SetupTree(); | 1401 LayerTreeHostAnimationTest::SetupTree(); |
| 1242 layer_ = FakePictureLayer::Create(layer_settings(), &client_); | 1402 layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 1243 layer_->SetBounds(gfx::Size(4, 4)); | 1403 layer_->SetBounds(gfx::Size(4, 4)); |
| 1244 client_.set_bounds(layer_->bounds()); | 1404 client_.set_bounds(layer_->bounds()); |
| 1245 layer_tree_host()->root_layer()->AddChild(layer_); | 1405 layer_tree_host()->root_layer()->AddChild(layer_); |
| 1406 |
| 1407 AttachPlayersToTimeline(); |
| 1408 |
| 1409 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 1410 player_child_->AttachLayer(layer_->id()); |
| 1246 } | 1411 } |
| 1247 | 1412 |
| 1248 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1413 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1249 | 1414 |
| 1250 void DidCommit() override { | 1415 void DidCommit() override { |
| 1251 if (layer_tree_host()->source_frame_number() == 1) | 1416 if (layer_tree_host()->source_frame_number() == 1) |
| 1252 AddAnimatedTransformToLayer(layer_.get(), 0.04, 5, 5); | 1417 AddAnimatedTransformToPlayer(player_child_.get(), 0.04, 5, 5); |
| 1253 } | 1418 } |
| 1254 | 1419 |
| 1255 void WillCommit() override { | 1420 void WillCommit() override { |
| 1256 if (layer_tree_host()->source_frame_number() == 2) { | 1421 if (layer_tree_host()->source_frame_number() == 2) { |
| 1257 // Block until the animation finishes on the compositor thread. Since | 1422 // Block until the animation finishes on the compositor thread. Since |
| 1258 // animations have already been ticked on the main thread, when the commit | 1423 // animations have already been ticked on the main thread, when the commit |
| 1259 // happens the state on the main thread will be consistent with having a | 1424 // happens the state on the main thread will be consistent with having a |
| 1260 // running animation but the state on the compositor thread will be | 1425 // running animation but the state on the compositor thread will be |
| 1261 // consistent with having only a finished animation. | 1426 // consistent with having only a finished animation. |
| 1262 completion_.Wait(); | 1427 completion_.Wait(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 : public LayerTreeHostAnimationTest { | 1471 : public LayerTreeHostAnimationTest { |
| 1307 public: | 1472 public: |
| 1308 LayerTreeHostAnimationTestNotifyAnimationFinished() | 1473 LayerTreeHostAnimationTestNotifyAnimationFinished() |
| 1309 : called_animation_started_(false), called_animation_finished_(false) {} | 1474 : called_animation_started_(false), called_animation_finished_(false) {} |
| 1310 | 1475 |
| 1311 void SetupTree() override { | 1476 void SetupTree() override { |
| 1312 LayerTreeHostAnimationTest::SetupTree(); | 1477 LayerTreeHostAnimationTest::SetupTree(); |
| 1313 picture_ = FakePictureLayer::Create(layer_settings(), &client_); | 1478 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 1314 picture_->SetBounds(gfx::Size(4, 4)); | 1479 picture_->SetBounds(gfx::Size(4, 4)); |
| 1315 client_.set_bounds(picture_->bounds()); | 1480 client_.set_bounds(picture_->bounds()); |
| 1316 picture_->set_layer_animation_delegate(this); | |
| 1317 layer_tree_host()->root_layer()->AddChild(picture_); | 1481 layer_tree_host()->root_layer()->AddChild(picture_); |
| 1482 |
| 1483 AttachPlayersToTimeline(); |
| 1484 player_->AttachLayer(picture_->id()); |
| 1485 player_->set_layer_animation_delegate(this); |
| 1318 } | 1486 } |
| 1319 | 1487 |
| 1320 void BeginTest() override { | 1488 void BeginTest() override { |
| 1321 PostAddLongAnimationToMainThread(picture_.get()); | 1489 PostAddLongAnimationToMainThreadPlayer(player_.get()); |
| 1322 } | 1490 } |
| 1323 | 1491 |
| 1324 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 1492 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
| 1325 TargetProperty::Type target_property, | 1493 TargetProperty::Type target_property, |
| 1326 int group) override { | 1494 int group) override { |
| 1327 called_animation_started_ = true; | 1495 called_animation_started_ = true; |
| 1328 layer_tree_host()->AnimateLayers(base::TimeTicks::FromInternalValue( | 1496 layer_tree_host()->AnimateLayers(base::TimeTicks::FromInternalValue( |
| 1329 std::numeric_limits<int64_t>::max())); | 1497 std::numeric_limits<int64_t>::max())); |
| 1330 PostSetNeedsCommitToMainThread(); | 1498 PostSetNeedsCommitToMainThread(); |
| 1331 } | 1499 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1345 private: | 1513 private: |
| 1346 bool called_animation_started_; | 1514 bool called_animation_started_; |
| 1347 bool called_animation_finished_; | 1515 bool called_animation_finished_; |
| 1348 FakeContentLayerClient client_; | 1516 FakeContentLayerClient client_; |
| 1349 scoped_refptr<FakePictureLayer> picture_; | 1517 scoped_refptr<FakePictureLayer> picture_; |
| 1350 }; | 1518 }; |
| 1351 | 1519 |
| 1352 SINGLE_AND_MULTI_THREAD_TEST_F( | 1520 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1353 LayerTreeHostAnimationTestNotifyAnimationFinished); | 1521 LayerTreeHostAnimationTestNotifyAnimationFinished); |
| 1354 | 1522 |
| 1523 // Check that SetTransformIsPotentiallyAnimatingChanged is called |
| 1524 // if we destroy LayerAnimationController and ElementAnimations. |
| 1525 class LayerTreeHostAnimationTestSetPotentiallyAnimatingOnLacDestruction |
| 1526 : public LayerTreeHostAnimationTest { |
| 1527 public: |
| 1528 void SetupTree() override { |
| 1529 prev_screen_space_transform_is_animating_ = true; |
| 1530 screen_space_transform_animation_stopped_ = false; |
| 1531 |
| 1532 LayerTreeHostAnimationTest::SetupTree(); |
| 1533 AttachPlayersToTimeline(); |
| 1534 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 1535 AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5); |
| 1536 } |
| 1537 |
| 1538 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1539 |
| 1540 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 1541 if (host_impl->pending_tree()->source_frame_number() <= 1) { |
| 1542 EXPECT_TRUE(host_impl->pending_tree() |
| 1543 ->root_layer() |
| 1544 ->screen_space_transform_is_animating()); |
| 1545 } else { |
| 1546 EXPECT_FALSE(host_impl->pending_tree() |
| 1547 ->root_layer() |
| 1548 ->screen_space_transform_is_animating()); |
| 1549 } |
| 1550 } |
| 1551 |
| 1552 void DidCommit() override { PostSetNeedsCommitToMainThread(); } |
| 1553 |
| 1554 void UpdateLayerTreeHost() override { |
| 1555 if (layer_tree_host()->source_frame_number() == 2) { |
| 1556 // Destroy player. |
| 1557 timeline_->DetachPlayer(player_.get()); |
| 1558 player_ = nullptr; |
| 1559 } |
| 1560 } |
| 1561 |
| 1562 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 1563 LayerTreeHostImpl::FrameData* frame_data, |
| 1564 DrawResult draw_result) override { |
| 1565 const bool screen_space_transform_is_animating = |
| 1566 host_impl->active_tree() |
| 1567 ->root_layer() |
| 1568 ->screen_space_transform_is_animating(); |
| 1569 |
| 1570 // Check that screen_space_transform_is_animating changes only once. |
| 1571 if (screen_space_transform_is_animating && |
| 1572 prev_screen_space_transform_is_animating_) |
| 1573 EXPECT_FALSE(screen_space_transform_animation_stopped_); |
| 1574 if (!screen_space_transform_is_animating && |
| 1575 prev_screen_space_transform_is_animating_) { |
| 1576 EXPECT_FALSE(screen_space_transform_animation_stopped_); |
| 1577 screen_space_transform_animation_stopped_ = true; |
| 1578 } |
| 1579 if (!screen_space_transform_is_animating && |
| 1580 !prev_screen_space_transform_is_animating_) |
| 1581 EXPECT_TRUE(screen_space_transform_animation_stopped_); |
| 1582 |
| 1583 prev_screen_space_transform_is_animating_ = |
| 1584 screen_space_transform_is_animating; |
| 1585 |
| 1586 return draw_result; |
| 1587 } |
| 1588 |
| 1589 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 1590 if (host_impl->active_tree()->source_frame_number() >= 2) |
| 1591 EndTest(); |
| 1592 } |
| 1593 |
| 1594 void AfterTest() override { |
| 1595 EXPECT_TRUE(screen_space_transform_animation_stopped_); |
| 1596 } |
| 1597 |
| 1598 bool prev_screen_space_transform_is_animating_; |
| 1599 bool screen_space_transform_animation_stopped_; |
| 1600 }; |
| 1601 |
| 1602 MULTI_THREAD_TEST_F( |
| 1603 LayerTreeHostAnimationTestSetPotentiallyAnimatingOnLacDestruction); |
| 1604 |
| 1605 // Check that we invalidate property trees on AnimationPlayer::SetNeedsCommit. |
| 1606 class LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit |
| 1607 : public LayerTreeHostAnimationTest { |
| 1608 public: |
| 1609 void SetupTree() override { |
| 1610 LayerTreeHostAnimationTest::SetupTree(); |
| 1611 layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 1612 layer_->SetBounds(gfx::Size(4, 4)); |
| 1613 client_.set_bounds(layer_->bounds()); |
| 1614 layer_tree_host()->root_layer()->AddChild(layer_); |
| 1615 |
| 1616 AttachPlayersToTimeline(); |
| 1617 |
| 1618 player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| 1619 player_child_->AttachLayer(layer_->id()); |
| 1620 } |
| 1621 |
| 1622 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1623 |
| 1624 void DidCommit() override { |
| 1625 if (layer_tree_host()->source_frame_number() == 1 || |
| 1626 layer_tree_host()->source_frame_number() == 2) |
| 1627 PostSetNeedsCommitToMainThread(); |
| 1628 } |
| 1629 |
| 1630 void UpdateLayerTreeHost() override { |
| 1631 if (layer_tree_host()->source_frame_number() == 1) { |
| 1632 EXPECT_FALSE(layer_tree_host()->property_trees()->needs_rebuild); |
| 1633 AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); |
| 1634 } |
| 1635 |
| 1636 EXPECT_TRUE(layer_tree_host()->property_trees()->needs_rebuild); |
| 1637 } |
| 1638 |
| 1639 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| 1640 if (host_impl->active_tree()->source_frame_number() >= 2) |
| 1641 EndTest(); |
| 1642 } |
| 1643 |
| 1644 void AfterTest() override {} |
| 1645 |
| 1646 private: |
| 1647 scoped_refptr<Layer> layer_; |
| 1648 FakeContentLayerClient client_; |
| 1649 }; |
| 1650 |
| 1651 MULTI_THREAD_TEST_F( |
| 1652 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); |
| 1653 |
| 1355 } // namespace | 1654 } // namespace |
| 1356 } // namespace cc | 1655 } // namespace cc |
| OLD | NEW |