OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // Needed on Windows to get |M_PI| from <cmath> | 5 // Needed on Windows to get |M_PI| from <cmath> |
6 #ifdef _WIN32 | 6 #ifdef _WIN32 |
7 #define _USE_MATH_DEFINES | 7 #define _USE_MATH_DEFINES |
8 #endif | 8 #endif |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 bool TransformOperation::BlendTransformOperations( | 93 bool TransformOperation::BlendTransformOperations( |
94 const TransformOperation* from, | 94 const TransformOperation* from, |
95 const TransformOperation* to, | 95 const TransformOperation* to, |
96 SkMScalar progress, | 96 SkMScalar progress, |
97 gfx::Transform* result) { | 97 gfx::Transform* result) { |
98 if (IsOperationIdentity(from) && IsOperationIdentity(to)) | 98 if (IsOperationIdentity(from) && IsOperationIdentity(to)) |
99 return true; | 99 return true; |
100 | 100 |
101 TransformOperation::Type interpolation_type = | 101 TransformOperation::Type interpolation_type = |
102 TransformOperation::TRANSFORM_OPERATION_IDENTITY; | 102 TransformOperation::TransformOperationIdentity; |
103 if (IsOperationIdentity(to)) | 103 if (IsOperationIdentity(to)) |
104 interpolation_type = from->type; | 104 interpolation_type = from->type; |
105 else | 105 else |
106 interpolation_type = to->type; | 106 interpolation_type = to->type; |
107 | 107 |
108 switch (interpolation_type) { | 108 switch (interpolation_type) { |
109 case TransformOperation::TRANSFORM_OPERATION_TRANSLATE: { | 109 case TransformOperation::TransformOperationTranslate: { |
110 SkMScalar from_x = IsOperationIdentity(from) ? 0 : from->translate.x; | 110 SkMScalar from_x = IsOperationIdentity(from) ? 0 : from->translate.x; |
111 SkMScalar from_y = IsOperationIdentity(from) ? 0 : from->translate.y; | 111 SkMScalar from_y = IsOperationIdentity(from) ? 0 : from->translate.y; |
112 SkMScalar from_z = IsOperationIdentity(from) ? 0 : from->translate.z; | 112 SkMScalar from_z = IsOperationIdentity(from) ? 0 : from->translate.z; |
113 SkMScalar to_x = IsOperationIdentity(to) ? 0 : to->translate.x; | 113 SkMScalar to_x = IsOperationIdentity(to) ? 0 : to->translate.x; |
114 SkMScalar to_y = IsOperationIdentity(to) ? 0 : to->translate.y; | 114 SkMScalar to_y = IsOperationIdentity(to) ? 0 : to->translate.y; |
115 SkMScalar to_z = IsOperationIdentity(to) ? 0 : to->translate.z; | 115 SkMScalar to_z = IsOperationIdentity(to) ? 0 : to->translate.z; |
116 result->Translate3d(BlendSkMScalars(from_x, to_x, progress), | 116 result->Translate3d(BlendSkMScalars(from_x, to_x, progress), |
117 BlendSkMScalars(from_y, to_y, progress), | 117 BlendSkMScalars(from_y, to_y, progress), |
118 BlendSkMScalars(from_z, to_z, progress)); | 118 BlendSkMScalars(from_z, to_z, progress)); |
119 break; | 119 break; |
120 } | 120 } |
121 case TransformOperation::TRANSFORM_OPERATION_ROTATE: { | 121 case TransformOperation::TransformOperationRotate: { |
122 SkMScalar axis_x = 0; | 122 SkMScalar axis_x = 0; |
123 SkMScalar axis_y = 0; | 123 SkMScalar axis_y = 0; |
124 SkMScalar axis_z = 1; | 124 SkMScalar axis_z = 1; |
125 SkMScalar from_angle = 0; | 125 SkMScalar from_angle = 0; |
126 SkMScalar to_angle = IsOperationIdentity(to) ? 0 : to->rotate.angle; | 126 SkMScalar to_angle = IsOperationIdentity(to) ? 0 : to->rotate.angle; |
127 if (ShareSameAxis(from, to, &axis_x, &axis_y, &axis_z, &from_angle)) { | 127 if (ShareSameAxis(from, to, &axis_x, &axis_y, &axis_z, &from_angle)) { |
128 result->RotateAbout(gfx::Vector3dF(axis_x, axis_y, axis_z), | 128 result->RotateAbout(gfx::Vector3dF(axis_x, axis_y, axis_z), |
129 BlendSkMScalars(from_angle, to_angle, progress)); | 129 BlendSkMScalars(from_angle, to_angle, progress)); |
130 } else { | 130 } else { |
131 gfx::Transform to_matrix; | 131 gfx::Transform to_matrix; |
132 if (!IsOperationIdentity(to)) | 132 if (!IsOperationIdentity(to)) |
133 to_matrix = to->matrix; | 133 to_matrix = to->matrix; |
134 gfx::Transform from_matrix; | 134 gfx::Transform from_matrix; |
135 if (!IsOperationIdentity(from)) | 135 if (!IsOperationIdentity(from)) |
136 from_matrix = from->matrix; | 136 from_matrix = from->matrix; |
137 *result = to_matrix; | 137 *result = to_matrix; |
138 if (!result->Blend(from_matrix, progress)) | 138 if (!result->Blend(from_matrix, progress)) |
139 return false; | 139 return false; |
140 } | 140 } |
141 break; | 141 break; |
142 } | 142 } |
143 case TransformOperation::TRANSFORM_OPERATION_SCALE: { | 143 case TransformOperation::TransformOperationScale: { |
144 SkMScalar from_x = IsOperationIdentity(from) ? 1 : from->scale.x; | 144 SkMScalar from_x = IsOperationIdentity(from) ? 1 : from->scale.x; |
145 SkMScalar from_y = IsOperationIdentity(from) ? 1 : from->scale.y; | 145 SkMScalar from_y = IsOperationIdentity(from) ? 1 : from->scale.y; |
146 SkMScalar from_z = IsOperationIdentity(from) ? 1 : from->scale.z; | 146 SkMScalar from_z = IsOperationIdentity(from) ? 1 : from->scale.z; |
147 SkMScalar to_x = IsOperationIdentity(to) ? 1 : to->scale.x; | 147 SkMScalar to_x = IsOperationIdentity(to) ? 1 : to->scale.x; |
148 SkMScalar to_y = IsOperationIdentity(to) ? 1 : to->scale.y; | 148 SkMScalar to_y = IsOperationIdentity(to) ? 1 : to->scale.y; |
149 SkMScalar to_z = IsOperationIdentity(to) ? 1 : to->scale.z; | 149 SkMScalar to_z = IsOperationIdentity(to) ? 1 : to->scale.z; |
150 result->Scale3d(BlendSkMScalars(from_x, to_x, progress), | 150 result->Scale3d(BlendSkMScalars(from_x, to_x, progress), |
151 BlendSkMScalars(from_y, to_y, progress), | 151 BlendSkMScalars(from_y, to_y, progress), |
152 BlendSkMScalars(from_z, to_z, progress)); | 152 BlendSkMScalars(from_z, to_z, progress)); |
153 break; | 153 break; |
154 } | 154 } |
155 case TransformOperation::TRANSFORM_OPERATION_SKEW: { | 155 case TransformOperation::TransformOperationSkew: { |
156 SkMScalar from_x = IsOperationIdentity(from) ? 0 : from->skew.x; | 156 SkMScalar from_x = IsOperationIdentity(from) ? 0 : from->skew.x; |
157 SkMScalar from_y = IsOperationIdentity(from) ? 0 : from->skew.y; | 157 SkMScalar from_y = IsOperationIdentity(from) ? 0 : from->skew.y; |
158 SkMScalar to_x = IsOperationIdentity(to) ? 0 : to->skew.x; | 158 SkMScalar to_x = IsOperationIdentity(to) ? 0 : to->skew.x; |
159 SkMScalar to_y = IsOperationIdentity(to) ? 0 : to->skew.y; | 159 SkMScalar to_y = IsOperationIdentity(to) ? 0 : to->skew.y; |
160 result->SkewX(BlendSkMScalars(from_x, to_x, progress)); | 160 result->SkewX(BlendSkMScalars(from_x, to_x, progress)); |
161 result->SkewY(BlendSkMScalars(from_y, to_y, progress)); | 161 result->SkewY(BlendSkMScalars(from_y, to_y, progress)); |
162 break; | 162 break; |
163 } | 163 } |
164 case TransformOperation::TRANSFORM_OPERATION_PERSPECTIVE: { | 164 case TransformOperation::TransformOperationPerspective: { |
165 SkMScalar from_perspective_depth = | 165 SkMScalar from_perspective_depth = |
166 IsOperationIdentity(from) ? std::numeric_limits<SkMScalar>::max() | 166 IsOperationIdentity(from) ? std::numeric_limits<SkMScalar>::max() |
167 : from->perspective_depth; | 167 : from->perspective_depth; |
168 SkMScalar to_perspective_depth = | 168 SkMScalar to_perspective_depth = |
169 IsOperationIdentity(to) ? std::numeric_limits<SkMScalar>::max() | 169 IsOperationIdentity(to) ? std::numeric_limits<SkMScalar>::max() |
170 : to->perspective_depth; | 170 : to->perspective_depth; |
171 if (from_perspective_depth == 0.f || to_perspective_depth == 0.f) | 171 if (from_perspective_depth == 0.f || to_perspective_depth == 0.f) |
172 return false; | 172 return false; |
173 | 173 |
174 SkMScalar blended_perspective_depth = BlendSkMScalars( | 174 SkMScalar blended_perspective_depth = BlendSkMScalars( |
175 1.f / from_perspective_depth, 1.f / to_perspective_depth, progress); | 175 1.f / from_perspective_depth, 1.f / to_perspective_depth, progress); |
176 | 176 |
177 if (blended_perspective_depth == 0.f) | 177 if (blended_perspective_depth == 0.f) |
178 return false; | 178 return false; |
179 | 179 |
180 result->ApplyPerspectiveDepth(1.f / blended_perspective_depth); | 180 result->ApplyPerspectiveDepth(1.f / blended_perspective_depth); |
181 break; | 181 break; |
182 } | 182 } |
183 case TransformOperation::TRANSFORM_OPERATION_MATRIX: { | 183 case TransformOperation::TransformOperationMatrix: { |
184 gfx::Transform to_matrix; | 184 gfx::Transform to_matrix; |
185 if (!IsOperationIdentity(to)) | 185 if (!IsOperationIdentity(to)) |
186 to_matrix = to->matrix; | 186 to_matrix = to->matrix; |
187 gfx::Transform from_matrix; | 187 gfx::Transform from_matrix; |
188 if (!IsOperationIdentity(from)) | 188 if (!IsOperationIdentity(from)) |
189 from_matrix = from->matrix; | 189 from_matrix = from->matrix; |
190 *result = to_matrix; | 190 *result = to_matrix; |
191 if (!result->Blend(from_matrix, progress)) | 191 if (!result->Blend(from_matrix, progress)) |
192 return false; | 192 return false; |
193 break; | 193 break; |
194 } | 194 } |
195 case TransformOperation::TRANSFORM_OPERATION_IDENTITY: | 195 case TransformOperation::TransformOperationIdentity: |
196 // Do nothing. | 196 // Do nothing. |
197 break; | 197 break; |
198 } | 198 } |
199 | 199 |
200 return true; | 200 return true; |
201 } | 201 } |
202 | 202 |
203 // If p = (px, py) is a point in the plane being rotated about (0, 0, nz), this | 203 // If p = (px, py) is a point in the plane being rotated about (0, 0, nz), this |
204 // function computes the angles we would have to rotate from p to get to | 204 // function computes the angles we would have to rotate from p to get to |
205 // (length(p), 0), (-length(p), 0), (0, length(p)), (0, -length(p)). If nz is | 205 // (length(p), 0), (-length(p), 0), (0, length(p)), (0, -length(p)). If nz is |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 SkMScalar max_progress, | 368 SkMScalar max_progress, |
369 gfx::BoxF* bounds) { | 369 gfx::BoxF* bounds) { |
370 bool is_identity_from = IsOperationIdentity(from); | 370 bool is_identity_from = IsOperationIdentity(from); |
371 bool is_identity_to = IsOperationIdentity(to); | 371 bool is_identity_to = IsOperationIdentity(to); |
372 if (is_identity_from && is_identity_to) { | 372 if (is_identity_from && is_identity_to) { |
373 *bounds = box; | 373 *bounds = box; |
374 return true; | 374 return true; |
375 } | 375 } |
376 | 376 |
377 TransformOperation::Type interpolation_type = | 377 TransformOperation::Type interpolation_type = |
378 TransformOperation::TRANSFORM_OPERATION_IDENTITY; | 378 TransformOperation::TransformOperationIdentity; |
379 if (is_identity_to) | 379 if (is_identity_to) |
380 interpolation_type = from->type; | 380 interpolation_type = from->type; |
381 else | 381 else |
382 interpolation_type = to->type; | 382 interpolation_type = to->type; |
383 | 383 |
384 switch (interpolation_type) { | 384 switch (interpolation_type) { |
385 case TransformOperation::TRANSFORM_OPERATION_IDENTITY: | 385 case TransformOperation::TransformOperationIdentity: |
386 *bounds = box; | 386 *bounds = box; |
387 return true; | 387 return true; |
388 case TransformOperation::TRANSFORM_OPERATION_TRANSLATE: | 388 case TransformOperation::TransformOperationTranslate: |
389 case TransformOperation::TRANSFORM_OPERATION_SKEW: | 389 case TransformOperation::TransformOperationSkew: |
390 case TransformOperation::TRANSFORM_OPERATION_PERSPECTIVE: | 390 case TransformOperation::TransformOperationPerspective: |
391 case TransformOperation::TRANSFORM_OPERATION_SCALE: { | 391 case TransformOperation::TransformOperationScale: { |
392 gfx::Transform from_transform; | 392 gfx::Transform from_transform; |
393 gfx::Transform to_transform; | 393 gfx::Transform to_transform; |
394 if (!BlendTransformOperations(from, to, min_progress, &from_transform) || | 394 if (!BlendTransformOperations(from, to, min_progress, &from_transform) || |
395 !BlendTransformOperations(from, to, max_progress, &to_transform)) | 395 !BlendTransformOperations(from, to, max_progress, &to_transform)) |
396 return false; | 396 return false; |
397 | 397 |
398 *bounds = box; | 398 *bounds = box; |
399 from_transform.TransformBox(bounds); | 399 from_transform.TransformBox(bounds); |
400 | 400 |
401 gfx::BoxF to_box = box; | 401 gfx::BoxF to_box = box; |
402 to_transform.TransformBox(&to_box); | 402 to_transform.TransformBox(&to_box); |
403 bounds->ExpandTo(to_box); | 403 bounds->ExpandTo(to_box); |
404 | 404 |
405 return true; | 405 return true; |
406 } | 406 } |
407 case TransformOperation::TRANSFORM_OPERATION_ROTATE: { | 407 case TransformOperation::TransformOperationRotate: { |
408 SkMScalar axis_x = 0; | 408 SkMScalar axis_x = 0; |
409 SkMScalar axis_y = 0; | 409 SkMScalar axis_y = 0; |
410 SkMScalar axis_z = 1; | 410 SkMScalar axis_z = 1; |
411 SkMScalar from_angle = 0; | 411 SkMScalar from_angle = 0; |
412 if (!ShareSameAxis(from, to, &axis_x, &axis_y, &axis_z, &from_angle)) | 412 if (!ShareSameAxis(from, to, &axis_x, &axis_y, &axis_z, &from_angle)) |
413 return false; | 413 return false; |
414 | 414 |
415 bool first_point = true; | 415 bool first_point = true; |
416 for (int i = 0; i < 8; ++i) { | 416 for (int i = 0; i < 8; ++i) { |
417 gfx::Point3F corner = box.origin(); | 417 gfx::Point3F corner = box.origin(); |
418 corner += gfx::Vector3dF(i & 1 ? box.width() : 0.f, | 418 corner += gfx::Vector3dF(i & 1 ? box.width() : 0.f, |
419 i & 2 ? box.height() : 0.f, | 419 i & 2 ? box.height() : 0.f, |
420 i & 4 ? box.depth() : 0.f); | 420 i & 4 ? box.depth() : 0.f); |
421 gfx::BoxF box_for_arc; | 421 gfx::BoxF box_for_arc; |
422 BoundingBoxForArc( | 422 BoundingBoxForArc( |
423 corner, from, to, min_progress, max_progress, &box_for_arc); | 423 corner, from, to, min_progress, max_progress, &box_for_arc); |
424 if (first_point) | 424 if (first_point) |
425 *bounds = box_for_arc; | 425 *bounds = box_for_arc; |
426 else | 426 else |
427 bounds->Union(box_for_arc); | 427 bounds->Union(box_for_arc); |
428 first_point = false; | 428 first_point = false; |
429 } | 429 } |
430 return true; | 430 return true; |
431 } | 431 } |
432 case TransformOperation::TRANSFORM_OPERATION_MATRIX: | 432 case TransformOperation::TransformOperationMatrix: |
433 return false; | 433 return false; |
434 } | 434 } |
435 NOTREACHED(); | 435 NOTREACHED(); |
436 return false; | 436 return false; |
437 } | 437 } |
438 | 438 |
439 } // namespace cc | 439 } // namespace cc |
OLD | NEW |