• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

images/H03-May-2022-5445

BUILD.gnH A D16-Feb-20211.6 KiB6358

DEPSH A D16-Feb-2021453 1918

README.mdH A D16-Feb-202116.7 KiB286239

animation.ccH A D16-Feb-20219.2 KiB291213

animation.hH A D16-Feb-20215.8 KiB16588

animation_curve.ccH A D16-Feb-20212 KiB7050

animation_curve.hH A D16-Feb-20213.6 KiB12378

animation_delegate.hH A D16-Feb-20211.4 KiB4229

animation_events.ccH A D16-Feb-20212.8 KiB8459

animation_events.hH A D16-Feb-20212.2 KiB8453

animation_export.hH A D16-Feb-2021791 3020

animation_host.ccH A D16-Feb-202129.5 KiB847661

animation_host.hH A D16-Feb-202111.1 KiB291192

animation_host_perftest.ccH A D16-Feb-20215.6 KiB171129

animation_host_unittest.ccH A D16-Feb-202117.7 KiB475339

animation_id_provider.ccH A D16-Feb-2021924 3420

animation_id_provider.hH A D16-Feb-2021681 2614

animation_target.hH A D16-Feb-20212 KiB5338

animation_timeline.ccH A D16-Feb-20215 KiB174134

animation_timeline.hH A D16-Feb-20213 KiB9659

animation_timeline_unittest.ccH A D16-Feb-20213.6 KiB10272

animation_unittest.ccH A D16-Feb-202119.4 KiB487374

element_animations.ccH A D16-Feb-202122.4 KiB614490

element_animations.hH A D16-Feb-20218.9 KiB222138

element_animations_unittest.ccH A D16-Feb-2021165.9 KiB3,9133,006

keyframe_effect.ccH A D16-Feb-202141.7 KiB1,138900

keyframe_effect.hH A D16-Feb-20217.8 KiB199110

keyframe_model.ccH A D16-Feb-202113.7 KiB366282

keyframe_model.hH A D16-Feb-202111.8 KiB299145

keyframe_model_unittest.ccH A D16-Feb-202160.4 KiB1,4101,304

keyframed_animation_curve.ccH A D16-Feb-202117.4 KiB549423

keyframed_animation_curve.hH A D16-Feb-202110.8 KiB350243

keyframed_animation_curve_unittest.ccH A D16-Feb-202150.9 KiB1,094882

scroll_offset_animation_curve.ccH A D16-Feb-202115.9 KiB440328

scroll_offset_animation_curve.hH A D16-Feb-20215.6 KiB14476

scroll_offset_animation_curve_factory.ccH A D16-Feb-20213.3 KiB9269

scroll_offset_animation_curve_factory.hH A D16-Feb-20211.7 KiB4530

scroll_offset_animation_curve_unittest.ccH A D16-Feb-202119.2 KiB458347

scroll_offset_animations.ccH A D16-Feb-20212.3 KiB7153

scroll_offset_animations.hH A D16-Feb-20212 KiB6330

scroll_offset_animations_impl.ccH A D16-Feb-20219.4 KiB251204

scroll_offset_animations_impl.hH A D16-Feb-20214.3 KiB10265

scroll_timeline.ccH A D16-Feb-20218.1 KiB225154

scroll_timeline.hH A D16-Feb-20215.4 KiB14688

scroll_timeline_unittest.ccH A D16-Feb-202121.2 KiB501362

timing_function.ccH A D16-Feb-20215.2 KiB183138

timing_function.hH A D16-Feb-20214.7 KiB14188

transform_operation.ccH A D16-Feb-202119.4 KiB515424

transform_operation.hH A D16-Feb-20212 KiB8358

transform_operations.ccH A D16-Feb-202113 KiB388326

transform_operations.hH A D16-Feb-20215.6 KiB14370

transform_operations_unittest.ccH A D16-Feb-202159.4 KiB1,8321,409

worklet_animation.ccH A D16-Feb-202110.1 KiB270196

worklet_animation.hH A D16-Feb-20216.9 KiB17397

worklet_animation_unittest.ccH A D16-Feb-202123.7 KiB562419

README.md

1# cc/animation
2
3[TOC]
4
5## Overview
6
7cc/animation provides animation support - generating output values (usually
8visual properties) based on a predefined function and changing input values.
9Currently the main clients of cc/animation are Blink and ui/, targeting
10composited layers, but the code is intended to be agnostic of the client it is
11supporting. Aspirationally we could eventually merge cc/animation and Blink
12animation and have only a single animation system for all of Chromium.
13
14This document covers two main topics. The first section explains how
15cc/animation actually works: how animations are ticked, what animation curves
16are, what the ownership model is, etc. Later sections document how other parts
17of Chromium interact with cc/animation, most prominently Blink and ui/.
18
19## cc/animation terminology
20
21[Animation](https://cs.chromium.org/chromium/src/cc/animation/animation.h)
22A cc::Animation is responsible for managing animating properties for a set of
23targets. Each target is represented by a [KeyframeEffect][] and can be animating
24multiple properties on that target; see KeyframeEffect below.
25
26A particular Animation may not own all the KeyframeEffects for a given
27target. Animation is only a grouping mechanism for related effects, and the
28grouping relationship is defined by the client. It is also the client's
29responsibility to deal with any conflicts that arise from animating the same
30property of the same target across multiple Animations.
31
32Each Animation has a copy on the impl thread, and will take care of
33synchronizing to/from the impl thread when requested.
34
35There is a 1:1 relationship between Animation and KeyframeEffect.
36
37[Keyframe model](https://codesearch.chromium.org/chromium/src/cc/animation/keyframe_model.h)
38KeyframeModels contain the state necessary to 'play' (interpolate values from) an
39
40[animation curve](https://codesearch.chromium.org/chromium/src/cc/animation/animation_curve.h),
41which is a function that returns a value given an input time. Aside from the
42animation curve itself, a keyframe model's state includes the run state (playing,
43paused, etc), the start time, the current direction (forwards, reverse), etc.
44An animation does not know or care what property is being animated, and holds
45only an opaque identifier for the property to allow clients to map output values
46to the correct properties.
47
48[Keyframe effect][]
49A KeyframeEffect owns a group of KeyframeModels for a single target (identified
50by [PropertyToElementIdMap][]). It is responsible for managing the KeyframeModels'
51running states (starting, running, paused, etc), as well as ticking the
52KeyframeModels when it is requested to produce new outputs for a given time.
53
54Note that a single KeyframeEffect may not own all the KeyframeModels for a
55given target. KeyframeEffect is only a grouping mechanism for related
56KeyframeModels. The commonality between keyframe models on the same target is
57found via ElementAnimations - there is only one ElementAnimations for a given
58target.
59
60Group:
61KeyframeModels that must be run together are called 'grouped' and have the same
62group id. Grouped KeyframeModels are guaranteed to start at the same time and no
63other KeyframeModels may animate any of the group's target properties until all
64KeyframeModels in the group have finished animating. It's also guaranteed that
65no two keyframe models within a keyframe effect that have both the same group id
66and property id.
67
68In general, KeyframeModels are grouped together based on their
69[animation target](https://codesearch.chromium.org/chromium/src/cc/animation/animation_target.h)
70(the entity whose property is being animated) and each such group is owned by an
71[animation](https://codesearch.chromium.org/chromium/src/cc/animation/animation.h).
72Note that there may be multiple animations with the same target (each
73with a set of KeyframeModels for that target); the
74[ElementAnimations](https://codesearch.chromium.org/chromium/src/cc/animation/element_animations.h)
75class wraps the multiple animations and has a 1:1 relationship with
76target entities.
77
78`TODO(smcgruer): Why are ElementAnimations and Animations separate?`
79
80In order to play an animation, input time values must be provided to the
81animation curve and output values fed back into the animating entity. This is
82called 'ticking' an animation and is the responsibility of the
83[animation host](https://codesearch.chromium.org/chromium/src/cc/animation/animation_host.h).
84The animation host has a list of currently ticking animations (i.e. those that have
85any non-deleted animations), which it iterates through whenever it receives a
86tick call from the client (along with a corresponding input time).  The
87animations then call into their non-deleted animations, retrieving the
88value from the animation curve.  As they are computed, output values are sent to
89the target which is responsible for passing them to the client entity that is
90being animated.
91
92### Types of Animation Curve
93
94As noted above, an animation curve is simply a function which converts an input
95time value into some output value. Animation curves are categorized based on
96their output type, and each such category can have multiple implementations that
97provide different conversion functions. There are many categories of animation
98curve, but some common ones are `FloatAnimationCurve`, `ColorAnimationCurve`,
99and `TransformAnimationCurve`.
100
101The most common implementation of the various animation curve categories are the
102[keyframed animation curves](https://codesearch.chromium.org/chromium/src/cc/animation/keyframed_animation_curve.h).
103These curves each have a set of keyframes which map a specific time to a
104specific output value. Producing an output value for a given input time is then
105a matter of identifying the two keyframes the time lies between, and
106interpolating between the keyframe output values. (Or simply using a keyframe
107output value directly, if the input time happens to line up exactly.) Exact
108details of how each animation curve category is interpolated can be found in the
109implementations.
110
111There is one category of animation curve that stands somewhat apart, the
112[scroll offset animation curve](https://codesearch.chromium.org/chromium/src/cc/animation/scroll_offset_animation_curve.h).
113This curve converts the input time into a scroll offset, interpolating between
114an initial scroll offset and an updateable target scroll offset. It has logic to
115handle different types of scrolling such as programmatic, keyboard, and mouse
116wheel scrolls.
117
118### Animation Timelines
119
120cc/animation has a concept of an
121[animation timeline](https://codesearch.chromium.org/chromium/src/cc/animation/animation_timeline.h).
122This should not be confused with the identically named Blink concept. In
123cc/animation, animation timelines are an implementation detail - they hold the
124animations and are responsible for syncing them to the impl thread (see
125below), but do not participate in the ticking process in any way.
126
127### Main/Impl Threads
128
129One part of cc/animation that is not client agnostic is its support for the
130[Chromium compositor thread](https://codesearch.chromium.org/chromium/src/cc/README.md).
131Most of the cc/animation classes have a `PushPropertiesTo` method, in which they
132synchronize necessary state from the main thread to the impl thread. It is
133feasible that such support could be abstracted if necessary, but so far it has
134not been required.
135
136## Current cc/animation Clients
137
138As noted above, the main clients of cc/animation are currently Blink for
139accelerated web animations, and ui/ for accelerated user interface animations.
140Both of these clients utilize
141[cc::Layer](https://codesearch.chromium.org/chromium/src/cc/layers/layer.h)
142as their animation entity and interact with cc/animation via the
143[MutatorHostClient](https://codesearch.chromium.org/chromium/src/cc/trees/mutator_host_client.h)
144interface (which is implemented by cc::LayerTreeHost and cc::LayerTreeHostImpl).
145Recently a third client, chrome/browser/vr/, has started using cc/animations as
146well. The vr/ client does not use cc::Layer as its animation entity.
147
148`TODO(smcgruer): Summarize how vr/ uses cc/animation.`
149
150### Supported Animatable Properties
151
152As cc::Layers are just textures which are reused for performance, clients that
153use composited layers as their animation entities are limited to animating
154properties that do not cause content to be redrawn. For example, a composited
155layer's opacity can be animated as promoted layers are aware of the content
156behind them.  On the other hand we cannot animate layer width as changing the
157width could modify layout - which then requires redrawing.
158
159### Interaction between cc/animation and Blink
160
161Blink is able to move compatible animations off the main thread by promoting
162the animating element into a layer. The Blink
163[Lifetime of a compositor animation](../../third_party/blink/renderer/core/animation/README.md#lifetime-of-a-compositor-animation)
164document describes how composited animations are created in blink. Once a
165compositor animation is created it is pushed through the commit cycle.
166
167![new animation]
168
169The lifetime of a newly started cc::Animation is roughly the following:
170
1711. An update to style or a new animation triggers a new [BeginMainFrame][] via
172   [ScheduleVisualUpdate][].
1731. [blink::DocumentAnimations::UpdateAnimations][] calls [blink::Animation::PreCommit][]
174   on each pending blink::Animation constructing the corresponding
175   cc::Animation via [blink::Animation::CreateCompositorAnimation][] (attaching
176   the animation to the cc::AnimationTimeline resulting in it being later pushed).
177   The KeyframeEffects are constructed via [blink::Animation::StartAnimationOnCompositor][].
1781. [AnimationHost::RegisterKeyframeEffectForElement][] creates a
179   cc::ElementAnimations for the target `element_id` if one does not already
180   exist. This ElementAnimations instance is shared by all animations with
181   the same target and tracks the existence of the target.
1821. During the commit, [cc::ElementAnimations::ElementRegistered][] is called on the
183   main thread's AnimationHost either:
184   - Before BlinkGenPropertyTrees, when a layer with the target `element_id` is
185     registered.
186   - After BlinkGenPropertyTrees, after a property tree node with the target
187     `element_id` is created on the main thread LayerTreeHost's `property_trees_`.
188   This begins ticking the attached KeyframeEffects and tracks that the element
189   exists in the active layer / property tree.
1901. [cc::LayerTreeHost::FinishCommitOnImplThread][] calls
191   [cc::AnimationHost::PushPropertiesTo][] which results in
192   [cc::AnimationTimeline::PushAttachedAnimationsToImplThread][] creating a
193   cc::Animation on the compositor thread's AnimationTimeline for each animation
194   missing from the compositor thread.
1951. [cc::Animation::PushPropertiesTo][] is called on every animation on the timeline.
196   When the `element_id` is pushed by [cc::KeyframeEffect::PushPropertiesTo][]
197   [cc::Animation::AttachElementForKeyframeEffect][] creates a compositor side
198   cc::ElementAnimations instance to track the existence of the element on the
199   compositor. Since animations are pushed after the layer and property trees,
200   the element should already exist on the pending tree. This will result in the
201   animation being added to the ticking animations list.
2021. Now the animation is ticking, meaning that [cc::Animation::Tick][] will be called
203   every frame and update the pending property tree nodes.
2041. When the pending tree is activated,
205   [cc::AnimationHost::ActivateAnimations][] updates the keyframe effects and
206   [cc::ElementAnimations::ElementRegistered][]
207   is called for the newly added element id on the active tree, setting
208   `has_element_in_active_list_`.
2091. Subsequent animation ticks will now update the property nodes on the active
210   tree.
211
212[new animation]: images/new-animation.png
213[BeginMainFrame]: https://cs.chromium.org/chromium/src/cc/trees/proxy_main.cc?type=cs&q=file:proxy_main%5C.cc+RequestMainFrameUpdate
214[ScheduleVisualUpdate]: https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/frame/local_frame.cc?type=cs&q=file:local_frame%5C.cc+ScheduleVisualUpdate
215[blink::DocumentAnimations::UpdateAnimations]: https://cs.chromium.org/search?q=function:blink::DocumentAnimations::UpdateAnimations+GetPendingAnimations
216[blink::Animation::PreCommit]: https://cs.chromium.org/search?q=function:blink::PendingAnimations::Update+%5C-%5C>PreCommit%5C(&g=0&l=57
217[blink::Animation::CreateCompositorAnimation]: https://cs.chromium.org/search?q=function:blink::Animation::CreateCompositorAnimation+%5E%5B+%5D*AttachCompositorTimeline
218[blink::Animation::StartAnimationOnCompositor]: https://cs.chromium.org/search?q=function:blink::Animation::StartAnimationOnCompositor+%5C-%5C>StartAnimationOnCompositor
219[AnimationHost::RegisterKeyframeEffectForElement]: https://cs.chromium.org/search?q=function:cc::AnimationHost::RegisterKeyframeEffectForElement+ElementAnimations::Create
220[cc::ElementAnimations::ElementRegistered]: https://cs.chromium.org/search?q=function:cc::ElementAnimations::ElementRegistered+%5C!has_element_in_any_list
221[cc::LayerTreeHost::FinishCommitOnImplThread]: https://cs.chromium.org/search?q=cc::LayerTreeHost::FinishCommitOnImplThread+file:%5C.cc
222[cc::AnimationHost::PushPropertiesTo]: https://cs.chromium.org/search/?q=function:cc::LayerTreeHost::FinishCommitOnImplThread+%5C-%5C>PushPropertiesTo
223[cc::AnimationTimeline::PushAttachedAnimationsToImplThread]: https://cs.chromium.org/search?q=function:cc::AnimationTimeline::PushAttachedAnimationsToImplThread+animation%5C-%5C>CreateImplInstance
224[cc::Animation::PushPropertiesTo]: https://cs.chromium.org/search?q=cc::Animation::PushPropertiesTo+file:%5C.cc
225[cc::KeyframeEffect::PushPropertiesTo]: https://cs.chromium.org/search?q=cc::KeyframeEffect::PushPropertiesTo+file:%5C.cc
226[cc::Animation::AttachElementForKeyframeEffect]: https://cs.chromium.org/search?q=cc::Animation::AttachElementForKeyframeEffect+file:%5C.cc
227[cc::Animation::Tick]: https://cs.chromium.org/search?q=cc::Animation::Tick+file:%5C.cc
228[cc::AnimationHost::ActivateAnimations]: https://cs.chromium.org/search?q=cc::AnimationHost::ActivateAnimations+ActivateKeyframeEffects
229[cc::ElementAnimations::ElementRegistered]: https://cs.chromium.org/search?q=cc::ElementAnimations::ElementRegistered+file:%5C.cc
230[KeyframeEffect]: https://cs.chromium.org/chromium/src/cc/animation/keyframe_effect.h
231[PropertyToElementIdMap]: https://cs.chromium.org/chromium/src/cc/trees/target_property.h?type=cs&g=0&l=42
232
233#### Animation Events
234The purpose of animation events ([cc::AnimationEvent][], not to confuse with
235[blink::AnimationEvent][]) is to synchronize animation state from cc::animation
236to its client. The typical life cycle of the events is:
2371. **Event Generation.**
238Events are generated on IMPL thread and collected into [cc::AnimationEvents][]
239container.  [cc::AnimationEvents][] are passed to the MAIN thread as part of
240[BeginMainFrame][] arguments.
2411. **Event Dispatch.**
242On the MAIN thread events are dispatched to [cc::KeyframeModel][]s to ensure
243they are synchronized to their counterparts on the IMPL side. TIME_UPDATED
244events skip this step since [cc::KeyframeModel][]s of worklet animations
245don't participate in generating and reacting to these events.
2461. **Event Delegation.**
247After the events are dispatched, they are delegated to
248[cc::AnimationDelegate][], the final destination of the events on cc:animation's
249client.
250
251There is a special type of events called impl_only events. They are generated by
252animations that are running on IMPL thread only. These events are not passed to
253the MAIN thread and skip dispatch stage. They are delegated to the
254[cc::AnimationDelegate][] on the IMPL thread.
255
256[cc::AnimationEvent]: https://cs.chromium.org/chromium/src/cc/animation/animation_events.h
257[cc::AnimationEvents]: https://cs.chromium.org/chromium/src/cc/animation/animation_events.h
258[blink::AnimationEvent]: https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/events/animation_event.h
259[cc::KeyframeModel]: https://cs.chromium.org/chromium/src/cc/animation/keyframe_model.h
260[cc::AnimationDelegate]: https://cs.chromium.org/chromium/src/cc/animation/animation_delegate.h
261
262`TODO(flackr): Document finishing / cancel / abort.`
263
264### Interaction between cc/animation and ui/
265
266`TODO(smcgruer): Write this.`
267
268## Additional References
269
270The Compositor Property Trees talk [slides](https://goo.gl/U4wXpW)
271includes discussion on compositor animations.
272
273The Project Heaviside [design document](https://goo.gl/pWaWyv)
274and [slides](https://goo.gl/iFpk4R) provide history on the Chromium
275and Blink animation system. The slides in particular include helpful
276software architecture diagrams.
277
278Smooth scrolling is implemented via animations. See also references to
279"scroll offset" animations in the cc code
280base. [Smooth Scrolling in Chromium](https://goo.gl/XXwAwk) provides
281an overview of smooth scrolling. There is further class header
282documentation in
283Blink's
284[platform/scroll](https://codesearch.chromium.org/chromium/src/third_party/blink/renderer/platform/scroll/)
285directory.
286