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

Side by Side Diff: cc/layer_tree_host_unittest_animation.cc

Issue 12517003: cc: Chromify the Animation and LayerAnimationController classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_impl.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"
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
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()->layerAnimationController();
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()->layerAnimationController();
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 };
285 285
286 SINGLE_AND_MULTI_THREAD_TEST_F( 286 SINGLE_AND_MULTI_THREAD_TEST_F(
287 LayerTreeHostAnimationTestAddAnimationWithTimingFunction) 287 LayerTreeHostAnimationTestAddAnimationWithTimingFunction)
288 288
289 // Ensures that main thread animations have their start times synchronized with 289 // Ensures that main thread animations have their start times synchronized with
290 // impl thread animations. 290 // impl thread animations.
291 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes : 291 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes :
292 public LayerTreeHostAnimationTest { 292 public LayerTreeHostAnimationTest {
293 public: 293 public:
294 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes() 294 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes()
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()->layerAnimationController();
306 Animation* animation = 306 Animation* animation =
307 controller->getAnimation(0, Animation::Opacity); 307 controller->GetAnimation(0, Animation::Opacity);
308 main_start_time_ = animation->startTime(); 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()->layerAnimationController();
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->startTime(); 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();
330 } 330 }
331 331
332 virtual void afterTest() OVERRIDE { 332 virtual void afterTest() OVERRIDE {
333 EXPECT_FLOAT_EQ(impl_start_time_, main_start_time_); 333 EXPECT_FLOAT_EQ(impl_start_time_, main_start_time_);
334 } 334 }
335 335
336 private: 336 private:
(...skipping 10 matching lines...) Expand all
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()->layerAnimationController();
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
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->setLayerAnimationDelegate(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->layerAnimationController()->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();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_impl.cc ('k') | cc/layer_tree_host_unittest_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698