Bug 1109390 part 20 - Add an options flag to GetAnimationsForCompositor to control; r=jwatt
authorBrian Birtles <birtles@gmail.com>
Wed, 01 Apr 2015 12:23:24 +0900
changeset 266795 ab074c8ddb56bf8e70108765895d81a5ef744681
parent 266794 7779bff82d843585cf55fd97abc53817c86ce22f
child 266796 6bec9324b5556f945f923292663468474065a89a
push id4830
push userjlund@mozilla.com
push dateMon, 29 Jun 2015 20:18:48 +0000
treeherdermozilla-beta@4c2175bb0420 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1109390
milestone40.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 1109390 part 20 - Add an options flag to GetAnimationsForCompositor to control; r=jwatt This patch adds an options flag to GetAnimationsForCompositor for two reasons. a) We want to reuse this functionality in nsLayoutUtils.cpp rather than duplicating the same logic. To do that and maintain the existing behavior, however, we need to *not* update the active layer tracker when calling this from nsLayoutUtils.cpp. b) It's surprising that GetAnimationsForCompositor also has this side effect of updating the active layer tracker. Adding this as an option makes it clear at the call site that this is what will happen.
layout/style/AnimationCommon.cpp
layout/style/AnimationCommon.h
layout/style/nsAnimationManager.h
layout/style/nsTransitionManager.h
--- a/layout/style/AnimationCommon.cpp
+++ b/layout/style/AnimationCommon.cpp
@@ -115,31 +115,37 @@ CommonAnimationManager::CheckNeedsRefres
   if (mIsObservingRefreshDriver) {
     mIsObservingRefreshDriver = false;
     mPresContext->RefreshDriver()->RemoveRefreshObserver(this, Flush_Style);
   }
 }
 
 AnimationPlayerCollection*
 CommonAnimationManager::GetAnimationsForCompositor(nsIContent* aContent,
-                                                   nsIAtom* aElementProperty,
-                                                   nsCSSProperty aProperty)
+  nsIAtom* aElementProperty,
+  nsCSSProperty aProperty,
+  GetCompositorAnimationOptions aFlags)
 {
   if (!aContent->MayHaveAnimations())
     return nullptr;
+
   AnimationPlayerCollection* collection =
     static_cast<AnimationPlayerCollection*>(
       aContent->GetProperty(aElementProperty));
   if (!collection ||
       !collection->HasAnimationOfProperty(aProperty) ||
       !collection->CanPerformOnCompositorThread(
         AnimationPlayerCollection::CanAnimate_AllowPartial)) {
     return nullptr;
   }
 
+  if (!(aFlags & GetCompositorAnimationOptions::NotifyActiveLayerTracker)) {
+    return collection;
+  }
+
   // This animation can be done on the compositor.
   // Mark the frame as active, in case we are able to throttle this animation.
   nsIFrame* frame = nsLayoutUtils::GetStyleFrame(collection->mElement);
   if (frame) {
     const auto& info = sLayerAnimationInfo;
     for (size_t i = 0; i < ArrayLength(info); i++) {
       if (aProperty == info[i].mProperty) {
         ActiveLayerTracker::NotifyAnimated(frame, aProperty);
--- a/layout/style/AnimationCommon.h
+++ b/layout/style/AnimationCommon.h
@@ -30,16 +30,24 @@ class nsIFrame;
 class nsPresContext;
 class nsStyleChangeList;
 
 namespace mozilla {
 
 class RestyleTracker;
 struct AnimationPlayerCollection;
 
+// Options to set when fetching animations to run on the compositor.
+enum class GetCompositorAnimationOptions {
+  // When fetching compositor animations, if there are any such animations,
+  // also let the ActiveLayerTracker know at the same time.
+  NotifyActiveLayerTracker = 1 << 0
+};
+MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(GetCompositorAnimationOptions)
+
 namespace css {
 
 bool IsGeometricProperty(nsCSSProperty aProperty);
 
 class CommonAnimationManager : public nsIStyleRuleProcessor,
                                public nsARefreshObserver {
 public:
   explicit CommonAnimationManager(nsPresContext *aPresContext);
@@ -153,22 +161,21 @@ protected:
   virtual nsIAtom* GetAnimationsAtom() = 0;
   virtual nsIAtom* GetAnimationsBeforeAtom() = 0;
   virtual nsIAtom* GetAnimationsAfterAtom() = 0;
 
   virtual bool IsAnimationManager() {
     return false;
   }
 
-  // When this returns a value other than nullptr, it also,
-  // as a side-effect, notifies the ActiveLayerTracker.
   static AnimationPlayerCollection*
   GetAnimationsForCompositor(nsIContent* aContent,
                              nsIAtom* aElementProperty,
-                             nsCSSProperty aProperty);
+                             nsCSSProperty aProperty,
+                             GetCompositorAnimationOptions aFlags);
 
   PRCList mElementCollections;
   nsPresContext *mPresContext; // weak (non-null from ctor to Disconnect)
   bool mIsObservingRefreshDriver;
 };
 
 /**
  * A style rule that maps property-StyleAnimationValue pairs.
--- a/layout/style/nsAnimationManager.h
+++ b/layout/style/nsAnimationManager.h
@@ -164,17 +164,18 @@ public:
     : mozilla::css::CommonAnimationManager(aPresContext)
   {
   }
 
   static mozilla::AnimationPlayerCollection*
   GetAnimationsForCompositor(nsIContent* aContent, nsCSSProperty aProperty)
   {
     return mozilla::css::CommonAnimationManager::GetAnimationsForCompositor(
-      aContent, nsGkAtoms::animationsProperty, aProperty);
+      aContent, nsGkAtoms::animationsProperty, aProperty,
+      mozilla::GetCompositorAnimationOptions::NotifyActiveLayerTracker);
   }
 
   void UpdateStyleAndEvents(mozilla::AnimationPlayerCollection* aEA,
                             mozilla::TimeStamp aRefreshTime,
                             mozilla::EnsureStyleRuleFlags aFlags);
   void QueueEvents(mozilla::AnimationPlayerCollection* aEA,
                    mozilla::EventArray &aEventsToDispatch);
 
--- a/layout/style/nsTransitionManager.h
+++ b/layout/style/nsTransitionManager.h
@@ -102,17 +102,18 @@ public:
   }
 
   typedef mozilla::AnimationPlayerCollection AnimationPlayerCollection;
 
   static AnimationPlayerCollection*
   GetAnimationsForCompositor(nsIContent* aContent, nsCSSProperty aProperty)
   {
     return mozilla::css::CommonAnimationManager::GetAnimationsForCompositor(
-      aContent, nsGkAtoms::transitionsProperty, aProperty);
+      aContent, nsGkAtoms::transitionsProperty, aProperty,
+      mozilla::GetCompositorAnimationOptions::NotifyActiveLayerTracker);
   }
 
   /**
    * StyleContextChanged
    *
    * To be called from nsFrameManager::ReResolveStyleContext when the
    * style of an element has changed, to initiate transitions from
    * that style change.  For style contexts with :before and :after