Index: ui/gfx/transform_util.cc |
diff --git a/ui/gfx/transform_util.cc b/ui/gfx/transform_util.cc |
index 655ce57f2bb2b799cbf7da1b69164d97e5a42dd0..055ec0d514a83b66a848b7f248cd24019952f8d8 100644 |
--- a/ui/gfx/transform_util.cc |
+++ b/ui/gfx/transform_util.cc |
@@ -107,7 +107,7 @@ bool Normalize(SkMatrix44& m) { |
// Cannot normalize. |
return false; |
- SkMScalar scale = 1.0 / m.get(3, 3); |
+ SkMScalar scale = SK_MScalar1 / m.get(3, 3); |
for (int i = 0; i < 4; i++) |
for (int j = 0; j < 4; j++) |
m.set(i, j, m.get(i, j) * scale); |
@@ -140,23 +140,24 @@ SkMatrix44 BuildSnappedTranslationMatrix(DecomposedTransform decomp) { |
} |
SkMatrix44 BuildRotationMatrix(const DecomposedTransform& decomp) { |
- double x = decomp.quaternion[0]; |
- double y = decomp.quaternion[1]; |
- double z = decomp.quaternion[2]; |
- double w = decomp.quaternion[3]; |
+ SkMScalar x = decomp.quaternion[0]; |
+ SkMScalar y = decomp.quaternion[1]; |
+ SkMScalar z = decomp.quaternion[2]; |
+ SkMScalar w = decomp.quaternion[3]; |
+ SkMScalar two = SkFloatToMScalar(2.0f); |
SkMatrix44 matrix(SkMatrix44::kUninitialized_Constructor); |
// Implicitly calls matrix.setIdentity() |
- matrix.set3x3(1.0 - 2.0 * (y * y + z * z), |
- 2.0 * (x * y + z * w), |
- 2.0 * (x * z - y * w), |
- 2.0 * (x * y - z * w), |
- 1.0 - 2.0 * (x * x + z * z), |
- 2.0 * (y * z + x * w), |
- 2.0 * (x * z + y * w), |
- 2.0 * (y * z - x * w), |
- 1.0 - 2.0 * (x * x + y * y)); |
+ matrix.set3x3(SK_MScalar1 - two * (y * y + z * z), |
danakj
2014/10/18 18:40:06
i think you should downcast to float after the com
Peter Kasting
2014/10/20 23:38:56
Done. It might be nice to have a test that would
danakj
2014/10/23 15:35:44
I agree, tho I'm not sure either :) +awoloszyn FYI
|
+ two * (x * y + z * w), |
+ two * (x * z - y * w), |
+ two * (x * y - z * w), |
+ SK_MScalar1 - two * (x * x + z * z), |
+ two * (y * z + x * w), |
+ two * (x * z + y * w), |
+ two * (y * z - x * w), |
+ SK_MScalar1 - two * (x * x + y * y)); |
return matrix; |
} |
@@ -373,7 +374,7 @@ bool DecomposeTransform(DecomposedTransform* decomp, |
// Compute X scale factor and normalize first row. |
decomp->scale[0] = Length3(row[0]); |
if (decomp->scale[0] != 0.0) |
- Scale3(row[0], 1.0 / decomp->scale[0]); |
+ Scale3(row[0], SK_MScalar1 / decomp->scale[0]); |
// Compute XY shear factor and make 2nd row orthogonal to 1st. |
decomp->skew[0] = Dot<3>(row[0], row[1]); |
@@ -382,7 +383,7 @@ bool DecomposeTransform(DecomposedTransform* decomp, |
// Now, compute Y scale and normalize 2nd row. |
decomp->scale[1] = Length3(row[1]); |
if (decomp->scale[1] != 0.0) |
- Scale3(row[1], 1.0 / decomp->scale[1]); |
+ Scale3(row[1], SK_MScalar1 / decomp->scale[1]); |
decomp->skew[0] /= decomp->scale[1]; |
@@ -395,7 +396,7 @@ bool DecomposeTransform(DecomposedTransform* decomp, |
// Next, get Z scale and normalize 3rd row. |
decomp->scale[2] = Length3(row[2]); |
if (decomp->scale[2] != 0.0) |
- Scale3(row[2], 1.0 / decomp->scale[2]); |
+ Scale3(row[2], SK_MScalar1 / decomp->scale[2]); |
decomp->skew[1] /= decomp->scale[2]; |
decomp->skew[2] /= decomp->scale[2]; |
@@ -413,14 +414,18 @@ bool DecomposeTransform(DecomposedTransform* decomp, |
} |
} |
- decomp->quaternion[0] = |
- 0.5 * std::sqrt(std::max(1.0 + row[0][0] - row[1][1] - row[2][2], 0.0)); |
- decomp->quaternion[1] = |
- 0.5 * std::sqrt(std::max(1.0 - row[0][0] + row[1][1] - row[2][2], 0.0)); |
- decomp->quaternion[2] = |
- 0.5 * std::sqrt(std::max(1.0 - row[0][0] - row[1][1] + row[2][2], 0.0)); |
- decomp->quaternion[3] = |
- 0.5 * std::sqrt(std::max(1.0 + row[0][0] + row[1][1] + row[2][2], 0.0)); |
+ SkMScalar half = SkFloatToMScalar(0.5f); |
+ double row00 = SkMScalarToDouble(row[0][0]); |
+ double row11 = SkMScalarToDouble(row[1][1]); |
+ double row22 = SkMScalarToDouble(row[2][2]); |
+ decomp->quaternion[0] = half * |
+ std::sqrt(SkDoubleToMScalar(std::max(1.0 + row00 - row11 - row22, 0.0))); |
danakj
2014/10/18 18:40:06
do the double to mscalar after taking the sqrt
Peter Kasting
2014/10/20 23:38:56
Done.
|
+ decomp->quaternion[1] = half * |
+ std::sqrt(SkDoubleToMScalar(std::max(1.0 - row00 + row11 - row22, 0.0))); |
+ decomp->quaternion[2] = half * |
+ std::sqrt(SkDoubleToMScalar(std::max(1.0 - row00 - row11 + row22, 0.0))); |
+ decomp->quaternion[3] = half * |
+ std::sqrt(SkDoubleToMScalar(std::max(1.0 + row00 + row11 + row22, 0.0))); |
if (row[2][1] > row[1][2]) |
decomp->quaternion[0] = -decomp->quaternion[0]; |