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 15 class SkCanvas; 16 class SkImageDeserializer; 17 class SkImageSerializer; 18 class SkTypeface; 19 class SkTypefaceDeserializer; 20 class SkTypefaceSerializer; 21 class SkWStream; 22 23 struct SkRect; 24 25 class SkPipeSerializer { 26 public: 27 SkPipeSerializer(); 28 ~SkPipeSerializer(); 29 30 // Ownership is not transferred, so caller must ceep the serializer alive 31 void setTypefaceSerializer(SkTypefaceSerializer*); 32 void setImageSerializer(SkImageSerializer*); 33 34 void resetCache(); 35 36 sk_sp<SkData> writeImage(SkImage*); 37 sk_sp<SkData> writePicture(SkPicture*); 38 39 void writeImage(SkImage*, SkWStream*); 40 void writePicture(SkPicture*, SkWStream*); 41 42 SkCanvas* beginWrite(const SkRect& cullBounds, SkWStream*); 43 void endWrite(); 44 45 private: 46 class Impl; 47 std::unique_ptr<Impl> fImpl; 48 }; 49 50 class SkPipeDeserializer { 51 public: 52 SkPipeDeserializer(); 53 ~SkPipeDeserializer(); 54 55 // Ownership is not transferred, so caller must ceep the deserializer alive 56 void setTypefaceDeserializer(SkTypefaceDeserializer*); 57 void setImageDeserializer(SkImageDeserializer*); 58 readImage(const SkData * data)59 sk_sp<SkImage> readImage(const SkData* data) { 60 if (!data) { 61 return nullptr; 62 } 63 return this->readImage(data->data(), data->size()); 64 } 65 readPicture(const SkData * data)66 sk_sp<SkPicture> readPicture(const SkData* data) { 67 if (!data) { 68 return nullptr; 69 } 70 return this->readPicture(data->data(), data->size()); 71 } 72 73 sk_sp<SkImage> readImage(const void*, size_t); 74 sk_sp<SkPicture> readPicture(const void*, size_t); 75 76 bool playback(const void*, size_t, SkCanvas*); 77 78 private: 79 class Impl; 80 std::unique_ptr<Impl> fImpl; 81 }; 82 83 ////////////////////////////////////////////////////////////////////////////////////////////////// 84 85 class SkTypefaceSerializer { 86 public: ~SkTypefaceSerializer()87 virtual ~SkTypefaceSerializer() {} 88 89 virtual sk_sp<SkData> serialize(SkTypeface*) = 0; 90 }; 91 92 class SkImageSerializer { 93 public: ~SkImageSerializer()94 virtual ~SkImageSerializer() {} 95 96 virtual sk_sp<SkData> serialize(SkImage*) = 0; 97 }; 98 99 100 class SkTypefaceDeserializer { 101 public: ~SkTypefaceDeserializer()102 virtual ~SkTypefaceDeserializer() {} 103 104 virtual sk_sp<SkTypeface> deserialize(const void* data, size_t size) = 0; 105 }; 106 107 #endif 108