aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/SkMultiPictureDocumentReader.h
blob: e0473a6539778fc941cf7db4dda0da850e3bf49e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#ifndef SkMultiPictureDocumentReader_DEFINED
#define SkMultiPictureDocumentReader_DEFINED

#include "../private/SkTArray.h"
#include "SkPicture.h"
#include "SkSize.h"
#include "SkStream.h"

/** A lightweight helper class for reading a Skia MultiPictureDocument. */
class SkMultiPictureDocumentReader {
public:
    /** Initialize the MultiPictureDocument.  Does not take ownership
        of the SkStreamSeekable. */
    bool init(SkStreamSeekable*);

    /** Return to factory settings. */
    void reset() {
        fSizes.reset();
        fPages.reset();
    }

    /** Call this after calling init() (otherwise you'll always get zero). */
    int pageCount() const { return fSizes.count(); }

    /** Deserialize a page from the stream.  Call init() first.  The
        SkStreamSeekable doesn't need to be the same object, but
        should point to the same information as before. */
    sk_sp<SkPicture> readPage(SkStreamSeekable*, int) const;

    /** Fetch the size of the given page, without deserializing the
        entire page. */
    SkSize pageSize(int i) const { return fSizes[i]; }

private:
    SkTArray<SkSize> fSizes;
    size_t fOffset;
    mutable SkTArray<sk_sp<SkPicture>> fPages;
};

#endif  // SkMultiPictureDocumentReader_DEFINED