tree: 1bd4d38401f202b5d5156af2120953d46b476a86 [path history] [tgz]
  1. BUILD.gn
  2. OWNERS
  3. README.md
  4. animatable/
  5. animation.cc
  6. animation.h
  7. animation.idl
  8. animation_clock.cc
  9. animation_clock.h
  10. animation_clock_test.cc
  11. animation_effect.cc
  12. animation_effect.h
  13. animation_effect.idl
  14. animation_effect_owner.h
  15. animation_effect_test.cc
  16. animation_effect_timing.idl
  17. animation_effect_timing_read_only.idl
  18. animation_input_helpers.cc
  19. animation_input_helpers.h
  20. animation_input_helpers_test.cc
  21. animation_sim_test.cc
  22. animation_test.cc
  23. animation_test_helper.cc
  24. animation_test_helper.h
  25. animation_time_delta.cc
  26. animation_time_delta.h
  27. animation_time_delta_test.cc
  28. animation_timeline.h
  29. animation_timeline.idl
  30. base_keyframe.idl
  31. base_property_indexed_keyframe.idl
  32. basic_shape_interpolation_functions.cc
  33. basic_shape_interpolation_functions.h
  34. color_property_functions.cc
  35. color_property_functions.h
  36. compositor_animations.cc
  37. compositor_animations.h
  38. compositor_animations_test.cc
  39. computed_effect_timing.idl
  40. css/
  41. css_angle_interpolation_type.cc
  42. css_angle_interpolation_type.h
  43. css_basic_shape_interpolation_type.cc
  44. css_basic_shape_interpolation_type.h
  45. css_border_image_length_box_interpolation_type.cc
  46. css_border_image_length_box_interpolation_type.h
  47. css_clip_interpolation_type.cc
  48. css_clip_interpolation_type.h
  49. css_color_interpolation_type.cc
  50. css_color_interpolation_type.h
  51. css_custom_list_interpolation_type.cc
  52. css_custom_list_interpolation_type.h
  53. css_default_interpolation_type.cc
  54. css_default_interpolation_type.h
  55. css_filter_list_interpolation_type.cc
  56. css_filter_list_interpolation_type.h
  57. css_font_size_interpolation_type.cc
  58. css_font_size_interpolation_type.h
  59. css_font_variation_settings_interpolation_type.cc
  60. css_font_variation_settings_interpolation_type.h
  61. css_font_weight_interpolation_type.cc
  62. css_font_weight_interpolation_type.h
  63. css_image_interpolation_type.cc
  64. css_image_interpolation_type.h
  65. css_image_list_interpolation_type.cc
  66. css_image_list_interpolation_type.h
  67. css_image_slice_interpolation_type.cc
  68. css_image_slice_interpolation_type.h
  69. css_interpolation_environment.h
  70. css_interpolation_type.cc
  71. css_interpolation_type.h
  72. css_interpolation_types_map.cc
  73. css_interpolation_types_map.h
  74. css_length_interpolation_type.cc
  75. css_length_interpolation_type.h
  76. css_length_list_interpolation_type.cc
  77. css_length_list_interpolation_type.h
  78. css_length_pair_interpolation_type.h
  79. css_number_interpolation_type.cc
  80. css_number_interpolation_type.h
  81. css_offset_rotate_interpolation_type.cc
  82. css_offset_rotate_interpolation_type.h
  83. css_paint_interpolation_type.cc
  84. css_paint_interpolation_type.h
  85. css_path_interpolation_type.cc
  86. css_path_interpolation_type.h
  87. css_position_axis_list_interpolation_type.cc
  88. css_position_axis_list_interpolation_type.h
  89. css_position_interpolation_type.h
  90. css_ray_interpolation_type.cc
  91. css_ray_interpolation_type.h
  92. css_resolution_interpolation_type.cc
  93. css_resolution_interpolation_type.h
  94. css_rotate_interpolation_type.cc
  95. css_rotate_interpolation_type.h
  96. css_scale_interpolation_type.cc
  97. css_scale_interpolation_type.h
  98. css_shadow_list_interpolation_type.cc
  99. css_shadow_list_interpolation_type.h
  100. css_size_list_interpolation_type.cc
  101. css_size_list_interpolation_type.h
  102. css_text_indent_interpolation_type.cc
  103. css_text_indent_interpolation_type.h
  104. css_time_interpolation_type.cc
  105. css_time_interpolation_type.h
  106. css_transform_interpolation_type.cc
  107. css_transform_interpolation_type.h
  108. css_transform_origin_interpolation_type.h
  109. css_translate_interpolation_type.cc
  110. css_translate_interpolation_type.h
  111. css_var_cycle_interpolation_type.cc
  112. css_var_cycle_interpolation_type.h
  113. css_visibility_interpolation_type.cc
  114. css_visibility_interpolation_type.h
  115. document_animation.h
  116. document_animation.idl
  117. document_animations.cc
  118. document_animations.h
  119. document_timeline.cc
  120. document_timeline.h
  121. document_timeline.idl
  122. document_timeline_options.idl
  123. document_timeline_test.cc
  124. effect_input.cc
  125. effect_input.h
  126. effect_input_test.cc
  127. effect_model.cc
  128. effect_model.h
  129. effect_stack.cc
  130. effect_stack.h
  131. effect_stack_test.cc
  132. effect_timing.idl
  133. element_animation.cc
  134. element_animation.h
  135. element_animation.idl
  136. element_animations.cc
  137. element_animations.h
  138. filter_interpolation_functions.cc
  139. filter_interpolation_functions.h
  140. image_list_property_functions.h
  141. image_slice_property_functions.h
  142. inert_effect.cc
  143. inert_effect.h
  144. interpolable_value.cc
  145. interpolable_value.h
  146. interpolable_value_test.cc
  147. interpolated_svg_path_source.h
  148. interpolation.h
  149. interpolation_effect.cc
  150. interpolation_effect.h
  151. interpolation_effect_test.cc
  152. interpolation_environment.h
  153. interpolation_type.h
  154. interpolation_types_map.h
  155. interpolation_value.h
  156. invalidatable_interpolation.cc
  157. invalidatable_interpolation.h
  158. keyframe.cc
  159. keyframe.h
  160. keyframe_animation_options.idl
  161. keyframe_effect.cc
  162. keyframe_effect.h
  163. keyframe_effect.idl
  164. keyframe_effect_model.cc
  165. keyframe_effect_model.h
  166. keyframe_effect_model_test.cc
  167. keyframe_effect_options.idl
  168. keyframe_effect_test.cc
  169. length_interpolation_functions.cc
  170. length_interpolation_functions.h
  171. length_list_property_functions.cc
  172. length_list_property_functions.h
  173. length_property_functions.cc
  174. length_property_functions.h
  175. length_units_checker.h
  176. list_interpolation_functions.cc
  177. list_interpolation_functions.h
  178. list_interpolation_functions_test.cc
  179. non_interpolable_value.h
  180. number_property_functions.cc
  181. number_property_functions.h
  182. optional_effect_timing.idl
  183. pairwise_interpolation_value.h
  184. path_interpolation_functions.cc
  185. path_interpolation_functions.h
  186. pending_animations.cc
  187. pending_animations.h
  188. primitive_interpolation.h
  189. property_handle.cc
  190. property_handle.h
  191. property_handle_test.cc
  192. sampled_effect.cc
  193. sampled_effect.h
  194. scroll_timeline.cc
  195. scroll_timeline.h
  196. scroll_timeline.idl
  197. scroll_timeline_options.idl
  198. scroll_timeline_test.cc
  199. shadow_interpolation_functions.cc
  200. shadow_interpolation_functions.h
  201. side_index.h
  202. size_interpolation_functions.cc
  203. size_interpolation_functions.h
  204. size_list_property_functions.cc
  205. size_list_property_functions.h
  206. string_keyframe.cc
  207. string_keyframe.h
  208. svg_angle_interpolation_type.cc
  209. svg_angle_interpolation_type.h
  210. svg_integer_interpolation_type.cc
  211. svg_integer_interpolation_type.h
  212. svg_integer_optional_integer_interpolation_type.cc
  213. svg_integer_optional_integer_interpolation_type.h
  214. svg_interpolation_environment.h
  215. svg_interpolation_type.cc
  216. svg_interpolation_type.h
  217. svg_interpolation_types_map.cc
  218. svg_interpolation_types_map.h
  219. svg_length_interpolation_type.cc
  220. svg_length_interpolation_type.h
  221. svg_length_list_interpolation_type.cc
  222. svg_length_list_interpolation_type.h
  223. svg_number_interpolation_type.cc
  224. svg_number_interpolation_type.h
  225. svg_number_list_interpolation_type.cc
  226. svg_number_list_interpolation_type.h
  227. svg_number_optional_number_interpolation_type.cc
  228. svg_number_optional_number_interpolation_type.h
  229. svg_path_interpolation_type.cc
  230. svg_path_interpolation_type.h
  231. svg_path_seg_interpolation_functions.cc
  232. svg_path_seg_interpolation_functions.h
  233. svg_point_list_interpolation_type.cc
  234. svg_point_list_interpolation_type.h
  235. svg_rect_interpolation_type.cc
  236. svg_rect_interpolation_type.h
  237. svg_transform_list_interpolation_type.cc
  238. svg_transform_list_interpolation_type.h
  239. svg_value_interpolation_type.cc
  240. svg_value_interpolation_type.h
  241. test_data/
  242. timing.cc
  243. timing.h
  244. timing_calculations.h
  245. timing_calculations_test.cc
  246. timing_input.cc
  247. timing_input.h
  248. timing_input_test.cc
  249. transition_interpolation.cc
  250. transition_interpolation.h
  251. transition_keyframe.cc
  252. transition_keyframe.h
  253. typed_interpolation_value.h
  254. underlying_length_checker.h
  255. underlying_value_owner.cc
  256. underlying_value_owner.h
  257. worklet_animation_base.h
  258. worklet_animation_controller.cc
  259. worklet_animation_controller.h
third_party/blink/renderer/core/animation/README.md

Source/core/animation

This directory contains the main thread animation engine. This implements the Web Animations timing model that drives CSS Animations, Transitions and exposes the Web Animations API (element.animate()) to Javascript.

Contacts

As of 2018 Blink animations is maintained by the cc/ team.

Specifications Implemented

Integration with Chromium

The Blink animation engine interacts with Blink/Chrome in the following ways:

  • Chromium's Compositor

    Chromium‘s compositor has a separate, more lightweight animation engine that runs separate to the main thread. Blink’s animation engine delegates animations to the compositor where possible for better performance and power utilisation.

    Compositable animations

    A subset of style properties (currently transform, opacity, filter, and backdrop-filter) can be mutated on the compositor thread. Animations that mutates only these properties are a candidate for being accelerated and run on compositor thread which ensures they are isolated from Blink's main thread work.

    Whether or not an animation can be accelerated is determined by CheckCanStartAnimationOnCompositor() which looks at several aspects such as the composite mode, other animations affecting same property, and whether the target element can be promoted and mutated in compositor.
    Reasons for not compositing animations are captured in FailureCodes.

    Lifetime of a compositor animation

    Animations that can be accelerated get added to the PendingAnimations list. The pending list is updates as part of document lifecycle and ensures each pending animation gets a corresponding cc::AnimationPlayer representing the animation on the compositor. The player is initialized with appropriate timing values and corresponding effects.

    Note that changing that animation playback rate, start time, or effect, simply adds the animation back on to the pending list and causes the compositor animation to be cancelled and a new one to be started. See Animation::PreCommit() for more details.

    An accelerated animation is still running on main thread ensuring that its effective output is reflected in the Element style. So while the compositor animation updates the visuals the main thread animation updates the computed style. There is a special case logic to ensure updates from such accelerated animations do not cause spurious commits from main to compositor (See CompositedLayerMapping::UpdateGraphicsLayerGeometry())

    A compositor animation provide updates on its playback state changes (e.g., on start, finish, abort) to its blink counterpart via CompositorAnimationDelegate interface. Blink animation uses the start event callback to obtain an accurate start time for the animation which is important to ensure its output accurately reflects the compositor animation output.

  • Javascript

    EffectInput contains the helper functions that are used to process a keyframe argument which can take an argument of either object or array form.

    PlayStateUpdateScope: whenever there is a mutation to the animation engine from JS level, this gets created and the destructor has the logic that handles everything. It keeps the old and new state of the animation, checks the difference and mutate the properties of the animation, at the end it calls SetOutdatedAnimation() to inform the animation timeline that the time state of this animation is dirtied.

    There are a couple of other integration points that are less critical to everyday browsing:

  • DevTools

    The animations timeline uses InspectorAnimationAgent to track all active animations. This class has interfaces for pausing, adjusting DocumentTimeline playback rate, and seeking animations.

    InspectorAnimationAgent clones the inspected animation in order to avoid firing animation events, and suppresses the effects of the original animation. From this point on, modifications can be made to the cloned animation without having any effect on the underlying animation or its listeners.

  • SVG

    The element.animate() API supports targeting SVG attributes in its keyframes. This is an experimental implementation guarded by the WebAnimationsSVG flag and not exposed on the web.

    This feature should provide a high fidelity alternative to our SMIL implementation.

Architecture

Animation Timing Model

The animation engine is built around the timing model described in the Web Animations spec.

This describes a hierarchy of entities:

  • DocumentTimeline: Represents the wall clock time.
    • Animation: Represents an individual animation and when it started playing.
      • AnimationEffect: Represents the effect an animation has during the animation (e.g. updating an element's color property).

Time trickles down from the DocumentTimeline and is transformed at each stage to produce some progress fraction that can be used to apply the effects of the animations.

For example:

// Page was loaded at 2:00:00PM, the time is currently 2:00:10PM.
// document.timeline.currentTime is currently 10000 (10 seconds).

let animation = element.animate([
    {transform: 'none'},
    {transform: 'rotate(200deg)'},
  ], {
    duration: 20000,  // 20 seconds
  });

animation.startTime = 6000;  // 6 seconds
  • DocumentTimeline notifies that the time is 10 seconds.
    • Animation computes that its currentTime is 4 seconds due to its startTime being at 6 seconds.
      • AnimationEffect has a duration of 20 seconds and computes that it has a progress of 20% from the parent animation being 4 seconds into the animation.

        The effect is animating an element from transform: none to transform: rotate(200deg) so it computes the current effect to be transfrom: rotate(40deg).

Lifecycle of an Animation

  1. An Animation is created via CSS1 or element.animate().
  2. At the start of the next frame the Animation and its AnimationEffect are updated with the currentTime of the DocumentTimeline.
  3. The AnimationEffect gets sampled with its computed localTime, pushes a SampledEffect into its target element's EffectStack and marks the elements style as dirty to ensure it gets updated later in the document lifecycle.
  4. During the next style resolve on the target element all the SampledEffects in its EffectStack are incorporated into building the element's ComputedStyle.

One key takeaway here is to note that timing updates are done in a separate phase to effect application. Effect application must occur during style resolution which is a highly complex process with a well defined place in the document lifecycle. Updates to animation timing will request style updates rather than invoke them directly.

1 CSS animations and transitions are actually created/destroyed during style resolve (step 4). There is special logic for forcing these animations to have their timing updated and their effects included in the same style resolve. An unfortunate side effect of this is that style resolution can cause style to get dirtied, this is currently a code health bug.

KeyframeEffect

Currently all animations use KeyframeEffect for their AnimationEffect. The generic AnimationEffect from which it inherits is an extention point in Web Animations where other kinds of animation effects can be defined later by other specs (for example Javascript callback based effects).

Structure of a KeyframeEffect

  • KeyframeEffect represents the effect an animation has (without any details of when it started or whether it's playing) and is comprised of three things:
    • Some Timing information (inherited from AnimationEffect).
      Example:

      {
        duration: 4000,
        easing: 'ease-in-out',
        iterations: 8,
        direction: 'alternate',
      }
      

      This is used to compute the percentage progress of the effect given the duration of time that the animation has been playing for.

    • The DOM Element that is being animated.

    • A KeyframeEffectModel that holds a sequence of keyframes to specify the properties being animated and what values they pass through.
      Example:

      [
        {backgroundColor: 'red', transform: 'rotate(0deg)'},
        {backgroundColor: 'yellow'},
        {backgroundColor: 'lime'},
        {backgroundColor: 'blue'},
        {backgroundColor: 'red', transform: 'rotate(360deg)'},
      ]
      

      These keyframes are used to compute:

      • A PropertySpecificKeyframe map that simply breaks up the input multi-property keyframes into per-property keyframe lists.
      • An InterpolationEffect which holds a set of Interpolations, each one representing the animated values between adjacent pairs of PropertySpecificKeyframes, and where in the percentage progress they are active.
        In the example keyframes above the [Interpolations][] generated would include, among the 5 different property specific keyframe pairs, one for backgroundColor: 'red' to backgroundColor: 'yellow' that applied from 0% to 25% and one for transform: 'rotate(0deg)' to transform: 'rotate(360deg)' that applied from 0% to 100%.

Lifecycle of an Interpolation

Interpolation is the data structure that style resolution uses to resolve what animated value to apply to an animated element's ComputedStyle.

  1. Interpolations are lazily instantiated prior to sampling.
  2. KeyframeEffectModels are sampled every frame (or as necessary) for a stack of Interpolations to apply to the associated Element and stashed away in the Element‘s ElementAnimationsEffectStack's SampledEffects.
  3. During style resolution on the target Element all the Interpolations are collected and organised by category according to whether it's a transition or not (transitions in Blink are suppressed in the presence of non-transition animations on the same property) and whether it affects custom properties or not (animated custom properties are animation-tainted and affect the processing of animation properties.
  4. TODO(alancutter): Describe what happens in processing a stack of interpolations.

Testing pointers

Test new animation features using end to end web-platform-tests to ensure cross-browser interoperability. Use unit testing when access to chrome internals is required. Test chrome specific features such as compositing of animation using LayoutTests or unit tests.

End to end testing

Features in the Web Animations spec are tested in web-animations. Writing web platform tests has pointers for how to get started. If Chrome does not correctly implement the spec, add a corresponding -expected.txt file with your test listing the expected failure in Chrome.

Layout tests are located in third_party/WebKit/LayoutTests. These should be written when needing end to end testing but either when testing chrome specific features (i.e. non-standardized) such as compositing or when the test requires access to chrome internal features not easily tested by web-platform-tests.

Unit testing

Unit testing of animations can range from extending Test when you will manually construct an instance of your object to extending RenderingTest where you can load HTML, enable compositing if necessary, and run assertions about the state.

Ongoing work

Properties And Values API

TODO: Summarize properties and values API.

Web Animations API

TODO: Summarize Web Animations API.

Animation Worklet

AnimationWorklet is a new primitive for creating high performance procedural animations on the web. It is being incubated as part of the CSS Houdini task force, and if successful will be transferred to that task force for full standardization.

A WorkletAnimation behaves and exposes the same animation interface as other web animation but it allows the animation itself to be highly customized in Javascript by providing an animate callback. These animations run inside an isolated worklet global scope.