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..d1b2b1cb05e566a026050c3ccd861f1b951be4a8 100644 |
--- a/ui/compositor/layer_animation_element.cc |
+++ b/ui/compositor/layer_animation_element.cc |
@@ -563,6 +563,108 @@ class ThreadedTransformTransition : public ThreadedLayerAnimationElement { |
DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); |
}; |
+// ChildCounterTransformTransition --------------------------------------------- |
+ |
+class ChildCounterTransformTransition : public ThreadedLayerAnimationElement { |
+ public: |
+ ChildCounterTransformTransition(const gfx::Transform& parent_start, |
+ const gfx::Transform& parent_target, |
+ base::TimeDelta duration) |
+ : ThreadedLayerAnimationElement(GetProperties(), duration), |
+ parent_start_(parent_start), |
+ parent_target_(parent_target) { |
+ } |
+ virtual ~ChildCounterTransformTransition() {} |
+ |
+ protected: |
+ virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
+ start_ = delegate->GetTransformForAnimation(); |
+ effective_start_ = start_ * parent_start_; |
+ float device_scale_factor = delegate->GetDeviceScaleFactor(); |
+ cc_start_ = Layer::ConvertTransformToCCTransform(start_, |
+ device_scale_factor); |
+ cc_effective_start_ = Layer::ConvertTransformToCCTransform( |
+ effective_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(start_, parent_target_)); |
+ } |
+ |
+ virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE { |
+ gfx::Transform target = ComputeWithParentTransform(cc_effective_start_, |
+ cc_parent_target_); |
+ scoped_ptr<cc::AnimationCurve> animation_curve( |
+ new TransformAnimationCurveAdapter(tween_type(), |
ajuma
2013/08/20 15:32:41
I think we'll to perform matrix inversion in the c
avallee
2013/08/22 22:21:59
Done.
|
+ cc_start_, |
+ target, |
+ 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(start_, parent_target_); |
ajuma
2013/08/20 15:32:41
If ComputeWithParentTransform turns out to be more
avallee
2013/08/22 22:21:59
I'll leave this here for now. We could compute the
|
+ } |
+ |
+ 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); |
+ if (!parent.GetInverse(&to_return)) { |
+ DLOG(WARNING) << "Parent transform not invertible."; |
ajuma
2013/08/20 15:32:41
Use a DCHECK instead of a DLOG (so that we crash a
avallee
2013/08/22 22:21:59
Done.
|
+ to_return.MakeIdentity(); |
+ } |
+ to_return.ConcatTransform(start); |
ajuma
2013/08/20 15:32:41
Since we're skipping initialization above, this is
avallee
2013/08/22 22:21:59
It's initialized either by successfully getting th
|
+ return to_return; |
ajuma
2013/08/20 15:32:41
This method isn't using |parent| anywhere. Is some
avallee
2013/08/22 22:21:59
parent.GetInverse inside the if statement.
|
+ } |
+ |
+ static AnimatableProperties GetProperties() { |
+ AnimatableProperties properties; |
+ properties.insert(LayerAnimationElement::TRANSFORM); |
+ return properties; |
+ } |
+ |
+ gfx::Transform start_; |
+ gfx::Transform cc_start_; |
+ gfx::Transform effective_start_; |
+ gfx::Transform cc_effective_start_; |
+ |
+ const gfx::Transform parent_start_; |
+ gfx::Transform cc_parent_start_; |
+ const gfx::Transform parent_target_; |
+ gfx::Transform cc_parent_target_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ChildCounterTransformTransition); |
+}; |
+ |
} // namespace |
// LayerAnimationElement::TargetValue ------------------------------------------ |
@@ -729,6 +831,16 @@ LayerAnimationElement* LayerAnimationElement::CreateTransformElement( |
} |
// static |
+LayerAnimationElement* LayerAnimationElement::CreateInverseTransformElement( |
+ const gfx::Transform& parent_start, |
+ const gfx::Transform& parent_end, |
+ base::TimeDelta duration) { |
+ return new ChildCounterTransformTransition(parent_start, |
+ parent_end, |
+ duration); |
+} |
+ |
+// static |
LayerAnimationElement* |
LayerAnimationElement::CreateInterpolatedTransformElement( |
InterpolatedTransform* interpolated_transform, |