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 mozilla_layers_AnimationStorageData_h 8 #define mozilla_layers_AnimationStorageData_h 9 10 #include "mozilla/dom/Nullable.h" 11 #include "mozilla/ComputedTimingFunction.h" // for ComputedTimingFunction 12 #include "mozilla/layers/LayersMessages.h" // for TransformData, etc 13 #include "mozilla/TimeStamp.h" // for TimeStamp 14 #include "mozilla/TimingParams.h" 15 #include "X11UndefineNone.h" 16 17 namespace mozilla { 18 19 namespace dom { 20 enum class CompositeOperation : uint8_t; 21 enum class IterationCompositeOperation : uint8_t; 22 }; // namespace dom 23 24 namespace layers { 25 26 struct PropertyAnimation { 27 struct SegmentData { 28 RefPtr<RawServoAnimationValue> mStartValue; 29 RefPtr<RawServoAnimationValue> mEndValue; 30 Maybe<mozilla::ComputedTimingFunction> mFunction; 31 float mStartPortion; 32 float mEndPortion; 33 dom::CompositeOperation mStartComposite; 34 dom::CompositeOperation mEndComposite; 35 }; 36 nsTArray<SegmentData> mSegments; 37 TimingParams mTiming; 38 39 // These two variables correspond to the variables of the same name in 40 // KeyframeEffectReadOnly and are used for the same purpose: to skip composing 41 // animations whose progress has not changed. 42 dom::Nullable<double> mProgressOnLastCompose; 43 uint64_t mCurrentIterationOnLastCompose = 0; 44 // These two variables are used for a similar optimization above but are 45 // applied to the timing function in each keyframe. 46 uint32_t mSegmentIndexOnLastCompose = 0; 47 dom::Nullable<double> mPortionInSegmentOnLastCompose; 48 49 TimeStamp mOriginTime; 50 Maybe<TimeDuration> mStartTime; 51 TimeDuration mHoldTime; 52 float mPlaybackRate; 53 dom::IterationCompositeOperation mIterationComposite; 54 bool mIsNotPlaying; 55 }; 56 57 struct PropertyAnimationGroup { 58 nsCSSPropertyID mProperty; 59 60 nsTArray<PropertyAnimation> mAnimations; 61 RefPtr<RawServoAnimationValue> mBaseStyle; 62 IsEmptyPropertyAnimationGroup63 bool IsEmpty() const { return mAnimations.IsEmpty(); } ClearPropertyAnimationGroup64 void Clear() { 65 mAnimations.Clear(); 66 mBaseStyle = nullptr; 67 } 68 }; 69 70 struct AnimationStorageData { 71 // Each entry in the array represents an animation list for one property. For 72 // transform-like properties (e.g. transform, rotate etc.), there may be 73 // multiple entries depending on how many transform-like properties we have. 74 nsTArray<PropertyAnimationGroup> mAnimation; 75 Maybe<TransformData> mTransformData; 76 // For motion path. We cached the gfx path for optimization. 77 RefPtr<gfx::Path> mCachedMotionPath; 78 79 AnimationStorageData() = default; 80 AnimationStorageData(AnimationStorageData&& aOther) = default; 81 AnimationStorageData& operator=(AnimationStorageData&& aOther) = default; 82 83 // Avoid any copy because mAnimation could be a large array. 84 AnimationStorageData(const AnimationStorageData& aOther) = delete; 85 AnimationStorageData& operator=(const AnimationStorageData& aOther) = delete; 86 IsEmptyAnimationStorageData87 bool IsEmpty() const { return mAnimation.IsEmpty(); } ClearAnimationStorageData88 void Clear() { 89 mAnimation.Clear(); 90 mTransformData.reset(); 91 mCachedMotionPath = nullptr; 92 } 93 }; 94 95 } // namespace layers 96 } // namespace mozilla 97 98 #endif // mozilla_layers_AnimationStorageData_h 99