blob: cbe492cc2234fc3c352f158e583fd54104282dcd [file] [log] [blame]
mtklein9db912c2015-05-19 11:11:26 -07001/*
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
mtklein59c12e32016-05-02 07:19:41 -070011#include "SkOnce.h"
bungemanf3c15b72015-08-19 11:56:48 -070012#include "SkPicture.h"
msarette8597a42016-03-24 10:41:47 -070013#include "SkRect.h"
bungemanf3c15b72015-08-19 11:56:48 -070014#include "SkTemplates.h"
mtklein9db912c2015-05-19 11:11:26 -070015
16class SkBBoxHierarchy;
msarette8597a42016-03-24 10:41:47 -070017class SkMatrix;
mtklein9db912c2015-05-19 11:11:26 -070018class SkRecord;
19
20// An implementation of SkPicture supporting an arbitrary number of drawing commands.
21class SkBigPicture final : public SkPicture {
22public:
mtklein9db912c2015-05-19 11:11:26 -070023 // 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 Reed7557bbb2017-12-24 19:50:57 -050039 SkBBoxHierarchy*, // We take ownership of the caller's ref.
40 size_t approxBytesUsedBySubPictures);
mtklein9db912c2015-05-19 11:11:26 -070041
42
43// SkPicture overrides
44 void playback(SkCanvas*, AbortCallback*) const override;
45 SkRect cullRect() const override;
Mike Klein88d90712018-01-27 17:30:04 +000046 int approximateOpCount() const override;
Mike Reed7557bbb2017-12-24 19:50:57 -050047 size_t approximateBytesUsed() const override;
mtklein9db912c2015-05-19 11:11:26 -070048 const SkBigPicture* asSkBigPicture() const override { return this; }
49
50// Used by GrLayerHoister
51 void partialPlayback(SkCanvas*,
mtkleinc6ad06a2015-08-19 09:51:00 -070052 int start,
53 int stop,
mtklein9db912c2015-05-19 11:11:26 -070054 const SkMatrix& initialCTM) const;
55// Used by GrRecordReplaceDraw
Hal Canary704cd322016-11-07 14:13:52 -050056 const SkBBoxHierarchy* bbh() const { return fBBH.get(); }
57 const SkRecord* record() const { return fRecord.get(); }
mtklein9db912c2015-05-19 11:11:26 -070058
59private:
mtklein9db912c2015-05-19 11:11:26 -070060 int drawableCount() const;
61 SkPicture const* const* drawablePicts() const;
62
Hal Canary704cd322016-11-07 14:13:52 -050063 const SkRect fCullRect;
Mike Reed7557bbb2017-12-24 19:50:57 -050064 const size_t fApproxBytesUsedBySubPictures;
Hal Canary704cd322016-11-07 14:13:52 -050065 sk_sp<const SkRecord> fRecord;
66 std::unique_ptr<const SnapshotArray> fDrawablePicts;
67 sk_sp<const SkBBoxHierarchy> fBBH;
mtklein9db912c2015-05-19 11:11:26 -070068};
69
70#endif//SkBigPicture_DEFINED