Bug 776401 Part 2: Add animation to the layer and then add segments directly to it r=roc

This commit is contained in:
David Zbarsky 2012-08-20 09:35:42 -04:00
parent 9adfa01a55
commit 15b5fb7346
3 changed files with 35 additions and 20 deletions

View File

@ -241,16 +241,20 @@ Layer::Layer(LayerManager* aManager, void* aImplData) :
Layer::~Layer()
{}
void
Layer::AddAnimation(const Animation& aAnimation)
Animation*
Layer::AddAnimation(TimeStamp aStart, TimeDuration aDuration, float aIterations,
int aDirection, nsCSSProperty aProperty, const AnimationData& aData)
{
if (!AsShadowableLayer() || !AsShadowableLayer()->HasShadow())
return;
Animation* anim = mAnimations.AppendElement();
anim->startTime() = aStart;
anim->duration() = aDuration;
anim->numIterations() = aIterations;
anim->direction() = aDirection;
anim->property() = aProperty;
anim->data() = aData;
MOZ_ASSERT(aAnimation.segments().Length() >= 1);
mAnimations.AppendElement(aAnimation);
Mutated();
return anim;
}
void

View File

@ -52,6 +52,7 @@ class ComputedTimingFunction;
namespace layers {
class Animation;
class AnimationData;
class CommonLayerAttributes;
class Layer;
class ThebesLayer;
@ -706,8 +707,11 @@ public:
*/
void SetIsFixedPosition(bool aFixedPosition) { mIsFixedPosition = aFixedPosition; }
// Call AddAnimation to add an animation to this layer from layout code.
void AddAnimation(const Animation& aAnimation);
// Call AddAnimation to add a new animation to this layer from layout code.
// Caller must add segments to the returned animation.
Animation* AddAnimation(mozilla::TimeStamp aStart, mozilla::TimeDuration aDuration,
float aIterations, int aDirection,
nsCSSProperty aProperty, const AnimationData& aData);
// ClearAnimations clears animations on this layer.
void ClearAnimations();
// This is only called when the layer tree is updated. Do not call this from

View File

@ -280,11 +280,26 @@ AddAnimationsForProperty(nsIFrame* aFrame, nsCSSProperty aProperty,
nsRect bounds = nsDisplayTransform::GetFrameBoundsForTransform(aFrame);
float scale = presContext->AppUnitsPerDevPixel();
TimeStamp startTime = ea->mStartTime;
TimeDuration duration = ea->mIterationDuration;
float iterations = ea->mIterationCount != NS_IEEEPositiveInfinity()
? ea->mIterationCount : -1;
int direction = ea->mDirection;
// If this is a visibility animation, we should not actually add it.
// This will be fixed in bug 783893
Animation* animation = nullptr;
for (PRUint32 propIdx = 0; propIdx < ea->mProperties.Length(); propIdx++) {
if (aProperty == ea->mProperties[propIdx].mProperty) {
animation = aLayer->AddAnimation(startTime, duration,
iterations, direction,
aProperty, aData);
break;
}
}
for (PRUint32 propIdx = 0; propIdx < ea->mProperties.Length(); propIdx++) {
AnimationProperty* property = &ea->mProperties[propIdx];
InfallibleTArray<AnimationSegment> segments;
if (aProperty != property->mProperty) {
continue;
@ -295,7 +310,7 @@ AddAnimationsForProperty(nsIFrame* aFrame, nsCSSProperty aProperty,
AnimationSegment* animSegment;
if (aProperty == eCSSProperty_transform) {
animSegment = segments.AppendElement();
animSegment = animation->segments().AppendElement();
animSegment->startState() = InfallibleTArray<TransformFunction>();
animSegment->endState() = InfallibleTArray<TransformFunction>();
@ -307,7 +322,7 @@ AddAnimationsForProperty(nsIFrame* aFrame, nsCSSProperty aProperty,
AddTransformFunctions(list, styleContext, presContext, bounds, scale,
animSegment->endState().get_ArrayOfTransformFunction());
} else if (aProperty == eCSSProperty_opacity) {
animSegment = segments.AppendElement();
animSegment = animation->segments().AppendElement();
animSegment->startState() = segment->mFromValue.GetFloatValue();
animSegment->endState() = segment->mToValue.GetFloatValue();
}
@ -316,14 +331,6 @@ AddAnimationsForProperty(nsIFrame* aFrame, nsCSSProperty aProperty,
animSegment->endPortion() = segment->mToKey;
animSegment->sampleFn() = ToTimingFunction(segment->mTimingFunction);
}
aLayer->AddAnimation(Animation(ea->mStartTime,
ea->mIterationDuration,
segments,
iterations,
ea->mDirection,
aProperty,
aData));
}
}