Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: Source/core/animation/CompositorAnimations.cpp

Issue 23874019: Web Animations CSS: Start running animations on the compositor (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Cleanup isRunning* and shouldCompositeForAnimation Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::canStartCompositorAnimation(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::startCompositorAnimation(const Element& element, cons t Timing& timing, const AnimationEffect& effect, Vector<int>& startedAnimationId s)
140 { 140 {
141 ASSERT(startedAnimationIds.isEmpty());
141 ASSERT(isCandidateForCompositorAnimation(timing, effect)); 142 ASSERT(isCandidateForCompositorAnimation(timing, effect));
142 ASSERT(canStartCompositorAnimation(element)); 143 ASSERT(canStartCompositorAnimation(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::getCompositorAnimations(timing, keyframeEffect, an imations, 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 cancelCompositorAnimation(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::cancelCompositorAnimation(const Element& element, int 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
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // FIXME: Support positive startDelay 318 // FIXME: Support positive startDelay
311 if (timing.startDelay > 0.0) 319 if (timing.startDelay > 0.0)
312 return false; 320 return false;
313 321
314 // All fill modes are supported (the calling code handles them). 322 // All fill modes are supported (the calling code handles them).
315 323
316 // FIXME: Support non-zero iteration start. 324 // FIXME: Support non-zero iteration start.
317 if (timing.iterationStart) 325 if (timing.iterationStart)
318 return false; 326 return false;
319 327
320 // FIXME: Compositor only supports finite, non-zero, integer iteration 328 // FIXME: Compositor only non-zero, integer iteration counts.
321 // counts. 329 if ((std::floor(timing.iterationCount) != timing.iterationCount) || !timing. iterationCount)
322 if (!std::isfinite(timing.iterationCount) || (std::floor(timing.iterationCou nt) != timing.iterationCount) || !timing.iterationCount)
323 return false; 330 return false;
324 331
325 if (!timing.iterationDuration) 332 if (!timing.iterationDuration)
326 return false; 333 return false;
327 334
328 // FIXME: Support other playback rates 335 // FIXME: Support other playback rates
329 if (timing.playbackRate != 1) 336 if (timing.playbackRate != 1)
330 return false; 337 return false;
331 338
332 // All directions are supported. 339 // All directions are supported.
(...skipping 11 matching lines...) Expand all
344 return false; 351 return false;
345 352
346 out.reverse = (timing.direction == Timing::PlaybackDirectionReverse 353 out.reverse = (timing.direction == Timing::PlaybackDirectionReverse
347 || timing.direction == Timing::PlaybackDirectionAlternateReverse); 354 || timing.direction == Timing::PlaybackDirectionAlternateReverse);
348 out.alternate = (timing.direction == Timing::PlaybackDirectionAlternate 355 out.alternate = (timing.direction == Timing::PlaybackDirectionAlternate
349 || timing.direction == Timing::PlaybackDirectionAlternateReverse); 356 || timing.direction == Timing::PlaybackDirectionAlternateReverse);
350 if (out.alternate && (skippedIterations % 2)) 357 if (out.alternate && (skippedIterations % 2))
351 out.reverse = !out.reverse; 358 out.reverse = !out.reverse;
352 359
353 out.adjustedIterationCount = std::floor(timing.iterationCount) - skippedIter ations; 360 out.adjustedIterationCount = std::floor(timing.iterationCount) - skippedIter ations;
354 ASSERT(out.adjustedIterationCount > 0); 361 if (!std::isfinite(timing.iterationCount))
362 out.adjustedIterationCount = -1;
363 // ASSERT(out.adjustedIterationCount > 0);
355 364
356 out.scaledTimeOffset = scaledStartDelay + skippedIterations * out.scaledDura tion; 365 out.scaledTimeOffset = scaledStartDelay + skippedIterations * out.scaledDura tion;
357 ASSERT(out.scaledTimeOffset <= 0); 366 ASSERT(out.scaledTimeOffset <= 0);
358 return true; 367 return true;
359 } 368 }
360 369
361 namespace { 370 namespace {
362 371
363 template<typename PlatformAnimationKeyframeType> 372 template<typename PlatformAnimationKeyframeType>
364 static PassOwnPtr<PlatformAnimationKeyframeType> createPlatformKeyframe(double o ffset, const AnimatableValue&, const IntSize&) 373 static PassOwnPtr<PlatformAnimationKeyframeType> createPlatformKeyframe(double o ffset, const AnimatableValue&, const IntSize&)
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 case TimingFunction::LinearFunction: 474 case TimingFunction::LinearFunction:
466 case TimingFunction::CubicBezierFunction: 475 case TimingFunction::CubicBezierFunction:
467 keyframeTimingFunction = &timingFunction; 476 keyframeTimingFunction = &timingFunction;
468 break; 477 break;
469 478
470 case TimingFunction::ChainedFunction: { 479 case TimingFunction::ChainedFunction: {
471 const ChainedTimingFunction* chained = static_cast<const Chained TimingFunction*>(&timingFunction); 480 const ChainedTimingFunction* chained = static_cast<const Chained TimingFunction*>(&timingFunction);
472 // ChainedTimingFunction criteria was checked in isCandidate, 481 // ChainedTimingFunction criteria was checked in isCandidate,
473 // assert it is valid. 482 // assert it is valid.
474 ASSERT(values.size() == chained->m_segments.size() + 1); 483 ASSERT(values.size() == chained->m_segments.size() + 1);
475 ASSERT(values[i].first == chained->m_segments[i].m_min); 484 // FIXME: first has been scaled, this assertion is not valid
485 // ASSERT(values[i].first == chained->m_segments[i].m_min);
476 486
477 keyframeTimingFunction = chained->m_segments[i].m_timingFunction .get(); 487 keyframeTimingFunction = chained->m_segments[i].m_timingFunction .get();
478 break; 488 break;
479 } 489 }
480 case TimingFunction::StepsFunction: 490 case TimingFunction::StepsFunction:
481 default: 491 default:
482 ASSERT_NOT_REACHED(); 492 ASSERT_NOT_REACHED();
483 } 493 }
484 } 494 }
485 495
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 551
542 animation->setIterations(compositorTiming.adjustedIterationCount); 552 animation->setIterations(compositorTiming.adjustedIterationCount);
543 animation->setTimeOffset(compositorTiming.scaledTimeOffset); 553 animation->setTimeOffset(compositorTiming.scaledTimeOffset);
544 animation->setAlternatesDirection(compositorTiming.alternate); 554 animation->setAlternatesDirection(compositorTiming.alternate);
545 555
546 animations.append(animation.release()); 556 animations.append(animation.release());
547 } 557 }
548 } 558 }
549 559
550 } // namespace WebCore 560 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698