OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
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 "SkBBoxHierarchy.h" |
8 #include "SkBitmapDevice.h" | 9 #include "SkBitmapDevice.h" |
9 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
10 #include "SkData.h" | 11 #include "SkData.h" |
11 #include "SkNoSaveLayerCanvas.h" | 12 #include "SkNoSaveLayerCanvas.h" |
12 #include "SkPictureUtils.h" | 13 #include "SkPictureUtils.h" |
13 #include "SkPixelRef.h" | 14 #include "SkPixelRef.h" |
14 #include "SkRRect.h" | 15 #include "SkRRect.h" |
| 16 #include "SkRecord.h" |
15 #include "SkShader.h" | 17 #include "SkShader.h" |
16 | 18 |
17 class PixelRefSet { | 19 class PixelRefSet { |
18 public: | 20 public: |
19 PixelRefSet(SkTDArray<SkPixelRef*>* array) : fArray(array) {} | 21 PixelRefSet(SkTDArray<SkPixelRef*>* array) : fArray(array) {} |
20 | 22 |
21 // This does a linear search on existing pixelrefs, so if this list gets big | 23 // This does a linear search on existing pixelrefs, so if this list gets big |
22 // we should use a more complex sorted/hashy thing. | 24 // we should use a more complex sorted/hashy thing. |
23 // | 25 // |
24 void add(SkPixelRef* pr) { | 26 void add(SkPixelRef* pr) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 canvas.clipRect(area, SkRegion::kIntersect_Op, false); | 210 canvas.clipRect(area, SkRegion::kIntersect_Op, false); |
209 canvas.drawPicture(pict); | 211 canvas.drawPicture(pict); |
210 | 212 |
211 SkData* data = NULL; | 213 SkData* data = NULL; |
212 int count = array.count(); | 214 int count = array.count(); |
213 if (count > 0) { | 215 if (count > 0) { |
214 data = SkData::NewFromMalloc(array.detach(), count * sizeof(SkPixelRef*)
); | 216 data = SkData::NewFromMalloc(array.detach(), count * sizeof(SkPixelRef*)
); |
215 } | 217 } |
216 return data; | 218 return data; |
217 } | 219 } |
| 220 |
| 221 struct MeasureRecords { |
| 222 template <typename T> size_t operator()(const T& op) { return 0; } |
| 223 size_t operator()(const SkRecords::DrawPicture& op) { |
| 224 return SkPictureUtils::ApproximateBytesUsed(op.picture); |
| 225 } |
| 226 }; |
| 227 |
| 228 size_t SkPictureUtils::ApproximateBytesUsed(const SkPicture* pict) { |
| 229 size_t byteCount = sizeof(*pict); |
| 230 |
| 231 byteCount += pict->fRecord->bytesUsed(); |
| 232 if (pict->fBBH.get()) { |
| 233 byteCount += pict->fBBH->bytesUsed(); |
| 234 } |
| 235 byteCount += |
| 236 pict->fDeletionListeners.reserved() * sizeof(SkPicture::DeletionListener
*) + |
| 237 pict->fDeletionListeners.count() * sizeof(SkPicture::DeletionListener); |
| 238 |
| 239 MeasureRecords visitor; |
| 240 for (unsigned curOp = 0; curOp < pict->fRecord->count(); curOp++) { |
| 241 byteCount += pict->fRecord->visit<size_t>(curOp, visitor); |
| 242 } |
| 243 |
| 244 return byteCount; |
| 245 } |
OLD | NEW |