OLD | NEW |
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/gfx/interpolated_transform.h" | 5 #include "ui/gfx/interpolated_transform.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/gfx/geometry/rect.h" | 8 #include "ui/gfx/geometry/rect.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 interpolated = interpolated_xform_diff_start_end.Interpolate(i + 100); | 83 interpolated = interpolated_xform_diff_start_end.Interpolate(i + 100); |
84 CheckApproximatelyEqual(xform, interpolated); | 84 CheckApproximatelyEqual(xform, interpolated); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 TEST(InterpolatedTransformTest, InterpolatedRotationAboutPivot) { | 88 TEST(InterpolatedTransformTest, InterpolatedRotationAboutPivot) { |
89 gfx::Point pivot(100, 100); | 89 gfx::Point pivot(100, 100); |
90 gfx::Point above_pivot(100, 200); | 90 gfx::Point above_pivot(100, 200); |
91 ui::InterpolatedRotation rot(0, 90); | 91 ui::InterpolatedRotation rot(0, 90); |
92 ui::InterpolatedTransformAboutPivot interpolated_xform( | 92 ui::InterpolatedTransformAboutPivot interpolated_xform( |
93 pivot, | 93 pivot, base::MakeUnique<ui::InterpolatedRotation>(0, 90)); |
94 new ui::InterpolatedRotation(0, 90)); | |
95 gfx::Transform result = interpolated_xform.Interpolate(0.0f); | 94 gfx::Transform result = interpolated_xform.Interpolate(0.0f); |
96 CheckApproximatelyEqual(gfx::Transform(), result); | 95 CheckApproximatelyEqual(gfx::Transform(), result); |
97 result = interpolated_xform.Interpolate(1.0f); | 96 result = interpolated_xform.Interpolate(1.0f); |
98 gfx::Point expected_result = pivot; | 97 gfx::Point expected_result = pivot; |
99 result.TransformPoint(&pivot); | 98 result.TransformPoint(&pivot); |
100 EXPECT_EQ(expected_result, pivot); | 99 EXPECT_EQ(expected_result, pivot); |
101 expected_result = gfx::Point(0, 100); | 100 expected_result = gfx::Point(0, 100); |
102 result.TransformPoint(&above_pivot); | 101 result.TransformPoint(&above_pivot); |
103 EXPECT_EQ(expected_result, above_pivot); | 102 EXPECT_EQ(expected_result, above_pivot); |
104 } | 103 } |
105 | 104 |
106 TEST(InterpolatedTransformTest, InterpolatedScaleAboutPivot) { | 105 TEST(InterpolatedTransformTest, InterpolatedScaleAboutPivot) { |
107 gfx::Point pivot(100, 100); | 106 gfx::Point pivot(100, 100); |
108 gfx::Point above_pivot(100, 200); | 107 gfx::Point above_pivot(100, 200); |
109 ui::InterpolatedTransformAboutPivot interpolated_xform( | 108 ui::InterpolatedTransformAboutPivot interpolated_xform( |
110 pivot, | 109 pivot, base::MakeUnique<ui::InterpolatedScale>(gfx::Point3F(1, 1, 1), |
111 new ui::InterpolatedScale(gfx::Point3F(1, 1, 1), gfx::Point3F(2, 2, 2))); | 110 gfx::Point3F(2, 2, 2))); |
112 gfx::Transform result = interpolated_xform.Interpolate(0.0f); | 111 gfx::Transform result = interpolated_xform.Interpolate(0.0f); |
113 CheckApproximatelyEqual(gfx::Transform(), result); | 112 CheckApproximatelyEqual(gfx::Transform(), result); |
114 result = interpolated_xform.Interpolate(1.0f); | 113 result = interpolated_xform.Interpolate(1.0f); |
115 gfx::Point expected_result = pivot; | 114 gfx::Point expected_result = pivot; |
116 result.TransformPoint(&pivot); | 115 result.TransformPoint(&pivot); |
117 EXPECT_EQ(expected_result, pivot); | 116 EXPECT_EQ(expected_result, pivot); |
118 expected_result = gfx::Point(100, 300); | 117 expected_result = gfx::Point(100, 300); |
119 result.TransformPoint(&above_pivot); | 118 result.TransformPoint(&above_pivot); |
120 EXPECT_EQ(expected_result, above_pivot); | 119 EXPECT_EQ(expected_result, above_pivot); |
121 } | 120 } |
(...skipping 11 matching lines...) Expand all Loading... |
133 break; | 132 break; |
134 case -90: | 133 case -90: |
135 new_pivot = gfx::Point(0, height); | 134 new_pivot = gfx::Point(0, height); |
136 break; | 135 break; |
137 case 180: | 136 case 180: |
138 case 360: | 137 case 360: |
139 new_pivot = old_pivot = gfx::Point(width / 2, height / 2); | 138 new_pivot = old_pivot = gfx::Point(width / 2, height / 2); |
140 break; | 139 break; |
141 } | 140 } |
142 | 141 |
143 std::unique_ptr<ui::InterpolatedTransform> rotation( | 142 std::unique_ptr<ui::InterpolatedTransform> rotation = |
144 new ui::InterpolatedTransformAboutPivot( | 143 base::MakeUnique<ui::InterpolatedTransformAboutPivot>( |
145 old_pivot, new ui::InterpolatedRotation(reversed ? degrees : 0, | 144 old_pivot, base::MakeUnique<ui::InterpolatedRotation>( |
146 reversed ? 0 : degrees))); | 145 reversed ? degrees : 0, reversed ? 0 : degrees)); |
147 | 146 |
148 std::unique_ptr<ui::InterpolatedTransform> translation( | 147 std::unique_ptr<ui::InterpolatedTransform> translation = |
149 new ui::InterpolatedTranslation( | 148 base::MakeUnique<ui::InterpolatedTranslation>( |
150 gfx::PointF(), gfx::PointF(new_pivot.x() - old_pivot.x(), | 149 gfx::PointF(), gfx::PointF(new_pivot.x() - old_pivot.x(), |
151 new_pivot.y() - old_pivot.y()))); | 150 new_pivot.y() - old_pivot.y())); |
152 | 151 |
153 float scale_factor = 0.9f; | 152 float scale_factor = 0.9f; |
154 std::unique_ptr<ui::InterpolatedTransform> scale_down( | 153 std::unique_ptr<ui::InterpolatedTransform> scale_down = |
155 new ui::InterpolatedScale(1.0f, scale_factor, 0.0f, 0.5f)); | 154 base::MakeUnique<ui::InterpolatedScale>(1.0f, scale_factor, 0.0f, 0.5f); |
156 | 155 |
157 std::unique_ptr<ui::InterpolatedTransform> scale_up( | 156 std::unique_ptr<ui::InterpolatedTransform> scale_up = |
158 new ui::InterpolatedScale(1.0f, 1.0f / scale_factor, 0.5f, 1.0f)); | 157 base::MakeUnique<ui::InterpolatedScale>(1.0f, 1.0f / scale_factor, 0.5f, |
| 158 1.0f); |
159 | 159 |
160 std::unique_ptr<ui::InterpolatedTransform> to_return( | 160 std::unique_ptr<ui::InterpolatedTransform> to_return = |
161 new ui::InterpolatedConstantTransform(gfx::Transform())); | 161 base::MakeUnique<ui::InterpolatedConstantTransform>(gfx::Transform()); |
162 | 162 |
163 scale_up->SetChild(scale_down.release()); | 163 scale_up->SetChild(std::move(scale_down)); |
164 translation->SetChild(scale_up.release()); | 164 translation->SetChild(std::move(scale_up)); |
165 rotation->SetChild(translation.release()); | 165 rotation->SetChild(std::move(translation)); |
166 to_return->SetChild(rotation.release()); | 166 to_return->SetChild(std::move(rotation)); |
167 to_return->SetReversed(reversed); | 167 to_return->SetReversed(reversed); |
168 | 168 |
169 return to_return.release(); | 169 return to_return.release(); |
170 } | 170 } |
171 | 171 |
172 TEST(InterpolatedTransformTest, ScreenRotationEndsCleanly) { | 172 TEST(InterpolatedTransformTest, ScreenRotationEndsCleanly) { |
173 for (int i = 0; i < 2; ++i) { | 173 for (int i = 0; i < 2; ++i) { |
174 for (int degrees = -360; degrees <= 360; degrees += 90) { | 174 for (int degrees = -360; degrees <= 360; degrees += 90) { |
175 const bool reversed = i == 1; | 175 const bool reversed = i == 1; |
176 std::unique_ptr<ui::InterpolatedTransform> screen_rotation( | 176 std::unique_ptr<ui::InterpolatedTransform> screen_rotation( |
(...skipping 13 matching lines...) Expand all Loading... |
190 | 190 |
191 ui::InterpolatedTransform* GetMaximize() { | 191 ui::InterpolatedTransform* GetMaximize() { |
192 gfx::Rect target_bounds(0, 0, 1920, 1080); | 192 gfx::Rect target_bounds(0, 0, 1920, 1080); |
193 gfx::Rect initial_bounds(30, 1000, 192, 108); | 193 gfx::Rect initial_bounds(30, 1000, 192, 108); |
194 | 194 |
195 float scale_x = static_cast<float>( | 195 float scale_x = static_cast<float>( |
196 target_bounds.height()) / initial_bounds.width(); | 196 target_bounds.height()) / initial_bounds.width(); |
197 float scale_y = static_cast<float>( | 197 float scale_y = static_cast<float>( |
198 target_bounds.width()) / initial_bounds.height(); | 198 target_bounds.width()) / initial_bounds.height(); |
199 | 199 |
200 std::unique_ptr<ui::InterpolatedTransform> scale(new ui::InterpolatedScale( | 200 std::unique_ptr<ui::InterpolatedTransform> scale = |
201 gfx::Point3F(1, 1, 1), gfx::Point3F(scale_x, scale_y, 1))); | 201 base::MakeUnique<ui::InterpolatedScale>( |
| 202 gfx::Point3F(1, 1, 1), gfx::Point3F(scale_x, scale_y, 1)); |
202 | 203 |
203 std::unique_ptr<ui::InterpolatedTransform> translation( | 204 std::unique_ptr<ui::InterpolatedTransform> translation = |
204 new ui::InterpolatedTranslation( | 205 base::MakeUnique<ui::InterpolatedTranslation>( |
205 gfx::PointF(), gfx::PointF(target_bounds.x() - initial_bounds.x(), | 206 gfx::PointF(), gfx::PointF(target_bounds.x() - initial_bounds.x(), |
206 target_bounds.y() - initial_bounds.y()))); | 207 target_bounds.y() - initial_bounds.y())); |
207 | 208 |
208 std::unique_ptr<ui::InterpolatedTransform> rotation( | 209 std::unique_ptr<ui::InterpolatedTransform> rotation = |
209 new ui::InterpolatedRotation(0, 4.0f)); | 210 base::MakeUnique<ui::InterpolatedRotation>(0, 4.0f); |
210 | 211 |
211 std::unique_ptr<ui::InterpolatedTransform> rotation_about_pivot( | 212 std::unique_ptr<ui::InterpolatedTransform> rotation_about_pivot( |
212 new ui::InterpolatedTransformAboutPivot( | 213 base::MakeUnique<ui::InterpolatedTransformAboutPivot>( |
213 gfx::Point(initial_bounds.width() * 0.5, | 214 gfx::Point(initial_bounds.width() * 0.5, |
214 initial_bounds.height() * 0.5), | 215 initial_bounds.height() * 0.5), |
215 rotation.release())); | 216 std::move(rotation))); |
216 | 217 |
217 scale->SetChild(translation.release()); | 218 scale->SetChild(std::move(translation)); |
218 rotation_about_pivot->SetChild(scale.release()); | 219 rotation_about_pivot->SetChild(std::move(scale)); |
219 | 220 |
220 rotation_about_pivot->SetReversed(true); | 221 rotation_about_pivot->SetReversed(true); |
221 | 222 |
222 return rotation_about_pivot.release(); | 223 return rotation_about_pivot.release(); |
223 } | 224 } |
224 | 225 |
225 TEST(InterpolatedTransformTest, MaximizeEndsCleanly) { | 226 TEST(InterpolatedTransformTest, MaximizeEndsCleanly) { |
226 std::unique_ptr<ui::InterpolatedTransform> maximize(GetMaximize()); | 227 std::unique_ptr<ui::InterpolatedTransform> maximize(GetMaximize()); |
227 gfx::Transform interpolated = maximize->Interpolate(1.0f); | 228 gfx::Transform interpolated = maximize->Interpolate(1.0f); |
228 SkMatrix44& m = interpolated.matrix(); | 229 SkMatrix44& m = interpolated.matrix(); |
229 // Upper-left 3x3 matrix should all be 0, 1 or -1. | 230 // Upper-left 3x3 matrix should all be 0, 1 or -1. |
230 for (int row = 0; row < 3; ++row) { | 231 for (int row = 0; row < 3; ++row) { |
231 for (int col = 0; col < 3; ++col) { | 232 for (int col = 0; col < 3; ++col) { |
232 float entry = m.get(row, col); | 233 float entry = m.get(row, col); |
233 EXPECT_TRUE(entry == 0 || entry == 1 || entry == -1); | 234 EXPECT_TRUE(entry == 0 || entry == 1 || entry == -1); |
234 } | 235 } |
235 } | 236 } |
236 } | 237 } |
OLD | NEW |