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 "include/core/SkBBHFactory.h"
9#include "src/core/SkBigPicture.h"
10#include "src/core/SkPictureCommon.h"
11#include "src/core/SkRecord.h"
12#include "src/core/SkRecordDraw.h"
13#include "src/core/SkTraceEvent.h"
14
15SkBigPicture::SkBigPicture(const SkRect& cull,
16 sk_sp<SkRecord> record,
17 std::unique_ptr<SnapshotArray> drawablePicts,
18 sk_sp<SkBBoxHierarchy> bbh,
19 size_t approxBytesUsedBySubPictures)
20 : fCullRect(cull)
21 , fApproxBytesUsedBySubPictures(approxBytesUsedBySubPictures)
22 , fRecord(std::move(record))
23 , fDrawablePicts(std::move(drawablePicts))
24 , fBBH(std::move(bbh))
25{}
26
27void 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
42void 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
56SkRect SkBigPicture::cullRect() const { return fCullRect; }
57int SkBigPicture::approximateOpCount() const { return fRecord->count(); }
58size_t SkBigPicture::approximateBytesUsed() const {
59 size_t bytes = sizeof(*this) + fRecord->bytesUsed() + fApproxBytesUsedBySubPictures;
60 if (fBBH) { bytes += fBBH->bytesUsed(); }
61 return bytes;
62}
63
64int SkBigPicture::drawableCount() const {
65 return fDrawablePicts ? fDrawablePicts->count() : 0;
66}
67
68SkPicture const* const* SkBigPicture::drawablePicts() const {
69 return fDrawablePicts ? fDrawablePicts->begin() : nullptr;
70}
71
72