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, |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 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. |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 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 | SkRect clipBounds = { 0, 0, 0, 0 }; |
| 32 | (void)canvas->getClipBounds(&clipBounds); |
| 33 | const bool useBBH = !clipBounds.contains(this->cullRect()); |
| 34 | |
| 35 | SkRecordDraw(*fRecord, |
| 36 | canvas, |
| 37 | this->drawablePicts(), |
| 38 | nullptr, |
| 39 | this->drawableCount(), |
| 40 | useBBH ? fBBH.get() : nullptr, |
| 41 | callback); |
| 42 | } |
| 43 | |
| 44 | void SkBigPicture::partialPlayback(SkCanvas* canvas, |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 45 | int start, |
| 46 | int stop, |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 47 | const SkMatrix& initialCTM) const { |
| 48 | SkASSERT(canvas); |
| 49 | SkRecordPartialDraw(*fRecord, |
| 50 | canvas, |
| 51 | this->drawablePicts(), |
| 52 | this->drawableCount(), |
| 53 | start, |
| 54 | stop, |
| 55 | initialCTM); |
| 56 | } |
| 57 | |
| 58 | const SkBigPicture::Analysis& SkBigPicture::analysis() const { |
mtklein | 59c12e3 | 2016-05-02 07:19:41 -0700 | [diff] [blame] | 59 | fAnalysisOnce([this] { fAnalysis.init(*fRecord); }); |
| 60 | return fAnalysis; |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | SkRect SkBigPicture::cullRect() const { return fCullRect; } |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 64 | bool SkBigPicture::willPlayBackBitmaps() const { return this->analysis().fWillPlaybackBitmaps; } |
| 65 | int SkBigPicture::numSlowPaths() const { return this->analysis().fNumSlowPathsAndDashEffects; } |
| 66 | int SkBigPicture::approximateOpCount() const { return fRecord->count(); } |
| 67 | size_t SkBigPicture::approximateBytesUsed() const { |
| 68 | size_t bytes = sizeof(*this) + fRecord->bytesUsed() + fApproxBytesUsedBySubPictures; |
| 69 | if (fBBH) { bytes += fBBH->bytesUsed(); } |
| 70 | return bytes; |
| 71 | } |
| 72 | |
| 73 | int SkBigPicture::drawableCount() const { |
| 74 | return fDrawablePicts ? fDrawablePicts->count() : 0; |
| 75 | } |
| 76 | |
| 77 | SkPicture const* const* SkBigPicture::drawablePicts() const { |
| 78 | return fDrawablePicts ? fDrawablePicts->begin() : nullptr; |
| 79 | } |
| 80 | |
mtklein | 59c12e3 | 2016-05-02 07:19:41 -0700 | [diff] [blame] | 81 | void SkBigPicture::Analysis::init(const SkRecord& record) { |
| 82 | TRACE_EVENT0("disabled-by-default-skia", "SkBigPicture::Analysis::init()"); |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 83 | SkBitmapHunter bitmap; |
| 84 | SkPathCounter path; |
| 85 | |
fmalita | 1e2e33a | 2016-05-12 10:53:49 -0700 | [diff] [blame] | 86 | bool hasBitmap = false; |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 87 | for (int i = 0; i < record.count(); i++) { |
mtklein | 343a63d | 2016-03-22 11:46:53 -0700 | [diff] [blame] | 88 | hasBitmap = hasBitmap || record.visit(i, bitmap); |
| 89 | record.visit(i, path); |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 90 | } |
| 91 | |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 92 | fWillPlaybackBitmaps = hasBitmap; |
| 93 | fNumSlowPathsAndDashEffects = SkTMin<int>(path.fNumSlowPathsAndDashEffects, 255); |
| 94 | } |