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 25 matching lines...) Expand all Loading... |
36 #include "core/animation/ElementAnimations.h" | 36 #include "core/animation/ElementAnimations.h" |
37 #include "core/animation/CompositorAnimationsImpl.h" | 37 #include "core/animation/CompositorAnimationsImpl.h" |
38 #include "core/animation/animatable/AnimatableDouble.h" | 38 #include "core/animation/animatable/AnimatableDouble.h" |
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/LayoutBoxModelObject.h" | 42 #include "core/layout/LayoutBoxModelObject.h" |
43 #include "core/layout/LayoutObject.h" | 43 #include "core/layout/LayoutObject.h" |
44 #include "core/layout/compositing/CompositedDeprecatedPaintLayerMapping.h" | 44 #include "core/layout/compositing/CompositedDeprecatedPaintLayerMapping.h" |
45 #include "core/paint/DeprecatedPaintLayer.h" | 45 #include "core/paint/DeprecatedPaintLayer.h" |
| 46 #include "platform/RuntimeEnabledFeatures.h" |
46 #include "platform/geometry/FloatBox.h" | 47 #include "platform/geometry/FloatBox.h" |
47 #include "public/platform/Platform.h" | 48 #include "public/platform/Platform.h" |
48 #include "public/platform/WebCompositorAnimation.h" | 49 #include "public/platform/WebCompositorAnimation.h" |
| 50 #include "public/platform/WebCompositorAnimationPlayer.h" |
49 #include "public/platform/WebCompositorSupport.h" | 51 #include "public/platform/WebCompositorSupport.h" |
50 #include "public/platform/WebFilterAnimationCurve.h" | 52 #include "public/platform/WebFilterAnimationCurve.h" |
51 #include "public/platform/WebFilterKeyframe.h" | 53 #include "public/platform/WebFilterKeyframe.h" |
52 #include "public/platform/WebFloatAnimationCurve.h" | 54 #include "public/platform/WebFloatAnimationCurve.h" |
53 #include "public/platform/WebFloatKeyframe.h" | 55 #include "public/platform/WebFloatKeyframe.h" |
54 #include "public/platform/WebTransformAnimationCurve.h" | 56 #include "public/platform/WebTransformAnimationCurve.h" |
55 #include "public/platform/WebTransformKeyframe.h" | 57 #include "public/platform/WebTransformKeyframe.h" |
56 | 58 |
57 #include <algorithm> | 59 #include <algorithm> |
58 #include <cmath> | 60 #include <cmath> |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 || (affectsFilter && attachedPlayer->affects(targetElement, CSSPrope
rtyWebkitFilter))) | 258 || (affectsFilter && attachedPlayer->affects(targetElement, CSSPrope
rtyWebkitFilter))) |
257 attachedPlayer->cancelAnimationOnCompositor(); | 259 attachedPlayer->cancelAnimationOnCompositor(); |
258 } | 260 } |
259 } | 261 } |
260 | 262 |
261 bool CompositorAnimations::canStartAnimationOnCompositor(const Element& element) | 263 bool CompositorAnimations::canStartAnimationOnCompositor(const Element& element) |
262 { | 264 { |
263 return element.layoutObject() && element.layoutObject()->compositingState()
== PaintsIntoOwnBacking; | 265 return element.layoutObject() && element.layoutObject()->compositingState()
== PaintsIntoOwnBacking; |
264 } | 266 } |
265 | 267 |
266 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) | 268 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) |
267 { | 269 { |
268 ASSERT(startedAnimationIds.isEmpty()); | 270 ASSERT(startedAnimationIds.isEmpty()); |
269 ASSERT(isCandidateForAnimationOnCompositor(timing, element, player, effect,
playerPlaybackRate)); | 271 ASSERT(isCandidateForAnimationOnCompositor(timing, element, &player, effect,
playerPlaybackRate)); |
270 ASSERT(canStartAnimationOnCompositor(element)); | 272 ASSERT(canStartAnimationOnCompositor(element)); |
271 | 273 |
272 const KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(ef
fect); | 274 const KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(ef
fect); |
273 | 275 |
274 DeprecatedPaintLayer* layer = toLayoutBoxModelObject(element.layoutObject())
->layer(); | 276 DeprecatedPaintLayer* layer = toLayoutBoxModelObject(element.layoutObject())
->layer(); |
275 ASSERT(layer); | 277 ASSERT(layer); |
276 | 278 |
277 Vector<OwnPtr<WebCompositorAnimation>> animations; | 279 Vector<OwnPtr<WebCompositorAnimation>> animations; |
278 CompositorAnimationsImpl::getAnimationOnCompositor(timing, group, startTime,
timeOffset, keyframeEffect, animations, playerPlaybackRate); | 280 CompositorAnimationsImpl::getAnimationOnCompositor(timing, group, startTime,
timeOffset, keyframeEffect, animations, playerPlaybackRate); |
279 ASSERT(!animations.isEmpty()); | 281 ASSERT(!animations.isEmpty()); |
280 for (auto& animation : animations) { | 282 for (auto& animation : animations) { |
281 int id = animation->id(); | 283 int id = animation->id(); |
282 if (!layer->compositedDeprecatedPaintLayerMapping()->mainGraphicsLayer()
->addAnimation(animation.release())) { | 284 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled()) { |
| 285 WebCompositorAnimationPlayer* compositorPlayer = player.compositorPl
ayer(); |
| 286 ASSERT(compositorPlayer); |
| 287 compositorPlayer->addAnimation(animation.leakPtr()); |
| 288 } else if (!layer->compositedDeprecatedPaintLayerMapping()->mainGraphics
Layer()->addAnimation(animation.release())) { |
283 // FIXME: We should know ahead of time whether these animations can
be started. | 289 // FIXME: We should know ahead of time whether these animations can
be started. |
284 for (int startedAnimationId : startedAnimationIds) | 290 for (int startedAnimationId : startedAnimationIds) |
285 cancelAnimationOnCompositor(element, startedAnimationId); | 291 cancelAnimationOnCompositor(element, player, startedAnimationId)
; |
286 startedAnimationIds.clear(); | 292 startedAnimationIds.clear(); |
287 return false; | 293 return false; |
288 } | 294 } |
289 startedAnimationIds.append(id); | 295 startedAnimationIds.append(id); |
290 } | 296 } |
291 ASSERT(!startedAnimationIds.isEmpty()); | 297 ASSERT(!startedAnimationIds.isEmpty()); |
292 return true; | 298 return true; |
293 } | 299 } |
294 | 300 |
295 void CompositorAnimations::cancelAnimationOnCompositor(const Element& element, i
nt id) | 301 void CompositorAnimations::cancelAnimationOnCompositor(const Element& element, c
onst AnimationPlayer& player, int id) |
296 { | 302 { |
297 if (!canStartAnimationOnCompositor(element)) { | 303 if (!canStartAnimationOnCompositor(element)) { |
298 // When an element is being detached, we cancel any associated | 304 // When an element is being detached, we cancel any associated |
299 // AnimationPlayers for CSS animations. But by the time we get | 305 // AnimationPlayers for CSS animations. But by the time we get |
300 // here the mapping will have been removed. | 306 // here the mapping will have been removed. |
301 // FIXME: Defer remove/pause operations until after the | 307 // FIXME: Defer remove/pause operations until after the |
302 // compositing update. | 308 // compositing update. |
303 return; | 309 return; |
304 } | 310 } |
305 toLayoutBoxModelObject(element.layoutObject())->layer()->compositedDeprecate
dPaintLayerMapping()->mainGraphicsLayer()->removeAnimation(id); | 311 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled()) { |
| 312 WebCompositorAnimationPlayer* compositorPlayer = player.compositorPlayer
(); |
| 313 ASSERT(compositorPlayer); |
| 314 compositorPlayer->removeAnimation(id); |
| 315 } else { |
| 316 toLayoutBoxModelObject(element.layoutObject())->layer()->compositedDepre
catedPaintLayerMapping()->mainGraphicsLayer()->removeAnimation(id); |
| 317 } |
306 } | 318 } |
307 | 319 |
308 void CompositorAnimations::pauseAnimationForTestingOnCompositor(const Element& e
lement, int id, double pauseTime) | 320 void CompositorAnimations::pauseAnimationForTestingOnCompositor(const Element& e
lement, const AnimationPlayer& player, int id, double pauseTime) |
309 { | 321 { |
310 // FIXME: canStartAnimationOnCompositor queries compositingState, which is n
ot necessarily up to date. | 322 // FIXME: canStartAnimationOnCompositor queries compositingState, which is n
ot necessarily up to date. |
311 // https://code.google.com/p/chromium/issues/detail?id=339847 | 323 // https://code.google.com/p/chromium/issues/detail?id=339847 |
312 DisableCompositingQueryAsserts disabler; | 324 DisableCompositingQueryAsserts disabler; |
313 | 325 |
314 if (!canStartAnimationOnCompositor(element)) { | 326 if (!canStartAnimationOnCompositor(element)) { |
315 ASSERT_NOT_REACHED(); | 327 ASSERT_NOT_REACHED(); |
316 return; | 328 return; |
317 } | 329 } |
318 toLayoutBoxModelObject(element.layoutObject())->layer()->compositedDeprecate
dPaintLayerMapping()->mainGraphicsLayer()->pauseAnimation(id, pauseTime); | 330 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled()) { |
| 331 WebCompositorAnimationPlayer* compositorPlayer = player.compositorPlayer
(); |
| 332 ASSERT(compositorPlayer); |
| 333 compositorPlayer->pauseAnimation(id, pauseTime); |
| 334 } else { |
| 335 toLayoutBoxModelObject(element.layoutObject())->layer()->compositedDepre
catedPaintLayerMapping()->mainGraphicsLayer()->pauseAnimation(id, pauseTime); |
| 336 } |
| 337 } |
| 338 |
| 339 bool CompositorAnimations::canAttachCompositedLayers(const Element& element, con
st AnimationPlayer& player) |
| 340 { |
| 341 if (!RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled()) |
| 342 return false; |
| 343 |
| 344 if (!player.compositorPlayer()) |
| 345 return false; |
| 346 |
| 347 if (!element.layoutObject() || !element.layoutObject()->isBoxModelObject()) |
| 348 return false; |
| 349 |
| 350 DeprecatedPaintLayer* layer = toLayoutBoxModelObject(element.layoutObject())
->layer(); |
| 351 |
| 352 if (!layer || !layer->isAllowedToQueryCompositingState() |
| 353 || !layer->compositedDeprecatedPaintLayerMapping() |
| 354 || !layer->compositedDeprecatedPaintLayerMapping()->mainGraphicsLayer()) |
| 355 return false; |
| 356 |
| 357 if (!layer->compositedDeprecatedPaintLayerMapping()->mainGraphicsLayer()->pl
atformLayer()) |
| 358 return false; |
| 359 |
| 360 return true; |
| 361 } |
| 362 |
| 363 void CompositorAnimations::attachCompositedLayers(const Element& element, const
AnimationPlayer& player) |
| 364 { |
| 365 ASSERT(element.layoutObject()); |
| 366 |
| 367 DeprecatedPaintLayer* layer = toLayoutBoxModelObject(element.layoutObject())
->layer(); |
| 368 ASSERT(layer); |
| 369 |
| 370 WebCompositorAnimationPlayer* compositorPlayer = player.compositorPlayer(); |
| 371 ASSERT(compositorPlayer); |
| 372 |
| 373 ASSERT(layer->compositedDeprecatedPaintLayerMapping()); |
| 374 compositorPlayer->attachLayer(layer->compositedDeprecatedPaintLayerMapping()
->mainGraphicsLayer()->platformLayer()); |
319 } | 375 } |
320 | 376 |
321 // ----------------------------------------------------------------------- | 377 // ----------------------------------------------------------------------- |
322 // CompositorAnimationsImpl | 378 // CompositorAnimationsImpl |
323 // ----------------------------------------------------------------------- | 379 // ----------------------------------------------------------------------- |
324 | 380 |
325 bool CompositorAnimationsImpl::convertTimingForCompositor(const Timing& timing,
double timeOffset, CompositorTiming& out, double playerPlaybackRate) | 381 bool CompositorAnimationsImpl::convertTimingForCompositor(const Timing& timing,
double timeOffset, CompositorTiming& out, double playerPlaybackRate) |
326 { | 382 { |
327 timing.assertValid(); | 383 timing.assertValid(); |
328 | 384 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 break; | 680 break; |
625 default: | 681 default: |
626 ASSERT_NOT_REACHED(); | 682 ASSERT_NOT_REACHED(); |
627 } | 683 } |
628 animations.append(animation.release()); | 684 animations.append(animation.release()); |
629 } | 685 } |
630 ASSERT(!animations.isEmpty()); | 686 ASSERT(!animations.isEmpty()); |
631 } | 687 } |
632 | 688 |
633 } // namespace blink | 689 } // namespace blink |
OLD | NEW |