Chromium Code Reviews| 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include "ui/gfx/transform.h" | 8 #include "ui/gfx/transform.h" |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 0, 0, 1); | 146 0, 0, 1); |
| 147 matrix_.preConcat(rot); | 147 matrix_.preConcat(rot); |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 void Transform::RotateAbout(const Vector3dF& axis, double degrees) { | 151 void Transform::RotateAbout(const Vector3dF& axis, double degrees) { |
| 152 if (matrix_.isIdentity()) { | 152 if (matrix_.isIdentity()) { |
| 153 matrix_.setRotateDegreesAbout(SkFloatToMScalar(axis.x()), | 153 matrix_.setRotateDegreesAbout(SkFloatToMScalar(axis.x()), |
| 154 SkFloatToMScalar(axis.y()), | 154 SkFloatToMScalar(axis.y()), |
| 155 SkFloatToMScalar(axis.z()), | 155 SkFloatToMScalar(axis.z()), |
| 156 degrees); | 156 SkDoubleToMScalar(degrees)); |
| 157 } else { | 157 } else { |
| 158 SkMatrix44 rot(SkMatrix44::kUninitialized_Constructor); | 158 SkMatrix44 rot(SkMatrix44::kUninitialized_Constructor); |
| 159 rot.setRotateDegreesAbout(SkFloatToMScalar(axis.x()), | 159 rot.setRotateDegreesAbout(SkFloatToMScalar(axis.x()), |
| 160 SkFloatToMScalar(axis.y()), | 160 SkFloatToMScalar(axis.y()), |
| 161 SkFloatToMScalar(axis.z()), | 161 SkFloatToMScalar(axis.z()), |
| 162 degrees); | 162 SkDoubleToMScalar(degrees)); |
| 163 matrix_.preConcat(rot); | 163 matrix_.preConcat(rot); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 void Transform::Scale(SkMScalar x, SkMScalar y) { matrix_.preScale(x, y, 1); } | 167 void Transform::Scale(SkMScalar x, SkMScalar y) { matrix_.preScale(x, y, 1); } |
| 168 | 168 |
| 169 void Transform::Scale3d(SkMScalar x, SkMScalar y, SkMScalar z) { | 169 void Transform::Scale3d(SkMScalar x, SkMScalar y, SkMScalar z) { |
| 170 matrix_.preScale(x, y, z); | 170 matrix_.preScale(x, y, z); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void Transform::Translate(SkMScalar x, SkMScalar y) { | 173 void Transform::Translate(SkMScalar x, SkMScalar y) { |
| 174 matrix_.preTranslate(x, y, 0); | 174 matrix_.preTranslate(x, y, 0); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void Transform::Translate3d(SkMScalar x, SkMScalar y, SkMScalar z) { | 177 void Transform::Translate3d(SkMScalar x, SkMScalar y, SkMScalar z) { |
| 178 matrix_.preTranslate(x, y, z); | 178 matrix_.preTranslate(x, y, z); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void Transform::SkewX(double angle_x) { | 181 void Transform::SkewX(double angle_x) { |
| 182 if (matrix_.isIdentity()) | 182 if (matrix_.isIdentity()) { |
| 183 matrix_.set(0, 1, TanDegrees(angle_x)); | 183 matrix_.set(0, 1, TanDegrees(angle_x)); |
| 184 else { | 184 } else { |
| 185 SkMatrix44 skew(SkMatrix44::kIdentity_Constructor); | 185 SkMatrix44 skew(SkMatrix44::kIdentity_Constructor); |
| 186 skew.set(0, 1, TanDegrees(angle_x)); | 186 skew.set(0, 1, TanDegrees(angle_x)); |
| 187 matrix_.preConcat(skew); | 187 matrix_.preConcat(skew); |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 void Transform::SkewY(double angle_y) { | 191 void Transform::SkewY(double angle_y) { |
| 192 if (matrix_.isIdentity()) | 192 if (matrix_.isIdentity()) { |
| 193 matrix_.set(1, 0, TanDegrees(angle_y)); | 193 matrix_.set(1, 0, TanDegrees(angle_y)); |
| 194 else { | 194 } else { |
| 195 SkMatrix44 skew(SkMatrix44::kIdentity_Constructor); | 195 SkMatrix44 skew(SkMatrix44::kIdentity_Constructor); |
| 196 skew.set(1, 0, TanDegrees(angle_y)); | 196 skew.set(1, 0, TanDegrees(angle_y)); |
| 197 matrix_.preConcat(skew); | 197 matrix_.preConcat(skew); |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 void Transform::ApplyPerspectiveDepth(SkMScalar depth) { | 201 void Transform::ApplyPerspectiveDepth(SkMScalar depth) { |
| 202 if (depth == 0) | 202 if (depth == 0) |
| 203 return; | 203 return; |
| 204 if (matrix_.isIdentity()) | 204 if (matrix_.isIdentity()) { |
| 205 matrix_.set(3, 2, -1.0 / depth); | 205 matrix_.set(3, 2, -SK_MScalar1 / depth); |
| 206 else { | 206 } else { |
| 207 SkMatrix44 m(SkMatrix44::kIdentity_Constructor); | 207 SkMatrix44 m(SkMatrix44::kIdentity_Constructor); |
| 208 m.set(3, 2, -1.0 / depth); | 208 m.set(3, 2, -SK_MScalar1 / depth); |
| 209 matrix_.preConcat(m); | 209 matrix_.preConcat(m); |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 | 212 |
| 213 void Transform::PreconcatTransform(const Transform& transform) { | 213 void Transform::PreconcatTransform(const Transform& transform) { |
| 214 matrix_.preConcat(transform.matrix_); | 214 matrix_.preConcat(transform.matrix_); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void Transform::ConcatTransform(const Transform& transform) { | 217 void Transform::ConcatTransform(const Transform& transform) { |
| 218 matrix_.postConcat(transform.matrix_); | 218 matrix_.postConcat(transform.matrix_); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 } else { | 509 } else { |
| 510 point->SetPoint(p[0], p[1], p[2]); | 510 point->SetPoint(p[0], p[1], p[2]); |
| 511 } | 511 } |
| 512 } | 512 } |
| 513 | 513 |
| 514 void Transform::TransformPointInternal(const SkMatrix44& xform, | 514 void Transform::TransformPointInternal(const SkMatrix44& xform, |
| 515 Point* point) const { | 515 Point* point) const { |
| 516 if (xform.isIdentity()) | 516 if (xform.isIdentity()) |
| 517 return; | 517 return; |
| 518 | 518 |
| 519 SkMScalar p[4] = {SkFloatToMScalar(point->x()), SkFloatToMScalar(point->y()), | 519 SkMScalar p[4] = {SkScalarToMScalar(SkIntToScalar(point->x())), |
|
danakj
2014/10/18 18:40:06
ditto with TODO?
Peter Kasting
2014/10/20 23:38:56
Done.
| |
| 520 0, 1}; | 520 SkScalarToMScalar(SkIntToScalar(point->y())), 0, 1}; |
| 521 | 521 |
| 522 xform.mapMScalars(p); | 522 xform.mapMScalars(p); |
| 523 | 523 |
| 524 point->SetPoint(ToRoundedInt(p[0]), ToRoundedInt(p[1])); | 524 point->SetPoint(ToRoundedInt(p[0]), ToRoundedInt(p[1])); |
| 525 } | 525 } |
| 526 | 526 |
| 527 std::string Transform::ToString() const { | 527 std::string Transform::ToString() const { |
| 528 return base::StringPrintf( | 528 return base::StringPrintf( |
| 529 "[ %+0.4f %+0.4f %+0.4f %+0.4f \n" | 529 "[ %+0.4f %+0.4f %+0.4f %+0.4f \n" |
| 530 " %+0.4f %+0.4f %+0.4f %+0.4f \n" | 530 " %+0.4f %+0.4f %+0.4f %+0.4f \n" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 542 matrix_.get(2, 1), | 542 matrix_.get(2, 1), |
| 543 matrix_.get(2, 2), | 543 matrix_.get(2, 2), |
| 544 matrix_.get(2, 3), | 544 matrix_.get(2, 3), |
| 545 matrix_.get(3, 0), | 545 matrix_.get(3, 0), |
| 546 matrix_.get(3, 1), | 546 matrix_.get(3, 1), |
| 547 matrix_.get(3, 2), | 547 matrix_.get(3, 2), |
| 548 matrix_.get(3, 3)); | 548 matrix_.get(3, 3)); |
| 549 } | 549 } |
| 550 | 550 |
| 551 } // namespace gfx | 551 } // namespace gfx |
| OLD | NEW |