mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame^] | 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 | |
| 14 | SkBigPicture::SkBigPicture(const SkRect& cull, |
| 15 | SkRecord* record, |
| 16 | SnapshotArray* drawablePicts, |
| 17 | SkBBoxHierarchy* bbh, |
| 18 | AccelData* accelData, |
| 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 | , fAccelData(accelData) // Take ownership of caller's ref. |
| 26 | {} |
| 27 | |
| 28 | void SkBigPicture::playback(SkCanvas* canvas, AbortCallback* callback) const { |
| 29 | SkASSERT(canvas); |
| 30 | |
| 31 | // If the query contains the whole picture, don't bother with the BBH. |
| 32 | SkRect clipBounds = { 0, 0, 0, 0 }; |
| 33 | (void)canvas->getClipBounds(&clipBounds); |
| 34 | const bool useBBH = !clipBounds.contains(this->cullRect()); |
| 35 | |
| 36 | SkRecordDraw(*fRecord, |
| 37 | canvas, |
| 38 | this->drawablePicts(), |
| 39 | nullptr, |
| 40 | this->drawableCount(), |
| 41 | useBBH ? fBBH.get() : nullptr, |
| 42 | callback); |
| 43 | } |
| 44 | |
| 45 | void SkBigPicture::partialPlayback(SkCanvas* canvas, |
| 46 | unsigned start, |
| 47 | unsigned stop, |
| 48 | const SkMatrix& initialCTM) const { |
| 49 | SkASSERT(canvas); |
| 50 | SkRecordPartialDraw(*fRecord, |
| 51 | canvas, |
| 52 | this->drawablePicts(), |
| 53 | this->drawableCount(), |
| 54 | start, |
| 55 | stop, |
| 56 | initialCTM); |
| 57 | } |
| 58 | |
| 59 | const SkBigPicture::Analysis& SkBigPicture::analysis() const { |
| 60 | auto create = [&]() { return SkNEW_ARGS(Analysis, (*fRecord)); }; |
| 61 | return *fAnalysis.get(create); |
| 62 | } |
| 63 | |
| 64 | SkRect SkBigPicture::cullRect() const { return fCullRect; } |
| 65 | bool SkBigPicture::hasText() const { return this->analysis().fHasText; } |
| 66 | bool SkBigPicture::willPlayBackBitmaps() const { return this->analysis().fWillPlaybackBitmaps; } |
| 67 | int SkBigPicture::numSlowPaths() const { return this->analysis().fNumSlowPathsAndDashEffects; } |
| 68 | int SkBigPicture::approximateOpCount() const { return fRecord->count(); } |
| 69 | size_t SkBigPicture::approximateBytesUsed() const { |
| 70 | size_t bytes = sizeof(*this) + fRecord->bytesUsed() + fApproxBytesUsedBySubPictures; |
| 71 | if (fBBH) { bytes += fBBH->bytesUsed(); } |
| 72 | return bytes; |
| 73 | } |
| 74 | |
| 75 | int SkBigPicture::drawableCount() const { |
| 76 | return fDrawablePicts ? fDrawablePicts->count() : 0; |
| 77 | } |
| 78 | |
| 79 | SkPicture const* const* SkBigPicture::drawablePicts() const { |
| 80 | return fDrawablePicts ? fDrawablePicts->begin() : nullptr; |
| 81 | } |
| 82 | |
| 83 | SkBigPicture::Analysis::Analysis(const SkRecord& record) { |
| 84 | SkTextHunter text; |
| 85 | SkBitmapHunter bitmap; |
| 86 | SkPathCounter path; |
| 87 | |
| 88 | bool hasText = false, hasBitmap = false; |
| 89 | for (unsigned i = 0; i < record.count(); i++) { |
| 90 | hasText = hasText || record.visit<bool>(i, text); |
| 91 | hasBitmap = hasBitmap || record.visit<bool>(i, bitmap); |
| 92 | record.visit<void>(i, path); |
| 93 | } |
| 94 | |
| 95 | fHasText = hasText; |
| 96 | fWillPlaybackBitmaps = hasBitmap; |
| 97 | fNumSlowPathsAndDashEffects = SkTMin<int>(path.fNumSlowPathsAndDashEffects, 255); |
| 98 | } |