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