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/WebCompositorAnimation.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/WebCompositorAnimationCurve.h" | |
11 #include "platform/animation/WebFilterAnimationCurve.h" | |
12 #include "platform/animation/WebFloatAnimationCurve.h" | |
13 #include "platform/animation/WebScrollOffsetAnimationCurve.h" | |
14 #include "platform/animation/WebTransformAnimationCurve.h" | |
15 | |
16 using cc::Animation; | |
17 using cc::AnimationIdProvider; | |
18 | |
19 using blink::WebCompositorAnimation; | |
20 using blink::WebCompositorAnimationCurve; | |
21 | |
22 namespace blink { | |
23 | |
24 #define STATIC_ASSERT_MATCHING_ENUM(expected, actual) \ | |
esprehn
2016/01/28 03:40:39
we don't have a macro for this already?
loyso (OOO)
2016/01/28 07:10:08
No, we don't. I have moved this code 'as-is' from
| |
25 static_assert(int(expected) == int(actual), "mismatching enums: " #expected) | |
26 | |
27 // Assert matching enums: TargetProperty | |
28 STATIC_ASSERT_MATCHING_ENUM( | |
29 blink::WebCompositorAnimation::TargetPropertyTransform, | |
30 cc::Animation::TRANSFORM); | |
31 STATIC_ASSERT_MATCHING_ENUM( | |
32 blink::WebCompositorAnimation::TargetPropertyOpacity, | |
33 cc::Animation::OPACITY); | |
34 STATIC_ASSERT_MATCHING_ENUM(blink::WebCompositorAnimation::TargetPropertyFilter, | |
35 cc::Animation::FILTER); | |
36 STATIC_ASSERT_MATCHING_ENUM( | |
37 blink::WebCompositorAnimation::TargetPropertyScrollOffset, | |
38 cc::Animation::SCROLL_OFFSET); | |
39 | |
40 | |
41 WebCompositorAnimation::WebCompositorAnimation( | |
42 const WebCompositorAnimationCurve& webCurve, | |
43 TargetProperty targetProperty, | |
44 int animationId, | |
45 int groupId) | |
46 { | |
47 if (!animationId) | |
48 animationId = AnimationIdProvider::NextAnimationId(); | |
esprehn
2016/01/28 03:40:39
animationId || ...; works too I think?
loyso (OOO)
2016/01/28 07:10:08
It would work and it's the same in terms of genera
jbroman
2016/01/28 15:27:23
Drive-by: no it wouldn't (unlike JavaScript, in C+
| |
49 if (!groupId) | |
50 groupId = AnimationIdProvider::NextGroupId(); | |
esprehn
2016/01/28 03:40:39
ditto
| |
51 | |
52 WebCompositorAnimationCurve::AnimationCurveType curveType = webCurve.type(); | |
53 scoped_ptr<cc::AnimationCurve> curve; | |
54 switch (curveType) { | |
55 case WebCompositorAnimationCurve::AnimationCurveTypeFloat: { | |
56 const blink::WebFloatAnimationCurve* floatCurve = static_cast<const blin k::WebFloatAnimationCurve*>(&webCurve); | |
57 curve = floatCurve->CloneToAnimationCurve(); | |
58 break; | |
59 } | |
60 case WebCompositorAnimationCurve::AnimationCurveTypeTransform: { | |
61 const blink::WebTransformAnimationCurve* transformCurve = static_cast<co nst blink::WebTransformAnimationCurve*>(&webCurve); | |
62 curve = transformCurve->CloneToAnimationCurve(); | |
63 break; | |
64 } | |
65 case WebCompositorAnimationCurve::AnimationCurveTypeFilter: { | |
66 const blink::WebFilterAnimationCurve* filterCurve = static_cast<const bl ink::WebFilterAnimationCurve*>(&webCurve); | |
67 curve = filterCurve->CloneToAnimationCurve(); | |
68 break; | |
69 } | |
70 case WebCompositorAnimationCurve::AnimationCurveTypeScrollOffset: { | |
71 const blink::WebScrollOffsetAnimationCurve* scrollCurve = static_cast<co nst blink::WebScrollOffsetAnimationCurve*>(&webCurve); | |
72 curve = scrollCurve->CloneToAnimationCurve(); | |
73 break; | |
74 } | |
75 } | |
76 m_animation = Animation::Create( | |
77 std::move(curve), animationId, groupId, | |
78 static_cast<cc::Animation::TargetProperty>(targetProperty)); | |
79 } | |
80 | |
81 WebCompositorAnimation::WebCompositorAnimation() {} | |
82 | |
83 WebCompositorAnimation::~WebCompositorAnimation() | |
84 { | |
esprehn
2016/01/28 03:40:39
move braces up for consistency
loyso (OOO)
2016/01/28 07:10:08
Done.
| |
85 } | |
86 | |
87 int WebCompositorAnimation::id() | |
88 { | |
89 return m_animation->id(); | |
90 } | |
91 | |
92 int WebCompositorAnimation::group() | |
93 { | |
94 return m_animation->group(); | |
95 } | |
96 | |
97 blink::WebCompositorAnimation::TargetProperty WebCompositorAnimation::targetProp erty() const | |
98 { | |
99 return static_cast<WebCompositorAnimation::TargetProperty>(m_animation->targ et_property()); | |
100 } | |
101 | |
102 double WebCompositorAnimation::iterations() const | |
103 { | |
104 return m_animation->iterations(); | |
105 } | |
106 | |
107 void WebCompositorAnimation::setIterations(double n) | |
108 { | |
109 m_animation->set_iterations(n); | |
110 } | |
111 | |
112 double WebCompositorAnimation::iterationStart() const | |
113 { | |
114 return m_animation->iteration_start(); | |
115 } | |
116 | |
117 void WebCompositorAnimation::setIterationStart(double iterationStart) | |
118 { | |
119 m_animation->set_iteration_start(iterationStart); | |
120 } | |
121 | |
122 double WebCompositorAnimation::startTime() const | |
123 { | |
124 return (m_animation->start_time() - base::TimeTicks()).InSecondsF(); | |
125 } | |
126 | |
127 void WebCompositorAnimation::setStartTime(double monotonicTime) | |
128 { | |
129 m_animation->set_start_time(base::TimeTicks::FromInternalValue( | |
130 monotonicTime * base::Time::kMicrosecondsPerSecond)); | |
131 } | |
132 | |
133 double WebCompositorAnimation::timeOffset() const | |
134 { | |
135 return m_animation->time_offset().InSecondsF(); | |
136 } | |
137 | |
138 void WebCompositorAnimation::setTimeOffset(double monotonicTime) | |
139 { | |
140 m_animation->set_time_offset(base::TimeDelta::FromSecondsD(monotonicTime)); | |
141 } | |
142 | |
143 blink::WebCompositorAnimation::Direction WebCompositorAnimation::direction() con st | |
144 { | |
145 switch (m_animation->direction()) { | |
146 case cc::Animation::DIRECTION_NORMAL: | |
147 return DirectionNormal; | |
148 case cc::Animation::DIRECTION_REVERSE: | |
149 return DirectionReverse; | |
150 case cc::Animation::DIRECTION_ALTERNATE: | |
151 return DirectionAlternate; | |
152 case cc::Animation::DIRECTION_ALTERNATE_REVERSE: | |
153 return DirectionAlternateReverse; | |
154 default: | |
155 NOTREACHED(); | |
156 } | |
157 return DirectionNormal; | |
158 } | |
159 | |
160 void WebCompositorAnimation::setDirection(Direction direction) | |
161 { | |
162 switch (direction) { | |
163 case DirectionNormal: | |
164 m_animation->set_direction(cc::Animation::DIRECTION_NORMAL); | |
165 break; | |
166 case DirectionReverse: | |
167 m_animation->set_direction(cc::Animation::DIRECTION_REVERSE); | |
168 break; | |
169 case DirectionAlternate: | |
170 m_animation->set_direction(cc::Animation::DIRECTION_ALTERNATE); | |
171 break; | |
172 case DirectionAlternateReverse: | |
173 m_animation->set_direction(cc::Animation::DIRECTION_ALTERNATE_REVERSE); | |
174 break; | |
175 } | |
176 } | |
177 | |
178 double WebCompositorAnimation::playbackRate() const | |
179 { | |
180 return m_animation->playback_rate(); | |
181 } | |
182 | |
183 void WebCompositorAnimation::setPlaybackRate(double playbackRate) | |
184 { | |
185 m_animation->set_playback_rate(playbackRate); | |
186 } | |
187 | |
188 blink::WebCompositorAnimation::FillMode WebCompositorAnimation::fillMode() const | |
189 { | |
190 switch (m_animation->fill_mode()) { | |
191 case cc::Animation::FILL_MODE_NONE: | |
192 return FillModeNone; | |
193 case cc::Animation::FILL_MODE_FORWARDS: | |
194 return FillModeForwards; | |
195 case cc::Animation::FILL_MODE_BACKWARDS: | |
196 return FillModeBackwards; | |
197 case cc::Animation::FILL_MODE_BOTH: | |
198 return FillModeBoth; | |
199 default: | |
200 NOTREACHED(); | |
201 } | |
202 return FillModeNone; | |
203 } | |
204 | |
205 void WebCompositorAnimation::setFillMode(FillMode fillMode) | |
206 { | |
207 switch (fillMode) { | |
208 case FillModeNone: | |
209 m_animation->set_fill_mode(cc::Animation::FILL_MODE_NONE); | |
210 break; | |
esprehn
2016/01/28 03:40:40
we should make our enums parallel and just cast he
loyso (OOO)
2016/01/28 07:10:08
Yeah, that's supposed to be the next step (a separ
| |
211 case FillModeForwards: | |
212 m_animation->set_fill_mode(cc::Animation::FILL_MODE_FORWARDS); | |
213 break; | |
214 case FillModeBackwards: | |
215 m_animation->set_fill_mode(cc::Animation::FILL_MODE_BACKWARDS); | |
216 break; | |
217 case FillModeBoth: | |
218 m_animation->set_fill_mode(cc::Animation::FILL_MODE_BOTH); | |
219 break; | |
220 } | |
221 } | |
222 | |
223 scoped_ptr<cc::Animation> WebCompositorAnimation::passAnimation() | |
224 { | |
225 m_animation->set_needs_synchronized_start_time(true); | |
226 return std::move(m_animation); | |
227 } | |
228 | |
229 cc::Animation* WebCompositorAnimation::releaseCCAnimation() | |
230 { | |
231 m_animation->set_needs_synchronized_start_time(true); | |
esprehn
2016/01/28 03:40:39
why do both of these need to call set_needs_synchr
loyso (OOO)
2016/01/28 07:10:08
'passAnimation' was copied 'as-is'. I want to pres
| |
232 return m_animation.release(); | |
233 } | |
234 | |
235 } // namespace blink | |
OLD | NEW |