AnimationInfo.h (5915B)
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/. */ 6 7 #ifndef GFX_ANIMATIONINFO_H 8 #define GFX_ANIMATIONINFO_H 9 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 17 18 struct RawServoAnimationValue; 19 class nsIContent; 20 class nsIFrame; 21 22 namespace mozilla { 23 24 class nsDisplayItem; 25 class nsDisplayListBuilder; 26 class EffectSet; 27 struct AnimationProperty; 28 29 namespace dom { 30 class Animation; 31 } // namespace dom 32 33 namespace gfx { 34 class Path; 35 } // namespace gfx 36 37 namespace layers { 38 39 class Animation; 40 class CompositorAnimations; 41 class Layer; 42 class WebRenderLayerManager; 43 struct CompositorAnimationData; 44 struct PropertyAnimationGroup; 45 46 class AnimationInfo final { 47 typedef nsTArray<Animation> AnimationArray; 48 49 public: 50 AnimationInfo(); 51 ~AnimationInfo(); 52 53 // Ensure that this AnimationInfo has a valid (non-zero) animations id. This 54 // value is unique across layers. 55 void EnsureAnimationsId(); 56 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(); 61 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(); 67 68 void SetAnimationGeneration(uint64_t aCount) { 69 mAnimationGeneration = Some(aCount); 70 } 71 Maybe<uint64_t> GetAnimationGeneration() const { 72 return mAnimationGeneration; 73 } 74 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; 84 } 85 const Maybe<TransformData>& GetTransformData() const { 86 return mStorageData.mTransformData; 87 } 88 const LayersId& GetLayersId() const { return mStorageData.mLayersId; } 89 bool ApplyPendingUpdatesForThisTransaction(); 90 bool HasTransformAnimation() const; 91 92 gfx::Path* CachedMotionPath() { return mStorageData.mCachedMotionPath; } 93 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); 98 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. 106 // 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); 112 113 void AddAnimationsForDisplayItem( 114 nsIFrame* aFrame, nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem, 115 DisplayItemType aType, WebRenderLayerManager* aLayerManager, 116 const Maybe<LayoutDevicePoint>& aPosition = Nothing()); 117 118 private: 119 enum class Send { 120 NextTransaction, 121 Immediate, 122 }; 123 void AddAnimationForProperty(nsIFrame* aFrame, 124 const AnimationProperty& aProperty, 125 dom::Animation* aAnimation, 126 const Maybe<TransformData>& aTransformData, 127 Send aSendFlag); 128 129 bool AddAnimationsForProperty( 130 nsIFrame* aFrame, const EffectSet* aEffects, 131 const nsTArray<RefPtr<dom::Animation>>& aCompositorAnimations, 132 const Maybe<TransformData>& aTransformData, 133 NonCustomCSSPropertyId aProperty, Send aSendFlag, 134 WebRenderLayerManager* aLayerManager); 135 136 void AddNonAnimatingTransformLikePropertiesStyles( 137 const nsCSSPropertyIDSet& aNonAnimatingProperties, nsIFrame* aFrame, 138 Send aSendFlag); 139 140 void MaybeStartPendingAnimation(Animation&, const TimeStamp& aReadyTime); 141 142 // mAnimations (and mPendingAnimations) are only set on the main thread. 143 // 144 // Once the animations are received on the compositor thread/process we 145 // use AnimationHelper::ExtractAnimations to transform the rather compact 146 // representation of animation data we transfer into something we can more 147 // readily use for sampling and then store it in mPropertyAnimationGroups 148 // (below) or CompositorAnimationStorage.mAnimations for WebRender. 149 AnimationArray mAnimations; 150 UniquePtr<AnimationArray> mPendingAnimations; 151 152 uint64_t mCompositorAnimationsId; 153 // The extracted data produced by AnimationHelper::ExtractAnimations(). 154 AnimationStorageData mStorageData; 155 // If this layer is used for OMTA, then this counter is used to ensure we 156 // stay in sync with the animation manager 157 Maybe<uint64_t> mAnimationGeneration; 158 bool mMutated; 159 }; 160 161 } // namespace layers 162 } // namespace mozilla 163 164 #endif // GFX_ANIMATIONINFO_H