Bug 1425837 - Part 2: Factor out the conversion from ServoAnimationValue into Matrix4x4. r=hiro
authorBoris Chiou <boris.chiou@gmail.com>
Mon, 18 Mar 2019 18:04:46 +0000
changeset 464935 5d416b07c9b9886d7456e9e209ed93247e497af8
parent 464934 07a1ab95598e298d92faf62534869ea45e8cd979
child 464936 6c55b82deb9ba9b5924ef6bfdecdffaf9f42307a
push id80792
push userbchiou@mozilla.com
push dateTue, 19 Mar 2019 08:04:11 +0000
treeherderautoland@08126c1f53fe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershiro
bugs1425837
milestone68.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 1425837 - Part 2: Factor out the conversion from ServoAnimationValue into Matrix4x4. r=hiro Both layers and web-render use this function, so we factor it out. Depends on D22562 Differential Revision: https://phabricator.services.mozilla.com/D22563
gfx/layers/AnimationHelper.cpp
gfx/layers/AnimationHelper.h
gfx/layers/composite/AsyncCompositionManager.cpp
--- a/gfx/layers/AnimationHelper.cpp
+++ b/gfx/layers/AnimationHelper.cpp
@@ -458,37 +458,29 @@ bool AnimationHelper::SampleAnimations(C
     Animation& animation = animations->LastElement();
     switch (animation.property()) {
       case eCSSProperty_opacity: {
         aStorage->SetAnimatedValue(
             iter.Key(), Servo_AnimationValue_GetOpacity(animationValue));
         break;
       }
       case eCSSProperty_transform: {
-        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(std::move(list),
-                                                           transformOrigin);
 
         gfx::Matrix4x4 transform =
-            nsDisplayTransform::GetResultingTransformMatrix(
-                props, origin, transformData.appUnitsPerDevPixel(), 0,
-                &transformData.bounds());
+            ServoAnimationValueToMatrix4x4(animationValue, transformData);
         gfx::Matrix4x4 frameTransform = transform;
         // If the parent has perspective transform, then the offset into
         // reference frame coordinates is already on this transform. If not,
         // then we need to ask for it to be added here.
         if (!transformData.hasPerspectiveParent()) {
-          nsLayoutUtils::PostTranslate(
-              transform, origin, transformData.appUnitsPerDevPixel(), true);
+          nsLayoutUtils::PostTranslate(transform, transformData.origin(),
+                                       transformData.appUnitsPerDevPixel(),
+                                       true);
         }
 
         transform.PostScale(transformData.inheritedXScale(),
                             transformData.inheritedYScale(), 1);
 
         aStorage->SetAnimatedValue(iter.Key(), std::move(transform),
                                    std::move(frameTransform), transformData);
         break;
@@ -496,10 +488,27 @@ bool AnimationHelper::SampleAnimations(C
       default:
         MOZ_ASSERT_UNREACHABLE("Unhandled animated property");
     }
   }
 
   return isAnimating;
 }
 
+gfx::Matrix4x4 AnimationHelper::ServoAnimationValueToMatrix4x4(
+    const RefPtr<RawServoAnimationValue>& aValue,
+    const TransformData& aTransformData) {
+  // FIXME: Bug 1457033: We should convert servo's animation value to matrix
+  // directly without nsCSSValueSharedList.
+  RefPtr<nsCSSValueSharedList> list;
+  Servo_AnimationValue_GetTransform(aValue, &list);
+  // We expect all our transform data to arrive in device pixels
+  gfx::Point3D transformOrigin = aTransformData.transformOrigin();
+  nsDisplayTransform::FrameTransformProperties props(std::move(list),
+                                                     transformOrigin);
+
+  return nsDisplayTransform::GetResultingTransformMatrix(
+      props, aTransformData.origin(), aTransformData.appUnitsPerDevPixel(), 0,
+      &aTransformData.bounds());
+}
+
 }  // namespace layers
 }  // namespace mozilla
--- a/gfx/layers/AnimationHelper.h
+++ b/gfx/layers/AnimationHelper.h
@@ -226,14 +226,23 @@ class AnimationHelper {
    * Returns true if there is any animation.
    * Note that even if there are only in-delay phase animations (i.e. not
    * visually effective), this function returns true to ensure we composite
    * again on the next tick.
    */
   static bool SampleAnimations(CompositorAnimationStorage* aStorage,
                                TimeStamp aPreviousFrameTime,
                                TimeStamp aCurrentFrameTime);
+
+  /**
+   * Convert an animation value into a matrix given the corresponding transform
+   * parameters. |aValue| must be a transform-like value (e.g. transform,
+   * translate etc.).
+   */
+  static gfx::Matrix4x4 ServoAnimationValueToMatrix4x4(
+      const RefPtr<RawServoAnimationValue>& aValue,
+      const TransformData& aTransformData);
 };
 
 }  // namespace layers
 }  // namespace mozilla
 
 #endif  // mozilla_layers_AnimationHelper_h
--- a/gfx/layers/composite/AsyncCompositionManager.cpp
+++ b/gfx/layers/composite/AsyncCompositionManager.cpp
@@ -592,33 +592,16 @@ void AsyncCompositionManager::AdjustFixe
       AlignFixedAndStickyLayers(aTransformedSubtreeRoot, child,
                                 aTransformScrollId, aPreviousTransformForRoot,
                                 newTransform, aFixedLayerMargins,
                                 aClipPartsCache);
     }
   }
 }
 
-static Matrix4x4 ServoAnimationValueToMatrix4x4(
-    const RefPtr<RawServoAnimationValue>& aValue,
-    const TransformData& aTransformData) {
-  // FIXME: Bug 1457033: We should convert servo's animation value to matrix
-  // directly without nsCSSValueSharedList.
-  RefPtr<nsCSSValueSharedList> list;
-  Servo_AnimationValue_GetTransform(aValue, &list);
-  // we expect all our transform data to arrive in device pixels
-  Point3D transformOrigin = aTransformData.transformOrigin();
-  nsDisplayTransform::FrameTransformProperties props(std::move(list),
-                                                     transformOrigin);
-
-  return nsDisplayTransform::GetResultingTransformMatrix(
-      props, aTransformData.origin(), aTransformData.appUnitsPerDevPixel(), 0,
-      &aTransformData.bounds());
-}
-
 static Matrix4x4 FrameTransformToTransformInDevice(
     const Matrix4x4& aFrameTransform, Layer* aLayer,
     const TransformData& aTransformData) {
   Matrix4x4 transformInDevice = aFrameTransform;
   // If our parent layer is a perspective layer, then the offset into reference
   // frame coordinates is already on that layer. If not, then we need to ask
   // for it to be added here.
   if (!aLayer->GetParent() ||
@@ -670,17 +653,18 @@ static void ApplyAnimatedValue(Layer* aL
       layerCompositor->SetShadowBaseTransform(aLayer->GetBaseTransform());
       layerCompositor->SetShadowTransformSetByAnimation(false);
       break;
     }
     case eCSSProperty_transform: {
       const TransformData& transformData = aAnimationData.get_TransformData();
 
       Matrix4x4 frameTransform =
-          ServoAnimationValueToMatrix4x4(aValue, transformData);
+          AnimationHelper::ServoAnimationValueToMatrix4x4(aValue,
+                                                          transformData);
 
       Matrix4x4 transform = FrameTransformToTransformInDevice(
           frameTransform, aLayer, transformData);
 
       layerCompositor->SetShadowBaseTransform(transform);
       layerCompositor->SetShadowTransformSetByAnimation(true);
       aStorage->SetAnimatedValue(aLayer->GetCompositorAnimationsId(),
                                  std::move(transform),
@@ -748,17 +732,18 @@ static bool SampleAnimations(Layer* aLay
           case eCSSProperty_transform: {
             MOZ_ASSERT(
                 layer->AsHostLayer()->GetShadowTransformSetByAnimation());
             MOZ_ASSERT(previousValue);
 #ifdef DEBUG
             const TransformData& transformData =
                 animations[0].data().get_TransformData();
             Matrix4x4 frameTransform =
-                ServoAnimationValueToMatrix4x4(animationValue, transformData);
+                AnimationHelper::ServoAnimationValueToMatrix4x4(animationValue,
+                                                                transformData);
             Matrix4x4 transformInDevice = FrameTransformToTransformInDevice(
                 frameTransform, layer, transformData);
             MOZ_ASSERT(previousValue->mTransform.mTransformInDevSpace
                            .FuzzyEqualsMultiplicative(transformInDevice));
 #endif
             // In the case of transform we have to set the unchanged
             // transform value again becasue APZC might have modified the
             // previous shadow base transform value.