| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #ifndef SkMultiPictureDocumentReader_DEFINED | 7 #ifndef SkMultiPictureDocumentReader_DEFINED |
| 8 #define SkMultiPictureDocumentReader_DEFINED | 8 #define SkMultiPictureDocumentReader_DEFINED |
| 9 | 9 |
| 10 #include "../private/SkTArray.h" | 10 #include "../private/SkTArray.h" |
| 11 #include "SkPicture.h" | 11 #include "SkPicture.h" |
| 12 #include "SkSize.h" | 12 #include "SkSize.h" |
| 13 #include "SkStream.h" | 13 #include "SkStream.h" |
| 14 | 14 |
| 15 /** A lightweight helper class for reading a Skia MultiPictureDocument. */ | 15 /** A lightweight helper class for reading a Skia MultiPictureDocument. */ |
| 16 class SkMultiPictureDocumentReader { | 16 class SkMultiPictureDocumentReader { |
| 17 public: | 17 public: |
| 18 /** Initialize the MultiPictureDocument. Does not take ownership | 18 /** Initialize the MultiPictureDocument. Does not take ownership |
| 19 of the SkStreamSeekable. */ | 19 of the SkStreamSeekable. */ |
| 20 bool init(SkStreamSeekable*); | 20 bool init(SkStreamSeekable*); |
| 21 | 21 |
| 22 /** Return to factory settings. */ | 22 /** Return to factory settings. */ |
| 23 void reset() { | 23 void reset() { |
| 24 fSizes.reset(); | 24 fSizes.reset(); |
| 25 fOffsets.reset(); | 25 fPages.reset(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 /** Call this after calling init() */ | 28 /** Call this after calling init() (otherwise you'll always get zero). */ |
| 29 int pageCount() const { return fSizes.count(); } | 29 int pageCount() const { return fSizes.count(); } |
| 30 | 30 |
| 31 /** Deserialize a page from the stream. Call init() first. The | 31 /** Deserialize a page from the stream. Call init() first. The |
| 32 SkStreamSeekable doesn't need to be the same object, but | 32 SkStreamSeekable doesn't need to be the same object, but |
| 33 should point to the same information as before. */ | 33 should point to the same information as before. */ |
| 34 sk_sp<SkPicture> readPage(SkStreamSeekable*, int) const; | 34 sk_sp<SkPicture> readPage(SkStreamSeekable*, int) const; |
| 35 | 35 |
| 36 /** Fetch the size of the given page, without deserializing the | 36 /** Fetch the size of the given page, without deserializing the |
| 37 entire page. */ | 37 entire page. */ |
| 38 SkSize pageSize(int i) const { return fSizes[i]; } | 38 SkSize pageSize(int i) const { return fSizes[i]; } |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 SkTArray<SkSize> fSizes; | 41 SkTArray<SkSize> fSizes; |
| 42 SkTArray<size_t> fOffsets; | 42 size_t fOffset; |
| 43 mutable SkTArray<sk_sp<SkPicture>> fPages; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 #endif // SkMultiPictureDocumentReader_DEFINED | 46 #endif // SkMultiPictureDocumentReader_DEFINED |
| OLD | NEW |