Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: src/utils/SkPictureUtils.cpp

Issue 490253003: Implement SkPicture::bytesUsed() for SkRecord backend (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: SkRecord visitor recursively measures SkPictures Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 class MeasureRecords : SkNoncopyable {
222 public:
223 MeasureRecords() : fSize(0) { }
224
225 template <typename T> void operator()(const T& op) {
mtklein 2014/11/18 21:38:32 Maybe just this? struct MeasureRecords { templa
mtklein 2014/11/18 21:46:23 Oh, sadly I think you have to do MeasureRecords v
tomhudson 2014/11/18 21:49:37 Acknowledged. (I think you posted this at the same
226 this->measure(op);
227 }
228
229 size_t measuredSize() const { return fSize; }
230 private:
231 void measure(const SkRecords::DrawPicture& p) {
232 this->fSize += SkPictureUtils::ApproximateBytesUsed(p.picture);
mtklein 2014/11/18 21:38:32 I applaud your adherence to the style guide, but t
233 }
234 template <typename T> void measure(const T&) { }
235
236 size_t fSize;
237 };
238
239 size_t SkPictureUtils::ApproximateBytesUsed(const SkPicture* pict) {
240 size_t byteCount = sizeof(*pict);
241
242 byteCount += pict->fRecord->bytesUsed();
243 if (pict->fBBH.get()) {
244 byteCount += pict->fBBH->bytesUsed();
245 }
246 byteCount +=
247 pict->fDeletionListeners.reserved() * sizeof(SkPicture::DeletionListener *) +
248 pict->fDeletionListeners.count() * sizeof(SkPicture::DeletionListener);
249
250 MeasureRecords visitor;
251 for (unsigned curOp = 0; curOp < pict->fRecord->count(); curOp++) {
252 pict->fRecord->visit<void>(curOp, visitor);
253 }
254 byteCount += visitor.measuredSize();
255
256 return byteCount;
257 }
OLDNEW
« src/core/SkRecord.h ('K') | « src/core/SkTileGrid.cpp ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698