| OLD | NEW |
| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 default: | 166 default: |
| 167 return false; | 167 return false; |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 CompositorAnimationsImpl::CompositorTiming out; | 172 CompositorAnimationsImpl::CompositorTiming out; |
| 173 if (!CompositorAnimationsImpl::convertTimingForCompositor(timing, 0, out, pl
ayerPlaybackRate)) | 173 if (!CompositorAnimationsImpl::convertTimingForCompositor(timing, 0, out, pl
ayerPlaybackRate)) |
| 174 return false; | 174 return false; |
| 175 | 175 |
| 176 if (timing.timingFunction->type() != TimingFunction::LinearFunction) { | 176 if (timing.timingFunction->type() == TimingFunction::CubicBezierFunction) { |
| 177 // Checks the of size of KeyframeVector instead of PropertySpecificKeyfr
ameVector. | 177 // FIXME: Fix compositor timing functions to accept inputs outside of |
| 178 // [0,1]. |
| 179 const CubicBezierTimingFunction& cubic = toCubicBezierTimingFunction(*ti
ming.timingFunction); |
| 178 const KeyframeVector& keyframes = keyframeEffect.getFrames(); | 180 const KeyframeVector& keyframes = keyframeEffect.getFrames(); |
| 179 if (keyframes.size() == 2 && keyframes.first()->easing().type() == Timin
gFunction::LinearFunction) | 181 double startRange = 0; |
| 180 return true; | 182 double endRange = 1; |
| 183 cubic.range(&startRange, &endRange); |
| 181 | 184 |
| 182 // FIXME: Support non-linear timing functions in the compositor for | 185 ASSERT(keyframes.size() >= 2); |
| 183 // more than two keyframes. | 186 if ((startRange < 0 || endRange > 1) && (keyframes.first()->easing().typ
e() != TimingFunction::LinearFunction || keyframes[keyframes.size() - 2]->easing
().type() != TimingFunction::LinearFunction)) |
| 184 return false; | 187 return false; |
| 185 } | 188 } |
| 186 | 189 |
| 187 return true; | 190 return true; |
| 188 } | 191 } |
| 189 | 192 |
| 190 bool CompositorAnimations::canStartAnimationOnCompositor(const Element& element) | 193 bool CompositorAnimations::canStartAnimationOnCompositor(const Element& element) |
| 191 { | 194 { |
| 192 return element.renderer() && element.renderer()->compositingState() == Paint
sIntoOwnBacking; | 195 return element.renderer() && element.renderer()->compositingState() == Paint
sIntoOwnBacking; |
| 193 } | 196 } |
| 194 | 197 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 out.scaledTimeOffset = -timing.startDelay + timeOffset; | 277 out.scaledTimeOffset = -timing.startDelay + timeOffset; |
| 275 out.playbackRate = timing.playbackRate * playerPlaybackRate; | 278 out.playbackRate = timing.playbackRate * playerPlaybackRate; |
| 276 out.fillMode = timing.fillMode == Timing::FillModeAuto ? Timing::FillModeNon
e : timing.fillMode; | 279 out.fillMode = timing.fillMode == Timing::FillModeAuto ? Timing::FillModeNon
e : timing.fillMode; |
| 277 out.iterationStart = timing.iterationStart; | 280 out.iterationStart = timing.iterationStart; |
| 278 out.assertValid(); | 281 out.assertValid(); |
| 279 return true; | 282 return true; |
| 280 } | 283 } |
| 281 | 284 |
| 282 namespace { | 285 namespace { |
| 283 | 286 |
| 287 void getCubicBezierTimingFunctionParameters(const TimingFunction& timingFunction
, bool& outCustom, |
| 288 WebCompositorAnimationCurve::TimingFunctionType& outEaseSubType, |
| 289 double& outX1, double& outY1, double& outX2, double& outY2) |
| 290 { |
| 291 const CubicBezierTimingFunction& cubic = toCubicBezierTimingFunction(timingF
unction); |
| 292 outCustom = false; |
| 293 |
| 294 switch (cubic.subType()) { |
| 295 case CubicBezierTimingFunction::Ease: |
| 296 outEaseSubType = WebCompositorAnimationCurve::TimingFunctionTypeEase; |
| 297 break; |
| 298 case CubicBezierTimingFunction::EaseIn: |
| 299 outEaseSubType = WebCompositorAnimationCurve::TimingFunctionTypeEaseIn; |
| 300 break; |
| 301 case CubicBezierTimingFunction::EaseOut: |
| 302 outEaseSubType = WebCompositorAnimationCurve::TimingFunctionTypeEaseOut; |
| 303 break; |
| 304 case CubicBezierTimingFunction::EaseInOut: |
| 305 outEaseSubType = WebCompositorAnimationCurve::TimingFunctionTypeEaseInOu
t; |
| 306 break; |
| 307 case CubicBezierTimingFunction::Custom: |
| 308 outCustom = true; |
| 309 outX1 = cubic.x1(); |
| 310 outY1 = cubic.y1(); |
| 311 outX2 = cubic.x2(); |
| 312 outY2 = cubic.y2(); |
| 313 break; |
| 314 default: |
| 315 ASSERT_NOT_REACHED(); |
| 316 } |
| 317 } |
| 318 |
| 319 void getStepsTimingFunctionParameters(const TimingFunction& timingFunction, int&
outSteps, float& outStepsStartOffset) |
| 320 { |
| 321 const StepsTimingFunction& steps = toStepsTimingFunction(timingFunction); |
| 322 |
| 323 outSteps = steps.numberOfSteps(); |
| 324 switch (steps.stepAtPosition()) { |
| 325 case StepsTimingFunction::Start: |
| 326 outStepsStartOffset = 1; |
| 327 break; |
| 328 case StepsTimingFunction::Middle: |
| 329 outStepsStartOffset = 0.5; |
| 330 break; |
| 331 case StepsTimingFunction::End: |
| 332 outStepsStartOffset = 0; |
| 333 break; |
| 334 default: |
| 335 ASSERT_NOT_REACHED(); |
| 336 } |
| 337 } |
| 338 |
| 284 template<typename PlatformAnimationCurveType, typename PlatformAnimationKeyframe
Type> | 339 template<typename PlatformAnimationCurveType, typename PlatformAnimationKeyframe
Type> |
| 285 void addKeyframeWithTimingFunction(PlatformAnimationCurveType& curve, const Plat
formAnimationKeyframeType& keyframe, const TimingFunction* timingFunction) | 340 void addKeyframeWithTimingFunction(PlatformAnimationCurveType& curve, const Plat
formAnimationKeyframeType& keyframe, const TimingFunction* timingFunction) |
| 286 { | 341 { |
| 287 if (!timingFunction) { | 342 if (!timingFunction) { |
| 288 curve.add(keyframe); | 343 curve.add(keyframe); |
| 289 return; | 344 return; |
| 290 } | 345 } |
| 291 | 346 |
| 292 switch (timingFunction->type()) { | 347 switch (timingFunction->type()) { |
| 293 case TimingFunction::LinearFunction: | 348 case TimingFunction::LinearFunction: |
| 294 curve.add(keyframe, WebCompositorAnimationCurve::TimingFunctionTypeLinea
r); | 349 curve.add(keyframe, WebCompositorAnimationCurve::TimingFunctionTypeLinea
r); |
| 295 return; | 350 break; |
| 296 | 351 |
| 297 case TimingFunction::CubicBezierFunction: { | 352 case TimingFunction::CubicBezierFunction: { |
| 298 const CubicBezierTimingFunction* cubic = toCubicBezierTimingFunction(tim
ingFunction); | 353 bool custom; |
| 354 WebCompositorAnimationCurve::TimingFunctionType easeSubType; |
| 355 double x1, y1; |
| 356 double x2, y2; |
| 357 getCubicBezierTimingFunctionParameters(*timingFunction, custom, easeSubT
ype, x1, y1, x2, y2); |
| 299 | 358 |
| 300 if (cubic->subType() == CubicBezierTimingFunction::Custom) { | 359 if (custom) |
| 301 curve.add(keyframe, cubic->x1(), cubic->y1(), cubic->x2(), cubic->y2
()); | 360 curve.add(keyframe, x1, y1, x2, y2); |
| 302 } else { | 361 else |
| 362 curve.add(keyframe, easeSubType); |
| 363 break; |
| 364 } |
| 303 | 365 |
| 304 WebCompositorAnimationCurve::TimingFunctionType easeType; | 366 case TimingFunction::StepsFunction: { |
| 305 switch (cubic->subType()) { | 367 int steps; |
| 306 case CubicBezierTimingFunction::Ease: | 368 float stepsStartOffset; |
| 307 easeType = WebCompositorAnimationCurve::TimingFunctionTypeEase; | 369 getStepsTimingFunctionParameters(*timingFunction, steps, stepsStartOffse
t); |
| 308 break; | |
| 309 case CubicBezierTimingFunction::EaseIn: | |
| 310 easeType = WebCompositorAnimationCurve::TimingFunctionTypeEaseIn
; | |
| 311 break; | |
| 312 case CubicBezierTimingFunction::EaseOut: | |
| 313 easeType = WebCompositorAnimationCurve::TimingFunctionTypeEaseOu
t; | |
| 314 break; | |
| 315 case CubicBezierTimingFunction::EaseInOut: | |
| 316 easeType = WebCompositorAnimationCurve::TimingFunctionTypeEaseIn
Out; | |
| 317 break; | |
| 318 | 370 |
| 319 // Custom Bezier are handled seperately. | 371 curve.add(keyframe, steps, stepsStartOffset); |
| 320 case CubicBezierTimingFunction::Custom: | 372 break; |
| 321 default: | 373 } |
| 322 ASSERT_NOT_REACHED(); | |
| 323 return; | |
| 324 } | |
| 325 | 374 |
| 326 curve.add(keyframe, easeType); | 375 default: |
| 327 } | 376 ASSERT_NOT_REACHED(); |
| 377 } |
| 378 } |
| 379 |
| 380 template <typename PlatformAnimationCurveType> |
| 381 void setTimingFunctionOnCurve(PlatformAnimationCurveType& curve, TimingFunction*
timingFunction) |
| 382 { |
| 383 if (!timingFunction) { |
| 384 curve.setLinearTimingFunction(); |
| 328 return; | 385 return; |
| 329 } | 386 } |
| 330 | 387 |
| 331 case TimingFunction::StepsFunction: | 388 switch (timingFunction->type()) { |
| 332 const StepsTimingFunction* steps = toStepsTimingFunction(timingFunction)
; | 389 case TimingFunction::LinearFunction: |
| 390 curve.setLinearTimingFunction(); |
| 391 break; |
| 333 | 392 |
| 393 case TimingFunction::CubicBezierFunction: { |
| 394 bool custom; |
| 395 WebCompositorAnimationCurve::TimingFunctionType easeSubType; |
| 396 double x1, y1; |
| 397 double x2, y2; |
| 398 getCubicBezierTimingFunctionParameters(*timingFunction, custom, easeSubT
ype, x1, y1, x2, y2); |
| 399 |
| 400 if (custom) |
| 401 curve.setCubicBezierTimingFunction(x1, y1, x2, y2); |
| 402 else |
| 403 curve.setCubicBezierTimingFunction(easeSubType); |
| 404 break; |
| 405 } |
| 406 |
| 407 case TimingFunction::StepsFunction: { |
| 408 int steps; |
| 334 float stepsStartOffset; | 409 float stepsStartOffset; |
| 335 switch (steps->stepAtPosition()) { | 410 getStepsTimingFunctionParameters(*timingFunction, steps, stepsStartOffse
t); |
| 336 case StepsTimingFunction::Start: | 411 |
| 337 stepsStartOffset = 1; | 412 curve.setStepsTimingFunction(steps, stepsStartOffset); |
| 338 break; | 413 break; |
| 339 case StepsTimingFunction::Middle: | 414 } |
| 340 stepsStartOffset = 0.5; | 415 |
| 341 break; | 416 default: |
| 342 case StepsTimingFunction::End: | 417 ASSERT_NOT_REACHED(); |
| 343 stepsStartOffset = 0; | |
| 344 break; | |
| 345 default: | |
| 346 ASSERT_NOT_REACHED(); | |
| 347 return; | |
| 348 } | |
| 349 curve.add(keyframe, steps->numberOfSteps(), stepsStartOffset); | |
| 350 return; | |
| 351 } | 418 } |
| 352 } | 419 } |
| 353 | 420 |
| 354 } // namespace anoymous | 421 } // namespace anoymous |
| 355 | 422 |
| 356 void CompositorAnimationsImpl::addKeyframesToCurve(WebCompositorAnimationCurve&
curve, const PropertySpecificKeyframeVector& keyframes, const Timing& timing) | 423 void CompositorAnimationsImpl::addKeyframesToCurve(WebCompositorAnimationCurve&
curve, const PropertySpecificKeyframeVector& keyframes, const Timing& timing) |
| 357 { | 424 { |
| 358 auto* lastKeyframe = keyframes.last().get(); | 425 auto* lastKeyframe = keyframes.last().get(); |
| 359 for (const auto& keyframe : keyframes) { | 426 for (const auto& keyframe : keyframes) { |
| 360 const TimingFunction* keyframeTimingFunction = 0; | 427 const TimingFunction* keyframeTimingFunction = 0; |
| 361 if (keyframe != lastKeyframe) { // Ignore timing function of last frame. | 428 if (keyframe != lastKeyframe) { // Ignore timing function of last frame. |
| 362 if (keyframes.size() == 2 && keyframes.first()->easing().type() == T
imingFunction::LinearFunction) | 429 keyframeTimingFunction = &keyframe->easing(); |
| 363 keyframeTimingFunction = timing.timingFunction.get(); | |
| 364 else | |
| 365 keyframeTimingFunction = &keyframe->easing(); | |
| 366 } | 430 } |
| 367 | 431 |
| 368 // FIXME: This relies on StringKeyframes being eagerly evaluated, which
will | 432 // FIXME: This relies on StringKeyframes being eagerly evaluated, which
will |
| 369 // not happen eventually. Instead we should extract the CSSValue here | 433 // not happen eventually. Instead we should extract the CSSValue here |
| 370 // and convert using another set of toAnimatableXXXOperations functions. | 434 // and convert using another set of toAnimatableXXXOperations functions. |
| 371 const AnimatableValue* value = keyframe->getAnimatableValue().get(); | 435 const AnimatableValue* value = keyframe->getAnimatableValue().get(); |
| 372 | 436 |
| 373 switch (curve.type()) { | 437 switch (curve.type()) { |
| 374 case WebCompositorAnimationCurve::AnimationCurveTypeFilter: { | 438 case WebCompositorAnimationCurve::AnimationCurveTypeFilter: { |
| 375 OwnPtr<WebFilterOperations> ops = adoptPtr(Platform::current()->comp
ositorSupport()->createFilterOperations()); | 439 OwnPtr<WebFilterOperations> ops = adoptPtr(Platform::current()->comp
ositorSupport()->createFilterOperations()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 getKeyframeValuesForProperty(&effect, property, compositorTiming.scaledD
uration, values); | 479 getKeyframeValuesForProperty(&effect, property, compositorTiming.scaledD
uration, values); |
| 416 | 480 |
| 417 WebCompositorAnimation::TargetProperty targetProperty; | 481 WebCompositorAnimation::TargetProperty targetProperty; |
| 418 OwnPtr<WebCompositorAnimationCurve> curve; | 482 OwnPtr<WebCompositorAnimationCurve> curve; |
| 419 switch (property) { | 483 switch (property) { |
| 420 case CSSPropertyOpacity: { | 484 case CSSPropertyOpacity: { |
| 421 targetProperty = WebCompositorAnimation::TargetPropertyOpacity; | 485 targetProperty = WebCompositorAnimation::TargetPropertyOpacity; |
| 422 | 486 |
| 423 WebFloatAnimationCurve* floatCurve = Platform::current()->compositor
Support()->createFloatAnimationCurve(); | 487 WebFloatAnimationCurve* floatCurve = Platform::current()->compositor
Support()->createFloatAnimationCurve(); |
| 424 addKeyframesToCurve(*floatCurve, values, timing); | 488 addKeyframesToCurve(*floatCurve, values, timing); |
| 489 setTimingFunctionOnCurve(*floatCurve, timing.timingFunction.get()); |
| 425 curve = adoptPtr(floatCurve); | 490 curve = adoptPtr(floatCurve); |
| 426 break; | 491 break; |
| 427 } | 492 } |
| 428 case CSSPropertyWebkitFilter: { | 493 case CSSPropertyWebkitFilter: { |
| 429 targetProperty = WebCompositorAnimation::TargetPropertyFilter; | 494 targetProperty = WebCompositorAnimation::TargetPropertyFilter; |
| 430 WebFilterAnimationCurve* filterCurve = Platform::current()->composit
orSupport()->createFilterAnimationCurve(); | 495 WebFilterAnimationCurve* filterCurve = Platform::current()->composit
orSupport()->createFilterAnimationCurve(); |
| 431 addKeyframesToCurve(*filterCurve, values, timing); | 496 addKeyframesToCurve(*filterCurve, values, timing); |
| 497 setTimingFunctionOnCurve(*filterCurve, timing.timingFunction.get()); |
| 432 curve = adoptPtr(filterCurve); | 498 curve = adoptPtr(filterCurve); |
| 433 break; | 499 break; |
| 434 } | 500 } |
| 435 case CSSPropertyTransform: { | 501 case CSSPropertyTransform: { |
| 436 targetProperty = WebCompositorAnimation::TargetPropertyTransform; | 502 targetProperty = WebCompositorAnimation::TargetPropertyTransform; |
| 437 WebTransformAnimationCurve* transformCurve = Platform::current()->co
mpositorSupport()->createTransformAnimationCurve(); | 503 WebTransformAnimationCurve* transformCurve = Platform::current()->co
mpositorSupport()->createTransformAnimationCurve(); |
| 438 addKeyframesToCurve(*transformCurve, values, timing); | 504 addKeyframesToCurve(*transformCurve, values, timing); |
| 505 setTimingFunctionOnCurve(*transformCurve, timing.timingFunction.get(
)); |
| 439 curve = adoptPtr(transformCurve); | 506 curve = adoptPtr(transformCurve); |
| 440 break; | 507 break; |
| 441 } | 508 } |
| 442 default: | 509 default: |
| 443 ASSERT_NOT_REACHED(); | 510 ASSERT_NOT_REACHED(); |
| 444 continue; | 511 continue; |
| 445 } | 512 } |
| 446 ASSERT(curve.get()); | 513 ASSERT(curve.get()); |
| 447 | 514 |
| 448 OwnPtr<WebCompositorAnimation> animation = adoptPtr(Platform::current()-
>compositorSupport()->createAnimation(*curve, targetProperty, group, 0)); | 515 OwnPtr<WebCompositorAnimation> animation = adoptPtr(Platform::current()-
>compositorSupport()->createAnimation(*curve, targetProperty, group, 0)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 break; | 554 break; |
| 488 default: | 555 default: |
| 489 ASSERT_NOT_REACHED(); | 556 ASSERT_NOT_REACHED(); |
| 490 } | 557 } |
| 491 animations.append(animation.release()); | 558 animations.append(animation.release()); |
| 492 } | 559 } |
| 493 ASSERT(!animations.isEmpty()); | 560 ASSERT(!animations.isEmpty()); |
| 494 } | 561 } |
| 495 | 562 |
| 496 } // namespace blink | 563 } // namespace blink |
| OLD | NEW |