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 | 8 |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 static void dec_canvas() { --gCanvasCounter; printf("----- dec canvas %d\n",
gCanvasCounter); } | 47 static void dec_canvas() { --gCanvasCounter; printf("----- dec canvas %d\n",
gCanvasCounter); } |
48 #else | 48 #else |
49 #define inc_layer() | 49 #define inc_layer() |
50 #define dec_layer() | 50 #define dec_layer() |
51 #define inc_rec() | 51 #define inc_rec() |
52 #define dec_rec() | 52 #define dec_rec() |
53 #define inc_canvas() | 53 #define inc_canvas() |
54 #define dec_canvas() | 54 #define dec_canvas() |
55 #endif | 55 #endif |
56 | 56 |
57 #ifdef SK_DEBUG | |
58 #include "SkPixelRef.h" | |
59 | |
60 /* | |
61 * Some pixelref subclasses can support being "locked" from another thread | |
62 * during the lock-scope of skia calling them. In these instances, this balance | |
63 * check will fail, but may not be indicative of a problem, so we allow a build | |
64 * flag to disable this check. | |
65 * | |
66 * Potentially another fix would be to have a (debug-only) virtual or flag on | |
67 * pixelref, which could tell us at runtime if this check is valid. That would | |
68 * eliminate the need for this heavy-handed build check. | |
69 */ | |
70 #ifdef SK_DISABLE_PIXELREF_LOCKCOUNT_BALANCE_CHECK | |
71 class AutoCheckLockCountBalance { | |
72 public: | |
73 AutoCheckLockCountBalance(const SkBitmap&) { /* do nothing */ } | |
74 }; | |
75 #else | |
76 class AutoCheckLockCountBalance { | |
77 public: | |
78 AutoCheckLockCountBalance(const SkBitmap& bm) : fPixelRef(bm.pixelRef()) { | |
79 fLockCount = fPixelRef ? fPixelRef->getLockCount() : 0; | |
80 } | |
81 ~AutoCheckLockCountBalance() { | |
82 const int count = fPixelRef ? fPixelRef->getLockCount() : 0; | |
83 SkASSERT(count == fLockCount); | |
84 } | |
85 | |
86 private: | |
87 const SkPixelRef* fPixelRef; | |
88 int fLockCount; | |
89 }; | |
90 #endif | |
91 | |
92 #define CHECK_LOCKCOUNT_BALANCE(bitmap) AutoCheckLockCountBalance clcb(bitmap) | |
93 | |
94 #else | |
95 #define CHECK_LOCKCOUNT_BALANCE(bitmap) | |
96 #endif | |
97 | |
98 typedef SkTLazy<SkPaint> SkLazyPaint; | 57 typedef SkTLazy<SkPaint> SkLazyPaint; |
99 | 58 |
100 void SkCanvas::predrawNotify() { | 59 void SkCanvas::predrawNotify() { |
101 if (fSurfaceBase) { | 60 if (fSurfaceBase) { |
102 fSurfaceBase->aboutToDraw(SkSurface::kRetain_ContentChangeMode); | 61 fSurfaceBase->aboutToDraw(SkSurface::kRetain_ContentChangeMode); |
103 } | 62 } |
104 } | 63 } |
105 | 64 |
106 /////////////////////////////////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////////////////////////////////// |
107 | 66 |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 if (bitmap.drawsNothing()) { | 1087 if (bitmap.drawsNothing()) { |
1129 return; | 1088 return; |
1130 } | 1089 } |
1131 | 1090 |
1132 SkLazyPaint lazy; | 1091 SkLazyPaint lazy; |
1133 if (NULL == paint) { | 1092 if (NULL == paint) { |
1134 paint = lazy.init(); | 1093 paint = lazy.init(); |
1135 } | 1094 } |
1136 | 1095 |
1137 SkDEBUGCODE(bitmap.validate();) | 1096 SkDEBUGCODE(bitmap.validate();) |
1138 CHECK_LOCKCOUNT_BALANCE(bitmap); | |
1139 | 1097 |
1140 SkRect storage; | 1098 SkRect storage; |
1141 const SkRect* bounds = NULL; | 1099 const SkRect* bounds = NULL; |
1142 if (paint && paint->canComputeFastBounds()) { | 1100 if (paint && paint->canComputeFastBounds()) { |
1143 bitmap.getBounds(&storage); | 1101 bitmap.getBounds(&storage); |
1144 matrix.mapRect(&storage); | 1102 matrix.mapRect(&storage); |
1145 bounds = &paint->computeFastBounds(storage, &storage); | 1103 bounds = &paint->computeFastBounds(storage, &storage); |
1146 } | 1104 } |
1147 | 1105 |
1148 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) | 1106 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 } | 1153 } |
1196 LOOPER_END | 1154 LOOPER_END |
1197 } | 1155 } |
1198 | 1156 |
1199 void SkCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, | 1157 void SkCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, |
1200 const SkPaint* paint) { | 1158 const SkPaint* paint) { |
1201 if (bitmap.drawsNothing()) { | 1159 if (bitmap.drawsNothing()) { |
1202 return; | 1160 return; |
1203 } | 1161 } |
1204 SkDEBUGCODE(bitmap.validate();) | 1162 SkDEBUGCODE(bitmap.validate();) |
1205 CHECK_LOCKCOUNT_BALANCE(bitmap); | |
1206 | 1163 |
1207 SkPaint tmp; | 1164 SkPaint tmp; |
1208 if (NULL == paint) { | 1165 if (NULL == paint) { |
1209 paint = &tmp; | 1166 paint = &tmp; |
1210 } | 1167 } |
1211 | 1168 |
1212 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) | 1169 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) |
1213 | 1170 |
1214 while (iter.next()) { | 1171 while (iter.next()) { |
1215 paint = &looper.paint(); | 1172 paint = &looper.paint(); |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2004 } | 1961 } |
2005 | 1962 |
2006 // this one is non-virtual, so it can be called safely by other canvas apis | 1963 // this one is non-virtual, so it can be called safely by other canvas apis |
2007 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1964 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
2008 const SkRect& dst, const SkPaint* paint, | 1965 const SkRect& dst, const SkPaint* paint, |
2009 DrawBitmapRectFlags flags) { | 1966 DrawBitmapRectFlags flags) { |
2010 if (bitmap.drawsNothing() || dst.isEmpty()) { | 1967 if (bitmap.drawsNothing() || dst.isEmpty()) { |
2011 return; | 1968 return; |
2012 } | 1969 } |
2013 | 1970 |
2014 CHECK_LOCKCOUNT_BALANCE(bitmap); | |
2015 | |
2016 SkRect storage; | 1971 SkRect storage; |
2017 const SkRect* bounds = &dst; | 1972 const SkRect* bounds = &dst; |
2018 if (NULL == paint || paint->canComputeFastBounds()) { | 1973 if (NULL == paint || paint->canComputeFastBounds()) { |
2019 if (paint) { | 1974 if (paint) { |
2020 bounds = &paint->computeFastBounds(dst, &storage); | 1975 bounds = &paint->computeFastBounds(dst, &storage); |
2021 } | 1976 } |
2022 if (this->quickReject(*bounds)) { | 1977 if (this->quickReject(*bounds)) { |
2023 return; | 1978 return; |
2024 } | 1979 } |
2025 } | 1980 } |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2547 if (!supported_for_raster_canvas(info)) { | 2502 if (!supported_for_raster_canvas(info)) { |
2548 return NULL; | 2503 return NULL; |
2549 } | 2504 } |
2550 | 2505 |
2551 SkBitmap bitmap; | 2506 SkBitmap bitmap; |
2552 if (!bitmap.installPixels(info, pixels, rowBytes)) { | 2507 if (!bitmap.installPixels(info, pixels, rowBytes)) { |
2553 return NULL; | 2508 return NULL; |
2554 } | 2509 } |
2555 return SkNEW_ARGS(SkCanvas, (bitmap)); | 2510 return SkNEW_ARGS(SkCanvas, (bitmap)); |
2556 } | 2511 } |
OLD | NEW |