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 8 #ifndef SkPipe_DEFINED 9 #define SkPipe_DEFINED 10 11 #include "SkData.h" 12 #include "SkImage.h" 13 #include "SkPicture.h" 14 #include "SkSerialProcs.h" 15 16 class SkCanvas; 17 class SkTypeface; 18 class SkWStream; 19 20 struct SkRect; 21 22 class SkPipeSerializer { 23 public: 24 SkPipeSerializer(); 25 ~SkPipeSerializer(); 26 27 void setSerialProcs(const SkSerialProcs&); 28 29 void resetCache(); 30 31 sk_sp<SkData> writeImage(SkImage*); 32 sk_sp<SkData> writePicture(SkPicture*); 33 34 void writeImage(SkImage*, SkWStream*); 35 void writePicture(SkPicture*, SkWStream*); 36 37 SkCanvas* beginWrite(const SkRect& cullBounds, SkWStream*); 38 void endWrite(); 39 40 private: 41 class Impl; 42 std::unique_ptr<Impl> fImpl; 43 }; 44 45 class SkPipeDeserializer { 46 public: 47 SkPipeDeserializer(); 48 ~SkPipeDeserializer(); 49 50 void setDeserialProcs(const SkDeserialProcs&); 51 52 sk_sp<SkImage> readImage(const SkData* data) { 53 if (!data) { 54 return nullptr; 55 } 56 return this->readImage(data->data(), data->size()); 57 } 58 59 sk_sp<SkPicture> readPicture(const SkData* data) { 60 if (!data) { 61 return nullptr; 62 } 63 return this->readPicture(data->data(), data->size()); 64 } 65 66 sk_sp<SkImage> readImage(const void*, size_t); 67 sk_sp<SkPicture> readPicture(const void*, size_t); 68 69 bool playback(const void*, size_t, SkCanvas*); 70 71 private: 72 class Impl; 73 std::unique_ptr<Impl> fImpl; 74 }; 75 76 #endif 77