Bug 1230056 part 1 - Add EffectCompositor::HasAnimationsForCompositor; r=dholbert

This commit is contained in:
Brian Birtles 2015-12-09 16:28:10 -05:00
Родитель d3b0e4b03c
Коммит c70be15294
4 изменённых файлов: 61 добавлений и 21 удалений

Просмотреть файл

@ -17,11 +17,28 @@ using mozilla::dom::KeyframeEffectReadOnly;
namespace mozilla {
/* static */ nsTArray<RefPtr<dom::Animation>>
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<RefPtr<dom::Animation>>* aMatches /*out*/)
{
nsTArray<RefPtr<dom::Animation>> 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<RefPtr<dom::Animation>>
EffectCompositor::GetAnimationsForCompositor(const nsIFrame* aFrame,
nsCSSProperty aProperty)
{
nsTArray<RefPtr<dom::Animation>> 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;
}

Просмотреть файл

@ -19,6 +19,9 @@ class Animation;
class EffectCompositor
{
public:
static bool HasAnimationsForCompositor(const nsIFrame* aFrame,
nsCSSProperty aProperty);
static nsTArray<RefPtr<dom::Animation>>
GetAnimationsForCompositor(const nsIFrame* aFrame,
nsCSSProperty aProperty);

Просмотреть файл

@ -118,6 +118,7 @@ public:
{
return Iterator::EndIterator(mEffects.Iter());
}
bool IsEmpty() const { return mEffects.IsEmpty(); }
static nsIAtom** GetEffectSetPropertyAtoms();

Просмотреть файл

@ -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<typename TestType>