| 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 "SkRSXform.h" | 10 #include "SkRSXform.h" |
| (...skipping 1568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 return -1; | 1579 return -1; |
| 1580 } | 1580 } |
| 1581 } | 1581 } |
| 1582 | 1582 |
| 1583 bool SkMatrix::getMinMaxScales(SkScalar scaleFactors[2]) const { | 1583 bool SkMatrix::getMinMaxScales(SkScalar scaleFactors[2]) const { |
| 1584 return get_scale_factor<kBoth_MinMaxOrBoth>(this->getType(), fMat, scaleFact
ors); | 1584 return get_scale_factor<kBoth_MinMaxOrBoth>(this->getType(), fMat, scaleFact
ors); |
| 1585 } | 1585 } |
| 1586 | 1586 |
| 1587 namespace { | 1587 namespace { |
| 1588 | 1588 |
| 1589 struct PODMatrix { | 1589 // SkMatrix is C++11 POD (trivial and standard-layout), but not aggregate (it ha
s private fields). |
| 1590 struct AggregateMatrix { |
| 1590 SkScalar matrix[9]; | 1591 SkScalar matrix[9]; |
| 1591 uint32_t typemask; | 1592 uint32_t typemask; |
| 1592 | 1593 |
| 1593 const SkMatrix& asSkMatrix() const { return *reinterpret_cast<const SkMatrix
*>(this); } | 1594 const SkMatrix& asSkMatrix() const { return *reinterpret_cast<const SkMatrix
*>(this); } |
| 1594 }; | 1595 }; |
| 1595 static_assert(sizeof(PODMatrix) == sizeof(SkMatrix), "PODMatrixSizeMismatch"); | 1596 static_assert(sizeof(AggregateMatrix) == sizeof(SkMatrix), "AggregateMatrix size
mismatch."); |
| 1596 | 1597 |
| 1597 } // namespace | 1598 } // namespace |
| 1598 | 1599 |
| 1599 const SkMatrix& SkMatrix::I() { | 1600 const SkMatrix& SkMatrix::I() { |
| 1600 static_assert(offsetof(SkMatrix, fMat) == offsetof(PODMatrix, matrix),
"BadfMat"); | 1601 static_assert(offsetof(SkMatrix,fMat) == offsetof(AggregateMatrix,matri
x), "fMat"); |
| 1601 static_assert(offsetof(SkMatrix, fTypeMask) == offsetof(PODMatrix, typemask)
, "BadfTypeMask"); | 1602 static_assert(offsetof(SkMatrix,fTypeMask) == offsetof(AggregateMatrix,typem
ask), "fTypeMask"); |
| 1602 | 1603 |
| 1603 static const PODMatrix identity = { {SK_Scalar1, 0, 0, | 1604 static const AggregateMatrix identity = { {SK_Scalar1, 0, 0, |
| 1604 0, SK_Scalar1, 0, | 1605 0, SK_Scalar1, 0, |
| 1605 0, 0, SK_Scalar1 }, | 1606 0, 0, SK_Scalar1 }, |
| 1606 kIdentity_Mask | kRectStaysRect_Mask}; | 1607 kIdentity_Mask | kRectStaysRect_Mas
k}; |
| 1607 SkASSERT(identity.asSkMatrix().isIdentity()); | 1608 SkASSERT(identity.asSkMatrix().isIdentity()); |
| 1608 return identity.asSkMatrix(); | 1609 return identity.asSkMatrix(); |
| 1609 } | 1610 } |
| 1610 | 1611 |
| 1611 const SkMatrix& SkMatrix::InvalidMatrix() { | 1612 const SkMatrix& SkMatrix::InvalidMatrix() { |
| 1612 static_assert(offsetof(SkMatrix, fMat) == offsetof(PODMatrix, matrix),
"BadfMat"); | 1613 static_assert(offsetof(SkMatrix,fMat) == offsetof(AggregateMatrix,matri
x), "fMat"); |
| 1613 static_assert(offsetof(SkMatrix, fTypeMask) == offsetof(PODMatrix, typemask)
, "BadfTypeMask"); | 1614 static_assert(offsetof(SkMatrix,fTypeMask) == offsetof(AggregateMatrix,typem
ask), "fTypeMask"); |
| 1614 | 1615 |
| 1615 static const PODMatrix invalid = | 1616 static const AggregateMatrix invalid = |
| 1616 { {SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, | 1617 { {SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, |
| 1617 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, | 1618 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, |
| 1618 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax }, | 1619 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax }, |
| 1619 kTranslate_Mask | kScale_Mask | kAffine_Mask | kPerspective_Mask }; | 1620 kTranslate_Mask | kScale_Mask | kAffine_Mask | kPerspective_Mask }; |
| 1620 return invalid.asSkMatrix(); | 1621 return invalid.asSkMatrix(); |
| 1621 } | 1622 } |
| 1622 | 1623 |
| 1623 bool SkMatrix::decomposeScale(SkSize* scale, SkMatrix* remaining) const { | 1624 bool SkMatrix::decomposeScale(SkSize* scale, SkMatrix* remaining) const { |
| 1624 if (this->hasPerspective()) { | 1625 if (this->hasPerspective()) { |
| 1625 return false; | 1626 return false; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1850 const SkScalar m11 = m00; | 1851 const SkScalar m11 = m00; |
| 1851 const SkScalar m12 = fTy; | 1852 const SkScalar m12 = fTy; |
| 1852 | 1853 |
| 1853 quad[0].set(m02, m12); | 1854 quad[0].set(m02, m12); |
| 1854 quad[1].set(m00 * width + m02, m10 * width + m12); | 1855 quad[1].set(m00 * width + m02, m10 * width + m12); |
| 1855 quad[2].set(m00 * width + m01 * height + m02, m10 * width + m11 * height + m
12); | 1856 quad[2].set(m00 * width + m01 * height + m02, m10 * width + m11 * height + m
12); |
| 1856 quad[3].set(m01 * height + m02, m11 * height + m12); | 1857 quad[3].set(m01 * height + m02, m11 * height + m12); |
| 1857 #endif | 1858 #endif |
| 1858 } | 1859 } |
| 1859 | 1860 |
| OLD | NEW |