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

Side by Side Diff: Source/core/animation/CompositorAnimations.cpp

Issue 467123002: Revert of Rename WebAnimation to WebCompositorAnimation (patchset #5 of https://codereview.chromium… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 25 matching lines...) Expand all
36 #include "core/animation/animatable/AnimatableDouble.h" 36 #include "core/animation/animatable/AnimatableDouble.h"
37 #include "core/animation/animatable/AnimatableFilterOperations.h" 37 #include "core/animation/animatable/AnimatableFilterOperations.h"
38 #include "core/animation/animatable/AnimatableTransform.h" 38 #include "core/animation/animatable/AnimatableTransform.h"
39 #include "core/animation/animatable/AnimatableValue.h" 39 #include "core/animation/animatable/AnimatableValue.h"
40 #include "core/rendering/RenderBoxModelObject.h" 40 #include "core/rendering/RenderBoxModelObject.h"
41 #include "core/rendering/RenderLayer.h" 41 #include "core/rendering/RenderLayer.h"
42 #include "core/rendering/RenderObject.h" 42 #include "core/rendering/RenderObject.h"
43 #include "core/rendering/compositing/CompositedLayerMapping.h" 43 #include "core/rendering/compositing/CompositedLayerMapping.h"
44 #include "platform/geometry/FloatBox.h" 44 #include "platform/geometry/FloatBox.h"
45 #include "public/platform/Platform.h" 45 #include "public/platform/Platform.h"
46 #include "public/platform/WebCompositorAnimation.h" 46 #include "public/platform/WebAnimation.h"
47 #include "public/platform/WebCompositorSupport.h" 47 #include "public/platform/WebCompositorSupport.h"
48 #include "public/platform/WebFilterAnimationCurve.h" 48 #include "public/platform/WebFilterAnimationCurve.h"
49 #include "public/platform/WebFilterKeyframe.h" 49 #include "public/platform/WebFilterKeyframe.h"
50 #include "public/platform/WebFloatAnimationCurve.h" 50 #include "public/platform/WebFloatAnimationCurve.h"
51 #include "public/platform/WebFloatKeyframe.h" 51 #include "public/platform/WebFloatKeyframe.h"
52 #include "public/platform/WebTransformAnimationCurve.h" 52 #include "public/platform/WebTransformAnimationCurve.h"
53 #include "public/platform/WebTransformKeyframe.h" 53 #include "public/platform/WebTransformKeyframe.h"
54 54
55 #include <algorithm> 55 #include <algorithm>
56 #include <cmath> 56 #include <cmath>
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 { 250 {
251 ASSERT(startedAnimationIds.isEmpty()); 251 ASSERT(startedAnimationIds.isEmpty());
252 ASSERT(isCandidateForAnimationOnCompositor(timing, effect)); 252 ASSERT(isCandidateForAnimationOnCompositor(timing, effect));
253 ASSERT(canStartAnimationOnCompositor(element)); 253 ASSERT(canStartAnimationOnCompositor(element));
254 254
255 const KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(ef fect); 255 const KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(ef fect);
256 256
257 RenderLayer* layer = toRenderBoxModelObject(element.renderer())->layer(); 257 RenderLayer* layer = toRenderBoxModelObject(element.renderer())->layer();
258 ASSERT(layer); 258 ASSERT(layer);
259 259
260 Vector<OwnPtr<WebCompositorAnimation> > animations; 260 Vector<OwnPtr<blink::WebAnimation> > animations;
261 CompositorAnimationsImpl::getAnimationOnCompositor(timing, startTime, keyfra meEffect, animations); 261 CompositorAnimationsImpl::getAnimationOnCompositor(timing, startTime, keyfra meEffect, animations);
262 ASSERT(!animations.isEmpty()); 262 ASSERT(!animations.isEmpty());
263 for (size_t i = 0; i < animations.size(); ++i) { 263 for (size_t i = 0; i < animations.size(); ++i) {
264 int id = animations[i]->id(); 264 int id = animations[i]->id();
265 if (!layer->compositedLayerMapping()->mainGraphicsLayer()->addAnimation( animations[i].release())) { 265 if (!layer->compositedLayerMapping()->mainGraphicsLayer()->addAnimation( animations[i].release())) {
266 // FIXME: We should know ahead of time whether these animations can be started. 266 // FIXME: We should know ahead of time whether these animations can be started.
267 for (size_t j = 0; j < startedAnimationIds.size(); ++j) 267 for (size_t j = 0; j < startedAnimationIds.size(); ++j)
268 cancelAnimationOnCompositor(element, startedAnimationIds[j]); 268 cancelAnimationOnCompositor(element, startedAnimationIds[j]);
269 startedAnimationIds.clear(); 269 startedAnimationIds.clear();
270 return false; 270 return false;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 template<typename PlatformAnimationCurveType, typename PlatformAnimationKeyframe Type> 359 template<typename PlatformAnimationCurveType, typename PlatformAnimationKeyframe Type>
360 void addKeyframeWithTimingFunction(PlatformAnimationCurveType& curve, const Plat formAnimationKeyframeType& keyframe, const TimingFunction* timingFunction) 360 void addKeyframeWithTimingFunction(PlatformAnimationCurveType& curve, const Plat formAnimationKeyframeType& keyframe, const TimingFunction* timingFunction)
361 { 361 {
362 if (!timingFunction) { 362 if (!timingFunction) {
363 curve.add(keyframe); 363 curve.add(keyframe);
364 return; 364 return;
365 } 365 }
366 366
367 switch (timingFunction->type()) { 367 switch (timingFunction->type()) {
368 case TimingFunction::LinearFunction: 368 case TimingFunction::LinearFunction:
369 curve.add(keyframe, WebCompositorAnimationCurve::TimingFunctionTypeLinea r); 369 curve.add(keyframe, blink::WebAnimationCurve::TimingFunctionTypeLinear);
370 return; 370 return;
371 371
372 case TimingFunction::CubicBezierFunction: { 372 case TimingFunction::CubicBezierFunction: {
373 const CubicBezierTimingFunction* cubic = toCubicBezierTimingFunction(tim ingFunction); 373 const CubicBezierTimingFunction* cubic = toCubicBezierTimingFunction(tim ingFunction);
374 374
375 if (cubic->subType() == CubicBezierTimingFunction::Custom) { 375 if (cubic->subType() == CubicBezierTimingFunction::Custom) {
376 curve.add(keyframe, cubic->x1(), cubic->y1(), cubic->x2(), cubic->y2 ()); 376 curve.add(keyframe, cubic->x1(), cubic->y1(), cubic->x2(), cubic->y2 ());
377 } else { 377 } else {
378 378
379 WebCompositorAnimationCurve::TimingFunctionType easeType; 379 blink::WebAnimationCurve::TimingFunctionType easeType;
380 switch (cubic->subType()) { 380 switch (cubic->subType()) {
381 case CubicBezierTimingFunction::Ease: 381 case CubicBezierTimingFunction::Ease:
382 easeType = WebCompositorAnimationCurve::TimingFunctionTypeEase; 382 easeType = blink::WebAnimationCurve::TimingFunctionTypeEase;
383 break; 383 break;
384 case CubicBezierTimingFunction::EaseIn: 384 case CubicBezierTimingFunction::EaseIn:
385 easeType = WebCompositorAnimationCurve::TimingFunctionTypeEaseIn ; 385 easeType = blink::WebAnimationCurve::TimingFunctionTypeEaseIn;
386 break; 386 break;
387 case CubicBezierTimingFunction::EaseOut: 387 case CubicBezierTimingFunction::EaseOut:
388 easeType = WebCompositorAnimationCurve::TimingFunctionTypeEaseOu t; 388 easeType = blink::WebAnimationCurve::TimingFunctionTypeEaseOut;
389 break; 389 break;
390 case CubicBezierTimingFunction::EaseInOut: 390 case CubicBezierTimingFunction::EaseInOut:
391 easeType = WebCompositorAnimationCurve::TimingFunctionTypeEaseIn Out; 391 easeType = blink::WebAnimationCurve::TimingFunctionTypeEaseInOut ;
392 break; 392 break;
393 393
394 // Custom Bezier are handled seperately. 394 // Custom Bezier are handled seperately.
395 case CubicBezierTimingFunction::Custom: 395 case CubicBezierTimingFunction::Custom:
396 default: 396 default:
397 ASSERT_NOT_REACHED(); 397 ASSERT_NOT_REACHED();
398 return; 398 return;
399 } 399 }
400 400
401 curve.add(keyframe, easeType); 401 curve.add(keyframe, easeType);
402 } 402 }
403 return; 403 return;
404 } 404 }
405 405
406 case TimingFunction::StepsFunction: 406 case TimingFunction::StepsFunction:
407 default: 407 default:
408 ASSERT_NOT_REACHED(); 408 ASSERT_NOT_REACHED();
409 return; 409 return;
410 } 410 }
411 } 411 }
412 412
413 } // namespace anoymous 413 } // namespace anoymous
414 414
415 void CompositorAnimationsImpl::addKeyframesToCurve(WebCompositorAnimationCurve& curve, const PropertySpecificKeyframeVector& keyframes, bool reverse) 415 void CompositorAnimationsImpl::addKeyframesToCurve(blink::WebAnimationCurve& cur ve, const PropertySpecificKeyframeVector& keyframes, bool reverse)
416 { 416 {
417 for (size_t i = 0; i < keyframes.size(); i++) { 417 for (size_t i = 0; i < keyframes.size(); i++) {
418 RefPtr<TimingFunction> reversedTimingFunction; 418 RefPtr<TimingFunction> reversedTimingFunction;
419 const TimingFunction* keyframeTimingFunction = 0; 419 const TimingFunction* keyframeTimingFunction = 0;
420 if (i < keyframes.size() - 1) { // Ignore timing function of last frame. 420 if (i < keyframes.size() - 1) { // Ignore timing function of last frame.
421 if (reverse) { 421 if (reverse) {
422 reversedTimingFunction = CompositorAnimationsTimingFunctionRever ser::reverse(keyframes[i + 1]->easing()); 422 reversedTimingFunction = CompositorAnimationsTimingFunctionRever ser::reverse(keyframes[i + 1]->easing());
423 keyframeTimingFunction = reversedTimingFunction.get(); 423 keyframeTimingFunction = reversedTimingFunction.get();
424 } else { 424 } else {
425 keyframeTimingFunction = keyframes[i]->easing(); 425 keyframeTimingFunction = keyframes[i]->easing();
426 } 426 }
427 } 427 }
428 428
429 // FIXME: This relies on StringKeyframes being eagerly evaluated, which will 429 // FIXME: This relies on StringKeyframes being eagerly evaluated, which will
430 // not happen eventually. Instead we should extract the CSSValue here 430 // not happen eventually. Instead we should extract the CSSValue here
431 // and convert using another set of toAnimatableXXXOperations functions. 431 // and convert using another set of toAnimatableXXXOperations functions.
432 const AnimatableValue* value = keyframes[i]->getAnimatableValue().get(); 432 const AnimatableValue* value = keyframes[i]->getAnimatableValue().get();
433 433
434 switch (curve.type()) { 434 switch (curve.type()) {
435 case WebCompositorAnimationCurve::AnimationCurveTypeFilter: { 435 case blink::WebAnimationCurve::AnimationCurveTypeFilter: {
436 OwnPtr<WebFilterOperations> ops = adoptPtr(Platform::current()->comp ositorSupport()->createFilterOperations()); 436 OwnPtr<blink::WebFilterOperations> ops = adoptPtr(blink::Platform::c urrent()->compositorSupport()->createFilterOperations());
437 toWebFilterOperations(toAnimatableFilterOperations(value)->operation s(), ops.get()); 437 toWebFilterOperations(toAnimatableFilterOperations(value)->operation s(), ops.get());
438 438
439 WebFilterKeyframe filterKeyframe(keyframes[i]->offset(), ops.release ()); 439 blink::WebFilterKeyframe filterKeyframe(keyframes[i]->offset(), ops. release());
440 WebFilterAnimationCurve* filterCurve = static_cast<WebFilterAnimatio nCurve*>(&curve); 440 blink::WebFilterAnimationCurve* filterCurve = static_cast<blink::Web FilterAnimationCurve*>(&curve);
441 addKeyframeWithTimingFunction(*filterCurve, filterKeyframe, keyframe TimingFunction); 441 addKeyframeWithTimingFunction(*filterCurve, filterKeyframe, keyframe TimingFunction);
442 break; 442 break;
443 } 443 }
444 case WebCompositorAnimationCurve::AnimationCurveTypeFloat: { 444 case blink::WebAnimationCurve::AnimationCurveTypeFloat: {
445 WebFloatKeyframe floatKeyframe(keyframes[i]->offset(), toAnimatableD ouble(value)->toDouble()); 445 blink::WebFloatKeyframe floatKeyframe(keyframes[i]->offset(), toAnim atableDouble(value)->toDouble());
446 WebFloatAnimationCurve* floatCurve = static_cast<WebFloatAnimationCu rve*>(&curve); 446 blink::WebFloatAnimationCurve* floatCurve = static_cast<blink::WebFl oatAnimationCurve*>(&curve);
447 addKeyframeWithTimingFunction(*floatCurve, floatKeyframe, keyframeTi mingFunction); 447 addKeyframeWithTimingFunction(*floatCurve, floatKeyframe, keyframeTi mingFunction);
448 break; 448 break;
449 } 449 }
450 case WebCompositorAnimationCurve::AnimationCurveTypeTransform: { 450 case blink::WebAnimationCurve::AnimationCurveTypeTransform: {
451 OwnPtr<WebTransformOperations> ops = adoptPtr(Platform::current()->c ompositorSupport()->createTransformOperations()); 451 OwnPtr<blink::WebTransformOperations> ops = adoptPtr(blink::Platform ::current()->compositorSupport()->createTransformOperations());
452 toWebTransformOperations(toAnimatableTransform(value)->transformOper ations(), ops.get()); 452 toWebTransformOperations(toAnimatableTransform(value)->transformOper ations(), ops.get());
453 453
454 WebTransformKeyframe transformKeyframe(keyframes[i]->offset(), ops.r elease()); 454 blink::WebTransformKeyframe transformKeyframe(keyframes[i]->offset() , ops.release());
455 WebTransformAnimationCurve* transformCurve = static_cast<WebTransfor mAnimationCurve*>(&curve); 455 blink::WebTransformAnimationCurve* transformCurve = static_cast<blin k::WebTransformAnimationCurve*>(&curve);
456 addKeyframeWithTimingFunction(*transformCurve, transformKeyframe, ke yframeTimingFunction); 456 addKeyframeWithTimingFunction(*transformCurve, transformKeyframe, ke yframeTimingFunction);
457 break; 457 break;
458 } 458 }
459 default: 459 default:
460 ASSERT_NOT_REACHED(); 460 ASSERT_NOT_REACHED();
461 } 461 }
462 } 462 }
463 } 463 }
464 464
465 void CompositorAnimationsImpl::getAnimationOnCompositor(const Timing& timing, do uble startTime, const KeyframeEffectModelBase& effect, Vector<OwnPtr<WebComposit orAnimation> >& animations) 465 void CompositorAnimationsImpl::getAnimationOnCompositor(const Timing& timing, do uble startTime, const KeyframeEffectModelBase& effect, Vector<OwnPtr<blink::WebA nimation> >& animations)
466 { 466 {
467 ASSERT(animations.isEmpty()); 467 ASSERT(animations.isEmpty());
468 CompositorTiming compositorTiming; 468 CompositorTiming compositorTiming;
469 bool timingValid = convertTimingForCompositor(timing, compositorTiming); 469 bool timingValid = convertTimingForCompositor(timing, compositorTiming);
470 ASSERT_UNUSED(timingValid, timingValid); 470 ASSERT_UNUSED(timingValid, timingValid);
471 471
472 PropertySet properties = effect.properties(); 472 PropertySet properties = effect.properties();
473 ASSERT(!properties.isEmpty()); 473 ASSERT(!properties.isEmpty());
474 for (PropertySet::iterator it = properties.begin(); it != properties.end(); ++it) { 474 for (PropertySet::iterator it = properties.begin(); it != properties.end(); ++it) {
475 475
476 PropertySpecificKeyframeVector values; 476 PropertySpecificKeyframeVector values;
477 getKeyframeValuesForProperty(&effect, *it, compositorTiming.scaledDurati on, compositorTiming.reverse, values); 477 getKeyframeValuesForProperty(&effect, *it, compositorTiming.scaledDurati on, compositorTiming.reverse, values);
478 478
479 WebCompositorAnimation::TargetProperty targetProperty; 479 blink::WebAnimation::TargetProperty targetProperty;
480 OwnPtr<WebCompositorAnimationCurve> curve; 480 OwnPtr<blink::WebAnimationCurve> curve;
481 switch (*it) { 481 switch (*it) {
482 case CSSPropertyOpacity: { 482 case CSSPropertyOpacity: {
483 targetProperty = WebCompositorAnimation::TargetPropertyOpacity; 483 targetProperty = blink::WebAnimation::TargetPropertyOpacity;
484 484
485 WebFloatAnimationCurve* floatCurve = Platform::current()->compositor Support()->createFloatAnimationCurve(); 485 blink::WebFloatAnimationCurve* floatCurve = blink::Platform::current ()->compositorSupport()->createFloatAnimationCurve();
486 addKeyframesToCurve(*floatCurve, values, compositorTiming.reverse); 486 addKeyframesToCurve(*floatCurve, values, compositorTiming.reverse);
487 curve = adoptPtr(floatCurve); 487 curve = adoptPtr(floatCurve);
488 break; 488 break;
489 } 489 }
490 case CSSPropertyWebkitFilter: { 490 case CSSPropertyWebkitFilter: {
491 targetProperty = WebCompositorAnimation::TargetPropertyFilter; 491 targetProperty = blink::WebAnimation::TargetPropertyFilter;
492 WebFilterAnimationCurve* filterCurve = Platform::current()->composit orSupport()->createFilterAnimationCurve(); 492 blink::WebFilterAnimationCurve* filterCurve = blink::Platform::curre nt()->compositorSupport()->createFilterAnimationCurve();
493 addKeyframesToCurve(*filterCurve, values, compositorTiming.reverse); 493 addKeyframesToCurve(*filterCurve, values, compositorTiming.reverse);
494 curve = adoptPtr(filterCurve); 494 curve = adoptPtr(filterCurve);
495 break; 495 break;
496 } 496 }
497 case CSSPropertyTransform: { 497 case CSSPropertyTransform: {
498 targetProperty = WebCompositorAnimation::TargetPropertyTransform; 498 targetProperty = blink::WebAnimation::TargetPropertyTransform;
499 WebTransformAnimationCurve* transformCurve = Platform::current()->co mpositorSupport()->createTransformAnimationCurve(); 499 blink::WebTransformAnimationCurve* transformCurve = blink::Platform: :current()->compositorSupport()->createTransformAnimationCurve();
500 addKeyframesToCurve(*transformCurve, values, compositorTiming.revers e); 500 addKeyframesToCurve(*transformCurve, values, compositorTiming.revers e);
501 curve = adoptPtr(transformCurve); 501 curve = adoptPtr(transformCurve);
502 break; 502 break;
503 } 503 }
504 default: 504 default:
505 ASSERT_NOT_REACHED(); 505 ASSERT_NOT_REACHED();
506 continue; 506 continue;
507 } 507 }
508 ASSERT(curve.get()); 508 ASSERT(curve.get());
509 509
510 OwnPtr<WebCompositorAnimation> animation = adoptPtr(Platform::current()- >compositorSupport()->createAnimation(*curve, targetProperty)); 510 OwnPtr<blink::WebAnimation> animation = adoptPtr(blink::Platform::curren t()->compositorSupport()->createAnimation(*curve, targetProperty));
511 511
512 if (!std::isnan(startTime)) 512 if (!std::isnan(startTime))
513 animation->setStartTime(startTime); 513 animation->setStartTime(startTime);
514 514
515 animation->setIterations(compositorTiming.adjustedIterationCount); 515 animation->setIterations(compositorTiming.adjustedIterationCount);
516 animation->setTimeOffset(compositorTiming.scaledTimeOffset); 516 animation->setTimeOffset(compositorTiming.scaledTimeOffset);
517 animation->setAlternatesDirection(compositorTiming.alternate); 517 animation->setAlternatesDirection(compositorTiming.alternate);
518 518
519 animations.append(animation.release()); 519 animations.append(animation.release());
520 } 520 }
521 ASSERT(!animations.isEmpty()); 521 ASSERT(!animations.isEmpty());
522 } 522 }
523 523
524 } // namespace blink 524 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/animation/AnimationTranslationUtilTest.cpp ('k') | Source/core/animation/CompositorAnimationsImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698