Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: cc/layer_tree_host_unittest_animation.cc

Issue 12774006: cc: Chromify Layer and LayerImpl classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: MoreAndroidCompilings Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer_tree_host_unittest.cc ('k') | cc/layer_tree_host_unittest_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/layer_tree_host.h" 5 #include "cc/layer_tree_host.h"
6 6
7 #include "cc/animation_curve.h" 7 #include "cc/animation_curve.h"
8 #include "cc/layer.h" 8 #include "cc/layer.h"
9 #include "cc/layer_animation_controller.h" 9 #include "cc/layer_animation_controller.h"
10 #include "cc/layer_impl.h" 10 #include "cc/layer_impl.h"
11 #include "cc/test/fake_content_layer.h" 11 #include "cc/test/fake_content_layer.h"
12 #include "cc/test/fake_content_layer_client.h" 12 #include "cc/test/fake_content_layer_client.h"
13 #include "cc/test/layer_tree_test_common.h" 13 #include "cc/test/layer_tree_test_common.h"
14 #include "cc/timing_function.h" 14 #include "cc/timing_function.h"
15 15
16 namespace cc { 16 namespace cc {
17 namespace { 17 namespace {
18 18
19 class LayerTreeHostAnimationTest : public ThreadedTest { 19 class LayerTreeHostAnimationTest : public ThreadedTest {
20 public: 20 public:
21 virtual void setupTree() OVERRIDE { 21 virtual void setupTree() OVERRIDE {
22 ThreadedTest::setupTree(); 22 ThreadedTest::setupTree();
23 m_layerTreeHost->rootLayer()->setLayerAnimationDelegate(this); 23 m_layerTreeHost->rootLayer()->set_layer_animation_delegate(this);
24 } 24 }
25 }; 25 };
26 26
27 // Makes sure that setNeedsAnimate does not cause the commitRequested() state to 27 // Makes sure that setNeedsAnimate does not cause the commitRequested() state to
28 // be set. 28 // be set.
29 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested : 29 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested :
30 public LayerTreeHostAnimationTest { 30 public LayerTreeHostAnimationTest {
31 public: 31 public:
32 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested() 32 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested()
33 : num_commits_(0) { 33 : num_commits_(0) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} 245 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {}
246 246
247 virtual void beginTest() OVERRIDE { 247 virtual void beginTest() OVERRIDE {
248 postAddAnimationToMainThread(m_layerTreeHost->rootLayer()); 248 postAddAnimationToMainThread(m_layerTreeHost->rootLayer());
249 } 249 }
250 250
251 virtual void animateLayers( 251 virtual void animateLayers(
252 LayerTreeHostImpl* host_impl, 252 LayerTreeHostImpl* host_impl,
253 base::TimeTicks monotonicTime) OVERRIDE { 253 base::TimeTicks monotonicTime) OVERRIDE {
254 LayerAnimationController* controller = 254 LayerAnimationController* controller =
255 m_layerTreeHost->rootLayer()->layerAnimationController(); 255 m_layerTreeHost->rootLayer()->layer_animation_controller();
256 Animation* animation = 256 Animation* animation =
257 controller->GetAnimation(0, Animation::Opacity); 257 controller->GetAnimation(0, Animation::Opacity);
258 if (!animation) 258 if (!animation)
259 return; 259 return;
260 260
261 const FloatAnimationCurve* curve = 261 const FloatAnimationCurve* curve =
262 animation->curve()->ToFloatAnimationCurve(); 262 animation->curve()->ToFloatAnimationCurve();
263 float startOpacity = curve->GetValue(0); 263 float startOpacity = curve->GetValue(0);
264 float endOpacity = curve->GetValue(curve->Duration()); 264 float endOpacity = curve->GetValue(curve->Duration());
265 float linearly_interpolated_opacity = 265 float linearly_interpolated_opacity =
266 0.25 * endOpacity + 0.75 * startOpacity; 266 0.25 * endOpacity + 0.75 * startOpacity;
267 double time = curve->Duration() * 0.25; 267 double time = curve->Duration() * 0.25;
268 // If the linear timing function associated with this animation was not 268 // If the linear timing function associated with this animation was not
269 // picked up, then the linearly interpolated opacity would be different 269 // picked up, then the linearly interpolated opacity would be different
270 // because of the default ease timing function. 270 // because of the default ease timing function.
271 EXPECT_FLOAT_EQ(linearly_interpolated_opacity, curve->GetValue(time)); 271 EXPECT_FLOAT_EQ(linearly_interpolated_opacity, curve->GetValue(time));
272 272
273 LayerAnimationController* controller_impl = 273 LayerAnimationController* controller_impl =
274 host_impl->rootLayer()->layerAnimationController(); 274 host_impl->rootLayer()->layer_animation_controller();
275 Animation* animation_impl = 275 Animation* animation_impl =
276 controller_impl->GetAnimation(0, Animation::Opacity); 276 controller_impl->GetAnimation(0, Animation::Opacity);
277 277
278 controller->RemoveAnimation(animation->id()); 278 controller->RemoveAnimation(animation->id());
279 controller_impl->RemoveAnimation(animation_impl->id()); 279 controller_impl->RemoveAnimation(animation_impl->id());
280 endTest(); 280 endTest();
281 } 281 }
282 282
283 virtual void afterTest() OVERRIDE {} 283 virtual void afterTest() OVERRIDE {}
284 }; 284 };
(...skipping 10 matching lines...) Expand all
295 : main_start_time_(-1), 295 : main_start_time_(-1),
296 impl_start_time_(-1) { 296 impl_start_time_(-1) {
297 } 297 }
298 298
299 virtual void beginTest() OVERRIDE { 299 virtual void beginTest() OVERRIDE {
300 postAddAnimationToMainThread(m_layerTreeHost->rootLayer()); 300 postAddAnimationToMainThread(m_layerTreeHost->rootLayer());
301 } 301 }
302 302
303 virtual void notifyAnimationStarted(double time) OVERRIDE { 303 virtual void notifyAnimationStarted(double time) OVERRIDE {
304 LayerAnimationController* controller = 304 LayerAnimationController* controller =
305 m_layerTreeHost->rootLayer()->layerAnimationController(); 305 m_layerTreeHost->rootLayer()->layer_animation_controller();
306 Animation* animation = 306 Animation* animation =
307 controller->GetAnimation(0, Animation::Opacity); 307 controller->GetAnimation(0, Animation::Opacity);
308 main_start_time_ = animation->start_time(); 308 main_start_time_ = animation->start_time();
309 controller->RemoveAnimation(animation->id()); 309 controller->RemoveAnimation(animation->id());
310 310
311 if (impl_start_time_ > 0) 311 if (impl_start_time_ > 0)
312 endTest(); 312 endTest();
313 } 313 }
314 314
315 virtual void updateAnimationState( 315 virtual void updateAnimationState(
316 LayerTreeHostImpl* impl_host, 316 LayerTreeHostImpl* impl_host,
317 bool hasUnfinishedAnimation) OVERRIDE { 317 bool hasUnfinishedAnimation) OVERRIDE {
318 LayerAnimationController* controller = 318 LayerAnimationController* controller =
319 impl_host->rootLayer()->layerAnimationController(); 319 impl_host->rootLayer()->layer_animation_controller();
320 Animation* animation = 320 Animation* animation =
321 controller->GetAnimation(0, Animation::Opacity); 321 controller->GetAnimation(0, Animation::Opacity);
322 if (!animation) 322 if (!animation)
323 return; 323 return;
324 324
325 impl_start_time_ = animation->start_time(); 325 impl_start_time_ = animation->start_time();
326 controller->RemoveAnimation(animation->id()); 326 controller->RemoveAnimation(animation->id());
327 327
328 if (main_start_time_ > 0) 328 if (main_start_time_ > 0)
329 endTest(); 329 endTest();
(...skipping 15 matching lines...) Expand all
345 public LayerTreeHostAnimationTest { 345 public LayerTreeHostAnimationTest {
346 public: 346 public:
347 LayerTreeHostAnimationTestAnimationFinishedEvents() {} 347 LayerTreeHostAnimationTestAnimationFinishedEvents() {}
348 348
349 virtual void beginTest() OVERRIDE { 349 virtual void beginTest() OVERRIDE {
350 postAddInstantAnimationToMainThread(); 350 postAddInstantAnimationToMainThread();
351 } 351 }
352 352
353 virtual void notifyAnimationFinished(double time) OVERRIDE { 353 virtual void notifyAnimationFinished(double time) OVERRIDE {
354 LayerAnimationController* controller = 354 LayerAnimationController* controller =
355 m_layerTreeHost->rootLayer()->layerAnimationController(); 355 m_layerTreeHost->rootLayer()->layer_animation_controller();
356 Animation* animation = 356 Animation* animation =
357 controller->GetAnimation(0, Animation::Opacity); 357 controller->GetAnimation(0, Animation::Opacity);
358 if (animation) 358 if (animation)
359 controller->RemoveAnimation(animation->id()); 359 controller->RemoveAnimation(animation->id());
360 endTest(); 360 endTest();
361 } 361 }
362 362
363 virtual void afterTest() OVERRIDE {} 363 virtual void afterTest() OVERRIDE {}
364 }; 364 };
365 365
366 SINGLE_AND_MULTI_THREAD_TEST_F( 366 SINGLE_AND_MULTI_THREAD_TEST_F(
367 LayerTreeHostAnimationTestAnimationFinishedEvents) 367 LayerTreeHostAnimationTestAnimationFinishedEvents)
368 368
369 // Ensures that when opacity is being animated, this value does not cause the 369 // Ensures that when opacity is being animated, this value does not cause the
370 // subtree to be skipped. 370 // subtree to be skipped.
371 class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity : 371 class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity :
372 public LayerTreeHostAnimationTest { 372 public LayerTreeHostAnimationTest {
373 public: 373 public:
374 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity() 374 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity()
375 : update_check_layer_(FakeContentLayer::Create(&client_)) { 375 : update_check_layer_(FakeContentLayer::Create(&client_)) {
376 } 376 }
377 377
378 virtual void setupTree() OVERRIDE { 378 virtual void setupTree() OVERRIDE {
379 update_check_layer_->setOpacity(0); 379 update_check_layer_->SetOpacity(0);
380 m_layerTreeHost->setRootLayer(update_check_layer_); 380 m_layerTreeHost->setRootLayer(update_check_layer_);
381 LayerTreeHostAnimationTest::setupTree(); 381 LayerTreeHostAnimationTest::setupTree();
382 } 382 }
383 383
384 virtual void beginTest() OVERRIDE { 384 virtual void beginTest() OVERRIDE {
385 postAddAnimationToMainThread(update_check_layer_.get()); 385 postAddAnimationToMainThread(update_check_layer_.get());
386 } 386 }
387 387
388 virtual void commitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE { 388 virtual void commitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE {
389 endTest(); 389 endTest();
390 } 390 }
391 391
392 virtual void afterTest() OVERRIDE { 392 virtual void afterTest() OVERRIDE {
393 // update() should have been called once, proving that the layer was not 393 // Update() should have been called once, proving that the layer was not
394 // skipped. 394 // skipped.
395 EXPECT_EQ(1, update_check_layer_->update_count()); 395 EXPECT_EQ(1, update_check_layer_->update_count());
396 396
397 // clear update_check_layer_ so LayerTreeHost dies. 397 // clear update_check_layer_ so LayerTreeHost dies.
398 update_check_layer_ = NULL; 398 update_check_layer_ = NULL;
399 } 399 }
400 400
401 private: 401 private:
402 FakeContentLayerClient client_; 402 FakeContentLayerClient client_;
403 scoped_refptr<FakeContentLayer> update_check_layer_; 403 scoped_refptr<FakeContentLayer> update_check_layer_;
404 }; 404 };
405 405
406 MULTI_THREAD_TEST_F( 406 MULTI_THREAD_TEST_F(
407 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity) 407 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity)
408 408
409 // Layers added to tree with existing active animations should have the 409 // Layers added to tree with existing active animations should have the
410 // animation correctly recognized. 410 // animation correctly recognized.
411 class LayerTreeHostAnimationTestLayerAddedWithAnimation : 411 class LayerTreeHostAnimationTestLayerAddedWithAnimation :
412 public LayerTreeHostAnimationTest { 412 public LayerTreeHostAnimationTest {
413 public: 413 public:
414 LayerTreeHostAnimationTestLayerAddedWithAnimation() { } 414 LayerTreeHostAnimationTestLayerAddedWithAnimation() { }
415 415
416 virtual void beginTest() OVERRIDE { 416 virtual void beginTest() OVERRIDE {
417 postSetNeedsCommitToMainThread(); 417 postSetNeedsCommitToMainThread();
418 } 418 }
419 419
420 virtual void didCommit() OVERRIDE { 420 virtual void didCommit() OVERRIDE {
421 if (m_layerTreeHost->commitNumber() == 1) { 421 if (m_layerTreeHost->commitNumber() == 1) {
422 scoped_refptr<Layer> layer = Layer::create(); 422 scoped_refptr<Layer> layer = Layer::Create();
423 layer->setLayerAnimationDelegate(this); 423 layer->set_layer_animation_delegate(this);
424 424
425 // Any valid AnimationCurve will do here. 425 // Any valid AnimationCurve will do here.
426 scoped_ptr<AnimationCurve> curve(EaseTimingFunction::create()); 426 scoped_ptr<AnimationCurve> curve(EaseTimingFunction::create());
427 scoped_ptr<Animation> animation( 427 scoped_ptr<Animation> animation(
428 Animation::Create(curve.Pass(), 1, 1, 428 Animation::Create(curve.Pass(), 1, 1,
429 Animation::Opacity)); 429 Animation::Opacity));
430 layer->layerAnimationController()->AddAnimation(animation.Pass()); 430 layer->layer_animation_controller()->AddAnimation(animation.Pass());
431 431
432 // We add the animation *before* attaching the layer to the tree. 432 // We add the animation *before* attaching the layer to the tree.
433 m_layerTreeHost->rootLayer()->addChild(layer); 433 m_layerTreeHost->rootLayer()->AddChild(layer);
434 } 434 }
435 } 435 }
436 436
437 virtual void animateLayers( 437 virtual void animateLayers(
438 LayerTreeHostImpl* impl_host, 438 LayerTreeHostImpl* impl_host,
439 base::TimeTicks monotonic_time) OVERRIDE { 439 base::TimeTicks monotonic_time) OVERRIDE {
440 endTest(); 440 endTest();
441 } 441 }
442 442
443 virtual void afterTest() OVERRIDE {} 443 virtual void afterTest() OVERRIDE {}
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 postSetNeedsCommitToMainThread(); 508 postSetNeedsCommitToMainThread();
509 } 509 }
510 510
511 virtual void animate(base::TimeTicks) OVERRIDE { 511 virtual void animate(base::TimeTicks) OVERRIDE {
512 if (num_draw_layers_ == 2) 512 if (num_draw_layers_ == 2)
513 return; 513 return;
514 m_layerTreeHost->setNeedsAnimate(); 514 m_layerTreeHost->setNeedsAnimate();
515 } 515 }
516 516
517 virtual void layout() OVERRIDE { 517 virtual void layout() OVERRIDE {
518 m_layerTreeHost->rootLayer()->setNeedsDisplay(); 518 m_layerTreeHost->rootLayer()->SetNeedsDisplay();
519 } 519 }
520 520
521 virtual void commitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE { 521 virtual void commitCompleteOnThread(LayerTreeHostImpl*) OVERRIDE {
522 if (num_draw_layers_ == 1) 522 if (num_draw_layers_ == 1)
523 num_commit_complete_++; 523 num_commit_complete_++;
524 } 524 }
525 525
526 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 526 virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
527 num_draw_layers_++; 527 num_draw_layers_++;
528 if (num_draw_layers_ == 2) 528 if (num_draw_layers_ == 2)
529 endTest(); 529 endTest();
530 } 530 }
531 531
532 virtual void afterTest() OVERRIDE { 532 virtual void afterTest() OVERRIDE {
533 // Check that we didn't commit twice between first and second draw. 533 // Check that we didn't commit twice between first and second draw.
534 EXPECT_EQ(1, num_commit_complete_); 534 EXPECT_EQ(1, num_commit_complete_);
535 } 535 }
536 536
537 private: 537 private:
538 int num_commit_complete_; 538 int num_commit_complete_;
539 int num_draw_layers_; 539 int num_draw_layers_;
540 }; 540 };
541 541
542 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate) 542 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate)
543 543
544 } // namespace 544 } // namespace
545 } // namespace cc 545 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tree_host_unittest.cc ('k') | cc/layer_tree_host_unittest_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698