Bug 1419851 - Handle OMTA throttle for webrender. r=kats,birtles draft
authorEthan Lin <ethlin@mozilla.com>
Thu, 23 Nov 2017 15:11:46 +0800
changeset 703061 482d4c185a1508ade1b35de480bb060873d4b137
parent 701610 b96f009478987d44a68a8d7cad40c6a3d6626235
child 741653 f9e11170c4c3748a74bfad3f5aef7c1ae0bdd2f2
push id90691
push userbmo:ethlin@mozilla.com
push dateFri, 24 Nov 2017 08:50:25 +0000
reviewerskats, birtles
bugs1419851
milestone59.0a1
Bug 1419851 - Handle OMTA throttle for webrender. r=kats,birtles MozReview-Commit-ID: 97qtJuh5I59
dom/animation/KeyframeEffectReadOnly.cpp
dom/animation/moz.build
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -15,16 +15,18 @@
 #include "mozilla/dom/KeyframeEffectBinding.h"
 #include "mozilla/AnimValuesStyleRule.h"
 #include "mozilla/AnimationUtils.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/EffectSet.h"
 #include "mozilla/FloatingPoint.h" // For IsFinite
 #include "mozilla/GeckoStyleContext.h"
 #include "mozilla/LayerAnimationInfo.h"
+#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/WebRenderUserData.h"
 #include "mozilla/LookAndFeel.h" // For LookAndFeel::GetInt
 #include "mozilla/KeyframeUtils.h"
 #include "mozilla/ServoBindings.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/TypeTraits.h"
 #include "Layers.h" // For Layer
 #include "nsComputedDOMStyle.h" // nsComputedDOMStyle::GetStyleContext
 #include "nsContentUtils.h"
@@ -1449,20 +1451,37 @@ KeyframeEffectReadOnly::CanThrottle() co
 
     EffectSet* effectSet = EffectSet::GetEffectSet(mTarget->mElement,
                                                    mTarget->mPseudoType);
     MOZ_ASSERT(effectSet, "CanThrottle should be called on an effect "
                           "associated with a target element");
     layers::Layer* layer =
       FrameLayerBuilder::GetDedicatedLayer(frame, record.mLayerType);
     // Unthrottle if the layer needs to be brought up to date
-    if (!layer ||
-        effectSet->GetAnimationGeneration() !=
+    if (layer) {
+      if (effectSet->GetAnimationGeneration() !=
           layer->GetAnimationGeneration()) {
-      return false;
+        return false;
+      }
+    } else {
+      RefPtr<layers::LayerManager> widgetLayerManager;
+      if (nsIWidget* widget = nsContentUtils::GetWidget(GetPresShell(), nullptr)) {
+        widgetLayerManager = widget->GetLayerManager();
+      }
+      if (layers::WebRenderLayerManager *wrlm = widgetLayerManager ?
+            widgetLayerManager->AsWebRenderLayerManager() : nullptr) {
+        RefPtr<layers::WebRenderAnimationData> animationData = wrlm->CommandBuilder()
+            .GetWebRenderUserData<layers::WebRenderAnimationData>(frame, (uint32_t)record.mLayerType);
+        if (!animationData ||
+            animationData->GetAnimationInfo().GetAnimationGeneration() != effectSet->GetAnimationGeneration()) {
+          return false;
+        }
+      } else {
+        return false;
+      }
     }
 
     // If this is a transform animation that affects the overflow region,
     // we should unthrottle the animation periodically.
     if (record.mProperty == eCSSProperty_transform &&
         !CanThrottleTransformChanges(*frame)) {
       return false;
     }
--- a/dom/animation/moz.build
+++ b/dom/animation/moz.build
@@ -63,9 +63,11 @@ UNIFIED_SOURCES += [
 ]
 
 LOCAL_INCLUDES += [
     '/dom/base',
     '/layout/base',
     '/layout/style',
 ]
 
+include('/ipc/chromium/chromium-config.mozbuild')
+
 FINAL_LIBRARY = 'xul'