Bug 1919083 - [ci] Enable os-integration variant for more suites, r=jmaher
[gecko.git] / gfx / layers / AnimationInfo.h
blob8c2a8f68adc1ce3f61244beede5bf4679f653879
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 GFX_ANIMATIONINFO_H
8 #define GFX_ANIMATIONINFO_H
10 #include "nsCSSPropertyIDSet.h"
11 #include "nsDisplayItemTypes.h"
12 #include "mozilla/Array.h"
13 #include "mozilla/UniquePtr.h"
14 #include "mozilla/FunctionRef.h"
15 #include "mozilla/layers/AnimationStorageData.h"
16 #include "mozilla/layers/LayersMessages.h" // for TransformData
18 struct RawServoAnimationValue;
19 class nsIContent;
20 class nsIFrame;
22 namespace mozilla {
24 class nsDisplayItem;
25 class nsDisplayListBuilder;
26 class EffectSet;
27 struct AnimationProperty;
29 namespace dom {
30 class Animation;
31 } // namespace dom
33 namespace gfx {
34 class Path;
35 } // namespace gfx
37 namespace layers {
39 class Animation;
40 class CompositorAnimations;
41 class Layer;
42 class WebRenderLayerManager;
43 struct CompositorAnimationData;
44 struct PropertyAnimationGroup;
46 class AnimationInfo final {
47 typedef nsTArray<Animation> AnimationArray;
49 public:
50 AnimationInfo();
51 ~AnimationInfo();
53 // Ensure that this AnimationInfo has a valid (non-zero) animations id. This
54 // value is unique across layers.
55 void EnsureAnimationsId();
57 // Call AddAnimation to add a new animation to this layer from layout code.
58 // Caller must fill in all the properties of the returned animation.
59 // A later animation overrides an earlier one.
60 Animation* AddAnimation();
62 // These are a parallel to AddAnimation and clearAnimations, except
63 // they add pending animations that apply only when the next
64 // transaction is begun. (See also
65 // SetBaseTransformForNextTransaction.)
66 Animation* AddAnimationForNextTransaction();
68 void SetAnimationGeneration(uint64_t aCount) {
69 mAnimationGeneration = Some(aCount);
71 Maybe<uint64_t> GetAnimationGeneration() const {
72 return mAnimationGeneration;
75 // ClearAnimations clears animations on this layer.
76 void ClearAnimations();
77 void ClearAnimationsForNextTransaction();
78 uint64_t GetCompositorAnimationsId() { return mCompositorAnimationsId; }
79 // Note: We don't set mAnimations on the compositor thread, so this will
80 // always return an empty array on the compositor thread.
81 AnimationArray& GetAnimations() { return mAnimations; }
82 nsTArray<PropertyAnimationGroup>& GetPropertyAnimationGroups() {
83 return mStorageData.mAnimation;
85 const Maybe<TransformData>& GetTransformData() const {
86 return mStorageData.mTransformData;
88 const LayersId& GetLayersId() const { return mStorageData.mLayersId; }
89 bool ApplyPendingUpdatesForThisTransaction();
90 bool HasTransformAnimation() const;
92 gfx::Path* CachedMotionPath() { return mStorageData.mCachedMotionPath; }
94 // In case of continuation, |aFrame| must be the first or the last
95 // continuation frame, otherwise this function might return Nothing().
96 static Maybe<uint64_t> GetGenerationFromFrame(
97 nsIFrame* aFrame, DisplayItemType aDisplayItemKey);
99 using CompositorAnimatableDisplayItemTypes =
100 Array<DisplayItemType,
101 nsCSSPropertyIDSet::CompositorAnimatableDisplayItemCount()>;
102 using AnimationGenerationCallback = FunctionRef<bool(
103 const Maybe<uint64_t>& aGeneration, DisplayItemType aDisplayItemType)>;
104 // Enumerates animation generations on |aFrame| for the given display item
105 // types and calls |aCallback| with the animation generation.
107 // The enumeration stops if |aCallback| returns false.
108 static void EnumerateGenerationOnFrame(
109 const nsIFrame* aFrame, const nsIContent* aContent,
110 const CompositorAnimatableDisplayItemTypes& aDisplayItemTypes,
111 AnimationGenerationCallback);
113 void AddAnimationsForDisplayItem(
114 nsIFrame* aFrame, nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem,
115 DisplayItemType aType, WebRenderLayerManager* aLayerManager,
116 const Maybe<LayoutDevicePoint>& aPosition = Nothing());
118 private:
119 enum class Send {
120 NextTransaction,
121 Immediate,
123 void AddAnimationForProperty(nsIFrame* aFrame,
124 const AnimationProperty& aProperty,
125 dom::Animation* aAnimation,
126 const Maybe<TransformData>& aTransformData,
127 Send aSendFlag);
129 bool AddAnimationsForProperty(
130 nsIFrame* aFrame, const EffectSet* aEffects,
131 const nsTArray<RefPtr<dom::Animation>>& aCompositorAnimations,
132 const Maybe<TransformData>& aTransformData, nsCSSPropertyID aProperty,
133 Send aSendFlag, WebRenderLayerManager* aLayerManager);
135 void AddNonAnimatingTransformLikePropertiesStyles(
136 const nsCSSPropertyIDSet& aNonAnimatingProperties, nsIFrame* aFrame,
137 Send aSendFlag);
139 void MaybeStartPendingAnimation(Animation&, const TimeStamp& aReadyTime);
141 // mAnimations (and mPendingAnimations) are only set on the main thread.
143 // Once the animations are received on the compositor thread/process we
144 // use AnimationHelper::ExtractAnimations to transform the rather compact
145 // representation of animation data we transfer into something we can more
146 // readily use for sampling and then store it in mPropertyAnimationGroups
147 // (below) or CompositorAnimationStorage.mAnimations for WebRender.
148 AnimationArray mAnimations;
149 UniquePtr<AnimationArray> mPendingAnimations;
151 uint64_t mCompositorAnimationsId;
152 // The extracted data produced by AnimationHelper::ExtractAnimations().
153 AnimationStorageData mStorageData;
154 // If this layer is used for OMTA, then this counter is used to ensure we
155 // stay in sync with the animation manager
156 Maybe<uint64_t> mAnimationGeneration;
157 bool mMutated;
160 } // namespace layers
161 } // namespace mozilla
163 #endif // GFX_ANIMATIONINFO_H