Bug 1000185 - Part 2: Add a bool to keep track of whether nsSMILAnimationController instances are registered with a refresh driver. r=birtles, a=abillings
authorDaniel Holbert <dholbert@cs.stanford.edu>
Tue, 20 May 2014 08:34:26 -0400
changeset 192344 cb78c3777143
parent 192343 542f83ec6345
child 192345 3fb029a11c05
push id3575
push userryanvm@gmail.com
push date2014-05-20 20:33 +0000
treeherdermozilla-beta@cb78c3777143 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles, abillings
bugs1000185
milestone30.0
Bug 1000185 - Part 2: Add a bool to keep track of whether nsSMILAnimationController instances are registered with a refresh driver. r=birtles, a=abillings
dom/smil/nsSMILAnimationController.cpp
dom/smil/nsSMILAnimationController.h
--- a/dom/smil/nsSMILAnimationController.cpp
+++ b/dom/smil/nsSMILAnimationController.cpp
@@ -24,16 +24,17 @@ using namespace mozilla::dom;
 //----------------------------------------------------------------------
 // ctors, dtors, factory methods
 
 nsSMILAnimationController::nsSMILAnimationController(nsIDocument* aDoc)
   : mAvgTimeBetweenSamples(0),
     mResampleNeeded(false),
     mDeferredStartSampling(false),
     mRunningSample(false),
+    mRegisteredWithRefreshDriver(false),
     mDocument(aDoc)
 {
   NS_ABORT_IF_FALSE(aDoc, "need a non-null document");
 
   nsRefreshDriver* refreshDriver = GetRefreshDriver();
   if (refreshDriver) {
     mStartTime = refreshDriver->MostRecentRefresh();
   } else {
@@ -44,16 +45,18 @@ nsSMILAnimationController::nsSMILAnimati
   Begin();
 }
 
 nsSMILAnimationController::~nsSMILAnimationController()
 {
   NS_ASSERTION(mAnimationElementTable.Count() == 0,
                "Animation controller shouldn't be tracking any animation"
                " elements when it dies");
+  NS_ASSERTION(!mRegisteredWithRefreshDriver,
+               "Leaving stale entry in refresh driver's observer list");
 }
 
 void
 nsSMILAnimationController::Disconnect()
 {
   NS_ABORT_IF_FALSE(mDocument, "disconnecting when we weren't connected...?");
   NS_ABORT_IF_FALSE(mRefCnt.get() == 1,
                     "Expecting to disconnect when doc is sole remaining owner");
@@ -255,36 +258,40 @@ nsSMILAnimationController::NotifyRefresh
 
 void
 nsSMILAnimationController::StartSampling(nsRefreshDriver* aRefreshDriver)
 {
   NS_ASSERTION(mPauseState == 0, "Starting sampling but controller is paused");
   NS_ASSERTION(!mDeferredStartSampling,
                "Started sampling but the deferred start flag is still set");
   if (aRefreshDriver) {
+    MOZ_ASSERT(!mRegisteredWithRefreshDriver,
+               "Redundantly registering with refresh driver");
     NS_ABORT_IF_FALSE(!GetRefreshDriver() ||
                       aRefreshDriver == GetRefreshDriver(),
                       "Starting sampling with wrong refresh driver");
     // We're effectively resuming from a pause so update our current sample time
     // or else it will confuse our "average time between samples" calculations.
     mCurrentSampleTime = mozilla::TimeStamp::Now();
     aRefreshDriver->AddRefreshObserver(this, Flush_Style);
+    mRegisteredWithRefreshDriver = true;
   }
 }
 
 void
 nsSMILAnimationController::StopSampling(nsRefreshDriver* aRefreshDriver)
 {
-  if (aRefreshDriver) {
+  if (aRefreshDriver && mRegisteredWithRefreshDriver) {
     // NOTE: The document might already have been detached from its PresContext
-    // (and RefreshDriver), which would make GetRefreshDriverForDoc return null.
+    // (and RefreshDriver), which would make GetRefreshDriver() return null.
     NS_ABORT_IF_FALSE(!GetRefreshDriver() ||
                       aRefreshDriver == GetRefreshDriver(),
                       "Stopping sampling with wrong refresh driver");
     aRefreshDriver->RemoveRefreshObserver(this, Flush_Style);
+    mRegisteredWithRefreshDriver = false;
   }
 }
 
 void
 nsSMILAnimationController::MaybeStartSampling(nsRefreshDriver* aRefreshDriver)
 {
   if (mDeferredStartSampling) {
     // We've received earlier 'MaybeStartSampling' calls, and we're
--- a/dom/smil/nsSMILAnimationController.h
+++ b/dom/smil/nsSMILAnimationController.h
@@ -209,16 +209,19 @@ protected:
 
   bool                       mResampleNeeded;
   // If we're told to start sampling but there are no animation elements we just
   // record the time, set the following flag, and then wait until we have an
   // animation element. Then we'll reset this flag and actually start sampling.
   bool                       mDeferredStartSampling;
   bool                       mRunningSample;
 
+  // Are we registered with our document's refresh driver?
+  bool                       mRegisteredWithRefreshDriver;
+
   // Store raw ptr to mDocument.  It owns the controller, so controller
   // shouldn't outlive it
   nsIDocument* mDocument;
 
   // Contains compositors used in our last sample.  We keep this around
   // so we can detect when an element/attribute used to be animated,
   // but isn't anymore for some reason. (e.g. if its <animate> element is
   // removed or retargeted)