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

Side by Side Diff: cc/trees/layer_tree_host_unittest_animation.cc

Issue 16871016: cc: Use BeginFrameArgs (Closed) Base URL: http://git.chromium.org/chromium/src.git@bfargs2
Patch Set: fix some tests; needs rebase; Created 7 years, 5 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
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/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/timing_function.h" 9 #include "cc/animation/timing_function.h"
10 #include "cc/layers/layer.h" 10 #include "cc/layers/layer.h"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 class LayerTreeHostAnimationTestTickAnimationWhileBackgrounded 257 class LayerTreeHostAnimationTestTickAnimationWhileBackgrounded
258 : public LayerTreeHostAnimationTest { 258 : public LayerTreeHostAnimationTest {
259 public: 259 public:
260 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded() 260 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded()
261 : num_animates_(0) {} 261 : num_animates_(0) {}
262 262
263 virtual void BeginTest() OVERRIDE { 263 virtual void BeginTest() OVERRIDE {
264 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); 264 PostAddAnimationToMainThread(layer_tree_host()->root_layer());
265 } 265 }
266 266
267 virtual void DidCommit() OVERRIDE {
268 layer_tree_host()->SetVisible(false);
269 }
270
267 // Use WillAnimateLayers to set visible false before the animation runs and 271 // Use WillAnimateLayers to set visible false before the animation runs and
268 // causes a commit, so we block the second visible animate in single-thread 272 // causes a commit, so we block the second visible animate in single-thread
269 // mode. 273 // mode.
270 virtual void WillAnimateLayers( 274 virtual void WillAnimateLayers(
271 LayerTreeHostImpl* host_impl, 275 LayerTreeHostImpl* host_impl,
272 base::TimeTicks monotonic_time) OVERRIDE { 276 base::TimeTicks monotonic_time) OVERRIDE {
273 if (num_animates_ < 2) { 277 TRACE_EVENT0("cc", __PRETTY_FUNCTION__);
274 if (!num_animates_) { 278 if (num_animates_ < 3) {
275 // We have a long animation running. It should continue to tick even
276 // if we are not visible.
277 PostSetVisibleToMainThread(false);
278 }
279 num_animates_++; 279 num_animates_++;
280 return; 280 return;
281 } 281 }
282 EndTest(); 282 EndTest();
283 } 283 }
284 284
285 virtual void AfterTest() OVERRIDE {} 285 virtual void AfterTest() OVERRIDE {}
286 286
287 private: 287 private:
288 int num_animates_; 288 int num_animates_;
(...skipping 15 matching lines...) Expand all
304 layer_tree_host()->root_layer()->AddChild(content_); 304 layer_tree_host()->root_layer()->AddChild(content_);
305 } 305 }
306 306
307 virtual void BeginTest() OVERRIDE { 307 virtual void BeginTest() OVERRIDE {
308 PostAddAnimationToMainThread(content_.get()); 308 PostAddAnimationToMainThread(content_.get());
309 } 309 }
310 310
311 virtual void AnimateLayers( 311 virtual void AnimateLayers(
312 LayerTreeHostImpl* host_impl, 312 LayerTreeHostImpl* host_impl,
313 base::TimeTicks monotonic_time) OVERRIDE { 313 base::TimeTicks monotonic_time) OVERRIDE {
314 if (!layer_tree_host()->root_layer())
315 return;
314 LayerAnimationController* controller = 316 LayerAnimationController* controller =
315 layer_tree_host()->root_layer()->children()[0]-> 317 layer_tree_host()->root_layer()->children()[0]->
316 layer_animation_controller(); 318 layer_animation_controller();
317 Animation* animation = 319 Animation* animation =
318 controller->GetAnimation(Animation::Opacity); 320 controller->GetAnimation(Animation::Opacity);
319 if (!animation) 321 if (!animation)
320 return; 322 return;
321 323
322 const FloatAnimationCurve* curve = 324 const FloatAnimationCurve* curve =
323 animation->curve()->ToFloatAnimationCurve(); 325 animation->curve()->ToFloatAnimationCurve();
324 float start_opacity = curve->GetValue(0.0); 326 float start_opacity = curve->GetValue(0.0);
325 float end_opacity = curve->GetValue(curve->Duration()); 327 float end_opacity = curve->GetValue(curve->Duration());
326 float linearly_interpolated_opacity = 328 float linearly_interpolated_opacity =
327 0.25f * end_opacity + 0.75f * start_opacity; 329 0.25f * end_opacity + 0.75f * start_opacity;
328 double time = curve->Duration() * 0.25; 330 double time = curve->Duration() * 0.25;
329 // If the linear timing function associated with this animation was not 331 // If the linear timing function associated with this animation was not
330 // picked up, then the linearly interpolated opacity would be different 332 // picked up, then the linearly interpolated opacity would be different
331 // because of the default ease timing function. 333 // because of the default ease timing function.
332 EXPECT_FLOAT_EQ(linearly_interpolated_opacity, curve->GetValue(time)); 334 EXPECT_FLOAT_EQ(linearly_interpolated_opacity, curve->GetValue(time));
333 335
336 if (!host_impl->active_tree()->root_layer())
337 return;
334 LayerAnimationController* controller_impl = 338 LayerAnimationController* controller_impl =
335 host_impl->active_tree()->root_layer()->children()[0]-> 339 host_impl->active_tree()->root_layer()->children()[0]->
336 layer_animation_controller(); 340 layer_animation_controller();
337 Animation* animation_impl = 341 Animation* animation_impl =
338 controller_impl->GetAnimation(Animation::Opacity); 342 controller_impl->GetAnimation(Animation::Opacity);
339 343
340 controller->RemoveAnimation(animation->id()); 344 controller->RemoveAnimation(animation->id());
341 controller_impl->RemoveAnimation(animation_impl->id()); 345 controller_impl->RemoveAnimation(animation_impl->id());
342 EndTest(); 346 EndTest();
343 } 347 }
344 348
345 virtual void AfterTest() OVERRIDE {} 349 virtual void AfterTest() OVERRIDE {}
346 350
347 FakeContentLayerClient client_; 351 FakeContentLayerClient client_;
348 scoped_refptr<FakeContentLayer> content_; 352 scoped_refptr<FakeContentLayer> content_;
349 }; 353 };
350 354
351 SINGLE_AND_MULTI_THREAD_TEST_F( 355 SINGLE_AND_MULTI_THREAD_TEST_F(
352 LayerTreeHostAnimationTestAddAnimationWithTimingFunction); 356 LayerTreeHostAnimationTestAddAnimationWithTimingFunction);
353 357
354 // Ensures that main thread animations have their start times synchronized with 358 // Ensures that main thread animations have their start times synchronized with
355 // impl thread animations. 359 // impl thread animations.
356 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes 360 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes
357 : public LayerTreeHostAnimationTest { 361 : public LayerTreeHostAnimationTest {
358 public: 362 public:
359 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes() 363 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes()
360 : main_start_time_(-1.0), 364 : test_is_setup_(false),
365 main_start_time_(-1.0),
361 impl_start_time_(-1.0) {} 366 impl_start_time_(-1.0) {}
362 367
363 virtual void SetupTree() OVERRIDE { 368 virtual void SetupTree() OVERRIDE {
364 LayerTreeHostAnimationTest::SetupTree(); 369 LayerTreeHostAnimationTest::SetupTree();
365 content_ = FakeContentLayer::Create(&client_); 370 content_ = FakeContentLayer::Create(&client_);
366 content_->SetBounds(gfx::Size(4, 4)); 371 content_->SetBounds(gfx::Size(4, 4));
367 content_->set_layer_animation_delegate(this); 372 content_->set_layer_animation_delegate(this);
368 layer_tree_host()->root_layer()->AddChild(content_); 373 layer_tree_host()->root_layer()->AddChild(content_);
374 test_is_setup_ = true;
369 } 375 }
370 376
371 virtual void BeginTest() OVERRIDE { 377 virtual void BeginTest() OVERRIDE {
372 PostAddAnimationToMainThread(content_.get()); 378 PostAddAnimationToMainThread(content_.get());
373 } 379 }
374 380
375 virtual void notifyAnimationStarted(double time) OVERRIDE { 381 virtual void notifyAnimationStarted(double time) OVERRIDE {
376 LayerAnimationController* controller = 382 LayerAnimationController* controller =
377 layer_tree_host()->root_layer()->children()[0]-> 383 layer_tree_host()->root_layer()->children()[0]->
378 layer_animation_controller(); 384 layer_animation_controller();
379 Animation* animation = 385 Animation* animation =
380 controller->GetAnimation(Animation::Opacity); 386 controller->GetAnimation(Animation::Opacity);
381 main_start_time_ = animation->start_time(); 387 main_start_time_ = animation->start_time();
382 controller->RemoveAnimation(animation->id()); 388 controller->RemoveAnimation(animation->id());
383 389
384 if (impl_start_time_ > 0.0) 390 if (impl_start_time_ > 0.0)
385 EndTest(); 391 EndTest();
386 } 392 }
387 393
388 virtual void UpdateAnimationState( 394 virtual void UpdateAnimationState(
389 LayerTreeHostImpl* impl_host, 395 LayerTreeHostImpl* impl_host,
390 bool has_unfinished_animation) OVERRIDE { 396 bool has_unfinished_animation) OVERRIDE {
397 if (!test_is_setup_ || !impl_host->active_tree()->root_layer())
398 return;
399
391 LayerAnimationController* controller = 400 LayerAnimationController* controller =
392 impl_host->active_tree()->root_layer()->children()[0]-> 401 impl_host->active_tree()->root_layer()->children()[0]->
393 layer_animation_controller(); 402 layer_animation_controller();
394 Animation* animation = 403 Animation* animation =
395 controller->GetAnimation(Animation::Opacity); 404 controller->GetAnimation(Animation::Opacity);
396 if (!animation) 405 if (!animation)
397 return; 406 return;
398 407
399 impl_start_time_ = animation->start_time(); 408 impl_start_time_ = animation->start_time();
400 controller->RemoveAnimation(animation->id()); 409 controller->RemoveAnimation(animation->id());
401 410
402 if (main_start_time_ > 0.0) 411 if (main_start_time_ > 0.0)
403 EndTest(); 412 EndTest();
404 } 413 }
405 414
406 virtual void AfterTest() OVERRIDE { 415 virtual void AfterTest() OVERRIDE {
407 EXPECT_FLOAT_EQ(impl_start_time_, main_start_time_); 416 EXPECT_FLOAT_EQ(impl_start_time_, main_start_time_);
408 } 417 }
409 418
410 private: 419 private:
420 bool test_is_setup_;
411 double main_start_time_; 421 double main_start_time_;
412 double impl_start_time_; 422 double impl_start_time_;
413 FakeContentLayerClient client_; 423 FakeContentLayerClient client_;
414 scoped_refptr<FakeContentLayer> content_; 424 scoped_refptr<FakeContentLayer> content_;
415 }; 425 };
416 426
417 SINGLE_AND_MULTI_THREAD_TEST_F( 427 SINGLE_AND_MULTI_THREAD_TEST_F(
418 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); 428 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes);
419 429
420 // Ensures that notify animation finished is called. 430 // Ensures that notify animation finished is called.
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 int finished_times_; 813 int finished_times_;
804 FakeContentLayerClient client_; 814 FakeContentLayerClient client_;
805 scoped_refptr<FakeContentLayer> content_; 815 scoped_refptr<FakeContentLayer> content_;
806 }; 816 };
807 817
808 MULTI_THREAD_TEST_F( 818 MULTI_THREAD_TEST_F(
809 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); 819 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations);
810 820
811 } // namespace 821 } // namespace
812 } // namespace cc 822 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698