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

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

Issue 946323002: Animations: Introduce compositor AnimationPlayer and AnimationTimeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 months 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
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 28 matching lines...) Expand all
39 #include "core/animation/animatable/AnimatableFilterOperations.h" 39 #include "core/animation/animatable/AnimatableFilterOperations.h"
40 #include "core/animation/animatable/AnimatableTransform.h" 40 #include "core/animation/animatable/AnimatableTransform.h"
41 #include "core/animation/animatable/AnimatableValue.h" 41 #include "core/animation/animatable/AnimatableValue.h"
42 #include "core/layout/Layer.h" 42 #include "core/layout/Layer.h"
43 #include "core/layout/LayoutObject.h" 43 #include "core/layout/LayoutObject.h"
44 #include "core/layout/compositing/CompositedLayerMapping.h" 44 #include "core/layout/compositing/CompositedLayerMapping.h"
45 #include "core/rendering/RenderBoxModelObject.h" 45 #include "core/rendering/RenderBoxModelObject.h"
46 #include "platform/geometry/FloatBox.h" 46 #include "platform/geometry/FloatBox.h"
47 #include "public/platform/Platform.h" 47 #include "public/platform/Platform.h"
48 #include "public/platform/WebCompositorAnimation.h" 48 #include "public/platform/WebCompositorAnimation.h"
49 #include "public/platform/WebCompositorAnimationPlayer.h"
49 #include "public/platform/WebCompositorSupport.h" 50 #include "public/platform/WebCompositorSupport.h"
50 #include "public/platform/WebFilterAnimationCurve.h" 51 #include "public/platform/WebFilterAnimationCurve.h"
51 #include "public/platform/WebFilterKeyframe.h" 52 #include "public/platform/WebFilterKeyframe.h"
52 #include "public/platform/WebFloatAnimationCurve.h" 53 #include "public/platform/WebFloatAnimationCurve.h"
53 #include "public/platform/WebFloatKeyframe.h" 54 #include "public/platform/WebFloatKeyframe.h"
54 #include "public/platform/WebTransformAnimationCurve.h" 55 #include "public/platform/WebTransformAnimationCurve.h"
55 #include "public/platform/WebTransformKeyframe.h" 56 #include "public/platform/WebTransformKeyframe.h"
56 57
57 #include <algorithm> 58 #include <algorithm>
58 #include <cmath> 59 #include <cmath>
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 || (affectsFilter && attachedPlayer->affects(targetElement, CSSPrope rtyWebkitFilter))) 249 || (affectsFilter && attachedPlayer->affects(targetElement, CSSPrope rtyWebkitFilter)))
249 attachedPlayer->cancelAnimationOnCompositor(); 250 attachedPlayer->cancelAnimationOnCompositor();
250 } 251 }
251 } 252 }
252 253
253 bool CompositorAnimations::canStartAnimationOnCompositor(const Element& element) 254 bool CompositorAnimations::canStartAnimationOnCompositor(const Element& element)
254 { 255 {
255 return element.renderer() && element.renderer()->compositingState() == Paint sIntoOwnBacking; 256 return element.renderer() && element.renderer()->compositingState() == Paint sIntoOwnBacking;
256 } 257 }
257 258
259 #define HEAVISIDE_ANIMATIONS 1
260
258 bool CompositorAnimations::startAnimationOnCompositor(const Element& element, in t group, double startTime, double timeOffset, const Timing& timing, const Animat ionPlayer* player, const AnimationEffect& effect, Vector<int>& startedAnimationI ds, double playerPlaybackRate) 261 bool CompositorAnimations::startAnimationOnCompositor(const Element& element, in t group, double startTime, double timeOffset, const Timing& timing, const Animat ionPlayer* player, const AnimationEffect& effect, Vector<int>& startedAnimationI ds, double playerPlaybackRate)
259 { 262 {
260 ASSERT(startedAnimationIds.isEmpty()); 263 ASSERT(startedAnimationIds.isEmpty());
261 ASSERT(isCandidateForAnimationOnCompositor(timing, element, player, effect, playerPlaybackRate)); 264 ASSERT(isCandidateForAnimationOnCompositor(timing, element, player, effect, playerPlaybackRate));
262 ASSERT(canStartAnimationOnCompositor(element)); 265 ASSERT(canStartAnimationOnCompositor(element));
263 266
264 const KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(ef fect); 267 const KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(ef fect);
265 268
266 Layer* layer = toRenderBoxModelObject(element.renderer())->layer(); 269 Layer* layer = toRenderBoxModelObject(element.renderer())->layer();
267 ASSERT(layer); 270 ASSERT(layer);
268 271
269 Vector<OwnPtr<WebCompositorAnimation>> animations; 272 Vector<OwnPtr<WebCompositorAnimation>> animations;
270 CompositorAnimationsImpl::getAnimationOnCompositor(timing, group, startTime, timeOffset, keyframeEffect, animations, playerPlaybackRate); 273 CompositorAnimationsImpl::getAnimationOnCompositor(timing, group, startTime, timeOffset, keyframeEffect, animations, playerPlaybackRate);
271 ASSERT(!animations.isEmpty()); 274 ASSERT(!animations.isEmpty());
272 for (auto& animation : animations) { 275 for (auto& animation : animations) {
273 int id = animation->id(); 276 int id = animation->id();
277 #if HEAVISIDE_ANIMATIONS
278 ASSERT(player);
279 WebCompositorAnimationPlayer* compositorPlayer = player->compositorPlaye r();
280 ASSERT(compositorPlayer);
281 compositorPlayer->attachLayer(layer->compositedLayerMapping()->mainGraph icsLayer()->platformLayer());
282 compositorPlayer->addAnimation(animation.leakPtr());
283 #else
274 if (!layer->compositedLayerMapping()->mainGraphicsLayer()->addAnimation( animation.release())) { 284 if (!layer->compositedLayerMapping()->mainGraphicsLayer()->addAnimation( animation.release())) {
275 // FIXME: We should know ahead of time whether these animations can be started. 285 // FIXME: We should know ahead of time whether these animations can be started.
276 for (int startedAnimationId : startedAnimationIds) 286 for (int startedAnimationId : startedAnimationIds)
277 cancelAnimationOnCompositor(element, startedAnimationId); 287 cancelAnimationOnCompositor(element, player, startedAnimationId) ;
278 startedAnimationIds.clear(); 288 startedAnimationIds.clear();
279 return false; 289 return false;
280 } 290 }
291 #endif
281 startedAnimationIds.append(id); 292 startedAnimationIds.append(id);
282 } 293 }
283 ASSERT(!startedAnimationIds.isEmpty()); 294 ASSERT(!startedAnimationIds.isEmpty());
284 return true; 295 return true;
285 } 296 }
286 297
287 void CompositorAnimations::cancelAnimationOnCompositor(const Element& element, i nt id) 298 void CompositorAnimations::cancelAnimationOnCompositor(const Element& element, c onst AnimationPlayer* player, int id)
288 { 299 {
289 if (!canStartAnimationOnCompositor(element)) { 300 if (!canStartAnimationOnCompositor(element)) {
290 // When an element is being detached, we cancel any associated 301 // When an element is being detached, we cancel any associated
291 // AnimationPlayers for CSS animations. But by the time we get 302 // AnimationPlayers for CSS animations. But by the time we get
292 // here the mapping will have been removed. 303 // here the mapping will have been removed.
293 // FIXME: Defer remove/pause operations until after the 304 // FIXME: Defer remove/pause operations until after the
294 // compositing update. 305 // compositing update.
295 return; 306 return;
296 } 307 }
308 #if HEAVISIDE_ANIMATIONS
309 ASSERT(player);
310 WebCompositorAnimationPlayer* compositorPlayer = player->compositorPlayer();
311 ASSERT(compositorPlayer);
312 compositorPlayer->removeAnimation(id);
313 #else
297 toRenderBoxModelObject(element.renderer())->layer()->compositedLayerMapping( )->mainGraphicsLayer()->removeAnimation(id); 314 toRenderBoxModelObject(element.renderer())->layer()->compositedLayerMapping( )->mainGraphicsLayer()->removeAnimation(id);
315 #endif
298 } 316 }
299 317
300 void CompositorAnimations::pauseAnimationForTestingOnCompositor(const Element& e lement, int id, double pauseTime) 318 void CompositorAnimations::pauseAnimationForTestingOnCompositor(const Element& e lement, const AnimationPlayer* player, int id, double pauseTime)
301 { 319 {
302 // FIXME: canStartAnimationOnCompositor queries compositingState, which is n ot necessarily up to date. 320 // FIXME: canStartAnimationOnCompositor queries compositingState, which is n ot necessarily up to date.
303 // https://code.google.com/p/chromium/issues/detail?id=339847 321 // https://code.google.com/p/chromium/issues/detail?id=339847
304 DisableCompositingQueryAsserts disabler; 322 DisableCompositingQueryAsserts disabler;
305 323
306 if (!canStartAnimationOnCompositor(element)) { 324 if (!canStartAnimationOnCompositor(element)) {
307 ASSERT_NOT_REACHED(); 325 ASSERT_NOT_REACHED();
308 return; 326 return;
309 } 327 }
328 #if HEAVISIDE_ANIMATIONS
329 ASSERT(player);
330 WebCompositorAnimationPlayer* compositorPlayer = player->compositorPlayer();
331 ASSERT(compositorPlayer);
332 compositorPlayer->pauseAnimation(id, pauseTime);
333 #else
310 toRenderBoxModelObject(element.renderer())->layer()->compositedLayerMapping( )->mainGraphicsLayer()->pauseAnimation(id, pauseTime); 334 toRenderBoxModelObject(element.renderer())->layer()->compositedLayerMapping( )->mainGraphicsLayer()->pauseAnimation(id, pauseTime);
335 #endif
311 } 336 }
312 337
313 // ----------------------------------------------------------------------- 338 // -----------------------------------------------------------------------
314 // CompositorAnimationsImpl 339 // CompositorAnimationsImpl
315 // ----------------------------------------------------------------------- 340 // -----------------------------------------------------------------------
316 341
317 bool CompositorAnimationsImpl::convertTimingForCompositor(const Timing& timing, double timeOffset, CompositorTiming& out, double playerPlaybackRate) 342 bool CompositorAnimationsImpl::convertTimingForCompositor(const Timing& timing, double timeOffset, CompositorTiming& out, double playerPlaybackRate)
318 { 343 {
319 timing.assertValid(); 344 timing.assertValid();
320 345
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 break; 641 break;
617 default: 642 default:
618 ASSERT_NOT_REACHED(); 643 ASSERT_NOT_REACHED();
619 } 644 }
620 animations.append(animation.release()); 645 animations.append(animation.release());
621 } 646 }
622 ASSERT(!animations.isEmpty()); 647 ASSERT(!animations.isEmpty());
623 } 648 }
624 649
625 } // namespace blink 650 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698