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 "include/core/SkImage.h"
12#include "include/core/SkPicture.h"
13#include "include/core/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 either in its native format or PNG.
22 *  The default action for typefaces is to use Skia's internal format.
23 */
24
25typedef sk_sp<SkData> (*SkSerialPictureProc)(SkPicture*, void* ctx);
26typedef sk_sp<SkData> (*SkSerialImageProc)(SkImage*, void* ctx);
27typedef sk_sp<SkData> (*SkSerialTypefaceProc)(SkTypeface*, void* ctx);
28
29/**
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.
32 */
33typedef sk_sp<SkPicture> (*SkDeserialPictureProc)(const void* data, size_t length, void* ctx);
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 */
42typedef sk_sp<SkImage> (*SkDeserialImageProc)(const void* data, size_t length, void* ctx);
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 */
48typedef sk_sp<SkTypeface> (*SkDeserialTypefaceProc)(const void* data, size_t length, void* ctx);
49
50struct SK_API SkSerialProcs {
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
61struct SK_API SkDeserialProcs {
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
74