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