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

Side by Side Diff: cc/layer_tree_host_unittest_animation.cc

Issue 11598005: Ref count layer animation controllers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years 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_impl.cc ('k') | cc/layer_tree_impl.h » ('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"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 , received_animation_started_notification_(false) 117 , received_animation_started_notification_(false)
118 , start_time_(0) { 118 , start_time_(0) {
119 } 119 }
120 120
121 virtual void beginTest() OVERRIDE { 121 virtual void beginTest() OVERRIDE {
122 postAddInstantAnimationToMainThread(); 122 postAddInstantAnimationToMainThread();
123 } 123 }
124 124
125 virtual void animateLayers( 125 virtual void animateLayers(
126 LayerTreeHostImpl* impl_host, 126 LayerTreeHostImpl* impl_host,
127 base::TimeTicks monotonic_time) OVERRIDE { 127 base::TimeTicks monotonic_time,
128 bool hasUnfinishedAnimation) OVERRIDE {
128 if (!num_animates_) { 129 if (!num_animates_) {
129 // The animation had zero duration so layerTreeHostImpl should no 130 // The animation had zero duration so layerTreeHostImpl should no
130 // longer need to animate its layers. 131 // longer need to animate its layers.
131 EXPECT_FALSE(impl_host->needsAnimateLayers()); 132 EXPECT_FALSE(hasUnfinishedAnimation);
132 num_animates_++; 133 num_animates_++;
133 first_monotonic_time_ = monotonic_time; 134 first_monotonic_time_ = monotonic_time;
134 return; 135 return;
135 } 136 }
136 EXPECT_LT(0, start_time_); 137 EXPECT_LT(0, start_time_);
137 EXPECT_TRUE(received_animation_started_notification_); 138 EXPECT_TRUE(received_animation_started_notification_);
138 endTest(); 139 endTest();
139 } 140 }
140 141
141 virtual void notifyAnimationStarted(double wall_clock_time) OVERRIDE { 142 virtual void notifyAnimationStarted(double wall_clock_time) OVERRIDE {
(...skipping 20 matching lines...) Expand all
162 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() 163 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws()
163 : started_animating_(false) { 164 : started_animating_(false) {
164 } 165 }
165 166
166 virtual void beginTest() OVERRIDE { 167 virtual void beginTest() OVERRIDE {
167 postAddAnimationToMainThread(m_layerTreeHost->rootLayer()); 168 postAddAnimationToMainThread(m_layerTreeHost->rootLayer());
168 } 169 }
169 170
170 virtual void animateLayers( 171 virtual void animateLayers(
171 LayerTreeHostImpl* host_impl, 172 LayerTreeHostImpl* host_impl,
172 base::TimeTicks monotonicTime) OVERRIDE { 173 base::TimeTicks monotonicTime,
174 bool hasUnfinishedAnimation) OVERRIDE {
173 started_animating_ = true; 175 started_animating_ = true;
174 } 176 }
175 177
176 virtual void drawLayersOnThread(LayerTreeHostImpl*) OVERRIDE { 178 virtual void drawLayersOnThread(LayerTreeHostImpl*) OVERRIDE {
177 if (started_animating_) 179 if (started_animating_)
178 endTest(); 180 endTest();
179 } 181 }
180 182
181 virtual bool prepareToDrawOnThread(LayerTreeHostImpl*) OVERRIDE { 183 virtual bool prepareToDrawOnThread(LayerTreeHostImpl*) OVERRIDE {
182 return false; 184 return false;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 public LayerTreeHostAnimationTest { 237 public LayerTreeHostAnimationTest {
236 public: 238 public:
237 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} 239 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {}
238 240
239 virtual void beginTest() OVERRIDE { 241 virtual void beginTest() OVERRIDE {
240 postAddAnimationToMainThread(m_layerTreeHost->rootLayer()); 242 postAddAnimationToMainThread(m_layerTreeHost->rootLayer());
241 } 243 }
242 244
243 virtual void animateLayers( 245 virtual void animateLayers(
244 LayerTreeHostImpl* host_impl, 246 LayerTreeHostImpl* host_impl,
245 base::TimeTicks monotonicTime) OVERRIDE { 247 base::TimeTicks monotonicTime,
248 bool hasUnfinishedAnimation) OVERRIDE {
246 LayerAnimationController* controller = 249 LayerAnimationController* controller =
247 m_layerTreeHost->rootLayer()->layerAnimationController(); 250 m_layerTreeHost->rootLayer()->layerAnimationController();
248 ActiveAnimation* animation = 251 ActiveAnimation* animation =
249 controller->getActiveAnimation(0, ActiveAnimation::Opacity); 252 controller->getActiveAnimation(0, ActiveAnimation::Opacity);
250 if (!animation) 253 if (!animation)
251 return; 254 return;
252 255
253 const FloatAnimationCurve* curve = 256 const FloatAnimationCurve* curve =
254 animation->curve()->toFloatAnimationCurve(); 257 animation->curve()->toFloatAnimationCurve();
255 float startOpacity = curve->getValue(0); 258 float startOpacity = curve->getValue(0);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 controller->getActiveAnimation(0, ActiveAnimation::Opacity); 302 controller->getActiveAnimation(0, ActiveAnimation::Opacity);
300 main_start_time_ = animation->startTime(); 303 main_start_time_ = animation->startTime();
301 controller->removeAnimation(animation->id()); 304 controller->removeAnimation(animation->id());
302 305
303 if (impl_start_time_ > 0) 306 if (impl_start_time_ > 0)
304 endTest(); 307 endTest();
305 } 308 }
306 309
307 virtual void animateLayers( 310 virtual void animateLayers(
308 LayerTreeHostImpl* impl_host, 311 LayerTreeHostImpl* impl_host,
309 base::TimeTicks monotonicTime) OVERRIDE { 312 base::TimeTicks monotonicTime,
313 bool hasUnfinishedAnimation) OVERRIDE {
310 LayerAnimationController* controller = 314 LayerAnimationController* controller =
311 impl_host->rootLayer()->layerAnimationController(); 315 impl_host->rootLayer()->layerAnimationController();
312 ActiveAnimation* animation = 316 ActiveAnimation* animation =
313 controller->getActiveAnimation(0, ActiveAnimation::Opacity); 317 controller->getActiveAnimation(0, ActiveAnimation::Opacity);
314 if (!animation) 318 if (!animation)
315 return; 319 return;
316 320
317 impl_start_time_ = animation->startTime(); 321 impl_start_time_ = animation->startTime();
318 controller->removeAnimation(animation->id()); 322 controller->removeAnimation(animation->id());
319 323
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 }; 399 };
396 400
397 MULTI_THREAD_TEST_F( 401 MULTI_THREAD_TEST_F(
398 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity) 402 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity)
399 403
400 // Layers added to tree with existing active animations should have the 404 // Layers added to tree with existing active animations should have the
401 // animation correctly recognized. 405 // animation correctly recognized.
402 class LayerTreeHostAnimationTestLayerAddedWithAnimation : 406 class LayerTreeHostAnimationTestLayerAddedWithAnimation :
403 public LayerTreeHostAnimationTest { 407 public LayerTreeHostAnimationTest {
404 public: 408 public:
405 LayerTreeHostAnimationTestLayerAddedWithAnimation() 409 LayerTreeHostAnimationTestLayerAddedWithAnimation() { }
406 : added_animation_(false) { 410
411 virtual void beginTest() OVERRIDE {
412 postSetNeedsCommitToMainThread();
407 } 413 }
408 414
409 virtual void beginTest() OVERRIDE { 415 virtual void didCommit() OVERRIDE {
410 EXPECT_FALSE(added_animation_); 416 if (m_layerTreeHost->commitNumber() == 1) {
417 scoped_refptr<Layer> layer = Layer::create();
418 layer->setLayerAnimationDelegate(this);
411 419
412 scoped_refptr<Layer> layer = Layer::create(); 420 // Any valid AnimationCurve will do here.
413 layer->setLayerAnimationDelegate(this); 421 scoped_ptr<AnimationCurve> curve(EaseTimingFunction::create());
422 scoped_ptr<ActiveAnimation> animation(
423 ActiveAnimation::create(curve.Pass(), 1, 1,
424 ActiveAnimation::Opacity));
425 layer->layerAnimationController()->addAnimation(animation.Pass());
414 426
415 // Any valid AnimationCurve will do here. 427 // We add the animation *before* attaching the layer to the tree.
416 scoped_ptr<AnimationCurve> curve(EaseTimingFunction::create()); 428 m_layerTreeHost->rootLayer()->addChild(layer);
417 scoped_ptr<ActiveAnimation> animation( 429 }
418 ActiveAnimation::create(curve.Pass(), 1, 1, ActiveAnimation::Opacity)); 430 }
419 layer->layerAnimationController()->addAnimation(animation.Pass());
420 431
421 // We add the animation *before* attaching the layer to the tree. 432 virtual void animateLayers(
422 m_layerTreeHost->rootLayer()->addChild(layer); 433 LayerTreeHostImpl* impl_host,
423 EXPECT_TRUE(added_animation_); 434 base::TimeTicks monotonic_time,
424 435 bool hasUnfinishedAnimation) OVERRIDE {
425 endTest(); 436 endTest();
426 } 437 }
427 438
428 virtual void didAddAnimation() OVERRIDE {
429 added_animation_ = true;
430 }
431
432 virtual void afterTest() OVERRIDE {} 439 virtual void afterTest() OVERRIDE {}
433
434 private:
435 bool added_animation_;
436 }; 440 };
437 441
438 SINGLE_AND_MULTI_THREAD_TEST_F( 442 SINGLE_AND_MULTI_THREAD_TEST_F(
439 LayerTreeHostAnimationTestLayerAddedWithAnimation) 443 LayerTreeHostAnimationTestLayerAddedWithAnimation)
440 444
441 class LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount : 445 class LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount :
442 public LayerTreeHostAnimationTest { 446 public LayerTreeHostAnimationTest {
443 public: 447 public:
444 LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount() 448 LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount()
445 : animated_commit_(-1) { 449 : animated_commit_(-1) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 532
529 private: 533 private:
530 int num_commit_complete_; 534 int num_commit_complete_;
531 int num_draw_layers_; 535 int num_draw_layers_;
532 }; 536 };
533 537
534 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate) 538 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate)
535 539
536 } // namespace 540 } // namespace
537 } // namespace cc 541 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tree_host_impl.cc ('k') | cc/layer_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698