OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/animation/CompositorAnimation.h" |
| 6 |
| 7 #include "cc/animation/animation.h" |
| 8 #include "cc/animation/animation_curve.h" |
| 9 #include "cc/animation/animation_id_provider.h" |
| 10 #include "platform/animation/CompositorAnimationCurve.h" |
| 11 #include "platform/animation/CompositorFilterAnimationCurve.h" |
| 12 #include "platform/animation/CompositorFloatAnimationCurve.h" |
| 13 #include "platform/animation/CompositorScrollOffsetAnimationCurve.h" |
| 14 #include "platform/animation/CompositorTransformAnimationCurve.h" |
| 15 |
| 16 using cc::Animation; |
| 17 using cc::AnimationIdProvider; |
| 18 |
| 19 using blink::CompositorAnimation; |
| 20 using blink::CompositorAnimationCurve; |
| 21 |
| 22 namespace blink { |
| 23 |
| 24 #define STATIC_ASSERT_ENUM(a, b) \ |
| 25 static_assert(static_cast<int>(a) == static_cast<int>(b), \ |
| 26 "mismatching enums: " #a) |
| 27 |
| 28 // TargetProperty |
| 29 STATIC_ASSERT_ENUM(CompositorAnimation::TargetPropertyTransform, cc::Animation::
TRANSFORM); |
| 30 STATIC_ASSERT_ENUM(CompositorAnimation::TargetPropertyOpacity, cc::Animation::OP
ACITY); |
| 31 STATIC_ASSERT_ENUM(CompositorAnimation::TargetPropertyFilter, cc::Animation::FIL
TER); |
| 32 STATIC_ASSERT_ENUM(CompositorAnimation::TargetPropertyScrollOffset, cc::Animatio
n::SCROLL_OFFSET); |
| 33 |
| 34 CompositorAnimation::CompositorAnimation(const CompositorAnimationCurve& webCurv
e, TargetProperty targetProperty, int animationId, int groupId) |
| 35 { |
| 36 if (!animationId) |
| 37 animationId = AnimationIdProvider::NextAnimationId(); |
| 38 if (!groupId) |
| 39 groupId = AnimationIdProvider::NextGroupId(); |
| 40 |
| 41 CompositorAnimationCurve::AnimationCurveType curveType = webCurve.type(); |
| 42 scoped_ptr<cc::AnimationCurve> curve; |
| 43 switch (curveType) { |
| 44 case CompositorAnimationCurve::AnimationCurveTypeFloat: { |
| 45 const blink::CompositorFloatAnimationCurve* floatCurve = static_cast<con
st blink::CompositorFloatAnimationCurve*>(&webCurve); |
| 46 curve = floatCurve->cloneToAnimationCurve(); |
| 47 break; |
| 48 } |
| 49 case CompositorAnimationCurve::AnimationCurveTypeTransform: { |
| 50 const blink::CompositorTransformAnimationCurve* transformCurve = static_
cast<const blink::CompositorTransformAnimationCurve*>(&webCurve); |
| 51 curve = transformCurve->cloneToAnimationCurve(); |
| 52 break; |
| 53 } |
| 54 case CompositorAnimationCurve::AnimationCurveTypeFilter: { |
| 55 const blink::CompositorFilterAnimationCurve* filterCurve = static_cast<c
onst blink::CompositorFilterAnimationCurve*>(&webCurve); |
| 56 curve = filterCurve->cloneToAnimationCurve(); |
| 57 break; |
| 58 } |
| 59 case CompositorAnimationCurve::AnimationCurveTypeScrollOffset: { |
| 60 const blink::CompositorScrollOffsetAnimationCurve* scrollCurve = static_
cast<const blink::CompositorScrollOffsetAnimationCurve*>(&webCurve); |
| 61 curve = scrollCurve->cloneToAnimationCurve(); |
| 62 break; |
| 63 } |
| 64 } |
| 65 m_animation = Animation::Create( |
| 66 std::move(curve), animationId, groupId, |
| 67 static_cast<cc::Animation::TargetProperty>(targetProperty)); |
| 68 } |
| 69 |
| 70 CompositorAnimation::CompositorAnimation() {} |
| 71 |
| 72 CompositorAnimation::~CompositorAnimation() {} |
| 73 |
| 74 int CompositorAnimation::id() |
| 75 { |
| 76 return m_animation->id(); |
| 77 } |
| 78 |
| 79 int CompositorAnimation::group() |
| 80 { |
| 81 return m_animation->group(); |
| 82 } |
| 83 |
| 84 blink::CompositorAnimation::TargetProperty CompositorAnimation::targetProperty()
const |
| 85 { |
| 86 return static_cast<CompositorAnimation::TargetProperty>(m_animation->target_
property()); |
| 87 } |
| 88 |
| 89 double CompositorAnimation::iterations() const |
| 90 { |
| 91 return m_animation->iterations(); |
| 92 } |
| 93 |
| 94 void CompositorAnimation::setIterations(double n) |
| 95 { |
| 96 m_animation->set_iterations(n); |
| 97 } |
| 98 |
| 99 double CompositorAnimation::iterationStart() const |
| 100 { |
| 101 return m_animation->iteration_start(); |
| 102 } |
| 103 |
| 104 void CompositorAnimation::setIterationStart(double iterationStart) |
| 105 { |
| 106 m_animation->set_iteration_start(iterationStart); |
| 107 } |
| 108 |
| 109 double CompositorAnimation::startTime() const |
| 110 { |
| 111 return (m_animation->start_time() - base::TimeTicks()).InSecondsF(); |
| 112 } |
| 113 |
| 114 void CompositorAnimation::setStartTime(double monotonicTime) |
| 115 { |
| 116 m_animation->set_start_time(base::TimeTicks::FromInternalValue( |
| 117 monotonicTime * base::Time::kMicrosecondsPerSecond)); |
| 118 } |
| 119 |
| 120 double CompositorAnimation::timeOffset() const |
| 121 { |
| 122 return m_animation->time_offset().InSecondsF(); |
| 123 } |
| 124 |
| 125 void CompositorAnimation::setTimeOffset(double monotonicTime) |
| 126 { |
| 127 m_animation->set_time_offset(base::TimeDelta::FromSecondsD(monotonicTime)); |
| 128 } |
| 129 |
| 130 blink::CompositorAnimation::Direction CompositorAnimation::direction() const |
| 131 { |
| 132 switch (m_animation->direction()) { |
| 133 case cc::Animation::DIRECTION_NORMAL: |
| 134 return DirectionNormal; |
| 135 case cc::Animation::DIRECTION_REVERSE: |
| 136 return DirectionReverse; |
| 137 case cc::Animation::DIRECTION_ALTERNATE: |
| 138 return DirectionAlternate; |
| 139 case cc::Animation::DIRECTION_ALTERNATE_REVERSE: |
| 140 return DirectionAlternateReverse; |
| 141 default: |
| 142 NOTREACHED(); |
| 143 } |
| 144 return DirectionNormal; |
| 145 } |
| 146 |
| 147 void CompositorAnimation::setDirection(Direction direction) |
| 148 { |
| 149 switch (direction) { |
| 150 case DirectionNormal: |
| 151 m_animation->set_direction(cc::Animation::DIRECTION_NORMAL); |
| 152 break; |
| 153 case DirectionReverse: |
| 154 m_animation->set_direction(cc::Animation::DIRECTION_REVERSE); |
| 155 break; |
| 156 case DirectionAlternate: |
| 157 m_animation->set_direction(cc::Animation::DIRECTION_ALTERNATE); |
| 158 break; |
| 159 case DirectionAlternateReverse: |
| 160 m_animation->set_direction(cc::Animation::DIRECTION_ALTERNATE_REVERSE); |
| 161 break; |
| 162 } |
| 163 } |
| 164 |
| 165 double CompositorAnimation::playbackRate() const |
| 166 { |
| 167 return m_animation->playback_rate(); |
| 168 } |
| 169 |
| 170 void CompositorAnimation::setPlaybackRate(double playbackRate) |
| 171 { |
| 172 m_animation->set_playback_rate(playbackRate); |
| 173 } |
| 174 |
| 175 blink::CompositorAnimation::FillMode CompositorAnimation::fillMode() const |
| 176 { |
| 177 switch (m_animation->fill_mode()) { |
| 178 case cc::Animation::FILL_MODE_NONE: |
| 179 return FillModeNone; |
| 180 case cc::Animation::FILL_MODE_FORWARDS: |
| 181 return FillModeForwards; |
| 182 case cc::Animation::FILL_MODE_BACKWARDS: |
| 183 return FillModeBackwards; |
| 184 case cc::Animation::FILL_MODE_BOTH: |
| 185 return FillModeBoth; |
| 186 default: |
| 187 NOTREACHED(); |
| 188 } |
| 189 return FillModeNone; |
| 190 } |
| 191 |
| 192 void CompositorAnimation::setFillMode(FillMode fillMode) |
| 193 { |
| 194 switch (fillMode) { |
| 195 case FillModeNone: |
| 196 m_animation->set_fill_mode(cc::Animation::FILL_MODE_NONE); |
| 197 break; |
| 198 case FillModeForwards: |
| 199 m_animation->set_fill_mode(cc::Animation::FILL_MODE_FORWARDS); |
| 200 break; |
| 201 case FillModeBackwards: |
| 202 m_animation->set_fill_mode(cc::Animation::FILL_MODE_BACKWARDS); |
| 203 break; |
| 204 case FillModeBoth: |
| 205 m_animation->set_fill_mode(cc::Animation::FILL_MODE_BOTH); |
| 206 break; |
| 207 } |
| 208 } |
| 209 |
| 210 scoped_ptr<cc::Animation> CompositorAnimation::passAnimation() |
| 211 { |
| 212 m_animation->set_needs_synchronized_start_time(true); |
| 213 return std::move(m_animation); |
| 214 } |
| 215 |
| 216 cc::Animation* CompositorAnimation::releaseCCAnimation() |
| 217 { |
| 218 m_animation->set_needs_synchronized_start_time(true); |
| 219 return m_animation.release(); |
| 220 } |
| 221 |
| 222 } // namespace blink |
OLD | NEW |