Bug 1455155 - Drop AnimationValue usage in gfx/. r=birtles
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 19 Apr 2018 13:50:14 +0900
changeset 467944 64bb57f4a03a8149e15b605f111b7e4bb4d22b40
parent 467943 ec79f317c9d7b58e6e67d845007325db51df535a
child 467945 25d665693e38463818f4387657643cc193ffed69
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1455155
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1455155 - Drop AnimationValue usage in gfx/. r=birtles Two AnimationValue are still used in AnimationPropertySegment since the AnimationPropertySegment is used in compose_animation_segment() which is also invoked on the main-thread, so we will fix it later in a bug that will drop AnimationValue usage on the main-thread side. MozReview-Commit-ID: B086g2qHtZL
gfx/layers/AnimationHelper.cpp
gfx/layers/AnimationHelper.h
gfx/layers/AnimationInfo.h
gfx/layers/Layers.h
gfx/layers/composite/AsyncCompositionManager.cpp
--- a/gfx/layers/AnimationHelper.cpp
+++ b/gfx/layers/AnimationHelper.cpp
@@ -7,16 +7,17 @@
 #include "AnimationHelper.h"
 #include "mozilla/ComputedTimingFunction.h" // for ComputedTimingFunction
 #include "mozilla/dom/AnimationEffectReadOnlyBinding.h" // for dom::FillMode
 #include "mozilla/dom/KeyframeEffectBinding.h" // for dom::IterationComposite
 #include "mozilla/dom/KeyframeEffectReadOnly.h" // for dom::KeyFrameEffectReadOnly
 #include "mozilla/dom/Nullable.h" // for dom::Nullable
 #include "mozilla/layers/CompositorThread.h" // for CompositorThreadHolder
 #include "mozilla/layers/LayerAnimationUtils.h" // for TimingFunctionToComputedTimingFunction
+#include "mozilla/ServoBindings.h" // for Servo_ComposeAnimationSegment, etc
 #include "mozilla/StyleAnimationValue.h" // for StyleAnimationValue, etc
 #include "nsDeviceContext.h"            // for AppUnitsPerCSSPixel
 #include "nsDisplayList.h"              // for nsDisplayTransform, etc
 
 namespace mozilla {
 namespace layers {
 
 void
@@ -134,17 +135,17 @@ CompositorAnimationStorage::SetAnimation
 }
 
 
 void
 AnimationHelper::SampleAnimationForEachNode(
   TimeStamp aTime,
   AnimationArray& aAnimations,
   InfallibleTArray<AnimData>& aAnimationData,
-  AnimationValue& aAnimationValue,
+  RefPtr<RawServoAnimationValue>& aAnimationValue,
   bool& aHasInEffectAnimations)
 {
   MOZ_ASSERT(!aAnimations.IsEmpty(), "Should be called with animations");
 
   // Process in order, since later aAnimations override earlier ones.
   for (size_t i = 0, iEnd = aAnimations.Length(); i < iEnd; ++i) {
     Animation& animation = aAnimations[i];
     AnimData& animData = aAnimationData[i];
@@ -201,33 +202,35 @@ AnimationHelper::SampleAnimationForEachN
     double portion =
       ComputedTimingFunction::GetPortion(animData.mFunctions[segmentIndex],
                                          positionInSegment,
                                      computedTiming.mBeforeFlag);
 
     AnimationPropertySegment animSegment;
     animSegment.mFromKey = 0.0;
     animSegment.mToKey = 1.0;
-    animSegment.mFromValue = animData.mStartValues[segmentIndex];
-    animSegment.mToValue = animData.mEndValues[segmentIndex];
+    animSegment.mFromValue =
+      AnimationValue(animData.mStartValues[segmentIndex]);
+    animSegment.mToValue =
+      AnimationValue(animData.mEndValues[segmentIndex]);
     animSegment.mFromComposite =
       static_cast<dom::CompositeOperation>(segment->startComposite());
     animSegment.mToComposite =
       static_cast<dom::CompositeOperation>(segment->endComposite());
 
     // interpolate the property
     dom::IterationCompositeOperation iterCompositeOperation =
         static_cast<dom::IterationCompositeOperation>(
           animation.iterationComposite());
 
-    aAnimationValue.mServo =
+    aAnimationValue =
       Servo_ComposeAnimationSegment(
         &animSegment,
-        aAnimationValue.mServo,
-        animData.mEndValues.LastElement().mServo,
+        aAnimationValue,
+        animData.mEndValues.LastElement(),
         iterCompositeOperation,
         portion,
         computedTiming.mCurrentIteration).Consume();
     aHasInEffectAnimations = true;
   }
 
 #ifdef DEBUG
   // Sanity check that all of animation data are the same.
@@ -402,48 +405,49 @@ CreateCSSValueList(const InfallibleTArra
   }
   if (aFunctions.Length() == 0) {
     result = new nsCSSValueList();
     result->mValue.SetNoneValue();
   }
   return new nsCSSValueSharedList(result.forget());
 }
 
-static AnimationValue
+static already_AddRefed<RawServoAnimationValue>
 ToAnimationValue(const Animatable& aAnimatable)
 {
-  AnimationValue result;
+  RefPtr<RawServoAnimationValue> result;
 
   switch (aAnimatable.type()) {
     case Animatable::Tnull_t:
       break;
     case Animatable::TArrayOfTransformFunction: {
       const InfallibleTArray<TransformFunction>& transforms =
         aAnimatable.get_ArrayOfTransformFunction();
       auto listOrError = CreateCSSValueList(transforms);
       if (listOrError.isOk()) {
         RefPtr<nsCSSValueSharedList> list = listOrError.unwrap();
         MOZ_ASSERT(list, "Transform list should be non null");
-        result = AnimationValue::Transform(*list);
+        result = Servo_AnimationValue_Transform(*list).Consume();
       }
       break;
     }
     case Animatable::Tfloat:
-      result = AnimationValue::Opacity(aAnimatable.get_float());
+      result = Servo_AnimationValue_Opacity(aAnimatable.get_float()).Consume();
       break;
     default:
       MOZ_ASSERT_UNREACHABLE("Unsupported type");
   }
-  return result;
+  return result.forget();
 }
 
 void
-AnimationHelper::SetAnimations(AnimationArray& aAnimations,
-                               InfallibleTArray<AnimData>& aAnimData,
-                               AnimationValue& aBaseAnimationStyle)
+AnimationHelper::SetAnimations(
+  AnimationArray& aAnimations,
+  InfallibleTArray<AnimData>& aAnimData,
+  RefPtr<RawServoAnimationValue>& aBaseAnimationStyle)
 {
   for (uint32_t i = 0; i < aAnimations.Length(); i++) {
     Animation& animation = aAnimations[i];
     // Adjust fill mode to fill forwards so that if the main thread is delayed
     // in clearing this animation we don't introduce flicker by jumping back to
     // the old underlying value
     switch (static_cast<dom::FillMode>(animation.fillMode())) {
       case dom::FillMode::None:
@@ -458,18 +462,20 @@ AnimationHelper::SetAnimations(Animation
 
     if (animation.baseStyle().type() != Animatable::Tnull_t) {
       aBaseAnimationStyle = ToAnimationValue(animation.baseStyle());
     }
 
     AnimData* data = aAnimData.AppendElement();
     InfallibleTArray<Maybe<ComputedTimingFunction>>& functions =
       data->mFunctions;
-    InfallibleTArray<AnimationValue>& startValues = data->mStartValues;
-    InfallibleTArray<AnimationValue>& endValues = data->mEndValues;
+    InfallibleTArray<RefPtr<RawServoAnimationValue>>& startValues =
+      data->mStartValues;
+    InfallibleTArray<RefPtr<RawServoAnimationValue>>& endValues =
+      data->mEndValues;
 
     const InfallibleTArray<AnimationSegment>& segments = animation.segments();
     for (const AnimationSegment& segment : segments) {
       startValues.AppendElement(ToAnimationValue(segment.startState()));
       endValues.AppendElement(ToAnimationValue(segment.endState()));
 
       TimingFunction tf = segment.sampleFn();
       Maybe<ComputedTimingFunction> ctf =
@@ -506,17 +512,17 @@ AnimationHelper::SampleAnimations(Compos
   for (auto iter = aStorage->ConstAnimationsTableIter();
        !iter.Done(); iter.Next()) {
     bool hasInEffectAnimations = false;
     AnimationArray* animations = iter.UserData();
     if (animations->IsEmpty()) {
       continue;
     }
 
-    AnimationValue animationValue;
+    RefPtr<RawServoAnimationValue> animationValue;
     InfallibleTArray<AnimData> animationData;
     AnimationHelper::SetAnimations(*animations,
                                    animationData,
                                    animationValue);
     AnimationHelper::SampleAnimationForEachNode(aTime,
                                                 *animations,
                                                 animationData,
                                                 animationValue,
@@ -525,22 +531,24 @@ AnimationHelper::SampleAnimations(Compos
     if (!hasInEffectAnimations) {
       continue;
     }
 
     // Store the AnimatedValue
     Animation& animation = animations->LastElement();
     switch (animation.property()) {
       case eCSSProperty_opacity: {
-        aStorage->SetAnimatedValue(iter.Key(), animationValue.GetOpacity());
+        aStorage->SetAnimatedValue(
+          iter.Key(),
+          Servo_AnimationValue_GetOpacity(animationValue));
         break;
       }
       case eCSSProperty_transform: {
-        RefPtr<const nsCSSValueSharedList> list =
-          animationValue.GetTransformList();
+        RefPtr<nsCSSValueSharedList> list;
+        Servo_AnimationValue_GetTransform(animationValue, &list);
         const TransformData& transformData = animation.data().get_TransformData();
         nsPoint origin = transformData.origin();
         // we expect all our transform data to arrive in device pixels
         gfx::Point3D transformOrigin = transformData.transformOrigin();
         nsDisplayTransform::FrameTransformProperties props(Move(list),
                                                            transformOrigin);
 
         gfx::Matrix4x4 transform =
--- a/gfx/layers/AnimationHelper.h
+++ b/gfx/layers/AnimationHelper.h
@@ -15,18 +15,18 @@
 namespace mozilla {
 struct AnimationValue;
 namespace layers {
 class Animation;
 
 typedef InfallibleTArray<layers::Animation> AnimationArray;
 
 struct AnimData {
-  InfallibleTArray<mozilla::AnimationValue> mStartValues;
-  InfallibleTArray<mozilla::AnimationValue> mEndValues;
+  InfallibleTArray<RefPtr<RawServoAnimationValue>> mStartValues;
+  InfallibleTArray<RefPtr<RawServoAnimationValue>> mEndValues;
   InfallibleTArray<Maybe<mozilla::ComputedTimingFunction>> mFunctions;
 };
 
 struct AnimationTransform {
   /*
    * This transform is calculated from sampleanimation in device pixel
    * and used by compositor.
    */
@@ -196,26 +196,26 @@ public:
   /**
    * Sample animations based on a given time stamp for a element(layer) with
    * its animation data.
    */
   static void
   SampleAnimationForEachNode(TimeStamp aTime,
                              AnimationArray& aAnimations,
                              InfallibleTArray<AnimData>& aAnimationData,
-                             AnimationValue& aAnimationValue,
+                             RefPtr<RawServoAnimationValue>& aAnimationValue,
                              bool& aHasInEffectAnimations);
   /**
    * Populates AnimData stuctures into |aAnimData| and |aBaseAnimationStyle|
    * based on |aAnimations|.
    */
   static void
   SetAnimations(AnimationArray& aAnimations,
                 InfallibleTArray<AnimData>& aAnimData,
-                AnimationValue& aBaseAnimationStyle);
+                RefPtr<RawServoAnimationValue>& aBaseAnimationStyle);
 
   /**
    * Get a unique id to represent the compositor animation between child
    * and parent side. This id will be used as a key to store animation
    * data in the CompositorAnimationStorage per compositor.
    * Each layer on the content side calls this when it gets new animation
    * data.
    */
--- a/gfx/layers/AnimationInfo.h
+++ b/gfx/layers/AnimationInfo.h
@@ -2,19 +2,22 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_ANIMATIONINFO_H
 #define GFX_ANIMATIONINFO_H
 
-#include "mozilla/StyleAnimationValue.h"
+#include "nsAutoPtr.h"
 #include "nsDisplayItemTypes.h"
 
+struct RawServoAnimationValue;
+class nsIFrame;
+
 namespace mozilla {
 namespace layers {
 
 class Animation;
 class CompositorAnimations;
 class Layer;
 class LayerManager;
 struct AnimData;
@@ -47,17 +50,20 @@ public:
   // ClearAnimations clears animations on this layer.
   void ClearAnimations();
   void ClearAnimationsForNextTransaction();
   void SetCompositorAnimations(const CompositorAnimations& aCompositorAnimations);
   bool StartPendingAnimations(const TimeStamp& aReadyTime);
   void TransferMutatedFlagToLayer(Layer* aLayer);
 
   uint64_t GetCompositorAnimationsId() { return mCompositorAnimationsId; }
-  AnimationValue GetBaseAnimationStyle() const { return mBaseAnimationStyle; }
+  RawServoAnimationValue* GetBaseAnimationStyle() const
+  {
+    return mBaseAnimationStyle;
+  }
   InfallibleTArray<AnimData>& GetAnimationData() { return mAnimationData; }
   AnimationArray& GetAnimations() { return mAnimations; }
   bool ApplyPendingUpdatesForThisTransaction();
   bool HasOpacityAnimation() const;
   bool HasTransformAnimation() const;
 
   static Maybe<uint64_t> GetGenerationFromFrame(nsIFrame* aFrame,
                                                 DisplayItemType aDisplayItemKey);
@@ -66,16 +72,16 @@ protected:
   LayerManager* mManager;
   AnimationArray mAnimations;
   uint64_t mCompositorAnimationsId;
   nsAutoPtr<AnimationArray> mPendingAnimations;
   InfallibleTArray<AnimData> mAnimationData;
   // If this layer is used for OMTA, then this counter is used to ensure we
   // stay in sync with the animation manager
   uint64_t mAnimationGeneration;
-  AnimationValue mBaseAnimationStyle;
+  RefPtr<RawServoAnimationValue> mBaseAnimationStyle;
   bool mMutated;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif // GFX_ANIMATIONINFO_H
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -20,17 +20,16 @@
 #include "gfx2DGlue.h"
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT_HELPER2, etc
 #include "mozilla/Array.h"
 #include "mozilla/DebugOnly.h"          // for DebugOnly
 #include "mozilla/EventForwards.h"      // for nsPaintEvent
 #include "mozilla/Maybe.h"              // for Maybe
 #include "mozilla/Poison.h"
 #include "mozilla/RefPtr.h"             // for already_AddRefed
-#include "mozilla/StyleAnimationValue.h" // for StyleAnimationValue, etc
 #include "mozilla/TimeStamp.h"          // for TimeStamp, TimeDuration
 #include "mozilla/UniquePtr.h"          // for UniquePtr
 #include "mozilla/gfx/BaseMargin.h"     // for BaseMargin
 #include "mozilla/gfx/BasePoint.h"      // for BasePoint
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/gfx/TiledRegion.h"    // for TiledIntRegion
 #include "mozilla/gfx/Types.h"          // for SurfaceFormat
 #include "mozilla/gfx/UserData.h"       // for UserData, etc
@@ -60,17 +59,16 @@ class nsDisplayListBuilder;
 class nsDisplayItem;
 
 extern uint8_t gLayerManagerLayerBuilder;
 
 namespace mozilla {
 
 class ComputedTimingFunction;
 class FrameLayerBuilder;
-class StyleAnimationValue;
 
 namespace gl {
 class GLContext;
 } // namespace gl
 
 namespace gfx {
 class DrawTarget;
 } // namespace gfx
@@ -1382,17 +1380,17 @@ public:
   uint64_t GetCompositorAnimationsId() { return mAnimationInfo.GetCompositorAnimationsId(); }
   InfallibleTArray<AnimData>& GetAnimationData();
 
   uint64_t GetAnimationGeneration() { return mAnimationInfo.GetAnimationGeneration(); }
 
   bool HasTransformAnimation() const;
   bool HasOpacityAnimation() const;
 
-  AnimationValue GetBaseAnimationStyle() const
+  RawServoAnimationValue* GetBaseAnimationStyle() const
   {
     return mAnimationInfo.GetBaseAnimationStyle();
   }
 
   /**
    * Returns the local transform for this layer: either mTransform or,
    * for shadow layers, GetShadowBaseTransform(), in either case with the
    * pre- and post-scales applied.
--- a/gfx/layers/composite/AsyncCompositionManager.cpp
+++ b/gfx/layers/composite/AsyncCompositionManager.cpp
@@ -6,17 +6,17 @@
 
 #include "mozilla/layers/AsyncCompositionManager.h"
 #include <stdint.h>                     // for uint32_t
 #include "FrameMetrics.h"               // for FrameMetrics
 #include "LayerManagerComposite.h"      // for LayerManagerComposite, etc
 #include "Layers.h"                     // for Layer, ContainerLayer, etc
 #include "gfxPoint.h"                   // for gfxPoint, gfxSize
 #include "gfxPrefs.h"                   // for gfxPrefs
-#include "mozilla/StyleAnimationValue.h" // for StyleAnimationValue, etc
+#include "mozilla/ServoBindings.h"      // for Servo_AnimationValue_GetOpacity, etc
 #include "mozilla/WidgetUtils.h"        // for ComputeTransformForRotation
 #include "mozilla/gfx/BaseRect.h"       // for BaseRect
 #include "mozilla/gfx/Point.h"          // for RoundedToInt, PointTyped
 #include "mozilla/gfx/Rect.h"           // for RoundedToInt, RectTyped
 #include "mozilla/gfx/ScaleFactor.h"    // for ScaleFactor
 #include "mozilla/layers/AnimationHelper.h"
 #include "mozilla/layers/APZSampler.h"  // for APZSampler
 #include "mozilla/layers/APZUtils.h"    // for CompleteAsyncTransform
@@ -575,35 +575,36 @@ AsyncCompositionManager::AlignFixedAndSt
   }
 }
 
 static void
 ApplyAnimatedValue(Layer* aLayer,
                    CompositorAnimationStorage* aStorage,
                    nsCSSPropertyID aProperty,
                    const AnimationData& aAnimationData,
-                   const AnimationValue& aValue)
+                   const RefPtr<RawServoAnimationValue>& aValue)
 {
-  if (aValue.IsNull()) {
+  if (!aValue) {
     // Return gracefully if we have no valid AnimationValue.
     return;
   }
 
   HostLayer* layerCompositor = aLayer->AsHostLayer();
   switch (aProperty) {
     case eCSSProperty_opacity: {
-      layerCompositor->SetShadowOpacity(aValue.GetOpacity());
+      float opacity = Servo_AnimationValue_GetOpacity(aValue);
+      layerCompositor->SetShadowOpacity(opacity);
       layerCompositor->SetShadowOpacitySetByAnimation(true);
-      aStorage->SetAnimatedValue(aLayer->GetCompositorAnimationsId(),
-                                 aValue.GetOpacity());
+      aStorage->SetAnimatedValue(aLayer->GetCompositorAnimationsId(), opacity);
 
       break;
     }
     case eCSSProperty_transform: {
-      RefPtr<const nsCSSValueSharedList> list = aValue.GetTransformList();
+      RefPtr<nsCSSValueSharedList> list;
+      Servo_AnimationValue_GetTransform(aValue, &list);
       const TransformData& transformData = aAnimationData.get_TransformData();
       nsPoint origin = transformData.origin();
       // we expect all our transform data to arrive in device pixels
       Point3D transformOrigin = transformData.transformOrigin();
       nsDisplayTransform::FrameTransformProperties props(Move(list),
                                                          transformOrigin);
 
       Matrix4x4 transform =
@@ -650,17 +651,18 @@ SampleAnimations(Layer* aLayer,
       [&] (Layer* layer)
       {
         AnimationArray& animations = layer->GetAnimations();
         if (animations.IsEmpty()) {
           return;
         }
         isAnimating = true;
         bool hasInEffectAnimations = false;
-        AnimationValue animationValue = layer->GetBaseAnimationStyle();
+        RefPtr<RawServoAnimationValue> animationValue =
+          layer->GetBaseAnimationStyle();
         AnimationHelper::SampleAnimationForEachNode(aTime,
                                                     animations,
                                                     layer->GetAnimationData(),
                                                     animationValue,
                                                     hasInEffectAnimations);
         if (hasInEffectAnimations) {
           Animation& animation = animations.LastElement();
           ApplyAnimatedValue(layer,