Bug 1479234 - Factor out a function getting an OMTAValue from the compositor. r?boris draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Tue, 31 Jul 2018 08:13:04 +0900
changeset 824476 b947e5f4367538b189f09a0003304a9b68b00742
parent 824450 f054ad308dd54d6920cdbe8c79b91391b7d0c93c
child 824477 dd1e164c5cecc77308d75f2e710af10f1998e5a3
push id117927
push userhikezoe@mozilla.com
push dateTue, 31 Jul 2018 00:42:56 +0000
reviewersboris
bugs1479234
milestone63.0a1
Bug 1479234 - Factor out a function getting an OMTAValue from the compositor. r?boris MozReview-Commit-ID: HciPnmLDiYd
dom/base/nsDOMWindowUtils.cpp
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -3650,16 +3650,44 @@ GetTargetFrame(const Element* aElement, 
       frame = nsLayoutUtils::GetAfterFrame(aElement);
     } else {
       return Err(NS_ERROR_INVALID_ARG);
     }
   }
   return frame;
 }
 
+static OMTAValue
+GetOMTAValue(nsIFrame* aFrame,
+             DisplayItemType aDisplayItemKey,
+             WebRenderBridgeChild* aWebRenderBridgeChild)
+{
+  OMTAValue value = mozilla::null_t();
+
+  Layer* layer =
+    FrameLayerBuilder::GetDedicatedLayer(aFrame, aDisplayItemKey);
+  if (layer) {
+    ShadowLayerForwarder* forwarder = layer->Manager()->AsShadowForwarder();
+    if (forwarder && forwarder->HasShadowManager()) {
+      forwarder->GetShadowManager()->
+        SendGetAnimationValue(layer->GetCompositorAnimationsId(), &value);
+    }
+  } else if (aWebRenderBridgeChild) {
+    RefPtr<WebRenderAnimationData> animationData =
+      GetWebRenderUserData<WebRenderAnimationData>(aFrame,
+                                                   (uint32_t)aDisplayItemKey);
+    if (animationData) {
+      aWebRenderBridgeChild->SendGetAnimationValue(
+        animationData->GetAnimationInfo().GetCompositorAnimationsId(),
+        &value);
+    }
+  }
+  return value;
+}
+
 NS_IMETHODIMP
 nsDOMWindowUtils::GetOMTAStyle(Element* aElement,
                                const nsAString& aProperty,
                                const nsAString& aPseudoElement,
                                nsAString& aResult)
 {
   if (!aElement) {
     return NS_ERROR_INVALID_ARG;
@@ -3674,59 +3702,27 @@ nsDOMWindowUtils::GetOMTAStyle(Element* 
   RefPtr<nsROCSSPrimitiveValue> cssValue = nullptr;
   if (frame && nsLayoutUtils::AreAsyncAnimationsEnabled()) {
     RefPtr<LayerManager> widgetLayerManager;
     if (nsIWidget* widget = GetWidget()) {
       widgetLayerManager = widget->GetLayerManager();
     }
 
     if (aProperty.EqualsLiteral("opacity")) {
-      OMTAValue value;
-
-      Layer* layer =
-        FrameLayerBuilder::GetDedicatedLayer(frame, DisplayItemType::TYPE_OPACITY);
-      if (layer) {
-        ShadowLayerForwarder* forwarder = layer->Manager()->AsShadowForwarder();
-        if (forwarder && forwarder->HasShadowManager()) {
-          forwarder->GetShadowManager()->
-            SendGetAnimationValue(layer->GetCompositorAnimationsId(), &value);
-        }
-      } else if (WebRenderBridgeChild* wrbc = GetWebRenderBridge()) {
-        RefPtr<WebRenderAnimationData> animationData =
-            GetWebRenderUserData<WebRenderAnimationData>(frame, (uint32_t)DisplayItemType::TYPE_OPACITY);
-        if (animationData) {
-          wrbc->SendGetAnimationValue(
-              animationData->GetAnimationInfo().GetCompositorAnimationsId(),
-              &value);
-        }
-      }
+      OMTAValue value = GetOMTAValue(frame,
+                                     DisplayItemType::TYPE_OPACITY,
+                                     GetWebRenderBridge());
       if (value.type() == OMTAValue::Tfloat) {
         cssValue = new nsROCSSPrimitiveValue;
         cssValue->SetNumber(value.get_float());
       }
     } else if (aProperty.EqualsLiteral("transform")) {
-      OMTAValue value;
-
-      Layer* layer =
-        FrameLayerBuilder::GetDedicatedLayer(frame, DisplayItemType::TYPE_TRANSFORM);
-      if (layer) {
-        ShadowLayerForwarder* forwarder = layer->Manager()->AsShadowForwarder();
-        if (forwarder && forwarder->HasShadowManager()) {
-          forwarder->GetShadowManager()->
-            SendGetAnimationValue(layer->GetCompositorAnimationsId(), &value);
-        }
-      } else if (WebRenderBridgeChild* wrbc = GetWebRenderBridge()) {
-        RefPtr<WebRenderAnimationData> animationData =
-            GetWebRenderUserData<WebRenderAnimationData>(frame, (uint32_t)DisplayItemType::TYPE_TRANSFORM);
-        if (animationData) {
-          wrbc->SendGetAnimationValue(
-              animationData->GetAnimationInfo().GetCompositorAnimationsId(),
-              &value);
-        }
-      }
+      OMTAValue value = GetOMTAValue(frame,
+                                     DisplayItemType::TYPE_TRANSFORM,
+                                     GetWebRenderBridge());
       if (value.type() == OMTAValue::TMatrix4x4) {
         cssValue = nsComputedDOMStyle::MatrixToCSSValue(value.get_Matrix4x4());
       }
     }
   }
 
   if (cssValue) {
     nsString text;