From 123fe58292b8e82e2c142adf6e9d0b676b45a881 Mon Sep 17 00:00:00 2001 From: Daniel Holbert Date: Thu, 18 Mar 2010 22:33:12 -0700 Subject: [PATCH] Bug 553075: Don't register for periodic SMIL sample callbacks until we've got some animations registered. r=roc --- content/smil/nsSMILAnimationController.cpp | 21 +++++++++++++++++++-- content/smil/nsSMILAnimationController.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/content/smil/nsSMILAnimationController.cpp b/content/smil/nsSMILAnimationController.cpp index 5ba080f1d2ac..a81ce3f2f0c0 100644 --- a/content/smil/nsSMILAnimationController.cpp +++ b/content/smil/nsSMILAnimationController.cpp @@ -81,6 +81,7 @@ GetRefreshDriverForDoc(nsIDocument* aDoc) nsSMILAnimationController::nsSMILAnimationController() : mResampleNeeded(PR_FALSE), + mDeferredStartSampling(PR_FALSE), mDocument(nsnull) { mAnimationElementTable.Init(); @@ -150,7 +151,11 @@ nsSMILAnimationController::Resume(PRUint32 aType) if (wasPaused && !mPauseState && mChildContainerTable.Count()) { Sample(); // Run the first sample manually - StartSampling(GetRefreshDriverForDoc(mDocument)); + if (mAnimationElementTable.Count()) { + StartSampling(GetRefreshDriverForDoc(mDocument)); + } else { + mDeferredStartSampling = PR_TRUE; + } } } @@ -185,6 +190,14 @@ nsSMILAnimationController::RegisterAnimationElement( nsISMILAnimationElement* aAnimationElement) { mAnimationElementTable.PutEntry(aAnimationElement); + if (mDeferredStartSampling) { + // mAnimationElementTable was empty until we just inserted its first element + NS_ABORT_IF_FALSE(mAnimationElementTable.Count() == 1, + "we shouldn't have deferred sampling if we already had " + "animations registered"); + mDeferredStartSampling = PR_FALSE; + StartSampling(GetRefreshDriverForDoc(mDocument)); + } } void @@ -695,7 +708,11 @@ nsSMILAnimationController::AddChild(nsSMILTimeContainer& aChild) if (!mPauseState && mChildContainerTable.Count() == 1) { Sample(); // Run the first sample manually - StartSampling(GetRefreshDriverForDoc(mDocument)); + if (mAnimationElementTable.Count()) { + StartSampling(GetRefreshDriverForDoc(mDocument)); + } else { + mDeferredStartSampling = PR_TRUE; + } } return NS_OK; diff --git a/content/smil/nsSMILAnimationController.h b/content/smil/nsSMILAnimationController.h index 761283604114..dac0e5974c3b 100644 --- a/content/smil/nsSMILAnimationController.h +++ b/content/smil/nsSMILAnimationController.h @@ -183,6 +183,7 @@ protected: AnimationElementHashtable mAnimationElementTable; TimeContainerHashtable mChildContainerTable; PRPackedBool mResampleNeeded; + PRPackedBool mDeferredStartSampling; // Store raw ptr to mDocument. It owns the controller, so controller // shouldn't outlive it