| 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 "cc/animation/animation_curve.h" | 7 #include "cc/animation/animation_curve.h" |
| 8 #include "cc/animation/layer_animation_controller.h" | 8 #include "cc/animation/layer_animation_controller.h" |
| 9 #include "cc/animation/scroll_offset_animation_curve.h" | 9 #include "cc/animation/scroll_offset_animation_curve.h" |
| 10 #include "cc/animation/timing_function.h" | 10 #include "cc/animation/timing_function.h" |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 break; | 390 break; |
| 391 case 4: | 391 case 4: |
| 392 EndTest(); | 392 EndTest(); |
| 393 break; | 393 break; |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 | 396 |
| 397 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 397 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 398 // At the start of every commit, block activations and make sure | 398 // At the start of every commit, block activations and make sure |
| 399 // we are backgrounded. | 399 // we are backgrounded. |
| 400 if (host_impl->settings().impl_side_painting) | 400 host_impl->BlockNotifyReadyToActivateForTesting(true); |
| 401 host_impl->BlockNotifyReadyToActivateForTesting(true); | |
| 402 PostSetVisibleToMainThread(false); | 401 PostSetVisibleToMainThread(false); |
| 403 } | 402 } |
| 404 | 403 |
| 405 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 404 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 406 if (!host_impl->settings().impl_side_painting) { | 405 if (!host_impl->settings().impl_side_painting) { |
| 407 // There are no activations to block if we're not impl-side-painting, | 406 // There are no activations to block if we're not impl-side-painting, |
| 408 // so just advance the test immediately. | 407 // so just advance the test immediately. |
| 409 if (host_impl->active_tree()->source_frame_number() < 3) | 408 if (host_impl->active_tree()->source_frame_number() < 3) |
| 410 UnblockActivations(host_impl); | 409 UnblockActivations(host_impl); |
| 411 return; | 410 return; |
| 412 } | 411 } |
| 413 | 412 |
| 414 // We block activation for several ticks to make sure that, even though | 413 // We block activation for several ticks to make sure that, even though |
| 415 // there is a pending tree with animations, we still do not background | 414 // there is a pending tree with animations, we still do not background |
| 416 // tick if the active tree is empty. | 415 // tick if the active tree is empty. |
| 417 if (host_impl->pending_tree()->source_frame_number() < 3) { | 416 if (host_impl->pending_tree()->source_frame_number() < 3) { |
| 418 base::MessageLoopProxy::current()->PostDelayedTask( | 417 base::MessageLoopProxy::current()->PostDelayedTask( |
| 419 FROM_HERE, | 418 FROM_HERE, |
| 420 base::Bind( | 419 base::Bind( |
| 421 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree:: | 420 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree:: |
| 422 UnblockActivations, | 421 UnblockActivations, |
| 423 base::Unretained(this), | 422 base::Unretained(this), |
| 424 host_impl), | 423 host_impl), |
| 425 4 * LowFrequencyAnimationInterval()); | 424 4 * LowFrequencyAnimationInterval()); |
| 426 } | 425 } |
| 427 } | 426 } |
| 428 | 427 |
| 429 virtual void UnblockActivations(LayerTreeHostImpl* host_impl) { | 428 virtual void UnblockActivations(LayerTreeHostImpl* host_impl) { |
| 430 if (host_impl->settings().impl_side_painting) | 429 host_impl->BlockNotifyReadyToActivateForTesting(false); |
| 431 host_impl->BlockNotifyReadyToActivateForTesting(false); | |
| 432 } | 430 } |
| 433 | 431 |
| 434 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 432 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 435 active_tree_was_animated_ = false; | 433 active_tree_was_animated_ = false; |
| 436 | 434 |
| 437 // Verify that commits are actually alternating with empty / non-empty | 435 // Verify that commits are actually alternating with empty / non-empty |
| 438 // trees. | 436 // trees. |
| 439 int frame_number = host_impl->active_tree()->source_frame_number(); | 437 int frame_number = host_impl->active_tree()->source_frame_number(); |
| 440 switch (frame_number) { | 438 switch (frame_number) { |
| 441 case 0: | 439 case 0: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 | 475 |
| 478 // The next commit is blocked until we become visible again. | 476 // The next commit is blocked until we become visible again. |
| 479 PostSetVisibleToMainThread(true); | 477 PostSetVisibleToMainThread(true); |
| 480 } | 478 } |
| 481 | 479 |
| 482 virtual void AfterTest() OVERRIDE {} | 480 virtual void AfterTest() OVERRIDE {} |
| 483 | 481 |
| 484 bool active_tree_was_animated_; | 482 bool active_tree_was_animated_; |
| 485 }; | 483 }; |
| 486 | 484 |
| 487 SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F( | 485 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 488 LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree); | 486 LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree); |
| 489 | 487 |
| 490 // Ensure that an animation's timing function is respected. | 488 // Ensure that an animation's timing function is respected. |
| 491 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction | 489 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction |
| 492 : public LayerTreeHostAnimationTest { | 490 : public LayerTreeHostAnimationTest { |
| 493 public: | 491 public: |
| 494 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} | 492 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} |
| 495 | 493 |
| 496 virtual void SetupTree() OVERRIDE { | 494 virtual void SetupTree() OVERRIDE { |
| 497 LayerTreeHostAnimationTest::SetupTree(); | 495 LayerTreeHostAnimationTest::SetupTree(); |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 | 1162 |
| 1165 scoped_refptr<Layer> layer = Layer::Create(); | 1163 scoped_refptr<Layer> layer = Layer::Create(); |
| 1166 layer_tree_host()->root_layer()->AddChild(layer); | 1164 layer_tree_host()->root_layer()->AddChild(layer); |
| 1167 layer->set_layer_animation_delegate(this); | 1165 layer->set_layer_animation_delegate(this); |
| 1168 layer->SetBounds(gfx::Size(4, 4)); | 1166 layer->SetBounds(gfx::Size(4, 4)); |
| 1169 AddOpacityTransitionToLayer(layer.get(), 1, 0.f, 0.5f, true); | 1167 AddOpacityTransitionToLayer(layer.get(), 1, 0.f, 0.5f, true); |
| 1170 } | 1168 } |
| 1171 } | 1169 } |
| 1172 | 1170 |
| 1173 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1171 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1174 if (host_impl->settings().impl_side_painting) | 1172 host_impl->BlockNotifyReadyToActivateForTesting(true); |
| 1175 host_impl->BlockNotifyReadyToActivateForTesting(true); | |
| 1176 } | 1173 } |
| 1177 | 1174 |
| 1178 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1175 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 1179 // For the commit that added animations to new and existing layers, keep | 1176 // For the commit that added animations to new and existing layers, keep |
| 1180 // blocking activation. We want to verify that even with activation blocked, | 1177 // blocking activation. We want to verify that even with activation blocked, |
| 1181 // the animation on the layer that's already in the active tree won't get a | 1178 // the animation on the layer that's already in the active tree won't get a |
| 1182 // head start. | 1179 // head start. |
| 1183 if (host_impl->settings().impl_side_painting && | 1180 if (!host_impl->settings().impl_side_painting || |
| 1184 host_impl->pending_tree()->source_frame_number() != 2) { | 1181 host_impl->pending_tree()->source_frame_number() != 2) |
| 1185 host_impl->BlockNotifyReadyToActivateForTesting(false); | 1182 host_impl->BlockNotifyReadyToActivateForTesting(false); |
| 1186 } | |
| 1187 } | 1183 } |
| 1188 | 1184 |
| 1189 virtual void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, | 1185 virtual void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, |
| 1190 const BeginFrameArgs& args) OVERRIDE { | 1186 const BeginFrameArgs& args) OVERRIDE { |
| 1191 if (!host_impl->pending_tree() || | 1187 if (!host_impl->pending_tree() || |
| 1192 host_impl->pending_tree()->source_frame_number() != 2) | 1188 host_impl->pending_tree()->source_frame_number() != 2) |
| 1193 return; | 1189 return; |
| 1194 | 1190 |
| 1195 frame_count_with_pending_tree_++; | 1191 frame_count_with_pending_tree_++; |
| 1196 if (frame_count_with_pending_tree_ == 2 && | 1192 if (frame_count_with_pending_tree_ == 2) |
| 1197 host_impl->settings().impl_side_painting) { | |
| 1198 host_impl->BlockNotifyReadyToActivateForTesting(false); | 1193 host_impl->BlockNotifyReadyToActivateForTesting(false); |
| 1199 } | |
| 1200 } | 1194 } |
| 1201 | 1195 |
| 1202 virtual void UpdateAnimationState(LayerTreeHostImpl* host_impl, | 1196 virtual void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
| 1203 bool has_unfinished_animation) OVERRIDE { | 1197 bool has_unfinished_animation) OVERRIDE { |
| 1204 LayerAnimationController* root_controller_impl = | 1198 LayerAnimationController* root_controller_impl = |
| 1205 host_impl->active_tree()->root_layer()->layer_animation_controller(); | 1199 host_impl->active_tree()->root_layer()->layer_animation_controller(); |
| 1206 Animation* root_animation = | 1200 Animation* root_animation = |
| 1207 root_controller_impl->GetAnimation(Animation::Opacity); | 1201 root_controller_impl->GetAnimation(Animation::Opacity); |
| 1208 if (!root_animation || root_animation->run_state() != Animation::Running) | 1202 if (!root_animation || root_animation->run_state() != Animation::Running) |
| 1209 return; | 1203 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1220 child_controller_impl->AbortAnimations(Animation::Opacity); | 1214 child_controller_impl->AbortAnimations(Animation::Opacity); |
| 1221 EndTest(); | 1215 EndTest(); |
| 1222 } | 1216 } |
| 1223 | 1217 |
| 1224 virtual void AfterTest() OVERRIDE {} | 1218 virtual void AfterTest() OVERRIDE {} |
| 1225 | 1219 |
| 1226 private: | 1220 private: |
| 1227 int frame_count_with_pending_tree_; | 1221 int frame_count_with_pending_tree_; |
| 1228 }; | 1222 }; |
| 1229 | 1223 |
| 1230 SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F( | 1224 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1231 LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers); | 1225 LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers); |
| 1232 | 1226 |
| 1233 class LayerTreeHostAnimationTestAddAnimationAfterAnimating | 1227 class LayerTreeHostAnimationTestAddAnimationAfterAnimating |
| 1234 : public LayerTreeHostAnimationTest { | 1228 : public LayerTreeHostAnimationTest { |
| 1235 public: | 1229 public: |
| 1236 LayerTreeHostAnimationTestAddAnimationAfterAnimating() | 1230 LayerTreeHostAnimationTestAddAnimationAfterAnimating() |
| 1237 : num_swap_buffers_(0) {} | 1231 : num_swap_buffers_(0) {} |
| 1238 | 1232 |
| 1239 virtual void SetupTree() OVERRIDE { | 1233 virtual void SetupTree() OVERRIDE { |
| 1240 LayerTreeHostAnimationTest::SetupTree(); | 1234 LayerTreeHostAnimationTest::SetupTree(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 private: | 1284 private: |
| 1291 scoped_refptr<Layer> content_; | 1285 scoped_refptr<Layer> content_; |
| 1292 int num_swap_buffers_; | 1286 int num_swap_buffers_; |
| 1293 }; | 1287 }; |
| 1294 | 1288 |
| 1295 SINGLE_AND_MULTI_THREAD_TEST_F( | 1289 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1296 LayerTreeHostAnimationTestAddAnimationAfterAnimating); | 1290 LayerTreeHostAnimationTestAddAnimationAfterAnimating); |
| 1297 | 1291 |
| 1298 } // namespace | 1292 } // namespace |
| 1299 } // namespace cc | 1293 } // namespace cc |
| OLD | NEW |