1 /* 2 * Copyright 2015 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "SkBBoxHierarchy.h" 9 #include "SkBigPicture.h" 10 #include "SkPictureCommon.h" 11 #include "SkRecord.h" 12 #include "SkRecordDraw.h" 13 #include "SkTraceEvent.h" 14 15 SkBigPicture::SkBigPicture(const SkRect& cull, 16 SkRecord* record, 17 SnapshotArray* drawablePicts, 18 SkBBoxHierarchy* bbh, 19 size_t approxBytesUsedBySubPictures) 20 : fCullRect(cull) 21 , fApproxBytesUsedBySubPictures(approxBytesUsedBySubPictures) 22 , fRecord(record) // Take ownership of caller's ref. 23 , fDrawablePicts(drawablePicts) // Take ownership. 24 , fBBH(bbh) // Take ownership of caller's ref. 25 {} 26 27 void SkBigPicture::playback(SkCanvas* canvas, AbortCallback* callback) const { 28 SkASSERT(canvas); 29 30 // If the query contains the whole picture, don't bother with the BBH. 31 const bool useBBH = !canvas->getLocalClipBounds().contains(this->cullRect()); 32 33 SkRecordDraw(*fRecord, 34 canvas, 35 this->drawablePicts(), 36 nullptr, 37 this->drawableCount(), 38 useBBH ? fBBH.get() : nullptr, 39 callback); 40 } 41 42 void SkBigPicture::partialPlayback(SkCanvas* canvas, 43 int start, 44 int stop, 45 const SkMatrix& initialCTM) const { 46 SkASSERT(canvas); 47 SkRecordPartialDraw(*fRecord, 48 canvas, 49 this->drawablePicts(), 50 this->drawableCount(), 51 start, 52 stop, 53 initialCTM); 54 } 55 56 SkRect SkBigPicture::cullRect() const { return fCullRect; } 57 int SkBigPicture::approximateOpCount() const { return fRecord->count(); } 58 size_t SkBigPicture::approximateBytesUsed() const { 59 size_t bytes = sizeof(*this) + fRecord->bytesUsed() + fApproxBytesUsedBySubPictures; 60 if (fBBH) { bytes += fBBH->bytesUsed(); } 61 return bytes; 62 } 63 64 int SkBigPicture::drawableCount() const { 65 return fDrawablePicts ? fDrawablePicts->count() : 0; 66 } 67 68 SkPicture const* const* SkBigPicture::drawablePicts() const { 69 return fDrawablePicts ? fDrawablePicts->begin() : nullptr; 70 } 71 72