Bug 1335942 - Part 3: Use AnimationValue as the argument in layers::SetAnimatable. draft
authorBoris Chiou <boris.chiou@gmail.com>
Tue, 07 Feb 2017 18:09:58 +0800
changeset 479846 517f76fa934dce99fcc251bd27d2bf4340f44ae1
parent 479845 fb365ea1793d7da8054381467e89c0b2c142bc7f
child 479847 7eb6697f2d0443373a519200562e489ce676d152
child 479851 db43eefac70ab24a5ca4850a7aa2d393d18cd6ee
child 481033 9fce3b15aca4ad652e325c169f6ae45b3715fdfe
push id44386
push userbmo:boris.chiou@gmail.com
push dateTue, 07 Feb 2017 12:37:56 +0000
bugs1335942
milestone54.0a1
Bug 1335942 - Part 3: Use AnimationValue as the argument in layers::SetAnimatable. MozReview-Commit-ID: 4XnLL6I291q
layout/painting/nsDisplayList.cpp
layout/style/ServoBindingList.h
layout/style/StyleAnimationValue.h
servo/components/style/gecko_bindings/bindings.rs
servo/ports/geckolib/glue.rs
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -382,37 +382,39 @@ ToTimingFunction(const Maybe<ComputedTim
   }
 
   uint32_t type = aCTF->GetType() == nsTimingFunction::Type::StepStart ? 1 : 2;
   return TimingFunction(StepFunction(aCTF->GetSteps(), type));
 }
 
 static void
 SetAnimatable(nsCSSPropertyID aProperty,
-              const StyleAnimationValue& aAnimationValue,
+              const AnimationValue& aAnimationValue,
               nsIFrame* aFrame,
               const TransformReferenceBox& aRefBox,
               layers::Animatable& aAnimatable)
 {
   MOZ_ASSERT(aFrame);
 
   if (aAnimationValue.IsNull()) {
     aAnimatable = null_t();
     return;
   }
 
   switch (aProperty) {
     case eCSSProperty_opacity:
-      aAnimatable = aAnimationValue.GetFloatValue();
+      aAnimatable = aAnimationValue.GetOpacity();
       break;
     case eCSSProperty_transform: {
       aAnimatable = InfallibleTArray<TransformFunction>();
+      TransformReferenceBox refBox(aFrame);
+      // TODO: Get transform from RawServoAnimationValue.
       nsCSSValueSharedList* list =
-        aAnimationValue.GetCSSValueSharedListValue();
-      TransformReferenceBox refBox(aFrame);
+        aAnimationValue.mGecko.GetCSSValueSharedListValue();
+      MOZ_ASSERT(list, "Invalid transform list");
       AddTransformFunctions(list->mHead,
                             aFrame->StyleContext(),
                             aFrame->PresContext(),
                             refBox,
                             aAnimatable.get_ArrayOfTransformFunction());
       break;
     }
     default:
@@ -428,17 +430,19 @@ SetBaseAnimationStyle(nsCSSPropertyID aP
 {
   MOZ_ASSERT(aFrame);
 
   StyleAnimationValue baseValue =
     EffectCompositor::GetBaseStyle(aProperty, aFrame);
   MOZ_ASSERT(!baseValue.IsNull(),
              "The base value should be already there");
 
-  SetAnimatable(aProperty, baseValue, aFrame, aRefBox, aBaseStyle);
+  // FIXME: Bug 1311257: We need to get the baseValue for
+  //        RawServoAnimationValue.
+  SetAnimatable(aProperty, { baseValue, nullptr }, aFrame, aRefBox, aBaseStyle);
 }
 
 static void
 AddAnimationForProperty(nsIFrame* aFrame, const AnimationProperty& aProperty,
                         dom::Animation* aAnimation, Layer* aLayer,
                         AnimationData& aData, bool aPending)
 {
   MOZ_ASSERT(aLayer->AsContainerLayer(), "Should only animate ContainerLayer");
@@ -520,21 +524,21 @@ AddAnimationForProperty(nsIFrame* aFrame
     animation->baseStyle() = null_t();
   }
 
   for (uint32_t segIdx = 0; segIdx < aProperty.mSegments.Length(); segIdx++) {
     const AnimationPropertySegment& segment = aProperty.mSegments[segIdx];
 
     AnimationSegment* animSegment = animation->segments().AppendElement();
     SetAnimatable(aProperty.mProperty,
-                  segment.mFromValue.mGecko,
+                  segment.mFromValue,
                   aFrame, refBox,
                   animSegment->startState());
     SetAnimatable(aProperty.mProperty,
-                  segment.mToValue.mGecko,
+                  segment.mToValue,
                   aFrame, refBox,
                   animSegment->endState());
 
     animSegment->startPortion() = segment.mFromKey;
     animSegment->endPortion() = segment.mToKey;
     animSegment->startComposite() =
       static_cast<uint8_t>(segment.mFromComposite);
     animSegment->endComposite() =
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -122,16 +122,18 @@ SERVO_BINDING_FUNC(Servo_AnimationValues
 SERVO_BINDING_FUNC(Servo_AnimationValues_Interpolate,
                    RawServoAnimationValueStrong,
                    RawServoAnimationValueBorrowed from,
                    RawServoAnimationValueBorrowed to,
                    double progress)
 SERVO_BINDING_FUNC(Servo_AnimationValues_Uncompute,
                    RawServoDeclarationBlockStrong,
                    RawServoAnimationValueBorrowedListBorrowed value)
+SERVO_BINDING_FUNC(Servo_AnimationValues_GetOpacity, float,
+                   RawServoAnimationValueBorrowed value)
 
 // Style attribute
 SERVO_BINDING_FUNC(Servo_ParseStyleAttribute, RawServoDeclarationBlockStrong,
                    const nsACString* data)
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_CreateEmpty,
                    RawServoDeclarationBlockStrong)
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_Clone, RawServoDeclarationBlockStrong,
                    RawServoDeclarationBlockBorrowed declarations)
--- a/layout/style/StyleAnimationValue.h
+++ b/layout/style/StyleAnimationValue.h
@@ -13,16 +13,17 @@
 #include "mozilla/UniquePtr.h"
 #include "nsStringFwd.h"
 #include "nsStringBuffer.h"
 #include "nsCoord.h"
 #include "nsColor.h"
 #include "nsCSSProps.h"
 #include "nsCSSValue.h"
 #include "nsStyleCoord.h"
+#include "ServoBindings.h"
 
 class nsIFrame;
 class nsStyleContext;
 class gfx3DMatrix;
 struct RawServoDeclarationBlock;
 
 namespace mozilla {
 
@@ -586,16 +587,23 @@ struct AnimationValue
 {
   StyleAnimationValue mGecko;
   RefPtr<RawServoAnimationValue> mServo;
 
   bool operator==(const AnimationValue& aOther) const {
     // FIXME: Bug 1337229: add a deep == impl for RawServoAnimationValue.
     return mGecko == aOther.mGecko && mServo == aOther.mServo;
   }
+
+  bool IsNull() const { return mGecko.IsNull() && !mServo; }
+
+  float GetOpacity() const {
+    return mServo ? Servo_AnimationValues_GetOpacity(mServo)
+                  : mGecko.GetFloatValue();
+  }
 };
 
 struct PropertyStyleAnimationValuePair
 {
   nsCSSPropertyID mProperty;
   AnimationValue mValue;
 };
 } // namespace mozilla
--- a/servo/components/style/gecko_bindings/bindings.rs
+++ b/servo/components/style/gecko_bindings/bindings.rs
@@ -1294,16 +1294,21 @@ extern "C" {
      -> RawServoAnimationValueStrong;
 }
 extern "C" {
     pub fn Servo_AnimationValues_Uncompute(value:
                                                RawServoAnimationValueBorrowedListBorrowed)
      -> RawServoDeclarationBlockStrong;
 }
 extern "C" {
+    pub fn Servo_AnimationValues_GetOpacity(value:
+                                                RawServoAnimationValueBorrowed)
+     -> f32;
+}
+extern "C" {
     pub fn Servo_ParseStyleAttribute(data: *const nsACString_internal)
      -> RawServoDeclarationBlockStrong;
 }
 extern "C" {
     pub fn Servo_DeclarationBlock_CreateEmpty()
      -> RawServoDeclarationBlockStrong;
 }
 extern "C" {
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -200,16 +200,28 @@ pub extern "C" fn Servo_AnimationValues_
                                  .collect();
 
     Arc::new(RwLock::new(PropertyDeclarationBlock {
         declarations: uncomputed_values,
         important_count: 0,
     })).into_strong()
 }
 
+#[no_mangle]
+pub extern "C" fn Servo_AnimationValues_GetOpacity(value: RawServoAnimationValueBorrowed)
+     -> f32
+{
+    let value = AnimationValue::as_arc(&value);
+    if let AnimationValue::Opacity(opacity) = **value {
+        opacity
+    } else {
+        panic!("The AnimationValue should be Opacity");
+    }
+}
+
 /// Takes a ServoAnimationValues and populates it with the animation values corresponding
 /// to a given property declaration block
 #[no_mangle]
 pub extern "C" fn Servo_AnimationValues_Populate(anim: RawGeckoAnimationValueListBorrowedMut,
                                                  declarations: RawServoDeclarationBlockBorrowed,
                                                  style: ServoComputedValuesBorrowed,
                                                  parent_style: ServoComputedValuesBorrowedOrNull,
                                                  pres_context: RawGeckoPresContextBorrowed)