Index: ui/compositor/layer_animation_element.cc |
diff --git a/ui/compositor/layer_animation_element.cc b/ui/compositor/layer_animation_element.cc |
index f70c1084a1db9e134227c54e7a883c83fc2e6433..52d974ca32dc34ee83432307515f33b723a032e3 100644 |
--- a/ui/compositor/layer_animation_element.cc |
+++ b/ui/compositor/layer_animation_element.cc |
@@ -563,6 +563,119 @@ class ThreadedTransformTransition : public ThreadedLayerAnimationElement { |
DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); |
}; |
+// ChildCounterTransformTransition --------------------------------------------- |
Ian Vollick
2013/08/26 14:19:55
I wonder if we could avoid the child/parent verbag
avallee
2013/08/27 19:29:25
Done.
|
+ |
+class ChildCounterTransformTransition : public ThreadedLayerAnimationElement { |
+ public: |
+ ChildCounterTransformTransition(const gfx::Transform& parent_start, |
+ const LayerAnimationElement* parent, |
+ base::TimeDelta duration) |
Ian Vollick
2013/08/26 14:19:55
This duration can be pulled from the 'parent' elem
avallee
2013/08/27 19:29:25
Plumbed through duration in a LAE constructor, mak
|
+ : ThreadedLayerAnimationElement(GetProperties(), duration), |
+ parent_start_(parent_start), |
+ parent_transition_(CheckAndCast(parent)) { |
+ } |
+ virtual ~ChildCounterTransformTransition() {} |
+ |
+ protected: |
+ virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
+ start_ = delegate->GetTransformForAnimation(); |
+ effective_start_ = parent_start_ * start_; |
+ |
+ TargetValue target; |
+ parent_transition_->GetTargetValue(&target); |
+ parent_target_ = target.transform; |
+ |
+ set_tween_type(parent_transition_->tween_type()); |
+ float device_scale_factor = delegate->GetDeviceScaleFactor(); |
+ cc_start_ = Layer::ConvertTransformToCCTransform(start_, |
+ device_scale_factor); |
+ cc_parent_start_ = Layer::ConvertTransformToCCTransform( |
+ parent_start_, |
+ device_scale_factor); |
+ cc_parent_target_ = Layer::ConvertTransformToCCTransform( |
+ parent_target_, |
+ device_scale_factor); |
+ } |
+ |
+ virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { |
+ if (delegate && Started()) { |
+ ThreadedLayerAnimationElement::OnAbort(delegate); |
+ delegate->SetTransformFromAnimation(ComputeCurrentTransform()); |
+ } |
+ } |
+ |
+ virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE { |
+ delegate->SetTransformFromAnimation( |
+ ComputeWithParentTransform(effective_start_, parent_target_)); |
+ } |
+ |
+ virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE { |
+ TransformAnimationCurveAdapter parent_curve(tween_type(), |
Ian Vollick
2013/08/26 14:19:55
The values in this function are built based on con
avallee
2013/08/27 19:29:25
Done.
|
+ cc_parent_start_, |
+ cc_parent_target_, |
+ duration()); |
+ scoped_ptr<cc::AnimationCurve> animation_curve( |
+ new CounterTransformCurveAdapter(parent_curve, |
+ cc_start_, |
+ duration())); |
+ scoped_ptr<cc::Animation> animation( |
+ cc::Animation::Create(animation_curve.Pass(), |
+ animation_id(), |
+ animation_group_id(), |
+ cc::Animation::Transform)); |
+ return animation.Pass(); |
+ } |
+ |
+ virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
+ target->transform = ComputeWithParentTransform(effective_start_, |
+ parent_target_); |
+ } |
+ |
+ private: |
+ gfx::Transform ComputeCurrentTransform() const { |
+ gfx::Transform parent_current = Tween::ValueBetween( |
+ Tween::CalculateValue(tween_type(), last_progressed_fraction()), |
+ parent_start_, |
+ parent_target_); |
+ return ComputeWithParentTransform(effective_start_, parent_current); |
+ } |
+ |
+ gfx::Transform ComputeWithParentTransform(gfx::Transform start, |
+ gfx::Transform parent) const { |
+ gfx::Transform to_return(gfx::Transform::kSkipInitialization); |
+ DCHECK(parent.GetInverse(&to_return)); |
+ |
+ to_return.PreconcatTransform(start); |
+ return to_return; |
+ } |
+ |
+ static AnimatableProperties GetProperties() { |
+ AnimatableProperties properties; |
+ properties.insert(LayerAnimationElement::TRANSFORM); |
+ return properties; |
+ } |
+ |
+ static const ThreadedTransformTransition* CheckAndCast( |
+ const LayerAnimationElement* element) { |
+ const AnimatableProperties& properties = element->properties(); |
+ DCHECK(properties.find(TRANSFORM) != properties.end()); |
+ return static_cast<const ThreadedTransformTransition*>(element); |
+ } |
+ |
+ gfx::Transform start_; |
Ian Vollick
2013/08/26 14:19:55
Do we need to store this at all?
avallee
2013/08/27 19:29:25
Thought we did, but reworked it so that it's no lo
|
+ gfx::Transform cc_start_; |
+ gfx::Transform effective_start_; |
+ |
+ const gfx::Transform parent_start_; |
+ gfx::Transform cc_parent_start_; |
+ gfx::Transform parent_target_; |
+ gfx::Transform cc_parent_target_; |
+ |
+ const ThreadedTransformTransition* const parent_transition_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ChildCounterTransformTransition); |
+}; |
+ |
} // namespace |
// LayerAnimationElement::TargetValue ------------------------------------------ |
@@ -729,6 +842,15 @@ LayerAnimationElement* LayerAnimationElement::CreateTransformElement( |
} |
// static |
+LayerAnimationElement* LayerAnimationElement::CreateCounterTransformElement( |
+ const gfx::Transform& parent_start, |
+ const LayerAnimationElement* parent) { |
+ return new ChildCounterTransformTransition(parent_start, |
+ parent, |
+ parent->duration()); |
Ian Vollick
2013/08/26 14:19:55
See above about ditching the 3rd param.
avallee
2013/08/27 19:29:25
Done.
|
+} |
+ |
+// static |
LayerAnimationElement* |
LayerAnimationElement::CreateInterpolatedTransformElement( |
InterpolatedTransform* interpolated_transform, |