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
16class SkBBoxHierarchy;
17class SkMatrix;
18class SkRecord;
19
20// An implementation of SkPicture supporting an arbitrary number of drawing commands.
21class SkBigPicture final : public SkPicture {
22public:
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.
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;
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
56    const SkBBoxHierarchy* bbh() const { return fBBH.get(); }
57    const SkRecord*     record() const { return fRecord.get(); }
58
59private:
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