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" |
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 | 1758 |
1759 void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { | 1759 void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
1760 this->onDrawPath(path, paint); | 1760 this->onDrawPath(path, paint); |
1761 } | 1761 } |
1762 | 1762 |
1763 void SkCanvas::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkP
aint* paint) { | 1763 void SkCanvas::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkP
aint* paint) { |
1764 this->onDrawImage(image, x, y, paint); | 1764 this->onDrawImage(image, x, y, paint); |
1765 } | 1765 } |
1766 | 1766 |
1767 void SkCanvas::drawImageRect(const SkImage* image, const SkRect* src, const SkRe
ct& dst, | 1767 void SkCanvas::drawImageRect(const SkImage* image, const SkRect* src, const SkRe
ct& dst, |
1768 const SkPaint* paint) { | 1768 const SkPaint* paint, SrcRectConstraint constraint)
{ |
1769 if (dst.isEmpty()) { | 1769 if (dst.isEmpty()) { |
1770 return; | 1770 return; |
1771 } | 1771 } |
1772 this->onDrawImageRect(image, src, dst, paint); | 1772 this->onDrawImageRect(image, src, dst, paint SRC_RECT_CONSTRAINT_ARG(constra
int)); |
1773 } | 1773 } |
1774 | 1774 |
1775 void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const
SkRect& dst, | 1775 void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const
SkRect& dst, |
1776 const SkPaint* paint) { | 1776 const SkPaint* paint) { |
1777 if (dst.isEmpty()) { | 1777 if (dst.isEmpty()) { |
1778 return; | 1778 return; |
1779 } | 1779 } |
1780 if (!SkNinePatchIter::Valid(image->width(), image->height(), center)) { | 1780 if (!SkNinePatchIter::Valid(image->width(), image->height(), center)) { |
1781 this->drawImageRect(image, NULL, dst, paint); | 1781 this->drawImageRect(image, NULL, dst, paint); |
1782 } | 1782 } |
1783 this->onDrawImageNine(image, center, dst, paint); | 1783 this->onDrawImageNine(image, center, dst, paint); |
1784 } | 1784 } |
1785 | 1785 |
1786 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, cons
t SkPaint* paint) { | 1786 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, cons
t SkPaint* paint) { |
1787 if (bitmap.drawsNothing()) { | 1787 if (bitmap.drawsNothing()) { |
1788 return; | 1788 return; |
1789 } | 1789 } |
1790 this->onDrawBitmap(bitmap, dx, dy, paint); | 1790 this->onDrawBitmap(bitmap, dx, dy, paint); |
1791 } | 1791 } |
1792 | 1792 |
1793 void SkCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, c
onst SkRect& dst, | 1793 void SkCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, c
onst SkRect& dst, |
1794 const SkPaint* paint, DrawBitmapRectFlags fl
ags) { | 1794 const SkPaint* paint, DrawBitmapRectFlags fl
ags) { |
1795 if (bitmap.drawsNothing() || dst.isEmpty()) { | 1795 if (bitmap.drawsNothing() || dst.isEmpty()) { |
1796 return; | 1796 return; |
1797 } | 1797 } |
1798 this->onDrawBitmapRect(bitmap, src, dst, paint, flags); | 1798 this->onDrawBitmapRect(bitmap, src, dst, paint, (SK_VIRTUAL_CONSTRAINT_TYPE)
flags); |
| 1799 } |
| 1800 |
| 1801 void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const S
kRect& dst, |
| 1802 const SkPaint* paint, SrcRectConstraint constraint
) { |
| 1803 if (bitmap.drawsNothing() || dst.isEmpty()) { |
| 1804 return; |
| 1805 } |
| 1806 this->onDrawBitmapRect(bitmap, src, dst, paint, (SK_VIRTUAL_CONSTRAINT_TYPE)
constraint); |
1799 } | 1807 } |
1800 | 1808 |
1801 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con
st SkRect& dst, | 1809 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con
st SkRect& dst, |
1802 const SkPaint* paint) { | 1810 const SkPaint* paint) { |
1803 if (bitmap.drawsNothing() || dst.isEmpty()) { | 1811 if (bitmap.drawsNothing() || dst.isEmpty()) { |
1804 return; | 1812 return; |
1805 } | 1813 } |
1806 if (!SkNinePatchIter::Valid(bitmap.width(), bitmap.height(), center)) { | 1814 if (!SkNinePatchIter::Valid(bitmap.width(), bitmap.height(), center)) { |
1807 this->drawBitmapRectToRect(bitmap, NULL, dst, paint); | 1815 this->drawBitmapRect(bitmap, dst, paint); |
1808 } | 1816 } |
1809 this->onDrawBitmapNine(bitmap, center, dst, paint); | 1817 this->onDrawBitmapNine(bitmap, center, dst, paint); |
1810 } | 1818 } |
1811 | 1819 |
1812 void SkCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, const SkPai
nt* paint) { | 1820 void SkCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, const SkPai
nt* paint) { |
1813 if (bitmap.drawsNothing()) { | 1821 if (bitmap.drawsNothing()) { |
1814 return; | 1822 return; |
1815 } | 1823 } |
1816 this->onDrawSprite(bitmap, left, top, paint); | 1824 this->onDrawSprite(bitmap, left, top, paint); |
1817 } | 1825 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2035 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &bounds) | 2043 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &bounds) |
2036 | 2044 |
2037 while (iter.next()) { | 2045 while (iter.next()) { |
2038 iter.fDevice->drawImage(iter, image, x, y, looper.paint()); | 2046 iter.fDevice->drawImage(iter, image, x, y, looper.paint()); |
2039 } | 2047 } |
2040 | 2048 |
2041 LOOPER_END | 2049 LOOPER_END |
2042 } | 2050 } |
2043 | 2051 |
2044 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk
Rect& dst, | 2052 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk
Rect& dst, |
2045 const SkPaint* paint) { | 2053 const SkPaint* paint SRC_RECT_CONSTRAINT_PARAM(co
nstraint)) { |
2046 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); | 2054 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); |
| 2055 SRC_RECT_CONSTRAINT_LOCAL_DEFAULT(constraint) |
2047 SkRect storage; | 2056 SkRect storage; |
2048 const SkRect* bounds = &dst; | 2057 const SkRect* bounds = &dst; |
2049 if (NULL == paint || paint->canComputeFastBounds()) { | 2058 if (NULL == paint || paint->canComputeFastBounds()) { |
2050 if (paint) { | 2059 if (paint) { |
2051 bounds = &paint->computeFastBounds(dst, &storage); | 2060 bounds = &paint->computeFastBounds(dst, &storage); |
2052 } | 2061 } |
2053 if (this->quickReject(*bounds)) { | 2062 if (this->quickReject(*bounds)) { |
2054 return; | 2063 return; |
2055 } | 2064 } |
2056 } | 2065 } |
2057 SkLazyPaint lazy; | 2066 SkLazyPaint lazy; |
2058 if (NULL == paint) { | 2067 if (NULL == paint) { |
2059 paint = lazy.init(); | 2068 paint = lazy.init(); |
2060 } | 2069 } |
2061 | 2070 |
2062 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) | 2071 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) |
2063 | 2072 |
2064 while (iter.next()) { | 2073 while (iter.next()) { |
2065 iter.fDevice->drawImageRect(iter, image, src, dst, looper.paint()); | 2074 iter.fDevice->drawImageRect(iter, image, src, dst, looper.paint(), const
raint); |
2066 } | 2075 } |
2067 | 2076 |
2068 LOOPER_END | 2077 LOOPER_END |
2069 } | 2078 } |
2070 | 2079 |
2071 void SkCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, cons
t SkPaint* paint) { | 2080 void SkCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, cons
t SkPaint* paint) { |
2072 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmap()"); | 2081 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmap()"); |
2073 SkDEBUGCODE(bitmap.validate();) | 2082 SkDEBUGCODE(bitmap.validate();) |
2074 | 2083 |
2075 if (NULL == paint || paint->canComputeFastBounds()) { | 2084 if (NULL == paint || paint->canComputeFastBounds()) { |
(...skipping 11 matching lines...) Expand all Loading... |
2087 } | 2096 } |
2088 | 2097 |
2089 SkMatrix matrix; | 2098 SkMatrix matrix; |
2090 matrix.setTranslate(x, y); | 2099 matrix.setTranslate(x, y); |
2091 this->internalDrawBitmap(bitmap, matrix, paint); | 2100 this->internalDrawBitmap(bitmap, matrix, paint); |
2092 } | 2101 } |
2093 | 2102 |
2094 // this one is non-virtual, so it can be called safely by other canvas apis | 2103 // this one is non-virtual, so it can be called safely by other canvas apis |
2095 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 2104 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
2096 const SkRect& dst, const SkPaint* paint, | 2105 const SkRect& dst, const SkPaint* paint, |
2097 DrawBitmapRectFlags flags) { | 2106 SrcRectConstraint constraint) { |
2098 if (bitmap.drawsNothing() || dst.isEmpty()) { | 2107 if (bitmap.drawsNothing() || dst.isEmpty()) { |
2099 return; | 2108 return; |
2100 } | 2109 } |
2101 | 2110 |
2102 SkRect storage; | 2111 SkRect storage; |
2103 const SkRect* bounds = &dst; | 2112 const SkRect* bounds = &dst; |
2104 if (NULL == paint || paint->canComputeFastBounds()) { | 2113 if (NULL == paint || paint->canComputeFastBounds()) { |
2105 if (paint) { | 2114 if (paint) { |
2106 bounds = &paint->computeFastBounds(dst, &storage); | 2115 bounds = &paint->computeFastBounds(dst, &storage); |
2107 } | 2116 } |
2108 if (this->quickReject(*bounds)) { | 2117 if (this->quickReject(*bounds)) { |
2109 return; | 2118 return; |
2110 } | 2119 } |
2111 } | 2120 } |
2112 | 2121 |
2113 SkLazyPaint lazy; | 2122 SkLazyPaint lazy; |
2114 if (NULL == paint) { | 2123 if (NULL == paint) { |
2115 paint = lazy.init(); | 2124 paint = lazy.init(); |
2116 } | 2125 } |
2117 | 2126 |
2118 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) | 2127 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) |
2119 | 2128 |
2120 while (iter.next()) { | 2129 while (iter.next()) { |
2121 iter.fDevice->drawBitmapRect(iter, bitmap, src, dst, looper.paint(), fla
gs); | 2130 iter.fDevice->drawBitmapRect(iter, bitmap, src, dst, looper.paint(), |
| 2131 (SK_VIRTUAL_CONSTRAINT_TYPE)constraint); |
2122 } | 2132 } |
2123 | 2133 |
2124 LOOPER_END | 2134 LOOPER_END |
2125 } | 2135 } |
2126 | 2136 |
2127 void SkCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const
SkRect& dst, | 2137 void SkCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const
SkRect& dst, |
2128 const SkPaint* paint, DrawBitmapRectFlags flags)
{ | 2138 const SkPaint* paint, SK_VIRTUAL_CONSTRAINT_TYPE
constraint) { |
2129 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmapRectToRect()")
; | 2139 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmapRectToRect()")
; |
2130 SkDEBUGCODE(bitmap.validate();) | 2140 SkDEBUGCODE(bitmap.validate();) |
2131 this->internalDrawBitmapRect(bitmap, src, dst, paint, flags); | 2141 this->internalDrawBitmapRect(bitmap, src, dst, paint, (SrcRectConstraint)con
straint); |
2132 } | 2142 } |
2133 | 2143 |
2134 void SkCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, cons
t SkRect& dst, | 2144 void SkCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, cons
t SkRect& dst, |
2135 const SkPaint* paint) { | 2145 const SkPaint* paint) { |
2136 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageNine()"); | 2146 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageNine()"); |
2137 | 2147 |
2138 SkRect storage; | 2148 SkRect storage; |
2139 const SkRect* bounds = &dst; | 2149 const SkRect* bounds = &dst; |
2140 if (NULL == paint || paint->canComputeFastBounds()) { | 2150 if (NULL == paint || paint->canComputeFastBounds()) { |
2141 if (paint) { | 2151 if (paint) { |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2759 } | 2769 } |
2760 | 2770 |
2761 if (matrix) { | 2771 if (matrix) { |
2762 canvas->concat(*matrix); | 2772 canvas->concat(*matrix); |
2763 } | 2773 } |
2764 } | 2774 } |
2765 | 2775 |
2766 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2776 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
2767 fCanvas->restoreToCount(fSaveCount); | 2777 fCanvas->restoreToCount(fSaveCount); |
2768 } | 2778 } |
OLD | NEW |