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