From c70be152947faa032c397d27b1d8051fb4ed484c Mon Sep 17 00:00:00 2001 From: Brian Birtles Date: Wed, 9 Dec 2015 16:28:10 -0500 Subject: [PATCH] Bug 1230056 part 1 - Add EffectCompositor::HasAnimationsForCompositor; r=dholbert --- dom/animation/EffectCompositor.cpp | 73 +++++++++++++++++++++++------- dom/animation/EffectCompositor.h | 3 ++ dom/animation/EffectSet.h | 1 + layout/base/nsLayoutUtils.cpp | 5 +- 4 files changed, 61 insertions(+), 21 deletions(-) diff --git a/dom/animation/EffectCompositor.cpp b/dom/animation/EffectCompositor.cpp index ab15ac0e6797..34e4a6d22c9e 100644 --- a/dom/animation/EffectCompositor.cpp +++ b/dom/animation/EffectCompositor.cpp @@ -17,11 +17,28 @@ using mozilla::dom::KeyframeEffectReadOnly; namespace mozilla { -/* static */ nsTArray> -EffectCompositor::GetAnimationsForCompositor(const nsIFrame* aFrame, - nsCSSProperty aProperty) +// Helper function to factor out the common logic from +// GetAnimationsForCompositor and HasAnimationsForCompositor. +// +// Takes an optional array to fill with eligible animations. +// +// Returns true if there are eligible animations, false otherwise. +bool +FindAnimationsForCompositor(const nsIFrame* aFrame, + nsCSSProperty aProperty, + nsTArray>* aMatches /*out*/) { - nsTArray> result; + MOZ_ASSERT(!aMatches || aMatches->IsEmpty(), + "Matches array, if provided, should be empty"); + + EffectSet* effects = EffectSet::GetEffectSet(aFrame); + if (!effects || effects->IsEmpty()) { + return false; + } + + if (aFrame->RefusedAsyncAnimation()) { + return false; + } if (!nsLayoutUtils::AreAsyncAnimationsEnabled()) { if (nsLayoutUtils::IsAnimationLoggingEnabled()) { @@ -30,18 +47,10 @@ EffectCompositor::GetAnimationsForCompositor(const nsIFrame* aFrame, "disabled"); AnimationUtils::LogAsyncAnimationFailure(message); } - return result; - } - - if (aFrame->RefusedAsyncAnimation()) { - return result; - } - - EffectSet* effects = EffectSet::GetEffectSet(aFrame); - if (!effects) { - return result; + return false; } + bool foundSome = false; for (KeyframeEffectReadOnly* effect : *effects) { MOZ_ASSERT(effect && effect->GetAnimation()); Animation* animation = effect->GetAnimation(); @@ -51,17 +60,47 @@ EffectCompositor::GetAnimationsForCompositor(const nsIFrame* aFrame, } if (effect->ShouldBlockCompositorAnimations(aFrame)) { - result.Clear(); - return result; + if (aMatches) { + aMatches->Clear(); + } + return false; } if (!effect->HasAnimationOfProperty(aProperty)) { continue; } - result.AppendElement(animation); + if (aMatches) { + aMatches->AppendElement(animation); + } + foundSome = true; } + MOZ_ASSERT(!foundSome || !aMatches || !aMatches->IsEmpty(), + "If return value is true, matches array should be non-empty"); + return foundSome; +} + +/* static */ bool +EffectCompositor::HasAnimationsForCompositor(const nsIFrame* aFrame, + nsCSSProperty aProperty) +{ + return FindAnimationsForCompositor(aFrame, aProperty, nullptr); +} + +/* static */ nsTArray> +EffectCompositor::GetAnimationsForCompositor(const nsIFrame* aFrame, + nsCSSProperty aProperty) +{ + nsTArray> result; + +#ifdef DEBUG + bool foundSome = +#endif + FindAnimationsForCompositor(aFrame, aProperty, &result); + MOZ_ASSERT(!foundSome || !result.IsEmpty(), + "If return value is true, matches array should be non-empty"); + return result; } diff --git a/dom/animation/EffectCompositor.h b/dom/animation/EffectCompositor.h index 2c6f3fb9c995..c9a3f3fd87ce 100644 --- a/dom/animation/EffectCompositor.h +++ b/dom/animation/EffectCompositor.h @@ -19,6 +19,9 @@ class Animation; class EffectCompositor { public: + static bool HasAnimationsForCompositor(const nsIFrame* aFrame, + nsCSSProperty aProperty); + static nsTArray> GetAnimationsForCompositor(const nsIFrame* aFrame, nsCSSProperty aProperty); diff --git a/dom/animation/EffectSet.h b/dom/animation/EffectSet.h index c8cbe8d9167c..5c827d47ba07 100644 --- a/dom/animation/EffectSet.h +++ b/dom/animation/EffectSet.h @@ -118,6 +118,7 @@ public: { return Iterator::EndIterator(mEffects.Iter()); } + bool IsEmpty() const { return mEffects.IsEmpty(); } static nsIAtom** GetEffectSetPropertyAtoms(); diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index cb893d44c2b8..7d3d29e98cce 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -374,10 +374,7 @@ bool nsLayoutUtils::HasAnimationsForCompositor(const nsIFrame* aFrame, nsCSSProperty aProperty) { - // XXX Bug 1230056 - Add EffectCompositor::HasAnimationsForCompositor to - // avoid allocating an array here only to throw it away. - return !EffectCompositor::GetAnimationsForCompositor(aFrame, - aProperty).IsEmpty(); + return !EffectCompositor::HasAnimationsForCompositor(aFrame, aProperty); } template