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 1605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 void SkMatrix::toString(SkString* str) const { | 1616 void SkMatrix::toString(SkString* str) const { |
1617 str->appendf("[%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f]", | 1617 str->appendf("[%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f]", |
1618 fMat[0], fMat[1], fMat[2], fMat[3], fMat[4], fMat[5], | 1618 fMat[0], fMat[1], fMat[2], fMat[3], fMat[4], fMat[5], |
1619 fMat[6], fMat[7], fMat[8]); | 1619 fMat[6], fMat[7], fMat[8]); |
1620 } | 1620 } |
1621 | 1621 |
1622 /////////////////////////////////////////////////////////////////////////////// | 1622 /////////////////////////////////////////////////////////////////////////////// |
1623 | 1623 |
1624 #include "SkMatrixUtils.h" | 1624 #include "SkMatrixUtils.h" |
1625 | 1625 |
1626 bool SkTreatAsSprite(const SkMatrix& mat, int width, int height, | 1626 bool SkTreatAsSprite(const SkMatrix& mat, const SkISize& size, const SkPaint& pa
int) { |
1627 unsigned subpixelBits) { | 1627 // Our path aa is 2-bits, and our rect aa is 8, so we could use 8, |
| 1628 // but in practice 4 seems enough (still looks smooth) and allows |
| 1629 // more slightly fractional cases to fall into the fast (sprite) case. |
| 1630 static const unsigned kAntiAliasSubpixelBits = 4; |
| 1631 |
| 1632 const unsigned subpixelBits = paint.isAntiAlias() ? kAntiAliasSubpixelBits :
0; |
| 1633 |
1628 // quick reject on affine or perspective | 1634 // quick reject on affine or perspective |
1629 if (mat.getType() & ~(SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask)) { | 1635 if (mat.getType() & ~(SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask)) { |
1630 return false; | 1636 return false; |
1631 } | 1637 } |
1632 | 1638 |
1633 // quick success check | 1639 // quick success check |
1634 if (!subpixelBits && !(mat.getType() & ~SkMatrix::kTranslate_Mask)) { | 1640 if (!subpixelBits && !(mat.getType() & ~SkMatrix::kTranslate_Mask)) { |
1635 return true; | 1641 return true; |
1636 } | 1642 } |
1637 | 1643 |
1638 // mapRect supports negative scales, so we eliminate those first | 1644 // mapRect supports negative scales, so we eliminate those first |
1639 if (mat.getScaleX() < 0 || mat.getScaleY() < 0) { | 1645 if (mat.getScaleX() < 0 || mat.getScaleY() < 0) { |
1640 return false; | 1646 return false; |
1641 } | 1647 } |
1642 | 1648 |
1643 SkRect dst; | 1649 SkRect dst; |
1644 SkIRect isrc = { 0, 0, width, height }; | 1650 SkIRect isrc = SkIRect::MakeSize(size); |
1645 | 1651 |
1646 { | 1652 { |
1647 SkRect src; | 1653 SkRect src; |
1648 src.set(isrc); | 1654 src.set(isrc); |
1649 mat.mapRect(&dst, src); | 1655 mat.mapRect(&dst, src); |
1650 } | 1656 } |
1651 | 1657 |
1652 // just apply the translate to isrc | 1658 // just apply the translate to isrc |
1653 isrc.offset(SkScalarRoundToInt(mat.getTranslateX()), | 1659 isrc.offset(SkScalarRoundToInt(mat.getTranslateX()), |
1654 SkScalarRoundToInt(mat.getTranslateY())); | 1660 SkScalarRoundToInt(mat.getTranslateY())); |
1655 | 1661 |
1656 if (subpixelBits) { | 1662 if (subpixelBits) { |
1657 isrc.fLeft <<= subpixelBits; | 1663 isrc.fLeft = SkLeftShift(isrc.fLeft, subpixelBits); |
1658 isrc.fTop <<= subpixelBits; | 1664 isrc.fTop = SkLeftShift(isrc.fTop, subpixelBits); |
1659 isrc.fRight <<= subpixelBits; | 1665 isrc.fRight = SkLeftShift(isrc.fRight, subpixelBits); |
1660 isrc.fBottom <<= subpixelBits; | 1666 isrc.fBottom = SkLeftShift(isrc.fBottom, subpixelBits); |
1661 | 1667 |
1662 const float scale = 1 << subpixelBits; | 1668 const float scale = 1 << subpixelBits; |
1663 dst.fLeft *= scale; | 1669 dst.fLeft *= scale; |
1664 dst.fTop *= scale; | 1670 dst.fTop *= scale; |
1665 dst.fRight *= scale; | 1671 dst.fRight *= scale; |
1666 dst.fBottom *= scale; | 1672 dst.fBottom *= scale; |
1667 } | 1673 } |
1668 | 1674 |
1669 SkIRect idst; | 1675 SkIRect idst; |
1670 dst.round(&idst); | 1676 dst.round(&idst); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 const SkScalar m11 = m00; | 1798 const SkScalar m11 = m00; |
1793 const SkScalar m12 = fTy; | 1799 const SkScalar m12 = fTy; |
1794 | 1800 |
1795 quad[0].set(m02, m12); | 1801 quad[0].set(m02, m12); |
1796 quad[1].set(m00 * width + m02, m10 * width + m12); | 1802 quad[1].set(m00 * width + m02, m10 * width + m12); |
1797 quad[2].set(m00 * width + m01 * height + m02, m10 * width + m11 * height + m
12); | 1803 quad[2].set(m00 * width + m01 * height + m02, m10 * width + m11 * height + m
12); |
1798 quad[3].set(m01 * height + m02, m11 * height + m12); | 1804 quad[3].set(m01 * height + m02, m11 * height + m12); |
1799 #endif | 1805 #endif |
1800 } | 1806 } |
1801 | 1807 |
OLD | NEW |