OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 return this->onNewSurface(info); | 987 return this->onNewSurface(info); |
988 } | 988 } |
989 | 989 |
990 SkSurface* SkCanvas::onNewSurface(const SkImageInfo& info) { | 990 SkSurface* SkCanvas::onNewSurface(const SkImageInfo& info) { |
991 SkBaseDevice* dev = this->getDevice(); | 991 SkBaseDevice* dev = this->getDevice(); |
992 return dev ? dev->newSurface(info) : NULL; | 992 return dev ? dev->newSurface(info) : NULL; |
993 } | 993 } |
994 | 994 |
995 ///////////////////////////////////////////////////////////////////////////// | 995 ///////////////////////////////////////////////////////////////////////////// |
996 | 996 |
997 // can't draw it if its empty, or its too big for a fixed-point width or height | |
998 static bool reject_bitmap(const SkBitmap& bitmap) { | |
999 return bitmap.width() <= 0 || bitmap.height() <= 0; | |
1000 } | |
1001 | |
1002 void SkCanvas::internalDrawBitmap(const SkBitmap& bitmap, | 997 void SkCanvas::internalDrawBitmap(const SkBitmap& bitmap, |
1003 const SkMatrix& matrix, const SkPaint* paint) { | 998 const SkMatrix& matrix, const SkPaint* paint) { |
1004 if (reject_bitmap(bitmap)) { | 999 if (bitmap.drawsNothing()) { |
1005 return; | 1000 return; |
1006 } | 1001 } |
1007 | 1002 |
1008 SkLazyPaint lazy; | 1003 SkLazyPaint lazy; |
1009 if (NULL == paint) { | 1004 if (NULL == paint) { |
1010 paint = lazy.init(); | 1005 paint = lazy.init(); |
1011 } | 1006 } |
1012 | 1007 |
1013 SkDEBUGCODE(bitmap.validate();) | 1008 SkDEBUGCODE(bitmap.validate();) |
1014 CHECK_LOCKCOUNT_BALANCE(bitmap); | 1009 CHECK_LOCKCOUNT_BALANCE(bitmap); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 } | 1054 } |
1060 } else { | 1055 } else { |
1061 dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint); | 1056 dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint); |
1062 } | 1057 } |
1063 } | 1058 } |
1064 LOOPER_END | 1059 LOOPER_END |
1065 } | 1060 } |
1066 | 1061 |
1067 void SkCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, | 1062 void SkCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, |
1068 const SkPaint* paint) { | 1063 const SkPaint* paint) { |
| 1064 if (bitmap.drawsNothing()) { |
| 1065 return; |
| 1066 } |
1069 SkDEBUGCODE(bitmap.validate();) | 1067 SkDEBUGCODE(bitmap.validate();) |
1070 CHECK_LOCKCOUNT_BALANCE(bitmap); | 1068 CHECK_LOCKCOUNT_BALANCE(bitmap); |
1071 | 1069 |
1072 if (reject_bitmap(bitmap)) { | |
1073 return; | |
1074 } | |
1075 | |
1076 SkPaint tmp; | 1070 SkPaint tmp; |
1077 if (NULL == paint) { | 1071 if (NULL == paint) { |
1078 paint = &tmp; | 1072 paint = &tmp; |
1079 } | 1073 } |
1080 | 1074 |
1081 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) | 1075 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) |
1082 | 1076 |
1083 while (iter.next()) { | 1077 while (iter.next()) { |
1084 paint = &looper.paint(); | 1078 paint = &looper.paint(); |
1085 SkImageFilter* filter = paint->getImageFilter(); | 1079 SkImageFilter* filter = paint->getImageFilter(); |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 if (fMCRec->fRasterClip->isEmpty()) return kEmpty_ClipType; | 1552 if (fMCRec->fRasterClip->isEmpty()) return kEmpty_ClipType; |
1559 if (fMCRec->fRasterClip->isRect()) return kRect_ClipType; | 1553 if (fMCRec->fRasterClip->isRect()) return kRect_ClipType; |
1560 return kComplex_ClipType; | 1554 return kComplex_ClipType; |
1561 } | 1555 } |
1562 | 1556 |
1563 const SkRegion& SkCanvas::getTotalClip() const { | 1557 const SkRegion& SkCanvas::getTotalClip() const { |
1564 return fMCRec->fRasterClip->forceGetBW(); | 1558 return fMCRec->fRasterClip->forceGetBW(); |
1565 } | 1559 } |
1566 | 1560 |
1567 SkBaseDevice* SkCanvas::createLayerDevice(SkBitmap::Config config, | 1561 SkBaseDevice* SkCanvas::createLayerDevice(SkBitmap::Config config, |
1568 int width, int height, | 1562 int width, int height, |
1569 bool isOpaque) { | 1563 bool isOpaque) { |
1570 SkBaseDevice* device = this->getTopDevice(); | 1564 SkBaseDevice* device = this->getTopDevice(); |
1571 if (device) { | 1565 if (device) { |
1572 return device->createCompatibleDeviceForSaveLayer(config, width, height, | 1566 return device->createCompatibleDeviceForSaveLayer(config, width, height, |
1573 isOpaque); | 1567 isOpaque); |
1574 } else { | 1568 } else { |
1575 return NULL; | 1569 return NULL; |
1576 } | 1570 } |
1577 } | 1571 } |
1578 | 1572 |
1579 GrContext* SkCanvas::getGrContext() { | 1573 GrContext* SkCanvas::getGrContext() { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1779 | 1773 |
1780 SkMatrix matrix; | 1774 SkMatrix matrix; |
1781 matrix.setTranslate(x, y); | 1775 matrix.setTranslate(x, y); |
1782 this->internalDrawBitmap(bitmap, matrix, paint); | 1776 this->internalDrawBitmap(bitmap, matrix, paint); |
1783 } | 1777 } |
1784 | 1778 |
1785 // this one is non-virtual, so it can be called safely by other canvas apis | 1779 // this one is non-virtual, so it can be called safely by other canvas apis |
1786 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1780 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
1787 const SkRect& dst, const SkPaint* paint, | 1781 const SkRect& dst, const SkPaint* paint, |
1788 DrawBitmapRectFlags flags) { | 1782 DrawBitmapRectFlags flags) { |
1789 if (bitmap.width() == 0 || bitmap.height() == 0 || dst.isEmpty()) { | 1783 if (bitmap.drawsNothing() || dst.isEmpty()) { |
1790 return; | 1784 return; |
1791 } | 1785 } |
1792 | 1786 |
1793 CHECK_LOCKCOUNT_BALANCE(bitmap); | 1787 CHECK_LOCKCOUNT_BALANCE(bitmap); |
1794 | 1788 |
1795 SkRect storage; | 1789 SkRect storage; |
1796 const SkRect* bounds = &dst; | 1790 const SkRect* bounds = &dst; |
1797 if (NULL == paint || paint->canComputeFastBounds()) { | 1791 if (NULL == paint || paint->canComputeFastBounds()) { |
1798 if (paint) { | 1792 if (paint) { |
1799 bounds = &paint->computeFastBounds(dst, &storage); | 1793 bounds = &paint->computeFastBounds(dst, &storage); |
(...skipping 26 matching lines...) Expand all Loading... |
1826 | 1820 |
1827 void SkCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix, | 1821 void SkCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix, |
1828 const SkPaint* paint) { | 1822 const SkPaint* paint) { |
1829 SkDEBUGCODE(bitmap.validate();) | 1823 SkDEBUGCODE(bitmap.validate();) |
1830 this->internalDrawBitmap(bitmap, matrix, paint); | 1824 this->internalDrawBitmap(bitmap, matrix, paint); |
1831 } | 1825 } |
1832 | 1826 |
1833 void SkCanvas::internalDrawBitmapNine(const SkBitmap& bitmap, | 1827 void SkCanvas::internalDrawBitmapNine(const SkBitmap& bitmap, |
1834 const SkIRect& center, const SkRect& dst, | 1828 const SkIRect& center, const SkRect& dst, |
1835 const SkPaint* paint) { | 1829 const SkPaint* paint) { |
| 1830 if (bitmap.drawsNothing()) { |
| 1831 return; |
| 1832 } |
1836 if (NULL == paint || paint->canComputeFastBounds()) { | 1833 if (NULL == paint || paint->canComputeFastBounds()) { |
1837 SkRect storage; | 1834 SkRect storage; |
1838 const SkRect* bounds = &dst; | 1835 const SkRect* bounds = &dst; |
1839 if (paint) { | 1836 if (paint) { |
1840 bounds = &paint->computeFastBounds(dst, &storage); | 1837 bounds = &paint->computeFastBounds(dst, &storage); |
1841 } | 1838 } |
1842 if (this->quickReject(*bounds)) { | 1839 if (this->quickReject(*bounds)) { |
1843 return; | 1840 return; |
1844 } | 1841 } |
1845 } | 1842 } |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2235 return *paint; | 2232 return *paint; |
2236 } | 2233 } |
2237 | 2234 |
2238 const SkRegion& SkCanvas::LayerIter::clip() const { return fImpl->getClip(); } | 2235 const SkRegion& SkCanvas::LayerIter::clip() const { return fImpl->getClip(); } |
2239 int SkCanvas::LayerIter::x() const { return fImpl->getX(); } | 2236 int SkCanvas::LayerIter::x() const { return fImpl->getX(); } |
2240 int SkCanvas::LayerIter::y() const { return fImpl->getY(); } | 2237 int SkCanvas::LayerIter::y() const { return fImpl->getY(); } |
2241 | 2238 |
2242 /////////////////////////////////////////////////////////////////////////////// | 2239 /////////////////////////////////////////////////////////////////////////////// |
2243 | 2240 |
2244 SkCanvas::ClipVisitor::~ClipVisitor() { } | 2241 SkCanvas::ClipVisitor::~ClipVisitor() { } |
OLD | NEW |