Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkMatrix.h" | 8 #include "SkMatrix.h" |
| 9 #include "SkFloatBits.h" | 9 #include "SkFloatBits.h" |
| 10 #include "SkLazyPtr.h" | |
| 11 #include "SkString.h" | 10 #include "SkString.h" |
| 12 | 11 |
| 13 // In a few places, we performed the following | 12 // In a few places, we performed the following |
| 14 // a * b + c * d + e | 13 // a * b + c * d + e |
| 15 // as | 14 // as |
| 16 // a * b + (c * d + e) | 15 // a * b + (c * d + e) |
| 17 // | 16 // |
| 18 // sdot and scross are indended to capture these compound operations into a | 17 // sdot and scross are indended to capture these compound operations into a |
| 19 // function, with an eye toward considering upscaling the intermediates to | 18 // function, with an eye toward considering upscaling the intermediates to |
| 20 // doubles for more precision (as we do in concat and invert). | 19 // doubles for more precision (as we do in concat and invert). |
| (...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1553 return -1; | 1552 return -1; |
| 1554 } | 1553 } |
| 1555 } | 1554 } |
| 1556 | 1555 |
| 1557 bool SkMatrix::getMinMaxScales(SkScalar scaleFactors[2]) const { | 1556 bool SkMatrix::getMinMaxScales(SkScalar scaleFactors[2]) const { |
| 1558 return get_scale_factor<kBoth_MinMaxOrBoth>(this->getType(), fMat, scaleFact ors); | 1557 return get_scale_factor<kBoth_MinMaxOrBoth>(this->getType(), fMat, scaleFact ors); |
| 1559 } | 1558 } |
| 1560 | 1559 |
| 1561 namespace { | 1560 namespace { |
| 1562 | 1561 |
| 1563 SkMatrix* create_identity() { | 1562 struct PODMatrix { |
| 1564 SkMatrix* m = SkNEW(SkMatrix); | 1563 SkScalar matrix[9]; |
| 1565 m->reset(); | 1564 uint32_t typemask; |
| 1566 return m; | |
| 1567 } | |
| 1568 | 1565 |
| 1569 SkMatrix* create_invalid() { | 1566 const SkMatrix& asSkMatrix() const { return *reinterpret_cast<const SkMatrix *>(this); } |
| 1570 SkMatrix* m = SkNEW(SkMatrix); | 1567 }; |
| 1571 m->setAll(SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, | 1568 SK_COMPILE_ASSERT(sizeof(PODMatrix) == sizeof(SkMatrix), PODMatrixSizeMismatch); |
|
bungeman-skia
2014/06/02 16:35:15
In addition to this, it would be nice for SkMatrix
| |
| 1572 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, | |
| 1573 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax); | |
| 1574 m->getType(); // Force the type to be computed. | |
| 1575 return m; | |
| 1576 } | |
| 1577 | 1569 |
| 1578 } // namespace | 1570 } // namespace |
| 1579 | 1571 |
| 1580 const SkMatrix& SkMatrix::I() { | 1572 const SkMatrix& SkMatrix::I() { |
| 1581 SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, identity, create_identity); | 1573 static const PODMatrix identity = { {SK_Scalar1, 0, 0, |
| 1582 return *identity.get(); | 1574 0, SK_Scalar1, 0, |
| 1575 0, 0, SK_Scalar1 }, | |
| 1576 kIdentity_Mask | kRectStaysRect_Mask}; | |
| 1577 SkASSERT(identity.asSkMatrix().isIdentity()); | |
| 1578 return identity.asSkMatrix(); | |
| 1583 } | 1579 } |
| 1584 | 1580 |
| 1585 const SkMatrix& SkMatrix::InvalidMatrix() { | 1581 const SkMatrix& SkMatrix::InvalidMatrix() { |
| 1586 SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, invalid, create_invalid); | 1582 static const PODMatrix invalid = |
| 1587 return *invalid.get(); | 1583 { {SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, |
| 1584 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, | |
| 1585 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax }, | |
| 1586 kTranslate_Mask | kScale_Mask | kAffine_Mask | kPerspective_Mask }; | |
| 1587 return invalid.asSkMatrix(); | |
| 1588 } | 1588 } |
| 1589 | 1589 |
| 1590 /////////////////////////////////////////////////////////////////////////////// | 1590 /////////////////////////////////////////////////////////////////////////////// |
| 1591 | 1591 |
| 1592 size_t SkMatrix::writeToMemory(void* buffer) const { | 1592 size_t SkMatrix::writeToMemory(void* buffer) const { |
| 1593 // TODO write less for simple matrices | 1593 // TODO write less for simple matrices |
| 1594 static const size_t sizeInMemory = 9 * sizeof(SkScalar); | 1594 static const size_t sizeInMemory = 9 * sizeof(SkScalar); |
| 1595 if (buffer) { | 1595 if (buffer) { |
| 1596 memcpy(buffer, fMat, sizeInMemory); | 1596 memcpy(buffer, fMat, sizeInMemory); |
| 1597 } | 1597 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1772 rotation1->fX = cos1; | 1772 rotation1->fX = cos1; |
| 1773 rotation1->fY = sin1; | 1773 rotation1->fY = sin1; |
| 1774 } | 1774 } |
| 1775 if (NULL != rotation2) { | 1775 if (NULL != rotation2) { |
| 1776 rotation2->fX = cos2; | 1776 rotation2->fX = cos2; |
| 1777 rotation2->fY = sin2; | 1777 rotation2->fY = sin2; |
| 1778 } | 1778 } |
| 1779 | 1779 |
| 1780 return true; | 1780 return true; |
| 1781 } | 1781 } |
| OLD | NEW |