xref: /aosp_15_r20/external/skia/include/docs/SkMultiPictureDocument.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2023 Google LLC
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 SkMultiPictureDocument_DEFINED
9 #define SkMultiPictureDocument_DEFINED
10 
11 #include "include/core/SkPicture.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/core/SkSize.h"
14 #include "include/core/SkTypes.h"
15 
16 #include <functional>
17 
18 class SkDocument;
19 class SkStreamSeekable;
20 class SkWStream;
21 struct SkDeserialProcs;
22 struct SkSerialProcs;
23 
24 struct SkDocumentPage {
25     sk_sp<SkPicture> fPicture;
26     SkSize fSize;
27 };
28 
29 namespace SkMultiPictureDocument {
30 /**
31  *  Writes into a file format that is similar to SkPicture::serialize()
32  *  Accepts a callback for endPage behavior
33  */
34 SK_API sk_sp<SkDocument> Make(SkWStream* dst, const SkSerialProcs* = nullptr,
35                               std::function<void(const SkPicture*)> onEndPage = nullptr);
36 
37 /**
38  *  Returns the number of pages in the SkMultiPictureDocument.
39  */
40 SK_API int ReadPageCount(SkStreamSeekable* src);
41 
42 /**
43  *  Read the SkMultiPictureDocument into the provided array of pages.
44  *  dstArrayCount must equal SkMultiPictureDocumentReadPageCount().
45  *  Return false on error.
46  */
47 SK_API bool Read(SkStreamSeekable* src,
48                  SkDocumentPage* dstArray,
49                  int dstArrayCount,
50                  const SkDeserialProcs* = nullptr);
51 }  // namespace SkMultiPictureDocument
52 
53 #endif  // SkMultiPictureDocument_DEFINED
54