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

Web tests are located in third_party/blink/web_tests. 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.