tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

AnimationStorageData.h (4102B)


      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/ServoStyleConsts.h"       // for ComputedTimingFunction
     12 #include "mozilla/layers/LayersMessages.h"  // for TransformData, etc
     13 #include "mozilla/layers/LayersTypes.h"     // for LayersId
     14 #include "mozilla/TimeStamp.h"              // for TimeStamp
     15 #include "mozilla/TimingParams.h"
     16 #include "X11UndefineNone.h"
     17 
     18 namespace mozilla {
     19 
     20 namespace dom {
     21 enum class CompositeOperation : uint8_t;
     22 enum class IterationCompositeOperation : uint8_t;
     23 };  // namespace dom
     24 
     25 namespace layers {
     26 
     27 struct PropertyAnimation {
     28  struct SegmentData {
     29    RefPtr<StyleAnimationValue> mStartValue;
     30    RefPtr<StyleAnimationValue> mEndValue;
     31    Maybe<mozilla::StyleComputedTimingFunction> mFunction;
     32    float mStartPortion;
     33    float mEndPortion;
     34    dom::CompositeOperation mStartComposite;
     35    dom::CompositeOperation mEndComposite;
     36  };
     37  nsTArray<SegmentData> mSegments;
     38  TimingParams mTiming;
     39 
     40  // These two variables correspond to the variables of the same name in
     41  // KeyframeEffectReadOnly and are used for the same purpose: to skip composing
     42  // animations whose progress has not changed.
     43  dom::Nullable<double> mProgressOnLastCompose;
     44  uint64_t mCurrentIterationOnLastCompose = 0;
     45  // These two variables are used for a similar optimization above but are
     46  // applied to the timing function in each keyframe.
     47  uint32_t mSegmentIndexOnLastCompose = 0;
     48  dom::Nullable<double> mPortionInSegmentOnLastCompose;
     49 
     50  TimeStamp mOriginTime;
     51  Maybe<TimeDuration> mStartTime;
     52  TimeDuration mHoldTime;
     53  float mPlaybackRate;
     54  dom::IterationCompositeOperation mIterationComposite;
     55  bool mIsNotPlaying;
     56 
     57  // The information for scroll-driven animations.
     58  Maybe<ScrollTimelineOptions> mScrollTimelineOptions;
     59 
     60  void ResetLastCompositionValues() {
     61    mCurrentIterationOnLastCompose = 0;
     62    mSegmentIndexOnLastCompose = 0;
     63    mProgressOnLastCompose.SetNull();
     64    mPortionInSegmentOnLastCompose.SetNull();
     65  }
     66 };
     67 
     68 struct PropertyAnimationGroup {
     69  NonCustomCSSPropertyId mProperty;
     70 
     71  nsTArray<PropertyAnimation> mAnimations;
     72  RefPtr<StyleAnimationValue> mBaseStyle;
     73 
     74  bool IsEmpty() const { return mAnimations.IsEmpty(); }
     75  void Clear() {
     76    mAnimations.Clear();
     77    mBaseStyle = nullptr;
     78  }
     79  void ResetLastCompositionValues() {
     80    for (PropertyAnimation& animation : mAnimations) {
     81      animation.ResetLastCompositionValues();
     82    }
     83  }
     84 };
     85 
     86 struct AnimationStorageData {
     87  // Each entry in the array represents an animation list for one property.  For
     88  // transform-like properties (e.g. transform, rotate etc.), there may be
     89  // multiple entries depending on how many transform-like properties we have.
     90  nsTArray<PropertyAnimationGroup> mAnimation;
     91  Maybe<TransformData> mTransformData;
     92  // For motion path. We cached the gfx path for optimization.
     93  RefPtr<gfx::Path> mCachedMotionPath;
     94  // This is used to communicate with the main-thread. E.g. to tell the fact
     95  // that this animation needs to be pre-rendered again on the main-thread, etc.
     96  LayersId mLayersId;
     97 
     98  AnimationStorageData() = default;
     99  AnimationStorageData(AnimationStorageData&& aOther) = default;
    100  AnimationStorageData& operator=(AnimationStorageData&& aOther) = default;
    101 
    102  // Avoid any copy because mAnimation could be a large array.
    103  AnimationStorageData(const AnimationStorageData& aOther) = delete;
    104  AnimationStorageData& operator=(const AnimationStorageData& aOther) = delete;
    105 
    106  bool IsEmpty() const { return mAnimation.IsEmpty(); }
    107  void Clear() {
    108    mAnimation.Clear();
    109    mTransformData.reset();
    110    mCachedMotionPath = nullptr;
    111  }
    112 };
    113 
    114 }  // namespace layers
    115 }  // namespace mozilla
    116 
    117 #endif  // mozilla_layers_AnimationStorageData_h