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 "SkString.h" | 10 #include "SkString.h" |
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 SK_COMPILE_ASSERT(offsetof(SkMatrix, fTypeMask) == offsetof(PODMatrix, typem
ask), BadfTypeMask); | 1596 SK_COMPILE_ASSERT(offsetof(SkMatrix, fTypeMask) == offsetof(PODMatrix, typem
ask), BadfTypeMask); |
1597 | 1597 |
1598 static const PODMatrix invalid = | 1598 static const PODMatrix invalid = |
1599 { {SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, | 1599 { {SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, |
1600 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, | 1600 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, |
1601 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax }, | 1601 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax }, |
1602 kTranslate_Mask | kScale_Mask | kAffine_Mask | kPerspective_Mask }; | 1602 kTranslate_Mask | kScale_Mask | kAffine_Mask | kPerspective_Mask }; |
1603 return invalid.asSkMatrix(); | 1603 return invalid.asSkMatrix(); |
1604 } | 1604 } |
1605 | 1605 |
| 1606 bool SkMatrix::decomposeScale(SkSize* scale, SkMatrix* remaining) const { |
| 1607 if (this->hasPerspective()) { |
| 1608 return false; |
| 1609 } |
| 1610 |
| 1611 const SkScalar sx = SkVector::Length(this->getScaleX(), this->getSkewY()); |
| 1612 const SkScalar sy = SkVector::Length(this->getSkewX(), this->getScaleY()); |
| 1613 if (!SkScalarIsFinite(sx) || !SkScalarIsFinite(sy) || |
| 1614 SkScalarNearlyZero(sx) || SkScalarNearlyZero(sy)) { |
| 1615 return false; |
| 1616 } |
| 1617 |
| 1618 if (scale) { |
| 1619 scale->set(sx, sy); |
| 1620 } |
| 1621 if (remaining) { |
| 1622 *remaining = *this; |
| 1623 remaining->postScale(SkScalarInvert(sx), SkScalarInvert(sy)); |
| 1624 } |
| 1625 return true; |
| 1626 } |
| 1627 |
1606 /////////////////////////////////////////////////////////////////////////////// | 1628 /////////////////////////////////////////////////////////////////////////////// |
1607 | 1629 |
1608 size_t SkMatrix::writeToMemory(void* buffer) const { | 1630 size_t SkMatrix::writeToMemory(void* buffer) const { |
1609 // TODO write less for simple matrices | 1631 // TODO write less for simple matrices |
1610 static const size_t sizeInMemory = 9 * sizeof(SkScalar); | 1632 static const size_t sizeInMemory = 9 * sizeof(SkScalar); |
1611 if (buffer) { | 1633 if (buffer) { |
1612 memcpy(buffer, fMat, sizeInMemory); | 1634 memcpy(buffer, fMat, sizeInMemory); |
1613 } | 1635 } |
1614 return sizeInMemory; | 1636 return sizeInMemory; |
1615 } | 1637 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1784 rotation1->fX = cos1; | 1806 rotation1->fX = cos1; |
1785 rotation1->fY = sin1; | 1807 rotation1->fY = sin1; |
1786 } | 1808 } |
1787 if (rotation2) { | 1809 if (rotation2) { |
1788 rotation2->fX = cos2; | 1810 rotation2->fX = cos2; |
1789 rotation2->fY = sin2; | 1811 rotation2->fY = sin2; |
1790 } | 1812 } |
1791 | 1813 |
1792 return true; | 1814 return true; |
1793 } | 1815 } |
OLD | NEW |