Bug 1690340 - Part 2: Use the new naming for the developer tools menu items. r=jdescottes
[gecko.git] / gfx / layers / AnimationHelper.h
blobf5a57b9c4d0a9ceda5ab7593a171e34eb60fc38d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_layers_AnimationHelper_h
8 #define mozilla_layers_AnimationHelper_h
10 #include "mozilla/dom/Nullable.h"
11 #include "mozilla/ComputedTimingFunction.h" // for ComputedTimingFunction
12 #include "mozilla/layers/AnimationStorageData.h"
13 #include "mozilla/layers/LayersMessages.h" // for TransformData, etc
14 #include "mozilla/webrender/WebRenderTypes.h" // for RenderRoot
15 #include "mozilla/TimeStamp.h" // for TimeStamp
16 #include "mozilla/TimingParams.h"
17 #include "mozilla/Types.h" // for SideBits
18 #include "X11UndefineNone.h"
19 #include <unordered_map>
21 namespace mozilla {
22 namespace layers {
23 class Animation;
24 class CompositorAnimationStorage;
25 struct AnimatedValue;
27 typedef nsTArray<layers::Animation> AnimationArray;
29 /**
30 * This utility class allows reusing code between the webrender and
31 * non-webrender compositor-side implementations. It provides
32 * utility functions for sampling animations at particular timestamps.
34 class AnimationHelper {
35 public:
36 enum class SampleResult { None, Skipped, Sampled };
38 /**
39 * Sample animations based on a given time stamp for a element(layer) with
40 * its animation data.
41 * Generally |aPreviousFrameTime| is used for the sampling if it's
42 * supplied to make the animation more in sync with other animations on the
43 * main-thread. But in the case where the animation just started at the time
44 * when the animation was sent to the compositor, |aCurrentFrameTime| is used
45 * for sampling instead to avoid flicker.
47 * Returns SampleResult::None if none of the animations are producing a result
48 * (e.g. they are in the delay phase with no backwards fill),
49 * SampleResult::Skipped if the animation output did not change since the last
50 * call of this function,
51 * SampleResult::Sampled if the animation output was updated.
53 * Using the same example from ExtractAnimations (below):
55 * Input |aPropertyAnimationGroups| (ignoring the base animation style):
57 * [
58 * Group A: [ { rotate, Animation A }, { rotate, Animation B } ],
59 * Group B: [ { scale, Animation B } ],
60 * Group C: [ { transform, Animation A }, { transform, Animation B } ],
61 * ]
63 * For each property group, this function interpolates each animation in turn,
64 * using the result of interpolating one animation as input for the next such
65 * that it reduces each property group to a single output value:
67 * [
68 * { rotate, RawServoAnimationValue },
69 * { scale, RawServoAnimationValue },
70 * { transform, RawServoAnimationValue },
71 * ]
73 * For transform animations, the caller (SampleAnimations) will combine the
74 * result of the various transform properties into a final matrix.
76 static SampleResult SampleAnimationForEachNode(
77 TimeStamp aPreviousFrameTime, TimeStamp aCurrentFrameTime,
78 const AnimatedValue* aPreviousValue,
79 nsTArray<PropertyAnimationGroup>& aPropertyAnimationGroups,
80 nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues);
82 /**
83 * Extract organized animation data by property into an array of
84 * PropertyAnimationGroup objects.
86 * For example, suppose we have the following animations:
88 * Animation A: [ transform, rotate ]
89 * Animation B: [ rotate, scale ]
90 * Animation C: [ transform ]
91 * Animation D: [ opacity ]
93 * When we go to send transform-like properties to the compositor, we
94 * sort them as follows:
96 * [
97 * { rotate: Animation A (rotate segments only) },
98 * { rotate: Animation B ( " " ) },
99 * { scale: Animation B (scale segments only) },
100 * { transform: Animation A (transform segments only) },
101 * { transform: Animation C ( " " ) },
104 * In this function, we group these animations together by property producing
105 * output such as the following:
108 * [ { rotate, Animation A }, { rotate, Animation B } ],
109 * [ { scale, Animation B } ],
110 * [ { transform, Animation A }, { transform, Animation B } ],
113 * In the process of grouping these animations, we also convert their values
114 * from the rather compact representation we use for transferring across the
115 * IPC boundary into something we can readily use for sampling.
117 static AnimationStorageData ExtractAnimations(
118 const LayersId& aLayersId, const AnimationArray& aAnimations);
121 * Get a unique id to represent the compositor animation between child
122 * and parent side. This id will be used as a key to store animation
123 * data in the CompositorAnimationStorage per compositor.
124 * Each layer on the content side calls this when it gets new animation
125 * data.
127 static uint64_t GetNextCompositorAnimationsId();
130 * Convert an array of animation values into a matrix given the corresponding
131 * transform parameters. |aValue| must be a transform-like value
132 * (e.g. transform, translate etc.).
134 static gfx::Matrix4x4 ServoAnimationValueToMatrix4x4(
135 const nsTArray<RefPtr<RawServoAnimationValue>>& aValue,
136 const TransformData& aTransformData, gfx::Path* aCachedMotionPath);
139 * Returns true if |aPrerenderedRect| transformed by |aTransform| were
140 * composited in |aClipRect| there appears area which wasn't pre-rendered
141 * on the main-thread. I.e. checkerboarding.
143 static bool ShouldBeJank(const LayoutDeviceRect& aPrerenderedRect,
144 SideBits aOverflowedSides,
145 const gfx::Matrix4x4& aTransform,
146 const ParentLayerRect& aClipRect);
149 } // namespace layers
150 } // namespace mozilla
152 #endif // mozilla_layers_AnimationHelper_h