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 |
| 12 #include <stddef.h> | |
|
reed1
2014/06/02 18:39:50
is this not already included (directly/indirectly)
mtklein
2014/06/02 18:40:31
Nope. offsetof wasn't defined until I included th
| |
| 13 | |
| 13 // In a few places, we performed the following | 14 // In a few places, we performed the following |
| 14 // a * b + c * d + e | 15 // a * b + c * d + e |
| 15 // as | 16 // as |
| 16 // a * b + (c * d + e) | 17 // a * b + (c * d + e) |
| 17 // | 18 // |
| 18 // sdot and scross are indended to capture these compound operations into a | 19 // sdot and scross are indended to capture these compound operations into a |
| 19 // function, with an eye toward considering upscaling the intermediates to | 20 // function, with an eye toward considering upscaling the intermediates to |
| 20 // doubles for more precision (as we do in concat and invert). | 21 // doubles for more precision (as we do in concat and invert). |
| 21 // | 22 // |
| 22 // However, these few lines that performed the last add before the "dot", cause | 23 // However, these few lines that performed the last add before the "dot", cause |
| (...skipping 1530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1553 return -1; | 1554 return -1; |
| 1554 } | 1555 } |
| 1555 } | 1556 } |
| 1556 | 1557 |
| 1557 bool SkMatrix::getMinMaxScales(SkScalar scaleFactors[2]) const { | 1558 bool SkMatrix::getMinMaxScales(SkScalar scaleFactors[2]) const { |
| 1558 return get_scale_factor<kBoth_MinMaxOrBoth>(this->getType(), fMat, scaleFact ors); | 1559 return get_scale_factor<kBoth_MinMaxOrBoth>(this->getType(), fMat, scaleFact ors); |
| 1559 } | 1560 } |
| 1560 | 1561 |
| 1561 namespace { | 1562 namespace { |
| 1562 | 1563 |
| 1563 SkMatrix* create_identity() { | 1564 struct PODMatrix { |
| 1564 SkMatrix* m = SkNEW(SkMatrix); | 1565 SkScalar matrix[9]; |
| 1565 m->reset(); | 1566 uint32_t typemask; |
| 1566 return m; | |
| 1567 } | |
| 1568 | 1567 |
| 1569 SkMatrix* create_invalid() { | 1568 const SkMatrix& asSkMatrix() const { return *reinterpret_cast<const SkMatrix *>(this); } |
|
bungeman-skia
2014/06/02 17:46:32
This cast is implementation defined. Of course, we
| |
| 1570 SkMatrix* m = SkNEW(SkMatrix); | 1569 }; |
| 1571 m->setAll(SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, | 1570 SK_COMPILE_ASSERT(sizeof(PODMatrix) == sizeof(SkMatrix), PODMatrixSizeMismatch); |
| 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 | 1571 |
| 1578 } // namespace | 1572 } // namespace |
| 1579 | 1573 |
| 1580 const SkMatrix& SkMatrix::I() { | 1574 const SkMatrix& SkMatrix::I() { |
| 1581 SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, identity, create_identity); | 1575 SK_COMPILE_ASSERT(offsetof(SkMatrix, fMat) == offsetof(PODMatrix, matri x), BadfMat); |
| 1582 return *identity.get(); | 1576 SK_COMPILE_ASSERT(offsetof(SkMatrix, fTypeMask) == offsetof(PODMatrix, typem ask), BadfTypeMask); |
| 1577 | |
| 1578 static const PODMatrix identity = { {SK_Scalar1, 0, 0, | |
| 1579 0, SK_Scalar1, 0, | |
| 1580 0, 0, SK_Scalar1 }, | |
| 1581 kIdentity_Mask | kRectStaysRect_Mask}; | |
| 1582 SkASSERT(identity.asSkMatrix().isIdentity()); | |
| 1583 return identity.asSkMatrix(); | |
| 1583 } | 1584 } |
| 1584 | 1585 |
| 1585 const SkMatrix& SkMatrix::InvalidMatrix() { | 1586 const SkMatrix& SkMatrix::InvalidMatrix() { |
| 1586 SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, invalid, create_invalid); | 1587 SK_COMPILE_ASSERT(offsetof(SkMatrix, fMat) == offsetof(PODMatrix, matri x), BadfMat); |
| 1587 return *invalid.get(); | 1588 SK_COMPILE_ASSERT(offsetof(SkMatrix, fTypeMask) == offsetof(PODMatrix, typem ask), BadfTypeMask); |
| 1589 | |
| 1590 static const PODMatrix invalid = | |
| 1591 { {SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, | |
| 1592 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, | |
| 1593 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax }, | |
| 1594 kTranslate_Mask | kScale_Mask | kAffine_Mask | kPerspective_Mask }; | |
| 1595 return invalid.asSkMatrix(); | |
| 1588 } | 1596 } |
| 1589 | 1597 |
| 1590 /////////////////////////////////////////////////////////////////////////////// | 1598 /////////////////////////////////////////////////////////////////////////////// |
| 1591 | 1599 |
| 1592 size_t SkMatrix::writeToMemory(void* buffer) const { | 1600 size_t SkMatrix::writeToMemory(void* buffer) const { |
| 1593 // TODO write less for simple matrices | 1601 // TODO write less for simple matrices |
| 1594 static const size_t sizeInMemory = 9 * sizeof(SkScalar); | 1602 static const size_t sizeInMemory = 9 * sizeof(SkScalar); |
| 1595 if (buffer) { | 1603 if (buffer) { |
| 1596 memcpy(buffer, fMat, sizeInMemory); | 1604 memcpy(buffer, fMat, sizeInMemory); |
| 1597 } | 1605 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1772 rotation1->fX = cos1; | 1780 rotation1->fX = cos1; |
| 1773 rotation1->fY = sin1; | 1781 rotation1->fY = sin1; |
| 1774 } | 1782 } |
| 1775 if (NULL != rotation2) { | 1783 if (NULL != rotation2) { |
| 1776 rotation2->fX = cos2; | 1784 rotation2->fX = cos2; |
| 1777 rotation2->fY = sin2; | 1785 rotation2->fY = sin2; |
| 1778 } | 1786 } |
| 1779 | 1787 |
| 1780 return true; | 1788 return true; |
| 1781 } | 1789 } |
| OLD | NEW |