Skip to content

Commit

Permalink
Bug 1171966 - Update SMIL animation styles only when there are pendin…
Browse files Browse the repository at this point in the history
…g change
  • Loading branch information
InternalError503 committed Aug 14, 2015
1 parent 2742148 commit f70be92
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
7 changes: 7 additions & 0 deletions dom/smil/nsSMILAnimationController.cpp
Expand Up @@ -32,6 +32,7 @@ nsSMILAnimationController::nsSMILAnimationController(nsIDocument* aDoc)
mDeferredStartSampling(false),
mRunningSample(false),
mRegisteredWithRefreshDriver(false),
mMightHavePendingStyleUpdates(false),
mDocument(aDoc)
{
MOZ_ASSERT(aDoc, "need a non-null document");
Expand Down Expand Up @@ -459,6 +460,7 @@ nsSMILAnimationController::DoSample(bool aSkipUnchangedContainers)
// when the inherited value is *also* being animated, we really should be
// traversing our animated nodes in an ancestors-first order (bug 501183)
currentCompositorTable->EnumerateEntries(DoComposeAttribute, nullptr);
mMightHavePendingStyleUpdates = true;

// Update last compositor table
mLastCompositorTable = currentCompositorTable.forget();
Expand Down Expand Up @@ -843,7 +845,12 @@ nsSMILAnimationController::AddStyleUpdate(AnimationElementPtrKey* aKey,
void
nsSMILAnimationController::AddStyleUpdatesTo(RestyleTracker& aTracker)
{
MOZ_ASSERT(mMightHavePendingStyleUpdates,
"Should only add style updates when we think we might have some");

mAnimationElementTable.EnumerateEntries(AddStyleUpdate, &aTracker);

mMightHavePendingStyleUpdates = false;
}

//----------------------------------------------------------------------
Expand Down
21 changes: 14 additions & 7 deletions dom/smil/nsSMILAnimationController.h
Expand Up @@ -74,10 +74,8 @@ class nsSMILAnimationController final : public nsSMILTimeContainer,

void SetResampleNeeded()
{
if (!mRunningSample) {
if (!mResampleNeeded) {
FlagDocumentNeedsFlush();
}
if (!mRunningSample && !mResampleNeeded) {
FlagDocumentNeedsFlush();
mResampleNeeded = true;
}
}
Expand All @@ -104,11 +102,17 @@ class nsSMILAnimationController final : public nsSMILTimeContainer,
void NotifyRefreshDriverDestroying(nsRefreshDriver* aRefreshDriver);

// Helper to check if we have any animation elements at all
bool HasRegisteredAnimations()
{ return mAnimationElementTable.Count() != 0; }
bool HasRegisteredAnimations() const
{
return mAnimationElementTable.Count() != 0;
}

void AddStyleUpdatesTo(mozilla::RestyleTracker& aTracker);

bool MightHavePendingStyleUpdates() const
{
return mMightHavePendingStyleUpdates;
}

protected:
~nsSMILAnimationController();

Expand Down Expand Up @@ -224,6 +228,9 @@ class nsSMILAnimationController final : public nsSMILTimeContainer,

// Are we registered with our document's refresh driver?
bool mRegisteredWithRefreshDriver;

// Have we updated animated values without adding them to the restyle tracker?
bool mMightHavePendingStyleUpdates;

// Store raw ptr to mDocument. It owns the controller, so controller
// shouldn't outlive it
Expand Down
18 changes: 7 additions & 11 deletions layout/base/RestyleManager.cpp
Expand Up @@ -1737,18 +1737,14 @@ RestyleManager::UpdateOnlyAnimationStyles()
bool doCSS = mLastUpdateForThrottledAnimations != now;
mLastUpdateForThrottledAnimations = now;

bool doSMIL = false;

nsIDocument* document = mPresContext->Document();
nsSMILAnimationController* animationController = nullptr;
if (document->HasAnimationController()) {
animationController = document->GetAnimationController();
// FIXME: Ideally, we only want to do this if animation timelines
// have advanced. However, different SMIL animations could be
// getting their time from different outermost SVG elements, so
// finding all of them might be a pain. So this could be optimized
// to set doSMIL to true in fewer cases.
doSMIL = true;
}
nsSMILAnimationController* animationController =
document->HasAnimationController() ?
document->GetAnimationController() :
nullptr;
bool doSMIL = animationController &&
animationController->MightHavePendingStyleUpdates();

if (!doCSS && !doSMIL) {
return;
Expand Down

0 comments on commit f70be92

Please sign in to comment.