Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: ui/compositor/transform_animation_curve_adapter.cc

Issue 2971503002: Transform animations should not collapse by default when interpolating (Closed)
Patch Set: try again Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/compositor/transform_animation_curve_adapter.h" 5 #include "ui/compositor/transform_animation_curve_adapter.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "cc/base/time_util.h" 8 #include "cc/base/time_util.h"
9 9
10 namespace ui { 10 namespace ui {
11 11
12 namespace {
13
14 static cc::TransformOperations wrapTransform(const gfx::Transform& transform) {
ajuma 2017/07/04 14:50:56 nit: capitalize function name
Ian Vollick 2017/07/04 16:15:18 Done.
15 cc::TransformOperations operations;
16 operations.AppendMatrix(transform);
17 return operations;
18 }
19
20 } // namespace
21
12 TransformAnimationCurveAdapter::TransformAnimationCurveAdapter( 22 TransformAnimationCurveAdapter::TransformAnimationCurveAdapter(
13 gfx::Tween::Type tween_type, 23 gfx::Tween::Type tween_type,
14 gfx::Transform initial_value, 24 gfx::Transform initial_value,
15 gfx::Transform target_value, 25 gfx::Transform target_value,
16 base::TimeDelta duration) 26 base::TimeDelta duration)
17 : tween_type_(tween_type), 27 : tween_type_(tween_type),
18 initial_value_(initial_value), 28 initial_value_(initial_value),
19 target_value_(target_value), 29 target_value_(target_value),
ajuma 2017/07/04 14:50:56 If we call WrapTransform here so the stored intial
Ian Vollick 2017/07/04 16:15:18 Done.
20 duration_(duration) { 30 duration_(duration) {
21 gfx::DecomposeTransform(&decomposed_initial_value_, initial_value_); 31 gfx::DecomposeTransform(&decomposed_initial_value_, initial_value_);
22 gfx::DecomposeTransform(&decomposed_target_value_, target_value_); 32 gfx::DecomposeTransform(&decomposed_target_value_, target_value_);
23 } 33 }
24 34
25 TransformAnimationCurveAdapter::TransformAnimationCurveAdapter( 35 TransformAnimationCurveAdapter::TransformAnimationCurveAdapter(
26 const TransformAnimationCurveAdapter& other) = default; 36 const TransformAnimationCurveAdapter& other) = default;
27 37
28 TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() { 38 TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() {
29 } 39 }
30 40
31 base::TimeDelta TransformAnimationCurveAdapter::Duration() const { 41 base::TimeDelta TransformAnimationCurveAdapter::Duration() const {
32 return duration_; 42 return duration_;
33 } 43 }
34 44
35 std::unique_ptr<cc::AnimationCurve> TransformAnimationCurveAdapter::Clone() 45 std::unique_ptr<cc::AnimationCurve> TransformAnimationCurveAdapter::Clone()
36 const { 46 const {
37 return base::WrapUnique(new TransformAnimationCurveAdapter( 47 return base::WrapUnique(new TransformAnimationCurveAdapter(
38 tween_type_, initial_value_, target_value_, duration_)); 48 tween_type_, initial_value_, target_value_, duration_));
39 } 49 }
40 50
41 gfx::Transform TransformAnimationCurveAdapter::GetValue( 51 cc::TransformOperations TransformAnimationCurveAdapter::GetValue(
42 base::TimeDelta t) const { 52 base::TimeDelta t) const {
43 if (t >= duration_) 53 if (t >= duration_)
44 return target_value_; 54 return wrapTransform(target_value_);
45 if (t <= base::TimeDelta()) 55 if (t <= base::TimeDelta())
46 return initial_value_; 56 return wrapTransform(initial_value_);
47 double progress = cc::TimeUtil::Divide(t, duration_); 57 double progress = cc::TimeUtil::Divide(t, duration_);
48 58
49 gfx::DecomposedTransform to_return = gfx::BlendDecomposedTransforms( 59 gfx::DecomposedTransform to_return = gfx::BlendDecomposedTransforms(
50 decomposed_target_value_, decomposed_initial_value_, 60 decomposed_target_value_, decomposed_initial_value_,
51 gfx::Tween::CalculateValue(tween_type_, progress)); 61 gfx::Tween::CalculateValue(tween_type_, progress));
52 return gfx::ComposeTransform(to_return); 62
63 return wrapTransform(gfx::ComposeTransform(to_return));
53 } 64 }
54 65
55 bool TransformAnimationCurveAdapter::AnimatedBoundsForBox( 66 bool TransformAnimationCurveAdapter::AnimatedBoundsForBox(
56 const gfx::BoxF& box, 67 const gfx::BoxF& box,
57 gfx::BoxF* bounds) const { 68 gfx::BoxF* bounds) const {
58 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports 69 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
59 // computing bounds for TransformOperationMatrix, use that to compute 70 // computing bounds for TransformOperationMatrix, use that to compute
60 // the bounds we need here. 71 // the bounds we need here.
61 return false; 72 return false;
62 } 73 }
(...skipping 22 matching lines...) Expand all
85 } 96 }
86 97
87 InverseTransformCurveAdapter::InverseTransformCurveAdapter( 98 InverseTransformCurveAdapter::InverseTransformCurveAdapter(
88 TransformAnimationCurveAdapter base_curve, 99 TransformAnimationCurveAdapter base_curve,
89 gfx::Transform initial_value, 100 gfx::Transform initial_value,
90 base::TimeDelta duration) 101 base::TimeDelta duration)
91 : base_curve_(base_curve), 102 : base_curve_(base_curve),
92 initial_value_(initial_value), 103 initial_value_(initial_value),
93 duration_(duration) { 104 duration_(duration) {
94 effective_initial_value_ = 105 effective_initial_value_ =
95 base_curve_.GetValue(base::TimeDelta()) * initial_value_; 106 base_curve_.GetValue(base::TimeDelta()).Apply() * initial_value_;
96 } 107 }
97 108
98 InverseTransformCurveAdapter::~InverseTransformCurveAdapter() { 109 InverseTransformCurveAdapter::~InverseTransformCurveAdapter() {
99 } 110 }
100 111
101 base::TimeDelta InverseTransformCurveAdapter::Duration() const { 112 base::TimeDelta InverseTransformCurveAdapter::Duration() const {
102 return duration_; 113 return duration_;
103 } 114 }
104 115
105 std::unique_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone() 116 std::unique_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone()
106 const { 117 const {
107 return base::WrapUnique( 118 return base::WrapUnique(
108 new InverseTransformCurveAdapter(base_curve_, initial_value_, duration_)); 119 new InverseTransformCurveAdapter(base_curve_, initial_value_, duration_));
109 } 120 }
110 121
111 gfx::Transform InverseTransformCurveAdapter::GetValue(base::TimeDelta t) const { 122 cc::TransformOperations InverseTransformCurveAdapter::GetValue(
123 base::TimeDelta t) const {
112 if (t <= base::TimeDelta()) 124 if (t <= base::TimeDelta())
113 return initial_value_; 125 return wrapTransform(initial_value_);
114 126
115 gfx::Transform base_transform = base_curve_.GetValue(t); 127 gfx::Transform base_transform = base_curve_.GetValue(t).Apply();
116 // Invert base 128 // Invert base
117 gfx::Transform to_return(gfx::Transform::kSkipInitialization); 129 gfx::Transform to_return(gfx::Transform::kSkipInitialization);
118 bool is_invertible = base_transform.GetInverse(&to_return); 130 bool is_invertible = base_transform.GetInverse(&to_return);
119 DCHECK(is_invertible); 131 DCHECK(is_invertible);
120 132
121 to_return.PreconcatTransform(effective_initial_value_); 133 to_return.PreconcatTransform(effective_initial_value_);
122 return to_return; 134
135 return wrapTransform(to_return);
123 } 136 }
124 137
125 bool InverseTransformCurveAdapter::AnimatedBoundsForBox( 138 bool InverseTransformCurveAdapter::AnimatedBoundsForBox(
126 const gfx::BoxF& box, 139 const gfx::BoxF& box,
127 gfx::BoxF* bounds) const { 140 gfx::BoxF* bounds) const {
128 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports 141 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
129 // computing bounds for TransformOperationMatrix, use that to compute 142 // computing bounds for TransformOperationMatrix, use that to compute
130 // the bounds we need here. 143 // the bounds we need here.
131 return false; 144 return false;
132 } 145 }
(...skipping 14 matching lines...) Expand all
147 float* start_scale) const { 160 float* start_scale) const {
148 return false; 161 return false;
149 } 162 }
150 163
151 bool InverseTransformCurveAdapter::MaximumTargetScale(bool forward_direction, 164 bool InverseTransformCurveAdapter::MaximumTargetScale(bool forward_direction,
152 float* max_scale) const { 165 float* max_scale) const {
153 return false; 166 return false;
154 } 167 }
155 168
156 } // namespace ui 169 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698