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 #ifndef SkBigPicture_DEFINED
9 #define SkBigPicture_DEFINED
10 
11 #include "SkOnce.h"
12 #include "SkPicture.h"
13 #include "SkRect.h"
14 #include "SkTemplates.h"
15 
16 class SkBBoxHierarchy;
17 class SkMatrix;
18 class SkRecord;
19 
20 // An implementation of SkPicture supporting an arbitrary number of drawing commands.
21 class SkBigPicture final : public SkPicture {
22 public:
23     // An array of refcounted const SkPicture pointers.
24     class SnapshotArray : ::SkNoncopyable {
25     public:
SnapshotArray(const SkPicture * pics[],int count)26         SnapshotArray(const SkPicture* pics[], int count) : fPics(pics), fCount(count) {}
~SnapshotArray()27         ~SnapshotArray() { for (int i = 0; i < fCount; i++) { fPics[i]->unref(); } }
28 
begin()29         const SkPicture* const* begin() const { return fPics; }
count()30         int count() const { return fCount; }
31     private:
32         SkAutoTMalloc<const SkPicture*> fPics;
33         int fCount;
34     };
35 
36     SkBigPicture(const SkRect& cull,
37                  SkRecord*,            // We take ownership of the caller's ref.
38                  SnapshotArray*,       // We take exclusive ownership.
39                  SkBBoxHierarchy*,     // We take ownership of the caller's ref.
40                  size_t approxBytesUsedBySubPictures);
41 
42 
43 // SkPicture overrides
44     void playback(SkCanvas*, AbortCallback*) const override;
45     SkRect cullRect() const override;
46     int approximateOpCount() const override;
47     size_t approximateBytesUsed() const override;
asSkBigPicture()48     const SkBigPicture* asSkBigPicture() const override { return this; }
49 
50 // Used by GrLayerHoister
51     void partialPlayback(SkCanvas*,
52                          int start,
53                          int stop,
54                          const SkMatrix& initialCTM) const;
55 // Used by GrRecordReplaceDraw
bbh()56     const SkBBoxHierarchy* bbh() const { return fBBH.get(); }
record()57     const SkRecord*     record() const { return fRecord.get(); }
58 
59 private:
60     int drawableCount() const;
61     SkPicture const* const* drawablePicts() const;
62 
63     const SkRect                         fCullRect;
64     const size_t                         fApproxBytesUsedBySubPictures;
65     sk_sp<const SkRecord>                fRecord;
66     std::unique_ptr<const SnapshotArray> fDrawablePicts;
67     sk_sp<const SkBBoxHierarchy>         fBBH;
68 };
69 
70 #endif//SkBigPicture_DEFINED
71