1 /* 2 * Copyright 2017 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 SkSerialProcs_DEFINED 9 #define SkSerialProcs_DEFINED 10 11 #include "SkImage.h" 12 #include "SkPicture.h" 13 #include "SkTypeface.h" 14 15 /** 16 * A serial-proc is asked to serialize the specified object (e.g. picture or image). 17 * If a data object is returned, it will be used (even if it is zero-length). 18 * If null is returned, then Skia will take its default action. 19 * 20 * The default action for pictures is to use Skia's internal format. 21 * The default action for images is to encode using PNG. 22 * The default action for typefaces is to use Skia's internal format. 23 */ 24 25 typedef sk_sp<SkData> (*SkSerialPictureProc)(SkPicture*, void* ctx); 26 typedef sk_sp<SkData> (*SkSerialImageProc)(SkImage*, void* ctx); 27 typedef sk_sp<SkData> (*SkSerialTypefaceProc)(SkTypeface*, void* ctx); 28 29 /** 30 * A deserial-proc is given the serialized form previously returned by the corresponding 31 * serial-proc, and should return the re-constituted object. In case of an error, the proc 32 * can return nullptr. 33 */ 34 35 typedef sk_sp<SkPicture> (*SkDeserialPictureProc)(const void* data, size_t length, void* ctx); 36 typedef sk_sp<SkImage> (*SkDeserialImageProc)(const void* data, size_t length, void* ctx); 37 typedef sk_sp<SkTypeface> (*SkDeserialTypefaceProc)(const void* data, size_t length, void* ctx); 38 39 struct SK_API SkSerialProcs { 40 SkSerialPictureProc fPictureProc = nullptr; 41 void* fPictureCtx = nullptr; 42 43 SkSerialImageProc fImageProc = nullptr; 44 void* fImageCtx = nullptr; 45 46 SkSerialTypefaceProc fTypefaceProc = nullptr; 47 void* fTypefaceCtx = nullptr; 48 }; 49 50 struct SK_API SkDeserialProcs { 51 SkDeserialPictureProc fPictureProc = nullptr; 52 void* fPictureCtx = nullptr; 53 54 SkDeserialImageProc fImageProc = nullptr; 55 void* fImageCtx = nullptr; 56 57 SkDeserialTypefaceProc fTypefaceProc = nullptr; 58 void* fTypefaceCtx = nullptr; 59 }; 60 61 #endif 62 63