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