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