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" | 10 #include "SkOnce.h" |
11 #include "SkString.h" | 11 #include "SkString.h" |
12 | 12 |
13 // In a few places, we performed the following | 13 // In a few places, we performed the following |
14 // a * b + c * d + e | 14 // a * b + c * d + e |
15 // as | 15 // as |
16 // a * b + (c * d + e) | 16 // a * b + (c * d + e) |
17 // | 17 // |
18 // sdot and scross are indended to capture these compound operations into a | 18 // sdot and scross are indended to capture these compound operations into a |
19 // function, with an eye toward considering upscaling the intermediates to | 19 // function, with an eye toward considering upscaling the intermediates to |
20 // doubles for more precision (as we do in concat and invert). | 20 // doubles for more precision (as we do in concat and invert). |
(...skipping 1530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1551 return factor; | 1551 return factor; |
1552 } else { | 1552 } else { |
1553 return -1; | 1553 return -1; |
1554 } | 1554 } |
1555 } | 1555 } |
1556 | 1556 |
1557 bool SkMatrix::getMinMaxScales(SkScalar scaleFactors[2]) const { | 1557 bool SkMatrix::getMinMaxScales(SkScalar scaleFactors[2]) const { |
1558 return get_scale_factor<kBoth_MinMaxOrBoth>(this->getType(), fMat, scaleFact
ors); | 1558 return get_scale_factor<kBoth_MinMaxOrBoth>(this->getType(), fMat, scaleFact
ors); |
1559 } | 1559 } |
1560 | 1560 |
1561 namespace { | 1561 static void reset_identity_matrix(SkMatrix* identity) { |
1562 | 1562 identity->reset(); |
1563 SkMatrix* create_identity() { | |
1564 SkMatrix* m = SkNEW(SkMatrix); | |
1565 m->reset(); | |
1566 return m; | |
1567 } | 1563 } |
1568 | 1564 |
1569 SkMatrix* create_invalid() { | |
1570 SkMatrix* m = SkNEW(SkMatrix); | |
1571 m->setAll(SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, | |
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 | |
1578 } // namespace | |
1579 | |
1580 const SkMatrix& SkMatrix::I() { | 1565 const SkMatrix& SkMatrix::I() { |
1581 SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, identity, create_identity); | 1566 // If you can use C++11 now, you might consider replacing this with a conste
xpr constructor. |
1582 return *identity.get(); | 1567 static SkMatrix gIdentity; |
| 1568 SK_DECLARE_STATIC_ONCE(once); |
| 1569 SkOnce(&once, reset_identity_matrix, &gIdentity); |
| 1570 return gIdentity; |
1583 } | 1571 } |
1584 | 1572 |
1585 const SkMatrix& SkMatrix::InvalidMatrix() { | 1573 const SkMatrix& SkMatrix::InvalidMatrix() { |
1586 SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, invalid, create_invalid); | 1574 static SkMatrix gInvalid; |
1587 return *invalid.get(); | 1575 static bool gOnce; |
| 1576 if (!gOnce) { |
| 1577 gInvalid.setAll(SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, |
| 1578 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, |
| 1579 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax); |
| 1580 gInvalid.getType(); // force the type to be computed |
| 1581 gOnce = true; |
| 1582 } |
| 1583 return gInvalid; |
1588 } | 1584 } |
1589 | 1585 |
1590 /////////////////////////////////////////////////////////////////////////////// | 1586 /////////////////////////////////////////////////////////////////////////////// |
1591 | 1587 |
1592 size_t SkMatrix::writeToMemory(void* buffer) const { | 1588 size_t SkMatrix::writeToMemory(void* buffer) const { |
1593 // TODO write less for simple matrices | 1589 // TODO write less for simple matrices |
1594 static const size_t sizeInMemory = 9 * sizeof(SkScalar); | 1590 static const size_t sizeInMemory = 9 * sizeof(SkScalar); |
1595 if (buffer) { | 1591 if (buffer) { |
1596 memcpy(buffer, fMat, sizeInMemory); | 1592 memcpy(buffer, fMat, sizeInMemory); |
1597 } | 1593 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 rotation1->fX = cos1; | 1768 rotation1->fX = cos1; |
1773 rotation1->fY = sin1; | 1769 rotation1->fY = sin1; |
1774 } | 1770 } |
1775 if (NULL != rotation2) { | 1771 if (NULL != rotation2) { |
1776 rotation2->fX = cos2; | 1772 rotation2->fX = cos2; |
1777 rotation2->fY = sin2; | 1773 rotation2->fY = sin2; |
1778 } | 1774 } |
1779 | 1775 |
1780 return true; | 1776 return true; |
1781 } | 1777 } |
OLD | NEW |