Permalink
Browse files

Bug 776401 Part 2: Add animation to the layer and then add segments d…

…irectly to it r=roc
  • Loading branch information...
1 parent d272ce0 commit 279368f31dbe7d28223da58f1294984258c064af @dzbarsky dzbarsky committed Aug 20, 2012
Showing with 36 additions and 21 deletions.
  1. +12 −8 gfx/layers/Layers.cpp
  2. +6 −2 gfx/layers/Layers.h
  3. +18 −11 layout/base/nsDisplayList.cpp
View
@@ -241,16 +241,20 @@ Layer::Layer(LayerManager* aManager, void* aImplData) :
Layer::~Layer()
{}
-void
-Layer::AddAnimation(const Animation& aAnimation)
-{
- if (!AsShadowableLayer() || !AsShadowableLayer()->HasShadow())
- return;
-
- MOZ_ASSERT(aAnimation.segments().Length() >= 1);
+Animation*
+Layer::AddAnimation(TimeStamp aStart, TimeDuration aDuration, float aIterations,
+ int aDirection, nsCSSProperty aProperty, const AnimationData& aData)
+{
+ Animation* anim = mAnimations.AppendElement();
+ anim->startTime() = aStart;
+ anim->duration() = aDuration;
+ anim->numIterations() = aIterations;
+ anim->direction() = aDirection;
+ anim->property() = aProperty;
+ anim->data() = aData;
- mAnimations.AppendElement(aAnimation);
Mutated();
+ return anim;
}
void
View
@@ -52,6 +52,7 @@ class ComputedTimingFunction;
namespace layers {
class Animation;
+class AnimationData;
class CommonLayerAttributes;
class Layer;
class ThebesLayer;
@@ -706,8 +707,11 @@ class THEBES_API Layer {
*/
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
@@ -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));
}
}

0 comments on commit 279368f

Please sign in to comment.