| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef TimingCalculations_h | 31 #ifndef TimingCalculations_h |
| 32 #define TimingCalculations_h | 32 #define TimingCalculations_h |
| 33 | 33 |
| 34 #include "core/animation/AnimationEffect.h" | 34 #include "core/animation/AnimationEffectReadOnly.h" |
| 35 #include "core/animation/Timing.h" | 35 #include "core/animation/Timing.h" |
| 36 #include "platform/animation/AnimationUtilities.h" | 36 #include "platform/animation/AnimationUtilities.h" |
| 37 #include "wtf/MathExtras.h" | 37 #include "wtf/MathExtras.h" |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 static inline double multiplyZeroAlwaysGivesZero(double x, double y) | 41 static inline double multiplyZeroAlwaysGivesZero(double x, double y) |
| 42 { | 42 { |
| 43 DCHECK(!isNull(x)); | 43 DCHECK(!isNull(x)); |
| 44 DCHECK(!isNull(y)); | 44 DCHECK(!isNull(y)); |
| 45 return x && y ? x * y : 0; | 45 return x && y ? x * y : 0; |
| 46 } | 46 } |
| 47 | 47 |
| 48 static inline AnimationEffect::Phase calculatePhase(double activeDuration, doubl
e localTime, const Timing& specified) | 48 static inline AnimationEffectReadOnly::Phase calculatePhase(double activeDuratio
n, double localTime, const Timing& specified) |
| 49 { | 49 { |
| 50 DCHECK_GE(activeDuration, 0); | 50 DCHECK_GE(activeDuration, 0); |
| 51 if (isNull(localTime)) | 51 if (isNull(localTime)) |
| 52 return AnimationEffect::PhaseNone; | 52 return AnimationEffectReadOnly::PhaseNone; |
| 53 double endTime = specified.startDelay + activeDuration + specified.endDelay; | 53 double endTime = specified.startDelay + activeDuration + specified.endDelay; |
| 54 if (localTime < std::min(specified.startDelay, endTime)) | 54 if (localTime < std::min(specified.startDelay, endTime)) |
| 55 return AnimationEffect::PhaseBefore; | 55 return AnimationEffectReadOnly::PhaseBefore; |
| 56 if (localTime >= std::min(specified.startDelay + activeDuration, endTime)) | 56 if (localTime >= std::min(specified.startDelay + activeDuration, endTime)) |
| 57 return AnimationEffect::PhaseAfter; | 57 return AnimationEffectReadOnly::PhaseAfter; |
| 58 return AnimationEffect::PhaseActive; | 58 return AnimationEffectReadOnly::PhaseActive; |
| 59 } | 59 } |
| 60 | 60 |
| 61 static inline bool isActiveInParentPhase(AnimationEffect::Phase parentPhase, Tim
ing::FillMode fillMode) | 61 static inline bool isActiveInParentPhase(AnimationEffectReadOnly::Phase parentPh
ase, Timing::FillMode fillMode) |
| 62 { | 62 { |
| 63 switch (parentPhase) { | 63 switch (parentPhase) { |
| 64 case AnimationEffect::PhaseBefore: | 64 case AnimationEffectReadOnly::PhaseBefore: |
| 65 return fillMode == Timing::FillMode::BACKWARDS || fillMode == Timing::Fi
llMode::BOTH; | 65 return fillMode == Timing::FillMode::BACKWARDS || fillMode == Timing::Fi
llMode::BOTH; |
| 66 case AnimationEffect::PhaseActive: | 66 case AnimationEffectReadOnly::PhaseActive: |
| 67 return true; | 67 return true; |
| 68 case AnimationEffect::PhaseAfter: | 68 case AnimationEffectReadOnly::PhaseAfter: |
| 69 return fillMode == Timing::FillMode::FORWARDS || fillMode == Timing::Fil
lMode::BOTH; | 69 return fillMode == Timing::FillMode::FORWARDS || fillMode == Timing::Fil
lMode::BOTH; |
| 70 default: | 70 default: |
| 71 NOTREACHED(); | 71 NOTREACHED(); |
| 72 return false; | 72 return false; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 static inline double calculateActiveTime(double activeDuration, Timing::FillMode
fillMode, double localTime, AnimationEffect::Phase parentPhase, AnimationEffect
::Phase phase, const Timing& specified) | 76 static inline double calculateActiveTime(double activeDuration, Timing::FillMode
fillMode, double localTime, AnimationEffectReadOnly::Phase parentPhase, Animati
onEffectReadOnly::Phase phase, const Timing& specified) |
| 77 { | 77 { |
| 78 DCHECK_GE(activeDuration, 0); | 78 DCHECK_GE(activeDuration, 0); |
| 79 DCHECK_EQ(phase, calculatePhase(activeDuration, localTime, specified)); | 79 DCHECK_EQ(phase, calculatePhase(activeDuration, localTime, specified)); |
| 80 | 80 |
| 81 switch (phase) { | 81 switch (phase) { |
| 82 case AnimationEffect::PhaseBefore: | 82 case AnimationEffectReadOnly::PhaseBefore: |
| 83 if (fillMode == Timing::FillMode::BACKWARDS || fillMode == Timing::FillM
ode::BOTH) | 83 if (fillMode == Timing::FillMode::BACKWARDS || fillMode == Timing::FillM
ode::BOTH) |
| 84 return 0; | 84 return 0; |
| 85 return nullValue(); | 85 return nullValue(); |
| 86 case AnimationEffect::PhaseActive: | 86 case AnimationEffectReadOnly::PhaseActive: |
| 87 if (isActiveInParentPhase(parentPhase, fillMode)) | 87 if (isActiveInParentPhase(parentPhase, fillMode)) |
| 88 return localTime - specified.startDelay; | 88 return localTime - specified.startDelay; |
| 89 return nullValue(); | 89 return nullValue(); |
| 90 case AnimationEffect::PhaseAfter: | 90 case AnimationEffectReadOnly::PhaseAfter: |
| 91 if (fillMode == Timing::FillMode::FORWARDS || fillMode == Timing::FillMo
de::BOTH) | 91 if (fillMode == Timing::FillMode::FORWARDS || fillMode == Timing::FillMo
de::BOTH) |
| 92 return std::max(0.0, std::min(activeDuration, activeDuration + speci
fied.endDelay)); | 92 return std::max(0.0, std::min(activeDuration, activeDuration + speci
fied.endDelay)); |
| 93 return nullValue(); | 93 return nullValue(); |
| 94 case AnimationEffect::PhaseNone: | 94 case AnimationEffectReadOnly::PhaseNone: |
| 95 DCHECK(isNull(localTime)); | 95 DCHECK(isNull(localTime)); |
| 96 return nullValue(); | 96 return nullValue(); |
| 97 default: | 97 default: |
| 98 NOTREACHED(); | 98 NOTREACHED(); |
| 99 return nullValue(); | 99 return nullValue(); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 static inline double calculateScaledActiveTime(double activeDuration, double act
iveTime, double startOffset, const Timing& specified) | 103 static inline double calculateScaledActiveTime(double activeDuration, double act
iveTime, double startOffset, const Timing& specified) |
| 104 { | 104 { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 119 return multiplyZeroAlwaysGivesZero(specified.playbackRate < 0 ? activeTime -
activeDuration : activeTime, specified.playbackRate) + startOffset; | 119 return multiplyZeroAlwaysGivesZero(specified.playbackRate < 0 ? activeTime -
activeDuration : activeTime, specified.playbackRate) + startOffset; |
| 120 } | 120 } |
| 121 | 121 |
| 122 static inline bool endsOnIterationBoundary(double iterationCount, double iterati
onStart) | 122 static inline bool endsOnIterationBoundary(double iterationCount, double iterati
onStart) |
| 123 { | 123 { |
| 124 DCHECK(std::isfinite(iterationCount)); | 124 DCHECK(std::isfinite(iterationCount)); |
| 125 return !fmod(iterationCount + iterationStart, 1); | 125 return !fmod(iterationCount + iterationStart, 1); |
| 126 } | 126 } |
| 127 | 127 |
| 128 // TODO(crbug.com/630915): Align this function with current Web Animations spec
text. | 128 // TODO(crbug.com/630915): Align this function with current Web Animations spec
text. |
| 129 static inline double calculateIterationTime(double iterationDuration, double rep
eatedDuration, double scaledActiveTime, double startOffset, AnimationEffect::Pha
se phase, const Timing& specified) | 129 static inline double calculateIterationTime(double iterationDuration, double rep
eatedDuration, double scaledActiveTime, double startOffset, AnimationEffectReadO
nly::Phase phase, const Timing& specified) |
| 130 { | 130 { |
| 131 DCHECK_GT(iterationDuration, 0); | 131 DCHECK_GT(iterationDuration, 0); |
| 132 DCHECK_EQ(repeatedDuration, multiplyZeroAlwaysGivesZero(iterationDuration, s
pecified.iterationCount)); | 132 DCHECK_EQ(repeatedDuration, multiplyZeroAlwaysGivesZero(iterationDuration, s
pecified.iterationCount)); |
| 133 | 133 |
| 134 if (isNull(scaledActiveTime)) | 134 if (isNull(scaledActiveTime)) |
| 135 return nullValue(); | 135 return nullValue(); |
| 136 | 136 |
| 137 DCHECK_GE(scaledActiveTime, 0); | 137 DCHECK_GE(scaledActiveTime, 0); |
| 138 DCHECK_LE(scaledActiveTime, repeatedDuration + startOffset); | 138 DCHECK_LE(scaledActiveTime, repeatedDuration + startOffset); |
| 139 | 139 |
| 140 if (!std::isfinite(scaledActiveTime) | 140 if (!std::isfinite(scaledActiveTime) |
| 141 || (scaledActiveTime - startOffset == repeatedDuration && specified.iter
ationCount && endsOnIterationBoundary(specified.iterationCount, specified.iterat
ionStart))) | 141 || (scaledActiveTime - startOffset == repeatedDuration && specified.iter
ationCount && endsOnIterationBoundary(specified.iterationCount, specified.iterat
ionStart))) |
| 142 return iterationDuration; | 142 return iterationDuration; |
| 143 | 143 |
| 144 DCHECK(std::isfinite(scaledActiveTime)); | 144 DCHECK(std::isfinite(scaledActiveTime)); |
| 145 double iterationTime = fmod(scaledActiveTime, iterationDuration); | 145 double iterationTime = fmod(scaledActiveTime, iterationDuration); |
| 146 | 146 |
| 147 // This implements step 3 of | 147 // This implements step 3 of |
| 148 // http://w3c.github.io/web-animations/#calculating-the-simple-iteration-pro
gress | 148 // http://w3c.github.io/web-animations/#calculating-the-simple-iteration-pro
gress |
| 149 if (iterationTime == 0 | 149 if (iterationTime == 0 |
| 150 && phase == AnimationEffect::PhaseAfter | 150 && phase == AnimationEffectReadOnly::PhaseAfter |
| 151 && repeatedDuration != 0 | 151 && repeatedDuration != 0 |
| 152 && scaledActiveTime != 0) | 152 && scaledActiveTime != 0) |
| 153 return iterationDuration; | 153 return iterationDuration; |
| 154 | 154 |
| 155 return iterationTime; | 155 return iterationTime; |
| 156 } | 156 } |
| 157 | 157 |
| 158 static inline double calculateCurrentIteration(double iterationDuration, double
iterationTime, double scaledActiveTime, const Timing& specified) | 158 static inline double calculateCurrentIteration(double iterationDuration, double
iterationTime, double scaledActiveTime, const Timing& specified) |
| 159 { | 159 { |
| 160 DCHECK_GT(iterationDuration, 0); | 160 DCHECK_GT(iterationDuration, 0); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 if (!std::isfinite(iterationDuration)) | 208 if (!std::isfinite(iterationDuration)) |
| 209 return directedTime; | 209 return directedTime; |
| 210 double timeFraction = directedTime / iterationDuration; | 210 double timeFraction = directedTime / iterationDuration; |
| 211 DCHECK(timeFraction >= 0 && timeFraction <= 1); | 211 DCHECK(timeFraction >= 0 && timeFraction <= 1); |
| 212 return multiplyZeroAlwaysGivesZero(iterationDuration, specified.timingFuncti
on->evaluate(timeFraction, accuracyForDuration(iterationDuration))); | 212 return multiplyZeroAlwaysGivesZero(iterationDuration, specified.timingFuncti
on->evaluate(timeFraction, accuracyForDuration(iterationDuration))); |
| 213 } | 213 } |
| 214 | 214 |
| 215 } // namespace blink | 215 } // namespace blink |
| 216 | 216 |
| 217 #endif | 217 #endif |
| OLD | NEW |