Bug 1375497 - Hook up the testing APIs in DOMWindowUtils. r=pchang
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 27 Jun 2017 20:29:06 -0400
changeset 415141 95c6960a133a7a183d77a3292834eec1b6e4618d
parent 415140 1eb44b686c347d6efd09e3cab3f8ab4dc05992e6
child 415142 a1832dd694e03f4b8c168c621bd1c3fe74de0bcb
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspchang
bugs1375497
milestone56.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 1375497 - Hook up the testing APIs in DOMWindowUtils. r=pchang DOMWindowUtils needs to handle both ClientLayerManager and WebRenderLayerManager in order for these APIs to work with webrender. There's unfortunately a fair amount of code duplication here but even using a common interface and polymorphism there's a fair amount of boilerplate so I'm not sure that's any better. MozReview-Commit-ID: Efggm9mBVNy
dom/base/nsDOMWindowUtils.cpp
dom/base/nsDOMWindowUtils.h
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -247,16 +247,29 @@ nsDOMWindowUtils::GetLayerTransaction()
     return nullptr;
 
   ShadowLayerForwarder* forwarder = manager->AsShadowForwarder();
   return forwarder && forwarder->HasShadowManager() ?
          forwarder->GetShadowManager() :
          nullptr;
 }
 
+WebRenderBridgeChild*
+nsDOMWindowUtils::GetWebRenderBridge()
+{
+  if (nsIWidget* widget = GetWidget()) {
+    if (LayerManager* lm = widget->GetLayerManager()) {
+      if (WebRenderLayerManager* wrlm = lm->AsWebRenderLayerManager()) {
+        return wrlm->WrBridge();
+      }
+    }
+  }
+  return nullptr;
+}
+
 NS_IMETHODIMP
 nsDOMWindowUtils::GetImageAnimationMode(uint16_t *aMode)
 {
   NS_ENSURE_ARG_POINTER(aMode);
   *aMode = 0;
   nsPresContext* presContext = GetPresContext();
   if (presContext) {
     *aMode = presContext->ImageAnimationMode();
@@ -2503,16 +2516,18 @@ nsDOMWindowUtils::AdvanceTimeAndRefresh(
   nsPresContext* presContext = GetPresContext();
   if (presContext) {
     nsRefreshDriver* driver = presContext->RefreshDriver();
     driver->AdvanceTimeAndRefresh(aMilliseconds);
 
     RefPtr<LayerTransactionChild> transaction = GetLayerTransaction();
     if (transaction && transaction->IPCOpen()) {
       transaction->SendSetTestSampleTime(driver->MostRecentRefresh());
+    } else if (WebRenderBridgeChild* wrbc = GetWebRenderBridge()) {
+      wrbc->SendSetTestSampleTime(driver->MostRecentRefresh());
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetLastTransactionId(uint64_t *aLastTransactionId)
@@ -2531,16 +2546,18 @@ NS_IMETHODIMP
 nsDOMWindowUtils::RestoreNormalRefresh()
 {
   // Kick the compositor out of test mode before the refresh driver, so that
   // the refresh driver doesn't send an update that gets ignored by the
   // compositor.
   RefPtr<LayerTransactionChild> transaction = GetLayerTransaction();
   if (transaction && transaction->IPCOpen()) {
     transaction->SendLeaveTestMode();
+  } else if (WebRenderBridgeChild* wrbc = GetWebRenderBridge()) {
+    wrbc->SendLeaveTestMode();
   }
 
   if (nsPresContext* pc = GetPresContext()) {
     nsRefreshDriver* driver = pc->RefreshDriver();
     driver->RestoreNormalRefresh();
   }
 
   return NS_OK;
@@ -3831,45 +3848,54 @@ nsDOMWindowUtils::GetOMTAStyle(nsIDOMEle
     }
   }
   if (frame && nsLayoutUtils::AreAsyncAnimationsEnabled()) {
     if (aProperty.EqualsLiteral("opacity")) {
       Layer* layer =
         FrameLayerBuilder::GetDedicatedLayer(frame,
                                              nsDisplayItem::TYPE_OPACITY);
       if (layer) {
+        float value = 0;
+        bool hadAnimatedOpacity = false;
         ShadowLayerForwarder* forwarder = layer->Manager()->AsShadowForwarder();
         if (forwarder && forwarder->HasShadowManager()) {
-          float value;
-          bool hadAnimatedOpacity;
           forwarder->GetShadowManager()->
             SendGetAnimationOpacity(layer->GetCompositorAnimationsId(),
                                     &value,
                                     &hadAnimatedOpacity);
 
-          if (hadAnimatedOpacity) {
-            cssValue = new nsROCSSPrimitiveValue;
-            cssValue->SetNumber(value);
-          }
+        } else if (WebRenderLayerManager* wrlm = layer->Manager()->AsWebRenderLayerManager()) {
+          wrlm->WrBridge()->SendGetAnimationOpacity(
+              layer->GetCompositorAnimationsId(),
+              &value,
+              &hadAnimatedOpacity);
+        }
+        if (hadAnimatedOpacity) {
+          cssValue = new nsROCSSPrimitiveValue;
+          cssValue->SetNumber(value);
         }
       }
     } else if (aProperty.EqualsLiteral("transform")) {
       Layer* layer =
         FrameLayerBuilder::GetDedicatedLayer(frame,
                                              nsDisplayItem::TYPE_TRANSFORM);
       if (layer) {
+        MaybeTransform transform;
         ShadowLayerForwarder* forwarder = layer->Manager()->AsShadowForwarder();
         if (forwarder && forwarder->HasShadowManager()) {
-          MaybeTransform transform;
           forwarder->GetShadowManager()->
             SendGetAnimationTransform(layer->GetCompositorAnimationsId(), &transform);
-          if (transform.type() == MaybeTransform::TMatrix4x4) {
-            Matrix4x4 matrix = transform.get_Matrix4x4();
-            cssValue = nsComputedDOMStyle::MatrixToCSSValue(matrix);
-          }
+        } else if (WebRenderLayerManager* wrlm = layer->Manager()->AsWebRenderLayerManager()) {
+          wrlm->WrBridge()->SendGetAnimationTransform(
+              layer->GetCompositorAnimationsId(),
+              &transform);
+        }
+        if (transform.type() == MaybeTransform::TMatrix4x4) {
+          Matrix4x4 matrix = transform.get_Matrix4x4();
+          cssValue = nsComputedDOMStyle::MatrixToCSSValue(matrix);
         }
       }
     }
   }
 
   if (cssValue) {
     nsString text;
     ErrorResult rv;
--- a/dom/base/nsDOMWindowUtils.h
+++ b/dom/base/nsDOMWindowUtils.h
@@ -19,16 +19,17 @@ class nsIWidget;
 class nsPresContext;
 class nsIDocument;
 class nsView;
 struct nsPoint;
 
 namespace mozilla {
   namespace layers {
     class LayerTransactionChild;
+    class WebRenderBridgeChild;
   } // namespace layers
 } // namespace mozilla
 
 class nsTranslationNodeList final : public nsITranslationNodeList
 {
 public:
   nsTranslationNodeList()
   {
@@ -76,16 +77,17 @@ protected:
   // widget returned by GetWidget.
   nsIWidget* GetWidget(nsPoint* aOffset = nullptr);
   nsIWidget* GetWidgetForElement(nsIDOMElement* aElement);
 
   nsIPresShell* GetPresShell();
   nsPresContext* GetPresContext();
   nsIDocument* GetDocument();
   mozilla::layers::LayerTransactionChild* GetLayerTransaction();
+  mozilla::layers::WebRenderBridgeChild* GetWebRenderBridge();
 
   NS_IMETHOD SendMouseEventCommon(const nsAString& aType,
                                   float aX,
                                   float aY,
                                   int32_t aButton,
                                   int32_t aClickCount,
                                   int32_t aModifiers,
                                   bool aIgnoreRootScrollFrame,