blob: e5a886a3329b777231f450ae8ed6d5509fa94e20 [file] [log] [blame]
Mike Reed60691a52017-12-05 15:11:24 -05001/*
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 Reed64f73762017-12-08 10:31:52 -050016 * 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 Reedb5213b82017-12-13 14:17:29 -050019 *
20 * The default action for pictures is to use Skia's internal format.
Mike Reedd07e4a22018-03-08 16:29:12 -050021 * The default action for images is to encode either in its native format or PNG.
Mike Reedb5213b82017-12-13 14:17:29 -050022 * The default action for typefaces is to use Skia's internal format.
Mike Reed60691a52017-12-05 15:11:24 -050023 */
24
Mike Reed64f73762017-12-08 10:31:52 -050025typedef sk_sp<SkData> (*SkSerialPictureProc)(SkPicture*, void* ctx);
26typedef sk_sp<SkData> (*SkSerialImageProc)(SkImage*, void* ctx);
27typedef sk_sp<SkData> (*SkSerialTypefaceProc)(SkTypeface*, void* ctx);
Mike Reed60691a52017-12-05 15:11:24 -050028
29/**
Mike Reedd07e4a22018-03-08 16:29:12 -050030 * 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 Reed60691a52017-12-05 15:11:24 -050032 */
Mike Reed60691a52017-12-05 15:11:24 -050033typedef sk_sp<SkPicture> (*SkDeserialPictureProc)(const void* data, size_t length, void* ctx);
Mike Reedd07e4a22018-03-08 16:29:12 -050034
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 Reed60691a52017-12-05 15:11:24 -050042typedef sk_sp<SkImage> (*SkDeserialImageProc)(const void* data, size_t length, void* ctx);
Mike Reedd07e4a22018-03-08 16:29:12 -050043
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 Reed60691a52017-12-05 15:11:24 -050048typedef sk_sp<SkTypeface> (*SkDeserialTypefaceProc)(const void* data, size_t length, void* ctx);
49
Mike Reed47fdf6c2017-12-20 14:12:07 -050050struct SK_API SkSerialProcs {
Mike Reed60691a52017-12-05 15:11:24 -050051 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 Reed47fdf6c2017-12-20 14:12:07 -050061struct SK_API SkDeserialProcs {
Mike Reed60691a52017-12-05 15:11:24 -050062 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