| 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 "src/core/SkBigPicture.h" |
| 9 |
|
| 10 |
#include "include/core/SkBBHFactory.h" |
| 11 |
#include "include/core/SkCanvas.h" |
| 12 |
#include "include/private/base/SkAssert.h" |
| 13 |
#include "src/core/SkRecord.h" |
| 14 |
#include "src/core/SkRecordDraw.h" |
| 15 |
#include "src/core/SkRecords.h" |
| 16 |
|
| 17 |
#include <utility> |
| 18 |
|
| 19 |
SkBigPicture::SkBigPicture(const SkRect& cull, |
| 20 |
sk_sp<SkRecord> record, |
| 21 |
std::unique_ptr<SnapshotArray> drawablePicts, |
| 22 |
sk_sp<SkBBoxHierarchy> bbh, |
| 23 |
size_t approxBytesUsedBySubPictures) |
| 24 |
: fCullRect(cull) |
| 25 |
, fApproxBytesUsedBySubPictures(approxBytesUsedBySubPictures) |
| 26 |
, fRecord(std::move(record)) |
| 27 |
, fDrawablePicts(std::move(drawablePicts)) |
| 28 |
, fBBH(std::move(bbh)) |
| 29 |
{} |
| 30 |
|
| 31 |
void SkBigPicture::playback(SkCanvas* canvas, AbortCallback* callback) const { |
| 32 |
SkASSERT(canvas); |
| 33 |
|
| 34 |
// If the query contains the whole picture, don't bother with the BBH. |
| 35 |
const bool useBBH = !canvas->getLocalClipBounds().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 |
struct NestedApproxOpCounter { |
| 47 |
int fCount = 0; |
| 48 |
|
| 49 |
template <typename T> void operator()(const T& op) { |
| 50 |
fCount += 1; |
| 51 |
} |
| 52 |
void operator()(const SkRecords::DrawPicture& op) { |
| 53 |
fCount += op.picture->approximateOpCount(true); |
| 54 |
} |
| 55 |
}; |
| 56 |
|
| 57 |
SkRect SkBigPicture::cullRect() const { return fCullRect; } |
| 58 |
int SkBigPicture::approximateOpCount(bool nested) const { |
| 59 |
if (nested) { |
| 60 |
NestedApproxOpCounter visitor; |
| 61 |
for (int i = 0; i < fRecord->count(); i++) { |
| 62 |
fRecord->visit(i, visitor); |
| 63 |
} |
| 64 |
return visitor.fCount; |
| 65 |
} else { |
| 66 |
return fRecord->count(); |
| 67 |
} |
| 68 |
} |
| 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 |
|