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

Side by Side Diff: third_party/WebKit/Source/core/animation/CustomCompositorAnimations.cpp

Issue 1602343002: compositor-worker: cc->blink mutation plumbing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@compositor-worker-ian-patch
Patch Set: Merge master + s/scoped_ptr/unique_ptr/ Created 4 years, 8 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "CustomCompositorAnimations.h"
6
7 #include "core/animation/Animation.h"
8 #include "core/animation/AnimationTimeline.h"
9 #include "core/animation/KeyframeEffect.h"
10 #include "core/animation/KeyframeEffectModel.h"
11 #include "core/animation/animatable/AnimatableDouble.h"
12 #include "core/animation/animatable/AnimatableTransform.h"
13 #include "core/animation/animatable/AnimatableValue.h"
14 #include "platform/TraceEvent.h"
15 #include "platform/graphics/CompositorMutation.h"
16 #include "platform/transforms/Matrix3DTransformOperation.h"
17 #include "platform/transforms/MatrixTransformOperation.h"
18 #include "platform/transforms/TransformOperations.h"
19
20 namespace blink {
21
22 namespace {
23
24 // Create keyframe effect with zero duration, fill mode forward, and two key
25 // frames with same value. This corresponding animation is always running and by
26 // updating the key frames we are able to control the applied value.
27 static KeyframeEffect* createInfiniteKeyFrameEffect(Element& element, CSSPropert yID propertyId, PassRefPtr<AnimatableValue> value)
28 {
29 AnimatableValueKeyframeVector keyframes(2);
30 keyframes[0] = AnimatableValueKeyframe::create();
31 keyframes[0]->setOffset(0.0);
32 keyframes[0]->setPropertyValue(propertyId, value.get());
33 keyframes[1] = AnimatableValueKeyframe::create();
34 keyframes[1]->setOffset(1.0);
35 keyframes[1]->setPropertyValue(propertyId, value.get());
36 keyframes[1]->setComposite(EffectModel::CompositeReplace);
37
38 Timing timing;
39 timing.iterationDuration = 0;
40 timing.fillMode = Timing::FillModeForwards;
41
42 AnimatableValueKeyframeEffectModel* effectModel = AnimatableValueKeyframeEff ectModel::create(keyframes);
43 return KeyframeEffect::create(&element, effectModel, timing);
44 }
45
46 static KeyframeEffect* updateInfiniteKeyframeEffect(const KeyframeEffect& keyfra meEffect, CSSPropertyID propertyId, PassRefPtr<AnimatableValue> value)
47 {
48 const KeyframeVector& oldFrames = toAnimatableValueKeyframeEffectModel(keyfr ameEffect.model())->getFrames();
49 AnimatableValueKeyframeVector keyframes(2);
50 keyframes[0] = toAnimatableValueKeyframe(oldFrames[0]->clone().get());
51 keyframes[1] = toAnimatableValueKeyframe(oldFrames[1]->clone().get());
52 keyframes[0]->setPropertyValue(propertyId, value.get());
53 keyframes[1]->setPropertyValue(propertyId, value.get());
54
55 AnimatableValueKeyframeEffectModel* effectModel = AnimatableValueKeyframeEff ectModel::create(keyframes);
56 return KeyframeEffect::create(keyframeEffect.target(), effectModel, keyframe Effect.specifiedTiming());
57 }
58
59 static Animation* createOrUpdateAnimation(Animation* animation, Element& element , CSSPropertyID propertyId, PassRefPtr<AnimatableValue> newValue)
60 {
61 if (!animation) {
62 KeyframeEffect* keyframeEffect = createInfiniteKeyFrameEffect(element, p ropertyId, newValue);
63 return element.document().timeline().play(keyframeEffect);
64 }
65 KeyframeEffect* keyframeEffect = updateInfiniteKeyframeEffect(*toKeyframeEff ect(animation->effect()), propertyId, newValue);
66 animation->setEffect(keyframeEffect);
67 return animation;
68 }
69
70 } // namespace
71
72 void CustomCompositorAnimations::applyUpdate(Element& element, const CompositorM utation& mutation)
73 {
74 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CustomComposit orAnimations::applyUpdate");
75
76 if (mutation.isOpacityMutated()) {
77 RefPtr<AnimatableValue> animatableValue = AnimatableDouble::create(mutat ion.opacity());
78 m_animation = createOrUpdateAnimation(m_animation, element, CSSPropertyO pacity, animatableValue.release());
79 }
80 if (mutation.isTransformMutated()) {
81 TransformOperations ops;
82 ops.operations().append(Matrix3DTransformOperation::create(Transformatio nMatrix(mutation.transform())));
83 RefPtr<AnimatableValue> animatableValue = AnimatableTransform::create(op s, 1);
84 m_animation = createOrUpdateAnimation(m_animation, element, CSSPropertyT ransform, animatableValue.release());
85 }
86 }
87
88 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698