Bug 1568876 - Make copyRule in the ChangesView fission compatible. r=rcaliman
[gecko.git] / gfx / layers / AnimationInfo.h
blobbc9bae3fc373e327a410fa533eca8768ea98c9d7
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 "nsAutoPtr.h"
11 #include "nsCSSPropertyIDSet.h"
12 #include "nsDisplayItemTypes.h"
13 #include "mozilla/Array.h"
15 struct RawServoAnimationValue;
16 class nsIContent;
17 class nsIFrame;
19 namespace mozilla {
20 namespace layers {
22 class Animation;
23 class CompositorAnimations;
24 class Layer;
25 class LayerManager;
26 struct PropertyAnimationGroup;
28 class AnimationInfo final {
29 typedef nsTArray<Animation> AnimationArray;
31 public:
32 AnimationInfo();
33 ~AnimationInfo();
35 // Ensure that this AnimationInfo has a valid (non-zero) animations id. This
36 // value is unique across layers.
37 void EnsureAnimationsId();
39 // Call AddAnimation to add a new animation to this layer from layout code.
40 // Caller must fill in all the properties of the returned animation.
41 // A later animation overrides an earlier one.
42 Animation* AddAnimation();
44 // These are a parallel to AddAnimation and clearAnimations, except
45 // they add pending animations that apply only when the next
46 // transaction is begun. (See also
47 // SetBaseTransformForNextTransaction.)
48 Animation* AddAnimationForNextTransaction();
50 void SetAnimationGeneration(uint64_t aCount) {
51 mAnimationGeneration = Some(aCount);
53 Maybe<uint64_t> GetAnimationGeneration() const {
54 return mAnimationGeneration;
57 // ClearAnimations clears animations on this layer.
58 void ClearAnimations();
59 void ClearAnimationsForNextTransaction();
60 void SetCompositorAnimations(
61 const CompositorAnimations& aCompositorAnimations);
62 bool StartPendingAnimations(const TimeStamp& aReadyTime);
63 void TransferMutatedFlagToLayer(Layer* aLayer);
65 uint64_t GetCompositorAnimationsId() { return mCompositorAnimationsId; }
66 // Note: We don't set mAnimations on the compositor thread, so this will
67 // always return an empty array on the compositor thread.
68 AnimationArray& GetAnimations() { return mAnimations; }
69 nsTArray<PropertyAnimationGroup>& GetPropertyAnimationGroups() {
70 return mPropertyAnimationGroups;
72 bool ApplyPendingUpdatesForThisTransaction();
73 bool HasTransformAnimation() const;
75 // In case of continuation, |aFrame| must be the first or the last
76 // continuation frame, otherwise this function might return Nothing().
77 static Maybe<uint64_t> GetGenerationFromFrame(
78 nsIFrame* aFrame, DisplayItemType aDisplayItemKey);
80 using CompositorAnimatableDisplayItemTypes =
81 Array<DisplayItemType,
82 nsCSSPropertyIDSet::CompositorAnimatableDisplayItemCount()>;
83 using AnimationGenerationCallback = std::function<bool(
84 const Maybe<uint64_t>& aGeneration, DisplayItemType aDisplayItemType)>;
85 // Enumerates animation generations on |aFrame| for the given display item
86 // types and calls |aCallback| with the animation generation.
88 // The enumeration stops if |aCallback| returns false.
89 static void EnumerateGenerationOnFrame(
90 const nsIFrame* aFrame, const nsIContent* aContent,
91 const CompositorAnimatableDisplayItemTypes& aDisplayItemTypes,
92 const AnimationGenerationCallback& aCallback);
94 protected:
95 // mAnimations (and mPendingAnimations) are only set on the main thread.
97 // Once the animations are received on the compositor thread/process we
98 // use AnimationHelper::ExtractAnimations to transform the rather compact
99 // representation of animation data we transfer into something we can more
100 // readily use for sampling and then store it in mPropertyAnimationGroups
101 // (below) or CompositorAnimationStorage.mAnimations for WebRender.
102 AnimationArray mAnimations;
103 nsAutoPtr<AnimationArray> mPendingAnimations;
105 uint64_t mCompositorAnimationsId;
106 // The extracted data produced by AnimationHelper::ExtractAnimations().
108 // Each entry in the array represents an animation list for one property. For
109 // transform-like properties (e.g. transform, rotate etc.), there may be
110 // multiple entries depending on how many transform-like properties we have.
111 nsTArray<PropertyAnimationGroup> mPropertyAnimationGroups;
112 // If this layer is used for OMTA, then this counter is used to ensure we
113 // stay in sync with the animation manager
114 Maybe<uint64_t> mAnimationGeneration;
115 bool mMutated;
118 } // namespace layers
119 } // namespace mozilla
121 #endif // GFX_ANIMATIONINFO_H