mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 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 | |
mtklein | 59c12e3 | 2016-05-02 07:19:41 -0700 | [diff] [blame] | 11 | #include "SkOnce.h" |
bungeman | f3c15b7 | 2015-08-19 11:56:48 -0700 | [diff] [blame] | 12 | #include "SkPicture.h" |
msarett | e8597a4 | 2016-03-24 10:41:47 -0700 | [diff] [blame] | 13 | #include "SkRect.h" |
bungeman | f3c15b7 | 2015-08-19 11:56:48 -0700 | [diff] [blame] | 14 | #include "SkTemplates.h" |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 15 | |
| 16 | class SkBBoxHierarchy; |
msarett | e8597a4 | 2016-03-24 10:41:47 -0700 | [diff] [blame] | 17 | class SkMatrix; |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 18 | class SkRecord; |
| 19 | |
| 20 | // An implementation of SkPicture supporting an arbitrary number of drawing commands. |
| 21 | class SkBigPicture final : public SkPicture { |
| 22 | public: |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 23 | // An array of refcounted const SkPicture pointers. |
| 24 | class SnapshotArray : ::SkNoncopyable { |
| 25 | public: |
| 26 | SnapshotArray(const SkPicture* pics[], int count) : fPics(pics), fCount(count) {} |
| 27 | ~SnapshotArray() { for (int i = 0; i < fCount; i++) { fPics[i]->unref(); } } |
| 28 | |
| 29 | const SkPicture* const* begin() const { return fPics; } |
| 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. |
Mike Reed | 7557bbb | 2017-12-24 19:50:57 -0500 | [diff] [blame^] | 39 | SkBBoxHierarchy*, // We take ownership of the caller's ref. |
| 40 | size_t approxBytesUsedBySubPictures); |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 41 | |
| 42 | |
| 43 | // SkPicture overrides |
| 44 | void playback(SkCanvas*, AbortCallback*) const override; |
| 45 | SkRect cullRect() const override; |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 46 | int approximateOpCount() const override; |
Mike Reed | 7557bbb | 2017-12-24 19:50:57 -0500 | [diff] [blame^] | 47 | size_t approximateBytesUsed() const override; |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 48 | const SkBigPicture* asSkBigPicture() const override { return this; } |
| 49 | |
| 50 | // Used by GrLayerHoister |
| 51 | void partialPlayback(SkCanvas*, |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 52 | int start, |
| 53 | int stop, |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 54 | const SkMatrix& initialCTM) const; |
| 55 | // Used by GrRecordReplaceDraw |
Hal Canary | 704cd32 | 2016-11-07 14:13:52 -0500 | [diff] [blame] | 56 | const SkBBoxHierarchy* bbh() const { return fBBH.get(); } |
| 57 | const SkRecord* record() const { return fRecord.get(); } |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 58 | |
| 59 | private: |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 60 | int drawableCount() const; |
| 61 | SkPicture const* const* drawablePicts() const; |
| 62 | |
Hal Canary | 704cd32 | 2016-11-07 14:13:52 -0500 | [diff] [blame] | 63 | const SkRect fCullRect; |
Mike Reed | 7557bbb | 2017-12-24 19:50:57 -0500 | [diff] [blame^] | 64 | const size_t fApproxBytesUsedBySubPictures; |
Hal Canary | 704cd32 | 2016-11-07 14:13:52 -0500 | [diff] [blame] | 65 | sk_sp<const SkRecord> fRecord; |
| 66 | std::unique_ptr<const SnapshotArray> fDrawablePicts; |
| 67 | sk_sp<const SkBBoxHierarchy> fBBH; |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | #endif//SkBigPicture_DEFINED |