| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkCanvasPriv.h" | 9 #include "SkCanvasPriv.h" |
| 10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
| 11 #include "SkDeviceImageFilterProxy.h" | 11 #include "SkDeviceImageFilterProxy.h" |
| 12 #include "SkDraw.h" | 12 #include "SkDraw.h" |
| 13 #include "SkDrawFilter.h" | 13 #include "SkDrawFilter.h" |
| 14 #include "SkDrawLooper.h" | 14 #include "SkDrawLooper.h" |
| 15 #include "SkImage.h" | 15 #include "SkImage.h" |
| 16 #include "SkMetaData.h" | 16 #include "SkMetaData.h" |
| 17 #include "SkPathOps.h" | 17 #include "SkPathOps.h" |
| 18 #include "SkPatchUtils.h" | 18 #include "SkPatchUtils.h" |
| 19 #include "SkPicture.h" | 19 #include "SkPicture.h" |
| 20 #include "SkRasterClip.h" | 20 #include "SkRasterClip.h" |
| 21 #include "SkRRect.h" | 21 #include "SkRRect.h" |
| 22 #include "SkSmallAllocator.h" | 22 #include "SkSmallAllocator.h" |
| 23 #include "SkSurface_Base.h" | 23 #include "SkSurface_Base.h" |
| 24 #include "SkTemplates.h" | 24 #include "SkTemplates.h" |
| 25 #include "SkTextBlob.h" | 25 #include "SkTextBlob.h" |
| 26 #include "SkTextFormatParams.h" | 26 #include "SkTextFormatParams.h" |
| 27 #include "SkTLazy.h" | 27 #include "SkTLazy.h" |
| 28 #include "SkTraceEvent.h" |
| 28 #include "SkUtils.h" | 29 #include "SkUtils.h" |
| 29 | 30 |
| 30 #if SK_SUPPORT_GPU | 31 #if SK_SUPPORT_GPU |
| 31 #include "GrRenderTarget.h" | 32 #include "GrRenderTarget.h" |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 // experimental for faster tiled drawing... | 35 // experimental for faster tiled drawing... |
| 35 //#define SK_ENABLE_CLIP_QUICKREJECT | 36 //#define SK_ENABLE_CLIP_QUICKREJECT |
| 36 | 37 |
| 37 //#define SK_TRACE_SAVERESTORE | 38 //#define SK_TRACE_SAVERESTORE |
| (...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 } | 1232 } |
| 1232 } else { | 1233 } else { |
| 1233 dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint); | 1234 dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint); |
| 1234 } | 1235 } |
| 1235 } | 1236 } |
| 1236 LOOPER_END | 1237 LOOPER_END |
| 1237 } | 1238 } |
| 1238 | 1239 |
| 1239 void SkCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, | 1240 void SkCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, |
| 1240 const SkPaint* paint) { | 1241 const SkPaint* paint) { |
| 1242 TRACE_EVENT0("skia", "SkCanvas::drawSprite()"); |
| 1241 if (bitmap.drawsNothing()) { | 1243 if (bitmap.drawsNothing()) { |
| 1242 return; | 1244 return; |
| 1243 } | 1245 } |
| 1244 SkDEBUGCODE(bitmap.validate();) | 1246 SkDEBUGCODE(bitmap.validate();) |
| 1245 | 1247 |
| 1246 SkPaint tmp; | 1248 SkPaint tmp; |
| 1247 if (NULL == paint) { | 1249 if (NULL == paint) { |
| 1248 paint = &tmp; | 1250 paint = &tmp; |
| 1249 } | 1251 } |
| 1250 | 1252 |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1677 } | 1679 } |
| 1678 } | 1680 } |
| 1679 #endif | 1681 #endif |
| 1680 | 1682 |
| 1681 return NULL; | 1683 return NULL; |
| 1682 | 1684 |
| 1683 } | 1685 } |
| 1684 | 1686 |
| 1685 void SkCanvas::drawDRRect(const SkRRect& outer, const SkRRect& inner, | 1687 void SkCanvas::drawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 1686 const SkPaint& paint) { | 1688 const SkPaint& paint) { |
| 1689 TRACE_EVENT0("skia", "SkCanvas::drawDRRect()"); |
| 1687 if (outer.isEmpty()) { | 1690 if (outer.isEmpty()) { |
| 1688 return; | 1691 return; |
| 1689 } | 1692 } |
| 1690 if (inner.isEmpty()) { | 1693 if (inner.isEmpty()) { |
| 1691 this->drawRRect(outer, paint); | 1694 this->drawRRect(outer, paint); |
| 1692 return; | 1695 return; |
| 1693 } | 1696 } |
| 1694 | 1697 |
| 1695 // We don't have this method (yet), but technically this is what we should | 1698 // We don't have this method (yet), but technically this is what we should |
| 1696 // be able to assert... | 1699 // be able to assert... |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1714 } | 1717 } |
| 1715 } | 1718 } |
| 1716 | 1719 |
| 1717 void SkCanvas::onDiscard() { | 1720 void SkCanvas::onDiscard() { |
| 1718 if (fSurfaceBase) { | 1721 if (fSurfaceBase) { |
| 1719 fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); | 1722 fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); |
| 1720 } | 1723 } |
| 1721 } | 1724 } |
| 1722 | 1725 |
| 1723 void SkCanvas::drawPaint(const SkPaint& paint) { | 1726 void SkCanvas::drawPaint(const SkPaint& paint) { |
| 1727 TRACE_EVENT0("skia", "SkCanvas::drawPaint()"); |
| 1724 this->internalDrawPaint(paint); | 1728 this->internalDrawPaint(paint); |
| 1725 } | 1729 } |
| 1726 | 1730 |
| 1727 void SkCanvas::internalDrawPaint(const SkPaint& paint) { | 1731 void SkCanvas::internalDrawPaint(const SkPaint& paint) { |
| 1728 LOOPER_BEGIN(paint, SkDrawFilter::kPaint_Type, NULL) | 1732 LOOPER_BEGIN(paint, SkDrawFilter::kPaint_Type, NULL) |
| 1729 | 1733 |
| 1730 while (iter.next()) { | 1734 while (iter.next()) { |
| 1731 iter.fDevice->drawPaint(iter, looper.paint()); | 1735 iter.fDevice->drawPaint(iter, looper.paint()); |
| 1732 } | 1736 } |
| 1733 | 1737 |
| 1734 LOOPER_END | 1738 LOOPER_END |
| 1735 } | 1739 } |
| 1736 | 1740 |
| 1737 void SkCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], | 1741 void SkCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], |
| 1738 const SkPaint& paint) { | 1742 const SkPaint& paint) { |
| 1743 TRACE_EVENT1("skia", "SkCanvas::drawPoints()", "count", static_cast<uint64_t
>(count)); |
| 1739 if ((long)count <= 0) { | 1744 if ((long)count <= 0) { |
| 1740 return; | 1745 return; |
| 1741 } | 1746 } |
| 1742 | 1747 |
| 1743 SkRect r, storage; | 1748 SkRect r, storage; |
| 1744 const SkRect* bounds = NULL; | 1749 const SkRect* bounds = NULL; |
| 1745 if (paint.canComputeFastBounds()) { | 1750 if (paint.canComputeFastBounds()) { |
| 1746 // special-case 2 points (common for drawing a single line) | 1751 // special-case 2 points (common for drawing a single line) |
| 1747 if (2 == count) { | 1752 if (2 == count) { |
| 1748 r.set(pts[0], pts[1]); | 1753 r.set(pts[0], pts[1]); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1760 LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds) | 1765 LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds) |
| 1761 | 1766 |
| 1762 while (iter.next()) { | 1767 while (iter.next()) { |
| 1763 iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint()); | 1768 iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint()); |
| 1764 } | 1769 } |
| 1765 | 1770 |
| 1766 LOOPER_END | 1771 LOOPER_END |
| 1767 } | 1772 } |
| 1768 | 1773 |
| 1769 void SkCanvas::drawRect(const SkRect& r, const SkPaint& paint) { | 1774 void SkCanvas::drawRect(const SkRect& r, const SkPaint& paint) { |
| 1775 TRACE_EVENT0("skia", "SkCanvas::drawRect()"); |
| 1770 SkRect storage; | 1776 SkRect storage; |
| 1771 const SkRect* bounds = NULL; | 1777 const SkRect* bounds = NULL; |
| 1772 if (paint.canComputeFastBounds()) { | 1778 if (paint.canComputeFastBounds()) { |
| 1773 bounds = &paint.computeFastBounds(r, &storage); | 1779 bounds = &paint.computeFastBounds(r, &storage); |
| 1774 if (this->quickReject(*bounds)) { | 1780 if (this->quickReject(*bounds)) { |
| 1775 return; | 1781 return; |
| 1776 } | 1782 } |
| 1777 } | 1783 } |
| 1778 | 1784 |
| 1779 LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, bounds) | 1785 LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, bounds) |
| 1780 | 1786 |
| 1781 while (iter.next()) { | 1787 while (iter.next()) { |
| 1782 iter.fDevice->drawRect(iter, r, looper.paint()); | 1788 iter.fDevice->drawRect(iter, r, looper.paint()); |
| 1783 } | 1789 } |
| 1784 | 1790 |
| 1785 LOOPER_END | 1791 LOOPER_END |
| 1786 } | 1792 } |
| 1787 | 1793 |
| 1788 void SkCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { | 1794 void SkCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { |
| 1795 TRACE_EVENT0("skia", "SkCanvas::drawOval()"); |
| 1789 SkRect storage; | 1796 SkRect storage; |
| 1790 const SkRect* bounds = NULL; | 1797 const SkRect* bounds = NULL; |
| 1791 if (paint.canComputeFastBounds()) { | 1798 if (paint.canComputeFastBounds()) { |
| 1792 bounds = &paint.computeFastBounds(oval, &storage); | 1799 bounds = &paint.computeFastBounds(oval, &storage); |
| 1793 if (this->quickReject(*bounds)) { | 1800 if (this->quickReject(*bounds)) { |
| 1794 return; | 1801 return; |
| 1795 } | 1802 } |
| 1796 } | 1803 } |
| 1797 | 1804 |
| 1798 LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds) | 1805 LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds) |
| 1799 | 1806 |
| 1800 while (iter.next()) { | 1807 while (iter.next()) { |
| 1801 iter.fDevice->drawOval(iter, oval, looper.paint()); | 1808 iter.fDevice->drawOval(iter, oval, looper.paint()); |
| 1802 } | 1809 } |
| 1803 | 1810 |
| 1804 LOOPER_END | 1811 LOOPER_END |
| 1805 } | 1812 } |
| 1806 | 1813 |
| 1807 void SkCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | 1814 void SkCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 1815 TRACE_EVENT0("skia", "SkCanvas::drawRRect()"); |
| 1808 SkRect storage; | 1816 SkRect storage; |
| 1809 const SkRect* bounds = NULL; | 1817 const SkRect* bounds = NULL; |
| 1810 if (paint.canComputeFastBounds()) { | 1818 if (paint.canComputeFastBounds()) { |
| 1811 bounds = &paint.computeFastBounds(rrect.getBounds(), &storage); | 1819 bounds = &paint.computeFastBounds(rrect.getBounds(), &storage); |
| 1812 if (this->quickReject(*bounds)) { | 1820 if (this->quickReject(*bounds)) { |
| 1813 return; | 1821 return; |
| 1814 } | 1822 } |
| 1815 } | 1823 } |
| 1816 | 1824 |
| 1817 if (rrect.isRect()) { | 1825 if (rrect.isRect()) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1847 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) | 1855 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) |
| 1848 | 1856 |
| 1849 while (iter.next()) { | 1857 while (iter.next()) { |
| 1850 iter.fDevice->drawDRRect(iter, outer, inner, looper.paint()); | 1858 iter.fDevice->drawDRRect(iter, outer, inner, looper.paint()); |
| 1851 } | 1859 } |
| 1852 | 1860 |
| 1853 LOOPER_END | 1861 LOOPER_END |
| 1854 } | 1862 } |
| 1855 | 1863 |
| 1856 void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { | 1864 void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
| 1865 TRACE_EVENT0("skia", "SkCanvas::drawPath()"); |
| 1857 if (!path.isFinite()) { | 1866 if (!path.isFinite()) { |
| 1858 return; | 1867 return; |
| 1859 } | 1868 } |
| 1860 | 1869 |
| 1861 SkRect storage; | 1870 SkRect storage; |
| 1862 const SkRect* bounds = NULL; | 1871 const SkRect* bounds = NULL; |
| 1863 if (!path.isInverseFillType() && paint.canComputeFastBounds()) { | 1872 if (!path.isInverseFillType() && paint.canComputeFastBounds()) { |
| 1864 const SkRect& pathBounds = path.getBounds(); | 1873 const SkRect& pathBounds = path.getBounds(); |
| 1865 bounds = &paint.computeFastBounds(pathBounds, &storage); | 1874 bounds = &paint.computeFastBounds(pathBounds, &storage); |
| 1866 if (this->quickReject(*bounds)) { | 1875 if (this->quickReject(*bounds)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1880 | 1889 |
| 1881 while (iter.next()) { | 1890 while (iter.next()) { |
| 1882 iter.fDevice->drawPath(iter, path, looper.paint()); | 1891 iter.fDevice->drawPath(iter, path, looper.paint()); |
| 1883 } | 1892 } |
| 1884 | 1893 |
| 1885 LOOPER_END | 1894 LOOPER_END |
| 1886 } | 1895 } |
| 1887 | 1896 |
| 1888 void SkCanvas::drawImage(const SkImage* image, SkScalar left, SkScalar top, | 1897 void SkCanvas::drawImage(const SkImage* image, SkScalar left, SkScalar top, |
| 1889 const SkPaint* paint) { | 1898 const SkPaint* paint) { |
| 1899 TRACE_EVENT0("skia", "SkCanvas::drawImage()"); |
| 1890 image->draw(this, left, top, paint); | 1900 image->draw(this, left, top, paint); |
| 1891 } | 1901 } |
| 1892 | 1902 |
| 1893 void SkCanvas::drawImageRect(const SkImage* image, const SkRect* src, | 1903 void SkCanvas::drawImageRect(const SkImage* image, const SkRect* src, |
| 1894 const SkRect& dst, | 1904 const SkRect& dst, |
| 1895 const SkPaint* paint) { | 1905 const SkPaint* paint) { |
| 1906 TRACE_EVENT0("skia", "SkCanvas::drawImageRect()"); |
| 1896 image->drawRect(this, src, dst, paint); | 1907 image->drawRect(this, src, dst, paint); |
| 1897 } | 1908 } |
| 1898 | 1909 |
| 1899 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, | 1910 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, |
| 1900 const SkPaint* paint) { | 1911 const SkPaint* paint) { |
| 1912 TRACE_EVENT0("skia", "SkCanvas::drawBitmap()"); |
| 1901 SkDEBUGCODE(bitmap.validate();) | 1913 SkDEBUGCODE(bitmap.validate();) |
| 1902 | 1914 |
| 1903 if (NULL == paint || paint->canComputeFastBounds()) { | 1915 if (NULL == paint || paint->canComputeFastBounds()) { |
| 1904 SkRect bounds = { | 1916 SkRect bounds = { |
| 1905 x, y, | 1917 x, y, |
| 1906 x + SkIntToScalar(bitmap.width()), | 1918 x + SkIntToScalar(bitmap.width()), |
| 1907 y + SkIntToScalar(bitmap.height()) | 1919 y + SkIntToScalar(bitmap.height()) |
| 1908 }; | 1920 }; |
| 1909 if (paint) { | 1921 if (paint) { |
| 1910 (void)paint->computeFastBounds(bounds, &bounds); | 1922 (void)paint->computeFastBounds(bounds, &bounds); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1948 while (iter.next()) { | 1960 while (iter.next()) { |
| 1949 iter.fDevice->drawBitmapRect(iter, bitmap, src, dst, looper.paint(), fla
gs); | 1961 iter.fDevice->drawBitmapRect(iter, bitmap, src, dst, looper.paint(), fla
gs); |
| 1950 } | 1962 } |
| 1951 | 1963 |
| 1952 LOOPER_END | 1964 LOOPER_END |
| 1953 } | 1965 } |
| 1954 | 1966 |
| 1955 void SkCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, | 1967 void SkCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, |
| 1956 const SkRect& dst, const SkPaint* paint, | 1968 const SkRect& dst, const SkPaint* paint, |
| 1957 DrawBitmapRectFlags flags) { | 1969 DrawBitmapRectFlags flags) { |
| 1970 TRACE_EVENT0("skia", "SkCanvas::drawBitmapRectToRect()"); |
| 1958 SkDEBUGCODE(bitmap.validate();) | 1971 SkDEBUGCODE(bitmap.validate();) |
| 1959 this->internalDrawBitmapRect(bitmap, src, dst, paint, flags); | 1972 this->internalDrawBitmapRect(bitmap, src, dst, paint, flags); |
| 1960 } | 1973 } |
| 1961 | 1974 |
| 1962 void SkCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix, | 1975 void SkCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix, |
| 1963 const SkPaint* paint) { | 1976 const SkPaint* paint) { |
| 1977 TRACE_EVENT0("skia", "SkCanvas::drawBitmapMatrix()"); |
| 1964 SkDEBUGCODE(bitmap.validate();) | 1978 SkDEBUGCODE(bitmap.validate();) |
| 1965 this->internalDrawBitmap(bitmap, matrix, paint); | 1979 this->internalDrawBitmap(bitmap, matrix, paint); |
| 1966 } | 1980 } |
| 1967 | 1981 |
| 1968 void SkCanvas::internalDrawBitmapNine(const SkBitmap& bitmap, | 1982 void SkCanvas::internalDrawBitmapNine(const SkBitmap& bitmap, |
| 1969 const SkIRect& center, const SkRect& dst, | 1983 const SkIRect& center, const SkRect& dst, |
| 1970 const SkPaint* paint) { | 1984 const SkPaint* paint) { |
| 1971 if (bitmap.drawsNothing()) { | 1985 if (bitmap.drawsNothing()) { |
| 1972 return; | 1986 return; |
| 1973 } | 1987 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 d.fLeft = dstX[x]; | 2044 d.fLeft = dstX[x]; |
| 2031 d.fRight = dstX[x+1]; | 2045 d.fRight = dstX[x+1]; |
| 2032 this->internalDrawBitmapRect(bitmap, &s, d, paint, | 2046 this->internalDrawBitmapRect(bitmap, &s, d, paint, |
| 2033 kNone_DrawBitmapRectFlag); | 2047 kNone_DrawBitmapRectFlag); |
| 2034 } | 2048 } |
| 2035 } | 2049 } |
| 2036 } | 2050 } |
| 2037 | 2051 |
| 2038 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, | 2052 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 2039 const SkRect& dst, const SkPaint* paint) { | 2053 const SkRect& dst, const SkPaint* paint) { |
| 2054 TRACE_EVENT0("skia", "SkCanvas::drawBitmapNine()"); |
| 2040 SkDEBUGCODE(bitmap.validate();) | 2055 SkDEBUGCODE(bitmap.validate();) |
| 2041 | 2056 |
| 2042 // Need a device entry-point, so gpu can use a mesh | 2057 // Need a device entry-point, so gpu can use a mesh |
| 2043 this->internalDrawBitmapNine(bitmap, center, dst, paint); | 2058 this->internalDrawBitmapNine(bitmap, center, dst, paint); |
| 2044 } | 2059 } |
| 2045 | 2060 |
| 2046 class SkDeviceFilteredPaint { | 2061 class SkDeviceFilteredPaint { |
| 2047 public: | 2062 public: |
| 2048 SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) { | 2063 SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) { |
| 2049 SkBaseDevice::TextFlags flags; | 2064 SkBaseDevice::TextFlags flags; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2209 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); | 2224 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); |
| 2210 iter.fDevice->drawTextBlob(iter, blob, x, y, dfp.paint()); | 2225 iter.fDevice->drawTextBlob(iter, blob, x, y, dfp.paint()); |
| 2211 } | 2226 } |
| 2212 | 2227 |
| 2213 LOOPER_END | 2228 LOOPER_END |
| 2214 } | 2229 } |
| 2215 | 2230 |
| 2216 // These will become non-virtual, so they always call the (virtual) onDraw... me
thod | 2231 // These will become non-virtual, so they always call the (virtual) onDraw... me
thod |
| 2217 void SkCanvas::drawText(const void* text, size_t byteLength, SkScalar x, SkScala
r y, | 2232 void SkCanvas::drawText(const void* text, size_t byteLength, SkScalar x, SkScala
r y, |
| 2218 const SkPaint& paint) { | 2233 const SkPaint& paint) { |
| 2234 TRACE_EVENT0("skia", "SkCanvas::drawText()"); |
| 2219 this->onDrawText(text, byteLength, x, y, paint); | 2235 this->onDrawText(text, byteLength, x, y, paint); |
| 2220 } | 2236 } |
| 2221 void SkCanvas::drawPosText(const void* text, size_t byteLength, const SkPoint po
s[], | 2237 void SkCanvas::drawPosText(const void* text, size_t byteLength, const SkPoint po
s[], |
| 2222 const SkPaint& paint) { | 2238 const SkPaint& paint) { |
| 2239 TRACE_EVENT0("skia", "SkCanvas::drawPosText()"); |
| 2223 this->onDrawPosText(text, byteLength, pos, paint); | 2240 this->onDrawPosText(text, byteLength, pos, paint); |
| 2224 } | 2241 } |
| 2225 void SkCanvas::drawPosTextH(const void* text, size_t byteLength, const SkScalar
xpos[], | 2242 void SkCanvas::drawPosTextH(const void* text, size_t byteLength, const SkScalar
xpos[], |
| 2226 SkScalar constY, const SkPaint& paint) { | 2243 SkScalar constY, const SkPaint& paint) { |
| 2244 TRACE_EVENT0("skia", "SkCanvas::drawPosTextH()"); |
| 2227 this->onDrawPosTextH(text, byteLength, xpos, constY, paint); | 2245 this->onDrawPosTextH(text, byteLength, xpos, constY, paint); |
| 2228 } | 2246 } |
| 2229 void SkCanvas::drawTextOnPath(const void* text, size_t byteLength, const SkPath&
path, | 2247 void SkCanvas::drawTextOnPath(const void* text, size_t byteLength, const SkPath&
path, |
| 2230 const SkMatrix* matrix, const SkPaint& paint) { | 2248 const SkMatrix* matrix, const SkPaint& paint) { |
| 2249 TRACE_EVENT0("skia", "SkCanvas::drawTextOnPath()"); |
| 2231 this->onDrawTextOnPath(text, byteLength, path, matrix, paint); | 2250 this->onDrawTextOnPath(text, byteLength, path, matrix, paint); |
| 2232 } | 2251 } |
| 2233 void SkCanvas::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, | 2252 void SkCanvas::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 2234 const SkPaint& paint) { | 2253 const SkPaint& paint) { |
| 2254 TRACE_EVENT0("skia", "SkCanvas::drawTextBlob()"); |
| 2235 if (blob) { | 2255 if (blob) { |
| 2236 this->onDrawTextBlob(blob, x, y, paint); | 2256 this->onDrawTextBlob(blob, x, y, paint); |
| 2237 } | 2257 } |
| 2238 } | 2258 } |
| 2239 | 2259 |
| 2240 void SkCanvas::drawVertices(VertexMode vmode, int vertexCount, | 2260 void SkCanvas::drawVertices(VertexMode vmode, int vertexCount, |
| 2241 const SkPoint verts[], const SkPoint texs[], | 2261 const SkPoint verts[], const SkPoint texs[], |
| 2242 const SkColor colors[], SkXfermode* xmode, | 2262 const SkColor colors[], SkXfermode* xmode, |
| 2243 const uint16_t indices[], int indexCount, | 2263 const uint16_t indices[], int indexCount, |
| 2244 const SkPaint& paint) { | 2264 const SkPaint& paint) { |
| 2265 TRACE_EVENT0("skia", "SkCanvas::drawVertices()"); |
| 2245 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, NULL) | 2266 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, NULL) |
| 2246 | 2267 |
| 2247 while (iter.next()) { | 2268 while (iter.next()) { |
| 2248 iter.fDevice->drawVertices(iter, vmode, vertexCount, verts, texs, | 2269 iter.fDevice->drawVertices(iter, vmode, vertexCount, verts, texs, |
| 2249 colors, xmode, indices, indexCount, | 2270 colors, xmode, indices, indexCount, |
| 2250 looper.paint()); | 2271 looper.paint()); |
| 2251 } | 2272 } |
| 2252 | 2273 |
| 2253 LOOPER_END | 2274 LOOPER_END |
| 2254 } | 2275 } |
| 2255 | 2276 |
| 2256 void SkCanvas::drawPatch(const SkPoint cubics[12], const SkColor colors[4], | 2277 void SkCanvas::drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 2257 const SkPoint texCoords[4], SkXfermode* xmode, const Sk
Paint& paint) { | 2278 const SkPoint texCoords[4], SkXfermode* xmode, const Sk
Paint& paint) { |
| 2279 TRACE_EVENT0("skia", "SkCanvas::drawPatch()"); |
| 2258 if (NULL == cubics) { | 2280 if (NULL == cubics) { |
| 2259 return; | 2281 return; |
| 2260 } | 2282 } |
| 2261 | 2283 |
| 2262 // Since a patch is always within the convex hull of the control points, we
discard it when its | 2284 // Since a patch is always within the convex hull of the control points, we
discard it when its |
| 2263 // bounding rectangle is completely outside the current clip. | 2285 // bounding rectangle is completely outside the current clip. |
| 2264 SkRect bounds; | 2286 SkRect bounds; |
| 2265 bounds.set(cubics, SkPatchUtils::kNumCtrlPts); | 2287 bounds.set(cubics, SkPatchUtils::kNumCtrlPts); |
| 2266 if (this->quickReject(bounds)) { | 2288 if (this->quickReject(bounds)) { |
| 2267 return; | 2289 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2282 LOOPER_END | 2304 LOOPER_END |
| 2283 } | 2305 } |
| 2284 | 2306 |
| 2285 ////////////////////////////////////////////////////////////////////////////// | 2307 ////////////////////////////////////////////////////////////////////////////// |
| 2286 // These methods are NOT virtual, and therefore must call back into virtual | 2308 // These methods are NOT virtual, and therefore must call back into virtual |
| 2287 // methods, rather than actually drawing themselves. | 2309 // methods, rather than actually drawing themselves. |
| 2288 ////////////////////////////////////////////////////////////////////////////// | 2310 ////////////////////////////////////////////////////////////////////////////// |
| 2289 | 2311 |
| 2290 void SkCanvas::drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, | 2312 void SkCanvas::drawARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b, |
| 2291 SkXfermode::Mode mode) { | 2313 SkXfermode::Mode mode) { |
| 2314 TRACE_EVENT0("skia", "SkCanvas::drawARGB()"); |
| 2292 SkPaint paint; | 2315 SkPaint paint; |
| 2293 | 2316 |
| 2294 paint.setARGB(a, r, g, b); | 2317 paint.setARGB(a, r, g, b); |
| 2295 if (SkXfermode::kSrcOver_Mode != mode) { | 2318 if (SkXfermode::kSrcOver_Mode != mode) { |
| 2296 paint.setXfermodeMode(mode); | 2319 paint.setXfermodeMode(mode); |
| 2297 } | 2320 } |
| 2298 this->drawPaint(paint); | 2321 this->drawPaint(paint); |
| 2299 } | 2322 } |
| 2300 | 2323 |
| 2301 void SkCanvas::drawColor(SkColor c, SkXfermode::Mode mode) { | 2324 void SkCanvas::drawColor(SkColor c, SkXfermode::Mode mode) { |
| 2325 TRACE_EVENT0("skia", "SkCanvas::drawColor()"); |
| 2302 SkPaint paint; | 2326 SkPaint paint; |
| 2303 | 2327 |
| 2304 paint.setColor(c); | 2328 paint.setColor(c); |
| 2305 if (SkXfermode::kSrcOver_Mode != mode) { | 2329 if (SkXfermode::kSrcOver_Mode != mode) { |
| 2306 paint.setXfermodeMode(mode); | 2330 paint.setXfermodeMode(mode); |
| 2307 } | 2331 } |
| 2308 this->drawPaint(paint); | 2332 this->drawPaint(paint); |
| 2309 } | 2333 } |
| 2310 | 2334 |
| 2311 void SkCanvas::drawPoint(SkScalar x, SkScalar y, const SkPaint& paint) { | 2335 void SkCanvas::drawPoint(SkScalar x, SkScalar y, const SkPaint& paint) { |
| 2336 TRACE_EVENT0("skia", "SkCanvas::drawPoint(SkPaint)"); |
| 2312 SkPoint pt; | 2337 SkPoint pt; |
| 2313 | 2338 |
| 2314 pt.set(x, y); | 2339 pt.set(x, y); |
| 2315 this->drawPoints(kPoints_PointMode, 1, &pt, paint); | 2340 this->drawPoints(kPoints_PointMode, 1, &pt, paint); |
| 2316 } | 2341 } |
| 2317 | 2342 |
| 2318 void SkCanvas::drawPoint(SkScalar x, SkScalar y, SkColor color) { | 2343 void SkCanvas::drawPoint(SkScalar x, SkScalar y, SkColor color) { |
| 2344 TRACE_EVENT0("skia", "SkCanvas::drawPoint(SkColor)"); |
| 2319 SkPoint pt; | 2345 SkPoint pt; |
| 2320 SkPaint paint; | 2346 SkPaint paint; |
| 2321 | 2347 |
| 2322 pt.set(x, y); | 2348 pt.set(x, y); |
| 2323 paint.setColor(color); | 2349 paint.setColor(color); |
| 2324 this->drawPoints(kPoints_PointMode, 1, &pt, paint); | 2350 this->drawPoints(kPoints_PointMode, 1, &pt, paint); |
| 2325 } | 2351 } |
| 2326 | 2352 |
| 2327 void SkCanvas::drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, | 2353 void SkCanvas::drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, |
| 2328 const SkPaint& paint) { | 2354 const SkPaint& paint) { |
| 2355 TRACE_EVENT0("skia", "SkCanvas::drawLine()"); |
| 2329 SkPoint pts[2]; | 2356 SkPoint pts[2]; |
| 2330 | 2357 |
| 2331 pts[0].set(x0, y0); | 2358 pts[0].set(x0, y0); |
| 2332 pts[1].set(x1, y1); | 2359 pts[1].set(x1, y1); |
| 2333 this->drawPoints(kLines_PointMode, 2, pts, paint); | 2360 this->drawPoints(kLines_PointMode, 2, pts, paint); |
| 2334 } | 2361 } |
| 2335 | 2362 |
| 2336 void SkCanvas::drawRectCoords(SkScalar left, SkScalar top, | 2363 void SkCanvas::drawRectCoords(SkScalar left, SkScalar top, |
| 2337 SkScalar right, SkScalar bottom, | 2364 SkScalar right, SkScalar bottom, |
| 2338 const SkPaint& paint) { | 2365 const SkPaint& paint) { |
| 2366 TRACE_EVENT0("skia", "SkCanvas::drawRectCoords()"); |
| 2339 SkRect r; | 2367 SkRect r; |
| 2340 | 2368 |
| 2341 r.set(left, top, right, bottom); | 2369 r.set(left, top, right, bottom); |
| 2342 this->drawRect(r, paint); | 2370 this->drawRect(r, paint); |
| 2343 } | 2371 } |
| 2344 | 2372 |
| 2345 void SkCanvas::drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, | 2373 void SkCanvas::drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, |
| 2346 const SkPaint& paint) { | 2374 const SkPaint& paint) { |
| 2375 TRACE_EVENT0("skia", "SkCanvas::drawCircle()"); |
| 2347 if (radius < 0) { | 2376 if (radius < 0) { |
| 2348 radius = 0; | 2377 radius = 0; |
| 2349 } | 2378 } |
| 2350 | 2379 |
| 2351 SkRect r; | 2380 SkRect r; |
| 2352 r.set(cx - radius, cy - radius, cx + radius, cy + radius); | 2381 r.set(cx - radius, cy - radius, cx + radius, cy + radius); |
| 2353 this->drawOval(r, paint); | 2382 this->drawOval(r, paint); |
| 2354 } | 2383 } |
| 2355 | 2384 |
| 2356 void SkCanvas::drawRoundRect(const SkRect& r, SkScalar rx, SkScalar ry, | 2385 void SkCanvas::drawRoundRect(const SkRect& r, SkScalar rx, SkScalar ry, |
| 2357 const SkPaint& paint) { | 2386 const SkPaint& paint) { |
| 2387 TRACE_EVENT0("skia", "SkCanvas::drawRoundRect()"); |
| 2358 if (rx > 0 && ry > 0) { | 2388 if (rx > 0 && ry > 0) { |
| 2359 if (paint.canComputeFastBounds()) { | 2389 if (paint.canComputeFastBounds()) { |
| 2360 SkRect storage; | 2390 SkRect storage; |
| 2361 if (this->quickReject(paint.computeFastBounds(r, &storage))) { | 2391 if (this->quickReject(paint.computeFastBounds(r, &storage))) { |
| 2362 return; | 2392 return; |
| 2363 } | 2393 } |
| 2364 } | 2394 } |
| 2365 SkRRect rrect; | 2395 SkRRect rrect; |
| 2366 rrect.setRectXY(r, rx, ry); | 2396 rrect.setRectXY(r, rx, ry); |
| 2367 this->drawRRect(rrect, paint); | 2397 this->drawRRect(rrect, paint); |
| 2368 } else { | 2398 } else { |
| 2369 this->drawRect(r, paint); | 2399 this->drawRect(r, paint); |
| 2370 } | 2400 } |
| 2371 } | 2401 } |
| 2372 | 2402 |
| 2373 void SkCanvas::drawArc(const SkRect& oval, SkScalar startAngle, | 2403 void SkCanvas::drawArc(const SkRect& oval, SkScalar startAngle, |
| 2374 SkScalar sweepAngle, bool useCenter, | 2404 SkScalar sweepAngle, bool useCenter, |
| 2375 const SkPaint& paint) { | 2405 const SkPaint& paint) { |
| 2406 TRACE_EVENT0("skia", "SkCanvas::drawArc()"); |
| 2376 if (SkScalarAbs(sweepAngle) >= SkIntToScalar(360)) { | 2407 if (SkScalarAbs(sweepAngle) >= SkIntToScalar(360)) { |
| 2377 this->drawOval(oval, paint); | 2408 this->drawOval(oval, paint); |
| 2378 } else { | 2409 } else { |
| 2379 SkPath path; | 2410 SkPath path; |
| 2380 if (useCenter) { | 2411 if (useCenter) { |
| 2381 path.moveTo(oval.centerX(), oval.centerY()); | 2412 path.moveTo(oval.centerX(), oval.centerY()); |
| 2382 } | 2413 } |
| 2383 path.arcTo(oval, startAngle, sweepAngle, !useCenter); | 2414 path.arcTo(oval, startAngle, sweepAngle, !useCenter); |
| 2384 if (useCenter) { | 2415 if (useCenter) { |
| 2385 path.close(); | 2416 path.close(); |
| 2386 } | 2417 } |
| 2387 this->drawPath(path, paint); | 2418 this->drawPath(path, paint); |
| 2388 } | 2419 } |
| 2389 } | 2420 } |
| 2390 | 2421 |
| 2391 void SkCanvas::drawTextOnPathHV(const void* text, size_t byteLength, | 2422 void SkCanvas::drawTextOnPathHV(const void* text, size_t byteLength, |
| 2392 const SkPath& path, SkScalar hOffset, | 2423 const SkPath& path, SkScalar hOffset, |
| 2393 SkScalar vOffset, const SkPaint& paint) { | 2424 SkScalar vOffset, const SkPaint& paint) { |
| 2425 TRACE_EVENT0("skia", "SkCanvas::drawTextOnPathHV()"); |
| 2394 SkMatrix matrix; | 2426 SkMatrix matrix; |
| 2395 | 2427 |
| 2396 matrix.setTranslate(hOffset, vOffset); | 2428 matrix.setTranslate(hOffset, vOffset); |
| 2397 this->drawTextOnPath(text, byteLength, path, &matrix, paint); | 2429 this->drawTextOnPath(text, byteLength, path, &matrix, paint); |
| 2398 } | 2430 } |
| 2399 | 2431 |
| 2400 /////////////////////////////////////////////////////////////////////////////// | 2432 /////////////////////////////////////////////////////////////////////////////// |
| 2401 void SkCanvas::EXPERIMENTAL_optimize(const SkPicture* picture) { | 2433 void SkCanvas::EXPERIMENTAL_optimize(const SkPicture* picture) { |
| 2402 SkBaseDevice* device = this->getDevice(); | 2434 SkBaseDevice* device = this->getDevice(); |
| 2403 if (device) { | 2435 if (device) { |
| 2404 device->EXPERIMENTAL_optimize(picture); | 2436 device->EXPERIMENTAL_optimize(picture); |
| 2405 } | 2437 } |
| 2406 } | 2438 } |
| 2407 | 2439 |
| 2408 void SkCanvas::drawPicture(const SkPicture* picture) { | 2440 void SkCanvas::drawPicture(const SkPicture* picture) { |
| 2441 TRACE_EVENT0("skia", "SkCanvas::drawPicture()"); |
| 2409 if (picture) { | 2442 if (picture) { |
| 2410 this->onDrawPicture(picture, NULL, NULL); | 2443 this->onDrawPicture(picture, NULL, NULL); |
| 2411 } | 2444 } |
| 2412 } | 2445 } |
| 2413 | 2446 |
| 2414 void SkCanvas::drawPicture(const SkPicture* picture, const SkMatrix* matrix, con
st SkPaint* paint) { | 2447 void SkCanvas::drawPicture(const SkPicture* picture, const SkMatrix* matrix, con
st SkPaint* paint) { |
| 2448 TRACE_EVENT0("skia", "SkCanvas::drawPicture(SkMatrix, SkPaint)"); |
| 2415 if (picture) { | 2449 if (picture) { |
| 2416 if (matrix && matrix->isIdentity()) { | 2450 if (matrix && matrix->isIdentity()) { |
| 2417 matrix = NULL; | 2451 matrix = NULL; |
| 2418 } | 2452 } |
| 2419 this->onDrawPicture(picture, matrix, paint); | 2453 this->onDrawPicture(picture, matrix, paint); |
| 2420 } | 2454 } |
| 2421 } | 2455 } |
| 2422 | 2456 |
| 2423 void SkCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, | 2457 void SkCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, |
| 2424 const SkPaint* paint) { | 2458 const SkPaint* paint) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2550 } | 2584 } |
| 2551 | 2585 |
| 2552 if (matrix) { | 2586 if (matrix) { |
| 2553 canvas->concat(*matrix); | 2587 canvas->concat(*matrix); |
| 2554 } | 2588 } |
| 2555 } | 2589 } |
| 2556 | 2590 |
| 2557 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2591 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 2558 fCanvas->restoreToCount(fSaveCount); | 2592 fCanvas->restoreToCount(fSaveCount); |
| 2559 } | 2593 } |
| OLD | NEW |