Bug 1195180 part 4 - Unregister from refresh observer when there are no animations needing ticks; r=heycam
authorBrian Birtles <birtles@gmail.com>
Mon, 28 Sep 2015 12:38:40 +0900
changeset 264598 6d53140de0b0b839c71f3ed713aff9bb8471d58b
parent 264597 9e72573ef43fef77a0d641721b91799876be2fab
child 264599 193b5f39f80635624b84cdb5a6a0dc155aae8281
push id65690
push userbbirtles@mozilla.com
push dateMon, 28 Sep 2015 03:38:57 +0000
treeherdermozilla-inbound@005e98e2c5c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1195180
milestone44.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 1195180 part 4 - Unregister from refresh observer when there are no animations needing ticks; r=heycam
dom/animation/DocumentTimeline.cpp
--- a/dom/animation/DocumentTimeline.cpp
+++ b/dom/animation/DocumentTimeline.cpp
@@ -90,16 +90,32 @@ DocumentTimeline::ToTimelineTime(const T
   result.SetValue(aTimeStamp - timing->GetNavigationStartTimeStamp());
   return result;
 }
 
 void
 DocumentTimeline::WillRefresh(mozilla::TimeStamp aTime)
 {
   MOZ_ASSERT(mIsObservingRefreshDriver);
+
+  bool needsTicks = false;
+
+  for (auto iter = mAnimations.Iter(); !iter.Done(); iter.Next()) {
+    Animation* animation = iter.Get()->GetKey();
+    needsTicks |= animation->NeedsTicks();
+  }
+
+  if (!needsTicks) {
+    // If another refresh driver observer destroys the nsPresContext,
+    // nsRefreshDriver will detect it and we won't be called.
+    MOZ_ASSERT(GetRefreshDriver(),
+               "Refresh driver should still be valid inside WillRefresh");
+    GetRefreshDriver()->RemoveRefreshObserver(this, Flush_Style);
+    mIsObservingRefreshDriver = false;
+  }
 }
 
 TimeStamp
 DocumentTimeline::ToTimeStamp(const TimeDuration& aTimeDuration) const
 {
   TimeStamp result;
   nsRefPtr<nsDOMNavigationTiming> timing = mDocument->GetNavigationTiming();
   if (MOZ_UNLIKELY(!timing)) {