Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: src/core/SkMatrix.cpp

Issue 304383005: Port most uses of SkOnce to SkLazyPtr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add mutex Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkLazyPtr.h ('k') | src/core/SkMessageBus.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkOnce.h" 10 #include "SkLazyPtr.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
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 static void reset_identity_matrix(SkMatrix* identity) { 1561 namespace {
1562 identity->reset(); 1562
1563 SkMatrix* create_identity() {
1564 SkMatrix* m = SkNEW(SkMatrix);
1565 m->reset();
1566 return m;
1563 } 1567 }
1564 1568
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
1565 const SkMatrix& SkMatrix::I() { 1580 const SkMatrix& SkMatrix::I() {
1566 // If you can use C++11 now, you might consider replacing this with a conste xpr constructor. 1581 SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, identity, create_identity);
1567 static SkMatrix gIdentity; 1582 return *identity.get();
1568 SK_DECLARE_STATIC_ONCE(once);
1569 SkOnce(&once, reset_identity_matrix, &gIdentity);
1570 return gIdentity;
1571 } 1583 }
1572 1584
1573 const SkMatrix& SkMatrix::InvalidMatrix() { 1585 const SkMatrix& SkMatrix::InvalidMatrix() {
1574 static SkMatrix gInvalid; 1586 SK_DECLARE_STATIC_LAZY_PTR(SkMatrix, invalid, create_invalid);
1575 static bool gOnce; 1587 return *invalid.get();
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;
1584 } 1588 }
1585 1589
1586 /////////////////////////////////////////////////////////////////////////////// 1590 ///////////////////////////////////////////////////////////////////////////////
1587 1591
1588 size_t SkMatrix::writeToMemory(void* buffer) const { 1592 size_t SkMatrix::writeToMemory(void* buffer) const {
1589 // TODO write less for simple matrices 1593 // TODO write less for simple matrices
1590 static const size_t sizeInMemory = 9 * sizeof(SkScalar); 1594 static const size_t sizeInMemory = 9 * sizeof(SkScalar);
1591 if (buffer) { 1595 if (buffer) {
1592 memcpy(buffer, fMat, sizeInMemory); 1596 memcpy(buffer, fMat, sizeInMemory);
1593 } 1597 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 rotation1->fX = cos1; 1772 rotation1->fX = cos1;
1769 rotation1->fY = sin1; 1773 rotation1->fY = sin1;
1770 } 1774 }
1771 if (NULL != rotation2) { 1775 if (NULL != rotation2) {
1772 rotation2->fX = cos2; 1776 rotation2->fX = cos2;
1773 rotation2->fY = sin2; 1777 rotation2->fY = sin2;
1774 } 1778 }
1775 1779
1776 return true; 1780 return true;
1777 } 1781 }
OLDNEW
« no previous file with comments | « src/core/SkLazyPtr.h ('k') | src/core/SkMessageBus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698