Mike Reed | 60691a5 | 2017-12-05 15:11:24 -0500 | [diff] [blame] | 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 | /** |
Mike Reed | 64f7376 | 2017-12-08 10:31:52 -0500 | [diff] [blame] | 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. |
Mike Reed | b5213b8 | 2017-12-13 14:17:29 -0500 | [diff] [blame] | 19 | * |
| 20 | * The default action for pictures is to use Skia's internal format. |
Mike Reed | d07e4a2 | 2018-03-08 16:29:12 -0500 | [diff] [blame] | 21 | * The default action for images is to encode either in its native format or PNG. |
Mike Reed | b5213b8 | 2017-12-13 14:17:29 -0500 | [diff] [blame] | 22 | * The default action for typefaces is to use Skia's internal format. |
Mike Reed | 60691a5 | 2017-12-05 15:11:24 -0500 | [diff] [blame] | 23 | */ |
| 24 | |
Mike Reed | 64f7376 | 2017-12-08 10:31:52 -0500 | [diff] [blame] | 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); |
Mike Reed | 60691a5 | 2017-12-05 15:11:24 -0500 | [diff] [blame] | 28 | |
| 29 | /** |
Mike Reed | d07e4a2 | 2018-03-08 16:29:12 -0500 | [diff] [blame] | 30 | * Called with the encoded form of a picture (previously written with a custom |
| 31 | * SkSerialPictureProc proc). Return a picture object, or nullptr indicating failure. |
Mike Reed | 60691a5 | 2017-12-05 15:11:24 -0500 | [diff] [blame] | 32 | */ |
Mike Reed | 60691a5 | 2017-12-05 15:11:24 -0500 | [diff] [blame] | 33 | typedef sk_sp<SkPicture> (*SkDeserialPictureProc)(const void* data, size_t length, void* ctx); |
Mike Reed | d07e4a2 | 2018-03-08 16:29:12 -0500 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Called with the encoded from of an image. The proc can return an image object, or if it |
| 37 | * returns nullptr, then Skia will take its default action to try to create an image from the data. |
| 38 | * |
| 39 | * Note that unlike SkDeserialPictureProc and SkDeserialTypefaceProc, return nullptr from this |
| 40 | * does not indicate failure, but is a signal for Skia to take its default action. |
| 41 | */ |
Mike Reed | 60691a5 | 2017-12-05 15:11:24 -0500 | [diff] [blame] | 42 | typedef sk_sp<SkImage> (*SkDeserialImageProc)(const void* data, size_t length, void* ctx); |
Mike Reed | d07e4a2 | 2018-03-08 16:29:12 -0500 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Called with the encoded form of a typeface (previously written with a custom |
| 46 | * SkSerialTypefaceProc proc). Return a typeface object, or nullptr indicating failure. |
| 47 | */ |
Mike Reed | 60691a5 | 2017-12-05 15:11:24 -0500 | [diff] [blame] | 48 | typedef sk_sp<SkTypeface> (*SkDeserialTypefaceProc)(const void* data, size_t length, void* ctx); |
| 49 | |
Mike Reed | 47fdf6c | 2017-12-20 14:12:07 -0500 | [diff] [blame] | 50 | struct SK_API SkSerialProcs { |
Mike Reed | 60691a5 | 2017-12-05 15:11:24 -0500 | [diff] [blame] | 51 | SkSerialPictureProc fPictureProc = nullptr; |
| 52 | void* fPictureCtx = nullptr; |
| 53 | |
| 54 | SkSerialImageProc fImageProc = nullptr; |
| 55 | void* fImageCtx = nullptr; |
| 56 | |
| 57 | SkSerialTypefaceProc fTypefaceProc = nullptr; |
| 58 | void* fTypefaceCtx = nullptr; |
| 59 | }; |
| 60 | |
Mike Reed | 47fdf6c | 2017-12-20 14:12:07 -0500 | [diff] [blame] | 61 | struct SK_API SkDeserialProcs { |
Mike Reed | 60691a5 | 2017-12-05 15:11:24 -0500 | [diff] [blame] | 62 | SkDeserialPictureProc fPictureProc = nullptr; |
| 63 | void* fPictureCtx = nullptr; |
| 64 | |
| 65 | SkDeserialImageProc fImageProc = nullptr; |
| 66 | void* fImageCtx = nullptr; |
| 67 | |
| 68 | SkDeserialTypefaceProc fTypefaceProc = nullptr; |
| 69 | void* fTypefaceCtx = nullptr; |
| 70 | }; |
| 71 | |
| 72 | #endif |
| 73 | |