• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SkBigPicture(const SkRect & cull,sk_sp<SkRecord> record,std::unique_ptr<SnapshotArray> drawablePicts,sk_sp<SkBBoxHierarchy> bbh,size_t approxBytesUsedBySubPictures)15 SkBigPicture::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 
playback(SkCanvas * canvas,AbortCallback * callback) const27 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     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 
partialPlayback(SkCanvas * canvas,int start,int stop,const SkM44 & initialCTM) const42 void SkBigPicture::partialPlayback(SkCanvas* canvas,
43                                    int start,
44                                    int stop,
45                                    const SkM44& initialCTM) const {
46     SkASSERT(canvas);
47     SkRecordPartialDraw(*fRecord,
48                         canvas,
49                         this->drawablePicts(),
50                         this->drawableCount(),
51                         start,
52                         stop,
53                         initialCTM);
54 }
55 
56 struct NestedApproxOpCounter {
57     int fCount = 0;
58 
operator ()NestedApproxOpCounter59     template <typename T> void operator()(const T& op) {
60         fCount += 1;
61     }
operator ()NestedApproxOpCounter62     void operator()(const SkRecords::DrawPicture& op) {
63         fCount += op.picture->approximateOpCount(true);
64     }
65 };
66 
cullRect() const67 SkRect SkBigPicture::cullRect()            const { return fCullRect; }
approximateOpCount(bool nested) const68 int SkBigPicture::approximateOpCount(bool nested) const {
69     if (nested) {
70         NestedApproxOpCounter visitor;
71         for (int i = 0; i < fRecord->count(); i++) {
72             fRecord->visit(i, visitor);
73         }
74         return visitor.fCount;
75     } else {
76         return fRecord->count();
77     }
78 }
approximateBytesUsed() const79 size_t SkBigPicture::approximateBytesUsed() const {
80     size_t bytes = sizeof(*this) + fRecord->bytesUsed() + fApproxBytesUsedBySubPictures;
81     if (fBBH) { bytes += fBBH->bytesUsed(); }
82     return bytes;
83 }
84 
drawableCount() const85 int SkBigPicture::drawableCount() const {
86     return fDrawablePicts ? fDrawablePicts->count() : 0;
87 }
88 
drawablePicts() const89 SkPicture const* const* SkBigPicture::drawablePicts() const {
90     return fDrawablePicts ? fDrawablePicts->begin() : nullptr;
91 }
92 
93