OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "public/platform/WebCompositorSupport.h" | 49 #include "public/platform/WebCompositorSupport.h" |
50 #include "public/platform/WebFilterAnimationCurve.h" | 50 #include "public/platform/WebFilterAnimationCurve.h" |
51 #include "public/platform/WebFloatAnimationCurve.h" | 51 #include "public/platform/WebFloatAnimationCurve.h" |
52 #include "public/platform/WebTransformAnimationCurve.h" | 52 #include "public/platform/WebTransformAnimationCurve.h" |
53 #include "public/platform/WebTransformOperations.h" | 53 #include "public/platform/WebTransformOperations.h" |
54 | 54 |
55 #include "wtf/OwnPtr.h" | 55 #include "wtf/OwnPtr.h" |
56 #include "wtf/text/CString.h" | 56 #include "wtf/text/CString.h" |
57 | 57 |
58 using namespace std; | 58 using namespace std; |
59 using namespace WebKit; | 59 using namespace blink; |
60 | 60 |
61 namespace WebCore { | 61 namespace WebCore { |
62 | 62 |
63 PassOwnPtr<WebTransformOperations> toWebTransformOperations(const TransformOpera
tions& transformOperations, const FloatSize& boxSize) | 63 PassOwnPtr<WebTransformOperations> toWebTransformOperations(const TransformOpera
tions& transformOperations, const FloatSize& boxSize) |
64 { | 64 { |
65 // We need to do a deep copy the transformOperations may contain ref pointer
s to TransformOperation objects. | 65 // We need to do a deep copy the transformOperations may contain ref pointer
s to TransformOperation objects. |
66 OwnPtr<WebTransformOperations> webTransformOperations = adoptPtr(Platform::c
urrent()->compositorSupport()->createTransformOperations()); | 66 OwnPtr<WebTransformOperations> webTransformOperations = adoptPtr(Platform::c
urrent()->compositorSupport()->createTransformOperations()); |
67 if (!webTransformOperations) | 67 if (!webTransformOperations) |
68 return nullptr; | 68 return nullptr; |
69 for (size_t j = 0; j < transformOperations.size(); ++j) { | 69 for (size_t j = 0; j < transformOperations.size(); ++j) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 case TransformOperation::None: | 131 case TransformOperation::None: |
132 // Do nothing. | 132 // Do nothing. |
133 break; | 133 break; |
134 } // switch | 134 } // switch |
135 } // for each operation | 135 } // for each operation |
136 | 136 |
137 return webTransformOperations.release(); | 137 return webTransformOperations.release(); |
138 } | 138 } |
139 | 139 |
140 template <class Value, class Keyframe, class Curve> | 140 template <class Value, class Keyframe, class Curve> |
141 bool appendKeyframeWithStandardTimingFunction(Curve* curve, double keyTime, cons
t Value* value, const Value* lastValue, WebKit::WebAnimationCurve::TimingFunctio
nType timingFunctionType, const FloatSize&) | 141 bool appendKeyframeWithStandardTimingFunction(Curve* curve, double keyTime, cons
t Value* value, const Value* lastValue, blink::WebAnimationCurve::TimingFunction
Type timingFunctionType, const FloatSize&) |
142 { | 142 { |
143 curve->add(Keyframe(keyTime, value->value()), timingFunctionType); | 143 curve->add(Keyframe(keyTime, value->value()), timingFunctionType); |
144 return true; | 144 return true; |
145 } | 145 } |
146 | 146 |
147 template <class Value, class Keyframe, class Curve> | 147 template <class Value, class Keyframe, class Curve> |
148 bool appendKeyframeWithCustomBezierTimingFunction(Curve* curve, double keyTime,
const Value* value, const Value* lastValue, double x1, double y1, double x2, dou
ble y2, const FloatSize&) | 148 bool appendKeyframeWithCustomBezierTimingFunction(Curve* curve, double keyTime,
const Value* value, const Value* lastValue, double x1, double y1, double x2, dou
ble y2, const FloatSize&) |
149 { | 149 { |
150 curve->add(Keyframe(keyTime, value->value()), x1, y1, x2, y2); | 150 curve->add(Keyframe(keyTime, value->value()), x1, y1, x2, y2); |
151 return true; | 151 return true; |
152 } | 152 } |
153 | 153 |
154 template <> | 154 template <> |
155 bool appendKeyframeWithStandardTimingFunction<TransformAnimationValue, WebTransf
ormKeyframe, WebTransformAnimationCurve>(WebTransformAnimationCurve* curve, doub
le keyTime, const TransformAnimationValue* value, const TransformAnimationValue*
lastValue, WebKit::WebAnimationCurve::TimingFunctionType timingFunctionType, co
nst FloatSize& boxSize) | 155 bool appendKeyframeWithStandardTimingFunction<TransformAnimationValue, WebTransf
ormKeyframe, WebTransformAnimationCurve>(WebTransformAnimationCurve* curve, doub
le keyTime, const TransformAnimationValue* value, const TransformAnimationValue*
lastValue, blink::WebAnimationCurve::TimingFunctionType timingFunctionType, con
st FloatSize& boxSize) |
156 { | 156 { |
157 bool canBlend = !lastValue; | 157 bool canBlend = !lastValue; |
158 OwnPtr<WebTransformOperations> operations(toWebTransformOperations(*value->v
alue(), boxSize)); | 158 OwnPtr<WebTransformOperations> operations(toWebTransformOperations(*value->v
alue(), boxSize)); |
159 if (!operations) | 159 if (!operations) |
160 return false; | 160 return false; |
161 if (!canBlend) { | 161 if (!canBlend) { |
162 OwnPtr<WebTransformOperations> lastOperations(toWebTransformOperations(*
lastValue->value(), boxSize)); | 162 OwnPtr<WebTransformOperations> lastOperations(toWebTransformOperations(*
lastValue->value(), boxSize)); |
163 if (!lastOperations) | 163 if (!lastOperations) |
164 return false; | 164 return false; |
165 canBlend = lastOperations->canBlendWith(*operations); | 165 canBlend = lastOperations->canBlendWith(*operations); |
(...skipping 19 matching lines...) Expand all Loading... |
185 canBlend = lastOperations->canBlendWith(*operations); | 185 canBlend = lastOperations->canBlendWith(*operations); |
186 } | 186 } |
187 if (canBlend) { | 187 if (canBlend) { |
188 curve->add(WebTransformKeyframe(keyTime, operations.release()), x1, y1,
x2, y2); | 188 curve->add(WebTransformKeyframe(keyTime, operations.release()), x1, y1,
x2, y2); |
189 return true; | 189 return true; |
190 } | 190 } |
191 return false; | 191 return false; |
192 } | 192 } |
193 | 193 |
194 template <> | 194 template <> |
195 bool appendKeyframeWithStandardTimingFunction<FilterAnimationValue, WebFilterKey
frame, WebFilterAnimationCurve>(WebFilterAnimationCurve* curve, double keyTime,
const FilterAnimationValue* value, const FilterAnimationValue* lastValue, WebKit
::WebAnimationCurve::TimingFunctionType timingFunctionType, const FloatSize& box
Size) | 195 bool appendKeyframeWithStandardTimingFunction<FilterAnimationValue, WebFilterKey
frame, WebFilterAnimationCurve>(WebFilterAnimationCurve* curve, double keyTime,
const FilterAnimationValue* value, const FilterAnimationValue* lastValue, blink:
:WebAnimationCurve::TimingFunctionType timingFunctionType, const FloatSize& boxS
ize) |
196 { | 196 { |
197 // FIXME(ajuma): In order to animate pixel-moving filters on the compositor
thread, we need | 197 // FIXME(ajuma): In order to animate pixel-moving filters on the compositor
thread, we need |
198 // to update overlap testing to take into account the bounds within which th
e animation | 198 // to update overlap testing to take into account the bounds within which th
e animation |
199 // will be contained, and we need the compositor to update layer bounds as t
he animation | 199 // will be contained, and we need the compositor to update layer bounds as t
he animation |
200 // progresses. | 200 // progresses. |
201 if (value->value()->hasFilterThatMovesPixels()) | 201 if (value->value()->hasFilterThatMovesPixels()) |
202 return false; | 202 return false; |
203 SkiaImageFilterBuilder builder; | 203 SkiaImageFilterBuilder builder; |
204 OwnPtr<WebFilterOperations> operations = adoptPtr(Platform::current()->compo
sitorSupport()->createFilterOperations()); | 204 OwnPtr<WebFilterOperations> operations = adoptPtr(Platform::current()->compo
sitorSupport()->createFilterOperations()); |
205 FilterOutsets outsets = value->value()->outsets(); | 205 FilterOutsets outsets = value->value()->outsets(); |
(...skipping 17 matching lines...) Expand all Loading... |
223 OwnPtr<WebFilterOperations> operations = adoptPtr(Platform::current()->compo
sitorSupport()->createFilterOperations()); | 223 OwnPtr<WebFilterOperations> operations = adoptPtr(Platform::current()->compo
sitorSupport()->createFilterOperations()); |
224 FilterOutsets outsets = value->value()->outsets(); | 224 FilterOutsets outsets = value->value()->outsets(); |
225 builder.setCropOffset(FloatSize(outsets.left(), outsets.top())); | 225 builder.setCropOffset(FloatSize(outsets.left(), outsets.top())); |
226 if (!builder.buildFilterOperations(*value->value(), operations.get())) | 226 if (!builder.buildFilterOperations(*value->value(), operations.get())) |
227 return false; | 227 return false; |
228 curve->add(WebFilterKeyframe(keyTime, operations.release()), x1, y1, x2, y2)
; | 228 curve->add(WebFilterKeyframe(keyTime, operations.release()), x1, y1, x2, y2)
; |
229 return true; | 229 return true; |
230 } | 230 } |
231 | 231 |
232 template <class Value, class Keyframe, class Curve> | 232 template <class Value, class Keyframe, class Curve> |
233 PassOwnPtr<WebKit::WebAnimation> createWebAnimation(const KeyframeValueList& val
ueList, const CSSAnimationData* animation, int animationId, double timeOffset, C
urve* curve, WebKit::WebAnimation::TargetProperty targetProperty, const FloatSiz
e& boxSize) | 233 PassOwnPtr<blink::WebAnimation> createWebAnimation(const KeyframeValueList& valu
eList, const CSSAnimationData* animation, int animationId, double timeOffset, Cu
rve* curve, blink::WebAnimation::TargetProperty targetProperty, const FloatSize&
boxSize) |
234 { | 234 { |
235 bool alternate = false; | 235 bool alternate = false; |
236 bool reverse = false; | 236 bool reverse = false; |
237 if (animation && animation->isDirectionSet()) { | 237 if (animation && animation->isDirectionSet()) { |
238 CSSAnimationData::AnimationDirection direction = animation->direction(); | 238 CSSAnimationData::AnimationDirection direction = animation->direction(); |
239 if (direction == CSSAnimationData::AnimationDirectionAlternate || direct
ion == CSSAnimationData::AnimationDirectionAlternateReverse) | 239 if (direction == CSSAnimationData::AnimationDirectionAlternate || direct
ion == CSSAnimationData::AnimationDirectionAlternateReverse) |
240 alternate = true; | 240 alternate = true; |
241 if (direction == CSSAnimationData::AnimationDirectionReverse || directio
n == CSSAnimationData::AnimationDirectionAlternateReverse) | 241 if (direction == CSSAnimationData::AnimationDirectionReverse || directio
n == CSSAnimationData::AnimationDirectionAlternateReverse) |
242 reverse = true; | 242 reverse = true; |
243 } | 243 } |
244 | 244 |
245 for (size_t i = 0; i < valueList.size(); i++) { | 245 for (size_t i = 0; i < valueList.size(); i++) { |
246 size_t index = reverse ? valueList.size() - i - 1 : i; | 246 size_t index = reverse ? valueList.size() - i - 1 : i; |
247 const Value* originalValue = static_cast<const Value*>(valueList.at(inde
x)); | 247 const Value* originalValue = static_cast<const Value*>(valueList.at(inde
x)); |
248 const Value* lastOriginalValue = 0; | 248 const Value* lastOriginalValue = 0; |
249 if (valueList.size() > 1 && ((reverse && index + 1 < valueList.size()) |
| (!reverse && index > 0))) | 249 if (valueList.size() > 1 && ((reverse && index + 1 < valueList.size()) |
| (!reverse && index > 0))) |
250 lastOriginalValue = static_cast<const Value*>(valueList.at(reverse ?
index + 1 : index - 1)); | 250 lastOriginalValue = static_cast<const Value*>(valueList.at(reverse ?
index + 1 : index - 1)); |
251 | 251 |
252 const TimingFunction* originalTimingFunction = originalValue->timingFunc
tion(); | 252 const TimingFunction* originalTimingFunction = originalValue->timingFunc
tion(); |
253 | 253 |
254 // If there hasn't been a timing function associated with this keyframe,
use the | 254 // If there hasn't been a timing function associated with this keyframe,
use the |
255 // animation's timing function, if we have one. | 255 // animation's timing function, if we have one. |
256 if (!originalTimingFunction && animation->isTimingFunctionSet()) | 256 if (!originalTimingFunction && animation->isTimingFunctionSet()) |
257 originalTimingFunction = animation->timingFunction(); | 257 originalTimingFunction = animation->timingFunction(); |
258 | 258 |
259 // Ease is the default timing function. | 259 // Ease is the default timing function. |
260 WebKit::WebAnimationCurve::TimingFunctionType timingFunctionType = WebKi
t::WebAnimationCurve::TimingFunctionTypeEase; | 260 blink::WebAnimationCurve::TimingFunctionType timingFunctionType = blink:
:WebAnimationCurve::TimingFunctionTypeEase; |
261 | 261 |
262 bool isUsingCustomBezierTimingFunction = false; | 262 bool isUsingCustomBezierTimingFunction = false; |
263 double x1 = 0; | 263 double x1 = 0; |
264 double y1 = 0; | 264 double y1 = 0; |
265 double x2 = 1; | 265 double x2 = 1; |
266 double y2 = 1; | 266 double y2 = 1; |
267 | 267 |
268 if (originalTimingFunction) { | 268 if (originalTimingFunction) { |
269 switch (originalTimingFunction->type()) { | 269 switch (originalTimingFunction->type()) { |
270 case TimingFunction::StepsFunction: | 270 case TimingFunction::StepsFunction: |
271 // FIXME: add support for steps timing function. | 271 // FIXME: add support for steps timing function. |
272 return nullptr; | 272 return nullptr; |
273 case TimingFunction::LinearFunction: | 273 case TimingFunction::LinearFunction: |
274 timingFunctionType = WebKit::WebAnimationCurve::TimingFunctionTy
peLinear; | 274 timingFunctionType = blink::WebAnimationCurve::TimingFunctionTyp
eLinear; |
275 break; | 275 break; |
276 case TimingFunction::CubicBezierFunction: | 276 case TimingFunction::CubicBezierFunction: |
277 { | 277 { |
278 const CubicBezierTimingFunction* originalBezierTimingFunctio
n = static_cast<const CubicBezierTimingFunction*>(originalTimingFunction); | 278 const CubicBezierTimingFunction* originalBezierTimingFunctio
n = static_cast<const CubicBezierTimingFunction*>(originalTimingFunction); |
279 isUsingCustomBezierTimingFunction = true; | 279 isUsingCustomBezierTimingFunction = true; |
280 x1 = originalBezierTimingFunction->x1(); | 280 x1 = originalBezierTimingFunction->x1(); |
281 y1 = originalBezierTimingFunction->y1(); | 281 y1 = originalBezierTimingFunction->y1(); |
282 x2 = originalBezierTimingFunction->x2(); | 282 x2 = originalBezierTimingFunction->x2(); |
283 y2 = originalBezierTimingFunction->y2(); | 283 y2 = originalBezierTimingFunction->y2(); |
284 break; | 284 break; |
(...skipping 11 matching lines...) Expand all Loading... |
296 | 296 |
297 bool addedKeyframe = false; | 297 bool addedKeyframe = false; |
298 if (isUsingCustomBezierTimingFunction) | 298 if (isUsingCustomBezierTimingFunction) |
299 addedKeyframe = appendKeyframeWithCustomBezierTimingFunction<Value,
Keyframe, Curve>(curve, keyTime, originalValue, lastOriginalValue, x1, y1, x2, y
2, boxSize); | 299 addedKeyframe = appendKeyframeWithCustomBezierTimingFunction<Value,
Keyframe, Curve>(curve, keyTime, originalValue, lastOriginalValue, x1, y1, x2, y
2, boxSize); |
300 else | 300 else |
301 addedKeyframe = appendKeyframeWithStandardTimingFunction<Value, Keyf
rame, Curve>(curve, keyTime, originalValue, lastOriginalValue, timingFunctionTyp
e, boxSize); | 301 addedKeyframe = appendKeyframeWithStandardTimingFunction<Value, Keyf
rame, Curve>(curve, keyTime, originalValue, lastOriginalValue, timingFunctionTyp
e, boxSize); |
302 if (!addedKeyframe) | 302 if (!addedKeyframe) |
303 return nullptr; | 303 return nullptr; |
304 } | 304 } |
305 | 305 |
306 OwnPtr<WebKit::WebAnimation> webAnimation = adoptPtr(Platform::current()->co
mpositorSupport()->createAnimation(*curve, targetProperty, animationId)); | 306 OwnPtr<blink::WebAnimation> webAnimation = adoptPtr(Platform::current()->com
positorSupport()->createAnimation(*curve, targetProperty, animationId)); |
307 | 307 |
308 int iterations = (animation && animation->isIterationCountSet()) ? animation
->iterationCount() : 1; | 308 int iterations = (animation && animation->isIterationCountSet()) ? animation
->iterationCount() : 1; |
309 webAnimation->setIterations(iterations); | 309 webAnimation->setIterations(iterations); |
310 webAnimation->setAlternatesDirection(alternate); | 310 webAnimation->setAlternatesDirection(alternate); |
311 | 311 |
312 // If timeOffset > 0, then the animation has started in the past. | 312 // If timeOffset > 0, then the animation has started in the past. |
313 webAnimation->setTimeOffset(timeOffset); | 313 webAnimation->setTimeOffset(timeOffset); |
314 | 314 |
315 return webAnimation.release(); | 315 return webAnimation.release(); |
316 } | 316 } |
317 | 317 |
318 PassOwnPtr<WebKit::WebAnimation> createWebAnimation(const KeyframeValueList& val
ues, const CSSAnimationData* animation, int animationId, double timeOffset, cons
t FloatSize& boxSize) | 318 PassOwnPtr<blink::WebAnimation> createWebAnimation(const KeyframeValueList& valu
es, const CSSAnimationData* animation, int animationId, double timeOffset, const
FloatSize& boxSize) |
319 { | 319 { |
320 switch (values.property()) { | 320 switch (values.property()) { |
321 case AnimatedPropertyWebkitTransform: { | 321 case AnimatedPropertyWebkitTransform: { |
322 OwnPtr<WebTransformAnimationCurve> curve = adoptPtr(Platform::current()-
>compositorSupport()->createTransformAnimationCurve()); | 322 OwnPtr<WebTransformAnimationCurve> curve = adoptPtr(Platform::current()-
>compositorSupport()->createTransformAnimationCurve()); |
323 return createWebAnimation<TransformAnimationValue, WebTransformKeyframe,
WebTransformAnimationCurve>(values, animation, animationId, timeOffset, curve.g
et(), WebKit::WebAnimation::TargetPropertyTransform, FloatSize(boxSize)); | 323 return createWebAnimation<TransformAnimationValue, WebTransformKeyframe,
WebTransformAnimationCurve>(values, animation, animationId, timeOffset, curve.g
et(), blink::WebAnimation::TargetPropertyTransform, FloatSize(boxSize)); |
324 } | 324 } |
325 | 325 |
326 case AnimatedPropertyOpacity: { | 326 case AnimatedPropertyOpacity: { |
327 OwnPtr<WebFloatAnimationCurve> curve = adoptPtr(Platform::current()->com
positorSupport()->createFloatAnimationCurve()); | 327 OwnPtr<WebFloatAnimationCurve> curve = adoptPtr(Platform::current()->com
positorSupport()->createFloatAnimationCurve()); |
328 return createWebAnimation<FloatAnimationValue, WebFloatKeyframe, WebFloa
tAnimationCurve>(values, animation, animationId, timeOffset, curve.get(), WebKit
::WebAnimation::TargetPropertyOpacity, FloatSize()); | 328 return createWebAnimation<FloatAnimationValue, WebFloatKeyframe, WebFloa
tAnimationCurve>(values, animation, animationId, timeOffset, curve.get(), blink:
:WebAnimation::TargetPropertyOpacity, FloatSize()); |
329 } | 329 } |
330 | 330 |
331 case AnimatedPropertyWebkitFilter: { | 331 case AnimatedPropertyWebkitFilter: { |
332 OwnPtr<WebFilterAnimationCurve> curve = adoptPtr(Platform::current()->co
mpositorSupport()->createFilterAnimationCurve()); | 332 OwnPtr<WebFilterAnimationCurve> curve = adoptPtr(Platform::current()->co
mpositorSupport()->createFilterAnimationCurve()); |
333 return createWebAnimation<FilterAnimationValue, WebFilterKeyframe, WebFi
lterAnimationCurve>(values, animation, animationId, timeOffset, curve.get(), Web
Kit::WebAnimation::TargetPropertyFilter, FloatSize(boxSize)); | 333 return createWebAnimation<FilterAnimationValue, WebFilterKeyframe, WebFi
lterAnimationCurve>(values, animation, animationId, timeOffset, curve.get(), bli
nk::WebAnimation::TargetPropertyFilter, FloatSize(boxSize)); |
334 } | 334 } |
335 | 335 |
336 case AnimatedPropertyBackgroundColor: | 336 case AnimatedPropertyBackgroundColor: |
337 case AnimatedPropertyInvalid: | 337 case AnimatedPropertyInvalid: |
338 return nullptr; | 338 return nullptr; |
339 } | 339 } |
340 | 340 |
341 return nullptr; | 341 return nullptr; |
342 } | 342 } |
343 | 343 |
344 } // namespace WebCore | 344 } // namespace WebCore |
OLD | NEW |