Bug 1419851 - Handle OMTA throttling for webrender. r?jrmuizel draft
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 06 Apr 2018 10:06:54 -0400
changeset 778567 961b7e39e439c0c7fe0b644df8bba68882401f0a
parent 777984 110f32790d38a258cab722064aae40736478ef51
push id105520
push userkgupta@mozilla.com
push dateFri, 06 Apr 2018 14:07:20 +0000
reviewersjrmuizel
bugs1419851
milestone61.0a1
Bug 1419851 - Handle OMTA throttling for webrender. r?jrmuizel Original patch by Ethan Lin <ethlin@mozilla.com>. MozReview-Commit-ID: AAIaskIsz9x
dom/animation/KeyframeEffectReadOnly.cpp
gfx/layers/AnimationInfo.cpp
gfx/layers/AnimationInfo.h
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -1192,22 +1192,20 @@ KeyframeEffectReadOnly::CanThrottle() co
     if (!HasEffectiveAnimationOfProperty(record.mProperty)) {
       continue;
     }
 
     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() !=
-          layer->GetAnimationGeneration()) {
+    Maybe<uint64_t> generation = layers::AnimationInfo::GetGenerationFromFrame(
+        frame, record.mLayerType);
+    // Unthrottle if the animation needs to be brought up to date
+    if (!generation || effectSet->GetAnimationGeneration() != *generation) {
       return false;
     }
 
     // If this is a transform animation that affects the overflow region,
     // we should unthrottle the animation periodically.
     if (HasTransformThatMightAffectOverflow() &&
         !CanThrottleTransformChangesInScrollable(*frame)) {
       return false;
--- a/gfx/layers/AnimationInfo.cpp
+++ b/gfx/layers/AnimationInfo.cpp
@@ -169,10 +169,29 @@ AnimationInfo::HasTransformAnimation() c
   for (uint32_t i = 0; i < mAnimations.Length(); i++) {
     if (mAnimations[i].property() == eCSSProperty_transform) {
       return true;
     }
   }
   return false;
 }
 
+/* static */ Maybe<uint64_t>
+AnimationInfo::GetGenerationFromFrame(nsIFrame* aFrame,
+                                      DisplayItemType aDisplayItemKey)
+{
+  layers::Layer* layer =
+    FrameLayerBuilder::GetDedicatedLayer(aFrame, aDisplayItemKey);
+  if (layer) {
+    return Some(layer->GetAnimationInfo().GetAnimationGeneration());
+  }
+
+  RefPtr<WebRenderAnimationData> animationData =
+      GetWebRenderUserData<WebRenderAnimationData>(aFrame, (uint32_t)aDisplayItemKey);
+  if (animationData) {
+    return Some(animationData->GetAnimationInfo().GetAnimationGeneration());
+  }
+
+  return Nothing();
+}
+
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/AnimationInfo.h
+++ b/gfx/layers/AnimationInfo.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_ANIMATIONINFO_H
 #define GFX_ANIMATIONINFO_H
 
 #include "mozilla/StyleAnimationValue.h"
+#include "nsDisplayItemTypes.h"
 
 namespace mozilla {
 namespace layers {
 
 class Animation;
 class CompositorAnimations;
 class Layer;
 class LayerManager;
@@ -53,16 +54,19 @@ public:
   uint64_t GetCompositorAnimationsId() { return mCompositorAnimationsId; }
   AnimationValue GetBaseAnimationStyle() const { return mBaseAnimationStyle; }
   InfallibleTArray<AnimData>& GetAnimationData() { return mAnimationData; }
   AnimationArray& GetAnimations() { return mAnimations; }
   bool ApplyPendingUpdatesForThisTransaction();
   bool HasOpacityAnimation() const;
   bool HasTransformAnimation() const;
 
+  static Maybe<uint64_t> GetGenerationFromFrame(nsIFrame* aFrame,
+                                                DisplayItemType aDisplayItemKey);
+
 protected:
   LayerManager* mManager;
   AnimationArray mAnimations;
   uint64_t mCompositorAnimationsId;
   nsAutoPtr<AnimationArray> mPendingAnimations;
   InfallibleTArray<AnimData> mAnimationData;
   // If this layer is used for OMTA, then this counter is used to ensure we
   // stay in sync with the animation manager