| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 default: | 116 default: |
| 117 ASSERT_NOT_REACHED(); | 117 ASSERT_NOT_REACHED(); |
| 118 return PassRefPtr<TimingFunction>(); | 118 return PassRefPtr<TimingFunction>(); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 // ----------------------------------------------------------------------- | 122 // ----------------------------------------------------------------------- |
| 123 // CompositorAnimations public API | 123 // CompositorAnimations public API |
| 124 // ----------------------------------------------------------------------- | 124 // ----------------------------------------------------------------------- |
| 125 | 125 |
| 126 bool CompositorAnimations::isCandidateForCompositorAnimation(const Timing& timin
g, const AnimationEffect& effect) | 126 bool CompositorAnimations::isCandidateForAnimationOnCompositor(const Timing& tim
ing, const AnimationEffect& effect) |
| 127 { | 127 { |
| 128 const KeyframeAnimationEffect& keyframeEffect = *toKeyframeAnimationEffect(&
effect); | 128 const KeyframeAnimationEffect& keyframeEffect = *toKeyframeAnimationEffect(&
effect); |
| 129 | 129 |
| 130 return CompositorAnimationsImpl::isCandidateForCompositor(keyframeEffect) | 130 return CompositorAnimationsImpl::isCandidateForCompositor(keyframeEffect) |
| 131 && CompositorAnimationsImpl::isCandidateForCompositor(timing, keyframeEf
fect.getFrames()); | 131 && CompositorAnimationsImpl::isCandidateForCompositor(timing, keyframeEf
fect.getFrames()); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool CompositorAnimations::canStartCompositorAnimation(const Element& element) | 134 bool CompositorAnimations::canStartAnimationOnCompositor(const Element& element) |
| 135 { | 135 { |
| 136 return element.renderer() && element.renderer()->compositingState() == Paint
sIntoOwnBacking; | 136 return element.renderer() && element.renderer()->compositingState() == Paint
sIntoOwnBacking; |
| 137 } | 137 } |
| 138 | 138 |
| 139 void CompositorAnimations::startCompositorAnimation(const Element& element, cons
t Timing& timing, const AnimationEffect& effect, Vector<int>& startedAnimationId
s) | 139 bool CompositorAnimations::startAnimationOnCompositor(const Element& element, co
nst Timing& timing, const AnimationEffect& effect, Vector<int>& startedAnimation
Ids) |
| 140 { | 140 { |
| 141 ASSERT(isCandidateForCompositorAnimation(timing, effect)); | 141 ASSERT(startedAnimationIds.isEmpty()); |
| 142 ASSERT(canStartCompositorAnimation(element)); | 142 ASSERT(isCandidateForAnimationOnCompositor(timing, effect)); |
| 143 ASSERT(canStartAnimationOnCompositor(element)); |
| 143 | 144 |
| 144 const KeyframeAnimationEffect& keyframeEffect = *toKeyframeAnimationEffect(&
effect); | 145 const KeyframeAnimationEffect& keyframeEffect = *toKeyframeAnimationEffect(&
effect); |
| 145 | 146 |
| 146 RenderLayer* layer = toRenderBoxModelObject(element.renderer())->layer(); | 147 RenderLayer* layer = toRenderBoxModelObject(element.renderer())->layer(); |
| 147 ASSERT(layer); | 148 ASSERT(layer); |
| 148 ASSERT(layer->renderBox()); | 149 ASSERT(layer->renderBox()); |
| 149 | 150 |
| 150 // FIXME: Should we check in some way if there is an animation already creat
ed? | |
| 151 Vector<OwnPtr<blink::WebAnimation> > animations; | 151 Vector<OwnPtr<blink::WebAnimation> > animations; |
| 152 CompositorAnimationsImpl::getCompositorAnimations(timing, keyframeEffect, an
imations, layer->renderBox()->pixelSnappedBorderBoxRect().size()); | 152 CompositorAnimationsImpl::getAnimationOnCompositor(timing, keyframeEffect, a
nimations, layer->renderBox()->pixelSnappedBorderBoxRect().size()); |
| 153 for (size_t i = 0; i < animations.size(); ++i) { | 153 for (size_t i = 0; i < animations.size(); ++i) { |
| 154 startedAnimationIds.append(animations[i]->id()); | 154 int id = animations[i]->id(); |
| 155 layer->compositedLayerMapping()->mainGraphicsLayer()->addAnimation(anima
tions[i].release()); | 155 if (!layer->compositedLayerMapping()->mainGraphicsLayer()->addAnimation(
animations[i].release())) { |
| 156 // FIXME: We should know ahead of time whether these animations can
be started. |
| 157 for (size_t j = 0; j < startedAnimationIds.size(); ++j) |
| 158 cancelAnimationOnCompositor(element, startedAnimationIds[j]); |
| 159 startedAnimationIds.clear(); |
| 160 return false; |
| 161 } |
| 162 startedAnimationIds.append(id); |
| 156 } | 163 } |
| 164 return true; |
| 157 } | 165 } |
| 158 | 166 |
| 159 void CompositorAnimations::cancelCompositorAnimation(const Element& element, int
id) | 167 void CompositorAnimations::cancelAnimationOnCompositor(const Element& element, i
nt id) |
| 160 { | 168 { |
| 161 // FIXME: Implement. | 169 if (!element.renderer() || element.renderer()->compositingState() != PaintsI
ntoOwnBacking) |
| 162 ASSERT_NOT_REACHED(); | 170 return; |
| 171 toRenderBoxModelObject(element.renderer())->layer()->compositedLayerMapping(
)->mainGraphicsLayer()->removeAnimation(id); |
| 163 } | 172 } |
| 164 | 173 |
| 165 // ----------------------------------------------------------------------- | 174 // ----------------------------------------------------------------------- |
| 166 // CompositorAnimationsKeyframeEffectHelper | 175 // CompositorAnimationsKeyframeEffectHelper |
| 167 // ----------------------------------------------------------------------- | 176 // ----------------------------------------------------------------------- |
| 168 | 177 |
| 169 PassOwnPtr<Vector<CSSPropertyID> > CompositorAnimationsKeyframeEffectHelper::get
Properties( | 178 PassOwnPtr<Vector<CSSPropertyID> > CompositorAnimationsKeyframeEffectHelper::get
Properties( |
| 170 const KeyframeAnimationEffect* effect) | 179 const KeyframeAnimationEffect* effect) |
| 171 { | 180 { |
| 172 const_cast<KeyframeAnimationEffect*>(effect)->ensureKeyframeGroups(); | 181 const_cast<KeyframeAnimationEffect*>(effect)->ensureKeyframeGroups(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 const KeyframeAnimationEffect::KeyframeVector frames = effect.getFrames(); | 248 const KeyframeAnimationEffect::KeyframeVector frames = effect.getFrames(); |
| 240 for (size_t i = 0; i < frames.size(); ++i) { | 249 for (size_t i = 0; i < frames.size(); ++i) { |
| 241 if (!isCandidateForCompositor(*frames[i].get())) | 250 if (!isCandidateForCompositor(*frames[i].get())) |
| 242 return false; | 251 return false; |
| 243 } | 252 } |
| 244 return true; | 253 return true; |
| 245 } | 254 } |
| 246 | 255 |
| 247 bool CompositorAnimationsImpl::isCandidateForCompositor(const Timing& timing, co
nst KeyframeAnimationEffect::KeyframeVector& frames) | 256 bool CompositorAnimationsImpl::isCandidateForCompositor(const Timing& timing, co
nst KeyframeAnimationEffect::KeyframeVector& frames) |
| 248 { | 257 { |
| 249 | |
| 250 CompositorTiming out; | 258 CompositorTiming out; |
| 251 if (!convertTimingForCompositor(timing, out)) | 259 if (!convertTimingForCompositor(timing, out)) |
| 252 return false; | 260 return false; |
| 253 | 261 |
| 254 return isCandidateForCompositor(*timing.timingFunction.get(), &frames); | 262 return isCandidateForCompositor(*timing.timingFunction.get(), &frames); |
| 255 } | 263 } |
| 256 | 264 |
| 257 bool CompositorAnimationsImpl::isCandidateForCompositor(const TimingFunction& ti
mingFunction, const KeyframeAnimationEffect::KeyframeVector* frames, bool isNest
edCall) | 265 bool CompositorAnimationsImpl::isCandidateForCompositor(const TimingFunction& ti
mingFunction, const KeyframeAnimationEffect::KeyframeVector* frames, bool isNest
edCall) |
| 258 { | 266 { |
| 259 switch (timingFunction.type()) { | 267 switch (timingFunction.type()) { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 } | 494 } |
| 487 } | 495 } |
| 488 | 496 |
| 489 ASSERT(!values[i].second->dependsOnUnderlyingValue()); | 497 ASSERT(!values[i].second->dependsOnUnderlyingValue()); |
| 490 RefPtr<AnimatableValue> value = values[i].second->compositeOnto(0); | 498 RefPtr<AnimatableValue> value = values[i].second->compositeOnto(0); |
| 491 OwnPtr<PlatformAnimationKeyframeType> keyframe = createPlatformKeyframe<
PlatformAnimationKeyframeType>(values[i].first, *value.get(), elementSize); | 499 OwnPtr<PlatformAnimationKeyframeType> keyframe = createPlatformKeyframe<
PlatformAnimationKeyframeType>(values[i].first, *value.get(), elementSize); |
| 492 addKeyframeWithTimingFunction(curve, *keyframe.get(), keyframeTimingFunc
tion); | 500 addKeyframeWithTimingFunction(curve, *keyframe.get(), keyframeTimingFunc
tion); |
| 493 } | 501 } |
| 494 } | 502 } |
| 495 | 503 |
| 496 void CompositorAnimationsImpl::getCompositorAnimations( | 504 void CompositorAnimationsImpl::getAnimationOnCompositor( |
| 497 const Timing& timing, const KeyframeAnimationEffect& effect, Vector<OwnPtr<b
link::WebAnimation> >& animations, const IntSize& elementSize) | 505 const Timing& timing, const KeyframeAnimationEffect& effect, Vector<OwnPtr<b
link::WebAnimation> >& animations, const IntSize& elementSize) |
| 498 { | 506 { |
| 499 CompositorTiming compositorTiming; | 507 CompositorTiming compositorTiming; |
| 500 bool timingValid = convertTimingForCompositor(timing, compositorTiming); | 508 bool timingValid = convertTimingForCompositor(timing, compositorTiming); |
| 501 ASSERT_UNUSED(timingValid, timingValid); | 509 ASSERT_UNUSED(timingValid, timingValid); |
| 502 | 510 |
| 503 RefPtr<TimingFunction> timingFunction = timing.timingFunction; | 511 RefPtr<TimingFunction> timingFunction = timing.timingFunction; |
| 504 if (compositorTiming.reverse) | 512 if (compositorTiming.reverse) |
| 505 timingFunction = CompositorAnimationsTimingFunctionReverser::reverse(tim
ingFunction.get()); | 513 timingFunction = CompositorAnimationsTimingFunctionReverser::reverse(tim
ingFunction.get()); |
| 506 | 514 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 | 552 |
| 545 animation->setIterations(compositorTiming.adjustedIterationCount); | 553 animation->setIterations(compositorTiming.adjustedIterationCount); |
| 546 animation->setTimeOffset(compositorTiming.scaledTimeOffset); | 554 animation->setTimeOffset(compositorTiming.scaledTimeOffset); |
| 547 animation->setAlternatesDirection(compositorTiming.alternate); | 555 animation->setAlternatesDirection(compositorTiming.alternate); |
| 548 | 556 |
| 549 animations.append(animation.release()); | 557 animations.append(animation.release()); |
| 550 } | 558 } |
| 551 } | 559 } |
| 552 | 560 |
| 553 } // namespace WebCore | 561 } // namespace WebCore |
| OLD | NEW |