| Index: ui/gfx/transform_util.cc
|
| diff --git a/ui/gfx/transform_util.cc b/ui/gfx/transform_util.cc
|
| index 90c8b56e5547937f76686bfa6934064e74207112..84b18ad8f918a21b8fcbf60fd177be52970c48a3 100644
|
| --- a/ui/gfx/transform_util.cc
|
| +++ b/ui/gfx/transform_util.cc
|
| @@ -12,51 +12,51 @@ namespace gfx {
|
|
|
| namespace {
|
|
|
| -double Length3(double v[3]) {
|
| +SkMScalar Length3(SkMScalar v[3]) {
|
| return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
| }
|
|
|
| -void Scale3(double v[3], double scale) {
|
| +void Scale3(SkMScalar v[3], SkMScalar scale) {
|
| for (int i = 0; i < 3; ++i)
|
| v[i] *= scale;
|
| }
|
|
|
| template <int n>
|
| -double Dot(const double* a, const double* b) {
|
| - double toReturn = 0;
|
| +SkMScalar Dot(const SkMScalar* a, const SkMScalar* b) {
|
| + SkMScalar toReturn = 0;
|
| for (int i = 0; i < n; ++i)
|
| toReturn += a[i] * b[i];
|
| return toReturn;
|
| }
|
|
|
| template <int n>
|
| -void Combine(double* out,
|
| - const double* a,
|
| - const double* b,
|
| - double scale_a,
|
| - double scale_b) {
|
| +void Combine(SkMScalar* out,
|
| + const SkMScalar* a,
|
| + const SkMScalar* b,
|
| + SkMScalar scale_a,
|
| + SkMScalar scale_b) {
|
| for (int i = 0; i < n; ++i)
|
| out[i] = a[i] * scale_a + b[i] * scale_b;
|
| }
|
|
|
| -void Cross3(double out[3], double a[3], double b[3]) {
|
| - double x = a[1] * b[2] - a[2] * b[1];
|
| - double y = a[2] * b[0] - a[0] * b[2];
|
| - double z = a[0] * b[1] - a[1] * b[0];
|
| +void Cross3(SkMScalar out[3], SkMScalar a[3], SkMScalar b[3]) {
|
| + SkMScalar x = a[1] * b[2] - a[2] * b[1];
|
| + SkMScalar y = a[2] * b[0] - a[0] * b[2];
|
| + SkMScalar z = a[0] * b[1] - a[1] * b[0];
|
| out[0] = x;
|
| out[1] = y;
|
| out[2] = z;
|
| }
|
|
|
| // Taken from http://www.w3.org/TR/css3-transforms/.
|
| -bool Slerp(double out[4],
|
| - const double q1[4],
|
| - const double q2[4],
|
| - double progress) {
|
| - double product = Dot<4>(q1, q2);
|
| +bool Slerp(SkMScalar out[4],
|
| + const SkMScalar q1[4],
|
| + const SkMScalar q2[4],
|
| + SkMScalar progress) {
|
| + SkMScalar product = Dot<4>(q1, q2);
|
|
|
| // Clamp product to -1.0 <= product <= 1.0.
|
| - product = std::min(std::max(product, -1.0), 1.0);
|
| + product = std::min(std::max(product, -SK_MScalar1), SK_MScalar1);
|
|
|
| // Interpolate angles along the shortest path. For example, to interpolate
|
| // between a 175 degree angle and a 185 degree angle, interpolate along the
|
| @@ -65,25 +65,25 @@ bool Slerp(double out[4],
|
| // the current W3C spec. Fixing the spec to match this approach is discussed
|
| // at:
|
| // http://lists.w3.org/Archives/Public/www-style/2013May/0131.html
|
| - double scale1 = 1.0;
|
| + SkMScalar scale1 = SK_MScalar1;
|
| if (product < 0) {
|
| product = -product;
|
| - scale1 = -1.0;
|
| + scale1 = -SK_MScalar1;
|
| }
|
|
|
| - const double epsilon = 1e-5;
|
| - if (std::abs(product - 1.0) < epsilon) {
|
| + const SkMScalar epsilon = 1e-5;
|
| + if (std::abs(product - SK_MScalar1) < epsilon) {
|
| for (int i = 0; i < 4; ++i)
|
| out[i] = q1[i];
|
| return true;
|
| }
|
|
|
| - double denom = std::sqrt(1 - product * product);
|
| - double theta = std::acos(product);
|
| - double w = std::sin(progress * theta) * (1 / denom);
|
| + SkMScalar denom = std::sqrt(1 - product * product);
|
| + SkMScalar theta = std::acos(product);
|
| + SkMScalar w = std::sin(progress * theta) * (1 / denom);
|
|
|
| scale1 *= std::cos(progress * theta) - product * w;
|
| - double scale2 = w;
|
| + SkMScalar scale2 = w;
|
| Combine<4>(out, q1, q2, scale1, scale2);
|
|
|
| return true;
|
| @@ -91,14 +91,14 @@ bool Slerp(double out[4],
|
|
|
| // Returns false if the matrix cannot be normalized.
|
| bool Normalize(SkMatrix44& m) {
|
| - if (m.getDouble(3, 3) == 0.0)
|
| + if (m.get(3, 3) == 0.0)
|
| // Cannot normalize.
|
| return false;
|
|
|
| - double scale = 1.0 / m.getDouble(3, 3);
|
| + SkMScalar scale = 1.0 / m.get(3, 3);
|
| for (int i = 0; i < 4; i++)
|
| for (int j = 0; j < 4; j++)
|
| - m.setDouble(i, j, m.getDouble(i, j) * scale);
|
| + m.set(i, j, m.get(i, j) * scale);
|
|
|
| return true;
|
| }
|
| @@ -125,9 +125,9 @@ DecomposedTransform::DecomposedTransform() {
|
| bool BlendDecomposedTransforms(DecomposedTransform* out,
|
| const DecomposedTransform& to,
|
| const DecomposedTransform& from,
|
| - double progress) {
|
| - double scalea = progress;
|
| - double scaleb = 1.0 - progress;
|
| + SkMScalar progress) {
|
| + SkMScalar scalea = progress;
|
| + SkMScalar scaleb = SK_MScalar1 - progress;
|
| Combine<3>(out->translate, to.translate, from.translate, scalea, scaleb);
|
| Combine<3>(out->scale, to.scale, from.scale, scalea, scaleb);
|
| Combine<3>(out->skew, to.skew, from.skew, scalea, scaleb);
|
| @@ -152,18 +152,17 @@ bool DecomposeTransform(DecomposedTransform* decomp,
|
| SkMatrix44 perspectiveMatrix = matrix;
|
|
|
| for (int i = 0; i < 3; ++i)
|
| - perspectiveMatrix.setDouble(3, i, 0.0);
|
| + perspectiveMatrix.set(3, i, 0.0);
|
|
|
| - perspectiveMatrix.setDouble(3, 3, 1.0);
|
| + perspectiveMatrix.set(3, 3, 1.0);
|
|
|
| // If the perspective matrix is not invertible, we are also unable to
|
| // decompose, so we'll bail early. Constant taken from SkMatrix44::invert.
|
| if (std::abs(perspectiveMatrix.determinant()) < 1e-8)
|
| return false;
|
|
|
| - if (matrix.getDouble(3, 0) != 0.0 ||
|
| - matrix.getDouble(3, 1) != 0.0 ||
|
| - matrix.getDouble(3, 2) != 0.0) {
|
| + if (matrix.get(3, 0) != 0.0 || matrix.get(3, 1) != 0.0 ||
|
| + matrix.get(3, 2) != 0.0) {
|
| // rhs is the right hand side of the equation.
|
| SkMScalar rhs[4] = {
|
| matrix.get(3, 0),
|
| @@ -195,12 +194,12 @@ bool DecomposeTransform(DecomposedTransform* decomp,
|
| }
|
|
|
| for (int i = 0; i < 3; i++)
|
| - decomp->translate[i] = matrix.getDouble(i, 3);
|
| + decomp->translate[i] = matrix.get(i, 3);
|
|
|
| - double row[3][3];
|
| + SkMScalar row[3][3];
|
| for (int i = 0; i < 3; i++)
|
| for (int j = 0; j < 3; ++j)
|
| - row[i][j] = matrix.getDouble(j, i);
|
| + row[i][j] = matrix.get(j, i);
|
|
|
| // Compute X scale factor and normalize first row.
|
| decomp->scale[0] = Length3(row[0]);
|
| @@ -235,7 +234,7 @@ bool DecomposeTransform(DecomposedTransform* decomp,
|
| // At this point, the matrix (in rows) is orthonormal.
|
| // Check for a coordinate system flip. If the determinant
|
| // is -1, then negate the matrix and the scaling factors.
|
| - double pdum3[3];
|
| + SkMScalar pdum3[3];
|
| Cross3(pdum3, row[1], row[2]);
|
| if (Dot<3>(row[0], pdum3) < 0) {
|
| for (int i = 0; i < 3; i++) {
|
| @@ -268,16 +267,15 @@ bool DecomposeTransform(DecomposedTransform* decomp,
|
| Transform ComposeTransform(const DecomposedTransform& decomp) {
|
| SkMatrix44 matrix(SkMatrix44::kIdentity_Constructor);
|
| for (int i = 0; i < 4; i++)
|
| - matrix.setDouble(3, i, decomp.perspective[i]);
|
| + matrix.set(3, i, decomp.perspective[i]);
|
|
|
| - matrix.preTranslate(SkDoubleToMScalar(decomp.translate[0]),
|
| - SkDoubleToMScalar(decomp.translate[1]),
|
| - SkDoubleToMScalar(decomp.translate[2]));
|
| + matrix.preTranslate(
|
| + decomp.translate[0], decomp.translate[1], decomp.translate[2]);
|
|
|
| - 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];
|
|
|
| SkMatrix44 rotation_matrix(SkMatrix44::kUninitialized_Constructor);
|
| rotation_matrix.set3x3(1.0 - 2.0 * (y * y + z * z),
|
| @@ -294,25 +292,23 @@ Transform ComposeTransform(const DecomposedTransform& decomp) {
|
|
|
| SkMatrix44 temp(SkMatrix44::kIdentity_Constructor);
|
| if (decomp.skew[2]) {
|
| - temp.setDouble(1, 2, decomp.skew[2]);
|
| + temp.set(1, 2, decomp.skew[2]);
|
| matrix.preConcat(temp);
|
| }
|
|
|
| if (decomp.skew[1]) {
|
| - temp.setDouble(1, 2, 0);
|
| - temp.setDouble(0, 2, decomp.skew[1]);
|
| + temp.set(1, 2, 0);
|
| + temp.set(0, 2, decomp.skew[1]);
|
| matrix.preConcat(temp);
|
| }
|
|
|
| if (decomp.skew[0]) {
|
| - temp.setDouble(0, 2, 0);
|
| - temp.setDouble(0, 1, decomp.skew[0]);
|
| + temp.set(0, 2, 0);
|
| + temp.set(0, 1, decomp.skew[0]);
|
| matrix.preConcat(temp);
|
| }
|
|
|
| - matrix.preScale(SkDoubleToMScalar(decomp.scale[0]),
|
| - SkDoubleToMScalar(decomp.scale[1]),
|
| - SkDoubleToMScalar(decomp.scale[2]));
|
| + matrix.preScale(decomp.scale[0], decomp.scale[1], decomp.scale[2]);
|
|
|
| Transform to_return;
|
| to_return.matrix() = matrix;
|
|
|