| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Torch Mobile, Inc. | 3 * Copyright (C) 2009 Torch Mobile, Inc. |
| 4 * Copyright (C) 2013 Google Inc. All rights reserved. | 4 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 #include "wtf/Assertions.h" | 38 #include "wtf/Assertions.h" |
| 39 #include "wtf/MathExtras.h" | 39 #include "wtf/MathExtras.h" |
| 40 | 40 |
| 41 #if CPU(X86_64) | 41 #if CPU(X86_64) |
| 42 #include <emmintrin.h> | 42 #include <emmintrin.h> |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 using namespace std; | 45 using namespace std; |
| 46 | 46 |
| 47 namespace WebCore { | 47 namespace blink { |
| 48 | 48 |
| 49 // | 49 // |
| 50 // Supporting Math Functions | 50 // Supporting Math Functions |
| 51 // | 51 // |
| 52 // This is a set of function from various places (attributed inline) to do thing
s like | 52 // This is a set of function from various places (attributed inline) to do thing
s like |
| 53 // inversion and decomposition of a 4x4 matrix. They are used throughout the cod
e | 53 // inversion and decomposition of a 4x4 matrix. They are used throughout the cod
e |
| 54 // | 54 // |
| 55 | 55 |
| 56 // | 56 // |
| 57 // Adapted from Matrix Inversion by Richard Carling, Graphics Gems <http://tog.a
cm.org/GraphicsGems/index.html>. | 57 // Adapted from Matrix Inversion by Richard Carling, Graphics Gems <http://tog.a
cm.org/GraphicsGems/index.html>. |
| (...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 resultY /= w; | 1290 resultY /= w; |
| 1291 resultZ /= w; | 1291 resultZ /= w; |
| 1292 } | 1292 } |
| 1293 } | 1293 } |
| 1294 | 1294 |
| 1295 bool TransformationMatrix::isInvertible() const | 1295 bool TransformationMatrix::isInvertible() const |
| 1296 { | 1296 { |
| 1297 if (isIdentityOrTranslation()) | 1297 if (isIdentityOrTranslation()) |
| 1298 return true; | 1298 return true; |
| 1299 | 1299 |
| 1300 double det = WebCore::determinant4x4(m_matrix); | 1300 double det = blink::determinant4x4(m_matrix); |
| 1301 | 1301 |
| 1302 if (fabs(det) < SMALL_NUMBER) | 1302 if (fabs(det) < SMALL_NUMBER) |
| 1303 return false; | 1303 return false; |
| 1304 | 1304 |
| 1305 return true; | 1305 return true; |
| 1306 } | 1306 } |
| 1307 | 1307 |
| 1308 TransformationMatrix TransformationMatrix::inverse() const | 1308 TransformationMatrix TransformationMatrix::inverse() const |
| 1309 { | 1309 { |
| 1310 if (isIdentityOrTranslation()) { | 1310 if (isIdentityOrTranslation()) { |
| 1311 // identity matrix | 1311 // identity matrix |
| 1312 if (m_matrix[3][0] == 0 && m_matrix[3][1] == 0 && m_matrix[3][2] == 0) | 1312 if (m_matrix[3][0] == 0 && m_matrix[3][1] == 0 && m_matrix[3][2] == 0) |
| 1313 return TransformationMatrix(); | 1313 return TransformationMatrix(); |
| 1314 | 1314 |
| 1315 // translation | 1315 // translation |
| 1316 return TransformationMatrix(1, 0, 0, 0, | 1316 return TransformationMatrix(1, 0, 0, 0, |
| 1317 0, 1, 0, 0, | 1317 0, 1, 0, 0, |
| 1318 0, 0, 1, 0, | 1318 0, 0, 1, 0, |
| 1319 -m_matrix[3][0], -m_matrix[3][1], -m_matrix[
3][2], 1); | 1319 -m_matrix[3][0], -m_matrix[3][1], -m_matrix[
3][2], 1); |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 TransformationMatrix invMat; | 1322 TransformationMatrix invMat; |
| 1323 bool inverted = WebCore::inverse(m_matrix, invMat.m_matrix); | 1323 bool inverted = blink::inverse(m_matrix, invMat.m_matrix); |
| 1324 if (!inverted) | 1324 if (!inverted) |
| 1325 return TransformationMatrix(); | 1325 return TransformationMatrix(); |
| 1326 | 1326 |
| 1327 return invMat; | 1327 return invMat; |
| 1328 } | 1328 } |
| 1329 | 1329 |
| 1330 void TransformationMatrix::makeAffine() | 1330 void TransformationMatrix::makeAffine() |
| 1331 { | 1331 { |
| 1332 m_matrix[0][2] = 0; | 1332 m_matrix[0][2] = 0; |
| 1333 m_matrix[0][3] = 0; | 1333 m_matrix[0][3] = 0; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 bool TransformationMatrix::decompose(DecomposedType& decomp) const | 1394 bool TransformationMatrix::decompose(DecomposedType& decomp) const |
| 1395 { | 1395 { |
| 1396 if (isIdentity()) { | 1396 if (isIdentity()) { |
| 1397 memset(&decomp, 0, sizeof(decomp)); | 1397 memset(&decomp, 0, sizeof(decomp)); |
| 1398 decomp.perspectiveW = 1; | 1398 decomp.perspectiveW = 1; |
| 1399 decomp.scaleX = 1; | 1399 decomp.scaleX = 1; |
| 1400 decomp.scaleY = 1; | 1400 decomp.scaleY = 1; |
| 1401 decomp.scaleZ = 1; | 1401 decomp.scaleZ = 1; |
| 1402 } | 1402 } |
| 1403 | 1403 |
| 1404 if (!WebCore::decompose(m_matrix, decomp)) | 1404 if (!blink::decompose(m_matrix, decomp)) |
| 1405 return false; | 1405 return false; |
| 1406 return true; | 1406 return true; |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 void TransformationMatrix::recompose(const DecomposedType& decomp) | 1409 void TransformationMatrix::recompose(const DecomposedType& decomp) |
| 1410 { | 1410 { |
| 1411 makeIdentity(); | 1411 makeIdentity(); |
| 1412 | 1412 |
| 1413 // first apply perspective | 1413 // first apply perspective |
| 1414 m_matrix[0][3] = decomp.perspectiveX; | 1414 m_matrix[0][3] = decomp.perspectiveX; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 // | 1514 // |
| 1515 // Since we know we will be using (0, 0, 1), and we only care about the z-co
mponent of | 1515 // Since we know we will be using (0, 0, 1), and we only care about the z-co
mponent of |
| 1516 // the transformed normal, then we only need the m33() element of the | 1516 // the transformed normal, then we only need the m33() element of the |
| 1517 // inverse-transpose. Therefore we do not need the transpose. | 1517 // inverse-transpose. Therefore we do not need the transpose. |
| 1518 // | 1518 // |
| 1519 // Additionally, if we only need the m33() element, we do not need to comput
e a full | 1519 // Additionally, if we only need the m33() element, we do not need to comput
e a full |
| 1520 // inverse. Instead, knowing the inverse of a matrix is adjoint(matrix) / de
terminant, | 1520 // inverse. Instead, knowing the inverse of a matrix is adjoint(matrix) / de
terminant, |
| 1521 // we can simply compute the m33() of the adjoint (adjugate) matrix, without
computing | 1521 // we can simply compute the m33() of the adjoint (adjugate) matrix, without
computing |
| 1522 // the full adjoint. | 1522 // the full adjoint. |
| 1523 | 1523 |
| 1524 double determinant = WebCore::determinant4x4(m_matrix); | 1524 double determinant = blink::determinant4x4(m_matrix); |
| 1525 | 1525 |
| 1526 // If the matrix is not invertible, then we assume its backface is not visib
le. | 1526 // If the matrix is not invertible, then we assume its backface is not visib
le. |
| 1527 if (fabs(determinant) < SMALL_NUMBER) | 1527 if (fabs(determinant) < SMALL_NUMBER) |
| 1528 return false; | 1528 return false; |
| 1529 | 1529 |
| 1530 double cofactor33 = determinant3x3(m11(), m12(), m14(), m21(), m22(), m24(),
m41(), m42(), m44()); | 1530 double cofactor33 = determinant3x3(m11(), m12(), m14(), m21(), m22(), m24(),
m41(), m42(), m44()); |
| 1531 double zComponentOfTransformedNormal = cofactor33 / determinant; | 1531 double zComponentOfTransformedNormal = cofactor33 / determinant; |
| 1532 | 1532 |
| 1533 return zComponentOfTransformedNormal < 0; | 1533 return zComponentOfTransformedNormal < 0; |
| 1534 } | 1534 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1549 ret.setDouble(2, 2, matrix.m33()); | 1549 ret.setDouble(2, 2, matrix.m33()); |
| 1550 ret.setDouble(2, 3, matrix.m43()); | 1550 ret.setDouble(2, 3, matrix.m43()); |
| 1551 ret.setDouble(3, 0, matrix.m14()); | 1551 ret.setDouble(3, 0, matrix.m14()); |
| 1552 ret.setDouble(3, 1, matrix.m24()); | 1552 ret.setDouble(3, 1, matrix.m24()); |
| 1553 ret.setDouble(3, 2, matrix.m34()); | 1553 ret.setDouble(3, 2, matrix.m34()); |
| 1554 ret.setDouble(3, 3, matrix.m44()); | 1554 ret.setDouble(3, 3, matrix.m44()); |
| 1555 return ret; | 1555 return ret; |
| 1556 } | 1556 } |
| 1557 | 1557 |
| 1558 } | 1558 } |
| OLD | NEW |