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, flags); |
1799 } | 1799 } |
1800 | 1800 |
| 1801 void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const S
kRect& dst, |
| 1802 const SkPaint* paint, SrcRectConstraint constraint
) { |
| 1803 // TODO: update virtual signature so we can past constraint directly |
| 1804 if (bitmap.drawsNothing() || dst.isEmpty()) { |
| 1805 return; |
| 1806 } |
| 1807 this->onDrawBitmapRect(bitmap, src, dst, paint, |
| 1808 kStrict_SrcRectConstraint == constraint ? |
| 1809 kNone_DrawBitmapRectFlag : kBleed_DrawBitmapRectFlag)
; |
| 1810 } |
| 1811 |
1801 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con
st SkRect& dst, | 1812 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con
st SkRect& dst, |
1802 const SkPaint* paint) { | 1813 const SkPaint* paint) { |
1803 if (bitmap.drawsNothing() || dst.isEmpty()) { | 1814 if (bitmap.drawsNothing() || dst.isEmpty()) { |
1804 return; | 1815 return; |
1805 } | 1816 } |
1806 if (!SkNinePatchIter::Valid(bitmap.width(), bitmap.height(), center)) { | 1817 if (!SkNinePatchIter::Valid(bitmap.width(), bitmap.height(), center)) { |
1807 this->drawBitmapRectToRect(bitmap, NULL, dst, paint); | 1818 this->drawBitmapRectToRect(bitmap, NULL, dst, paint); |
1808 } | 1819 } |
1809 this->onDrawBitmapNine(bitmap, center, dst, paint); | 1820 this->onDrawBitmapNine(bitmap, center, dst, paint); |
1810 } | 1821 } |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2035 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &bounds) | 2046 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &bounds) |
2036 | 2047 |
2037 while (iter.next()) { | 2048 while (iter.next()) { |
2038 iter.fDevice->drawImage(iter, image, x, y, looper.paint()); | 2049 iter.fDevice->drawImage(iter, image, x, y, looper.paint()); |
2039 } | 2050 } |
2040 | 2051 |
2041 LOOPER_END | 2052 LOOPER_END |
2042 } | 2053 } |
2043 | 2054 |
2044 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk
Rect& dst, | 2055 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk
Rect& dst, |
2045 const SkPaint* paint) { | 2056 const SkPaint* paint SRC_RECT_CONSTRAINT_PARAM(co
nstraint)) { |
2046 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); | 2057 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); |
| 2058 SRC_RECT_CONSTRAINT_LOCAL_DEFAULT(constraint) |
2047 SkRect storage; | 2059 SkRect storage; |
2048 const SkRect* bounds = &dst; | 2060 const SkRect* bounds = &dst; |
2049 if (NULL == paint || paint->canComputeFastBounds()) { | 2061 if (NULL == paint || paint->canComputeFastBounds()) { |
2050 if (paint) { | 2062 if (paint) { |
2051 bounds = &paint->computeFastBounds(dst, &storage); | 2063 bounds = &paint->computeFastBounds(dst, &storage); |
2052 } | 2064 } |
2053 if (this->quickReject(*bounds)) { | 2065 if (this->quickReject(*bounds)) { |
2054 return; | 2066 return; |
2055 } | 2067 } |
2056 } | 2068 } |
2057 SkLazyPaint lazy; | 2069 SkLazyPaint lazy; |
2058 if (NULL == paint) { | 2070 if (NULL == paint) { |
2059 paint = lazy.init(); | 2071 paint = lazy.init(); |
2060 } | 2072 } |
2061 | 2073 |
2062 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) | 2074 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) |
2063 | 2075 |
2064 while (iter.next()) { | 2076 while (iter.next()) { |
2065 iter.fDevice->drawImageRect(iter, image, src, dst, looper.paint()); | 2077 iter.fDevice->drawImageRect(iter, image, src, dst, looper.paint(), const
raint); |
2066 } | 2078 } |
2067 | 2079 |
2068 LOOPER_END | 2080 LOOPER_END |
2069 } | 2081 } |
2070 | 2082 |
2071 void SkCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, cons
t SkPaint* paint) { | 2083 void SkCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, cons
t SkPaint* paint) { |
2072 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmap()"); | 2084 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmap()"); |
2073 SkDEBUGCODE(bitmap.validate();) | 2085 SkDEBUGCODE(bitmap.validate();) |
2074 | 2086 |
2075 if (NULL == paint || paint->canComputeFastBounds()) { | 2087 if (NULL == paint || paint->canComputeFastBounds()) { |
(...skipping 11 matching lines...) Expand all Loading... |
2087 } | 2099 } |
2088 | 2100 |
2089 SkMatrix matrix; | 2101 SkMatrix matrix; |
2090 matrix.setTranslate(x, y); | 2102 matrix.setTranslate(x, y); |
2091 this->internalDrawBitmap(bitmap, matrix, paint); | 2103 this->internalDrawBitmap(bitmap, matrix, paint); |
2092 } | 2104 } |
2093 | 2105 |
2094 // this one is non-virtual, so it can be called safely by other canvas apis | 2106 // 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, | 2107 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
2096 const SkRect& dst, const SkPaint* paint, | 2108 const SkRect& dst, const SkPaint* paint, |
2097 DrawBitmapRectFlags flags) { | 2109 SrcRectConstraint constraint) { |
2098 if (bitmap.drawsNothing() || dst.isEmpty()) { | 2110 if (bitmap.drawsNothing() || dst.isEmpty()) { |
2099 return; | 2111 return; |
2100 } | 2112 } |
2101 | 2113 |
2102 SkRect storage; | 2114 SkRect storage; |
2103 const SkRect* bounds = &dst; | 2115 const SkRect* bounds = &dst; |
2104 if (NULL == paint || paint->canComputeFastBounds()) { | 2116 if (NULL == paint || paint->canComputeFastBounds()) { |
2105 if (paint) { | 2117 if (paint) { |
2106 bounds = &paint->computeFastBounds(dst, &storage); | 2118 bounds = &paint->computeFastBounds(dst, &storage); |
2107 } | 2119 } |
2108 if (this->quickReject(*bounds)) { | 2120 if (this->quickReject(*bounds)) { |
2109 return; | 2121 return; |
2110 } | 2122 } |
2111 } | 2123 } |
2112 | 2124 |
2113 SkLazyPaint lazy; | 2125 SkLazyPaint lazy; |
2114 if (NULL == paint) { | 2126 if (NULL == paint) { |
2115 paint = lazy.init(); | 2127 paint = lazy.init(); |
2116 } | 2128 } |
2117 | 2129 |
2118 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) | 2130 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) |
2119 | 2131 |
2120 while (iter.next()) { | 2132 while (iter.next()) { |
2121 iter.fDevice->drawBitmapRect(iter, bitmap, src, dst, looper.paint(), fla
gs); | 2133 iter.fDevice->drawBitmapRect(iter, bitmap, src, dst, looper.paint(), con
straint); |
2122 } | 2134 } |
2123 | 2135 |
2124 LOOPER_END | 2136 LOOPER_END |
2125 } | 2137 } |
2126 | 2138 |
2127 void SkCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const
SkRect& dst, | 2139 void SkCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const
SkRect& dst, |
2128 const SkPaint* paint, DrawBitmapRectFlags flags)
{ | 2140 const SkPaint* paint, DrawBitmapRectFlags flags)
{ |
2129 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmapRectToRect()")
; | 2141 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmapRectToRect()")
; |
2130 SkDEBUGCODE(bitmap.validate();) | 2142 SkDEBUGCODE(bitmap.validate();) |
2131 this->internalDrawBitmapRect(bitmap, src, dst, paint, flags); | 2143 this->internalDrawBitmapRect(bitmap, src, dst, paint, |
| 2144 kNone_DrawBitmapRectFlag == flags ? |
| 2145 kStrict_SrcRectConstraint : kFast_SrcRectConstr
aint); |
2132 } | 2146 } |
2133 | 2147 |
2134 void SkCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, cons
t SkRect& dst, | 2148 void SkCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, cons
t SkRect& dst, |
2135 const SkPaint* paint) { | 2149 const SkPaint* paint) { |
2136 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageNine()"); | 2150 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageNine()"); |
2137 | 2151 |
2138 SkRect storage; | 2152 SkRect storage; |
2139 const SkRect* bounds = &dst; | 2153 const SkRect* bounds = &dst; |
2140 if (NULL == paint || paint->canComputeFastBounds()) { | 2154 if (NULL == paint || paint->canComputeFastBounds()) { |
2141 if (paint) { | 2155 if (paint) { |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2759 } | 2773 } |
2760 | 2774 |
2761 if (matrix) { | 2775 if (matrix) { |
2762 canvas->concat(*matrix); | 2776 canvas->concat(*matrix); |
2763 } | 2777 } |
2764 } | 2778 } |
2765 | 2779 |
2766 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2780 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
2767 fCanvas->restoreToCount(fSaveCount); | 2781 fCanvas->restoreToCount(fSaveCount); |
2768 } | 2782 } |
OLD | NEW |