From 92c8f10ebf7bc31ec0d01ae33d054e01e71a09e7 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Thu, 19 Mar 2015 21:10:00 -0700 Subject: [PATCH] Bug 1125455 patch 6 - Only search the properties list of the animation once when adding animations to the compositor. r=birtles This removes the duplication where AddAnimationsForProperty calls HasAnimationOfProperty which goes over the list once, and then AddAnimationForProperty searches the list again and skips all but the item found before. It also makes it easier, in patch 7, to perform additional tests on the item that we found. --- layout/base/nsDisplayList.cpp | 75 +++++++++++++++++------------------ 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index 4afa515f8df6..8b50c829ec4c 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -332,7 +332,7 @@ static void AddTransformFunctions(nsCSSValueList* aList, } static TimingFunction -ToTimingFunction(ComputedTimingFunction& aCTF) +ToTimingFunction(const ComputedTimingFunction& aCTF) { if (aCTF.GetType() == nsTimingFunction::Function) { const nsSMILKeySpline* spline = aCTF.GetFunction(); @@ -345,7 +345,7 @@ ToTimingFunction(ComputedTimingFunction& aCTF) } static void -AddAnimationForProperty(nsIFrame* aFrame, nsCSSProperty aProperty, +AddAnimationForProperty(nsIFrame* aFrame, const AnimationProperty& aProperty, AnimationPlayer* aPlayer, Layer* aLayer, AnimationData& aData, bool aPending) { @@ -373,44 +373,33 @@ AddAnimationForProperty(nsIFrame* aFrame, nsCSSProperty aProperty, animation->duration() = timing.mIterationDuration; animation->iterationCount() = timing.mIterationCount; animation->direction() = timing.mDirection; - animation->property() = aProperty; + animation->property() = aProperty.mProperty; animation->data() = aData; - dom::Animation* anim = aPlayer->GetSource(); - for (size_t propIdx = 0; - propIdx < anim->Properties().Length(); - propIdx++) { - AnimationProperty& property = anim->Properties()[propIdx]; + for (uint32_t segIdx = 0; segIdx < aProperty.mSegments.Length(); segIdx++) { + const AnimationPropertySegment& segment = aProperty.mSegments[segIdx]; - if (aProperty != property.mProperty) { - continue; + AnimationSegment* animSegment = animation->segments().AppendElement(); + if (aProperty.mProperty == eCSSProperty_transform) { + animSegment->startState() = InfallibleTArray(); + animSegment->endState() = InfallibleTArray(); + + nsCSSValueSharedList* list = + segment.mFromValue.GetCSSValueSharedListValue(); + AddTransformFunctions(list->mHead, styleContext, presContext, bounds, + animSegment->startState().get_ArrayOfTransformFunction()); + + list = segment.mToValue.GetCSSValueSharedListValue(); + AddTransformFunctions(list->mHead, styleContext, presContext, bounds, + animSegment->endState().get_ArrayOfTransformFunction()); + } else if (aProperty.mProperty == eCSSProperty_opacity) { + animSegment->startState() = segment.mFromValue.GetFloatValue(); + animSegment->endState() = segment.mToValue.GetFloatValue(); } - for (uint32_t segIdx = 0; segIdx < property.mSegments.Length(); segIdx++) { - AnimationPropertySegment& segment = property.mSegments[segIdx]; - - AnimationSegment* animSegment = animation->segments().AppendElement(); - if (aProperty == eCSSProperty_transform) { - animSegment->startState() = InfallibleTArray(); - animSegment->endState() = InfallibleTArray(); - - nsCSSValueSharedList* list = - segment.mFromValue.GetCSSValueSharedListValue(); - AddTransformFunctions(list->mHead, styleContext, presContext, bounds, - animSegment->startState().get_ArrayOfTransformFunction()); - - list = segment.mToValue.GetCSSValueSharedListValue(); - AddTransformFunctions(list->mHead, styleContext, presContext, bounds, - animSegment->endState().get_ArrayOfTransformFunction()); - } else if (aProperty == eCSSProperty_opacity) { - animSegment->startState() = segment.mFromValue.GetFloatValue(); - animSegment->endState() = segment.mToValue.GetFloatValue(); - } - - animSegment->startPortion() = segment.mFromKey; - animSegment->endPortion() = segment.mToKey; - animSegment->sampleFn() = ToTimingFunction(segment.mTimingFunction); - } + animSegment->startPortion() = segment.mFromKey; + animSegment->endPortion() = segment.mToKey; + animSegment->sampleFn() = ToTimingFunction(segment.mTimingFunction); } } @@ -418,12 +407,20 @@ static void AddAnimationsForProperty(nsIFrame* aFrame, nsCSSProperty aProperty, AnimationPlayerPtrArray& aPlayers, Layer* aLayer, AnimationData& aData, - bool aPending) { + bool aPending) +{ for (size_t playerIdx = 0; playerIdx < aPlayers.Length(); playerIdx++) { AnimationPlayer* player = aPlayers[playerIdx]; + if (!player->IsRunning()) { + continue; + } dom::Animation* anim = player->GetSource(); - if (!(anim && anim->HasAnimationOfProperty(aProperty) && - player->IsRunning())) { + if (!anim) { + continue; + } + const AnimationProperty* property = + anim->GetAnimationOfProperty(aProperty); + if (!property) { continue; } @@ -443,7 +440,7 @@ AddAnimationsForProperty(nsIFrame* aFrame, nsCSSProperty aProperty, } } - AddAnimationForProperty(aFrame, aProperty, player, aLayer, aData, aPending); + AddAnimationForProperty(aFrame, *property, player, aLayer, aData, aPending); player->SetIsRunningOnCompositor(); } }