Debian Codegraph @

include/core/SkSerialProcs.h

raw ◀ ▶
1 Debian patch touch this file
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/SkFourByteTag.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/private/base/SkAPI.h"
14
15 #include <cstddef>
16 #include <optional>
17
18 class SkData;
19 class SkImage;
20 class SkPicture;
21 class SkTypeface;
22 class SkReadBuffer;
23 class SkStream;
24 enum SkAlphaType : int;
25 namespace sktext::gpu {
26 class Slug;
27 }
28
29 using SkSerialReturnType = sk_sp<const SkData>;
30 /**
31 * A serial-proc is asked to serialize the specified object (e.g. picture or image).
32 * If a data object is returned, it will be used (even if it is zero-length).
33 * If null is returned, then Skia will take its default action.
34 *
35 * The default action for pictures is to use Skia's internal format.
36 * The default action for images is to encode either in its native format or PNG.
37 * The default action for typefaces is to use Skia's internal format.
38 */
39 using SkSerialPictureProc = SkSerialReturnType (*)(SkPicture*, void* ctx);
40 using SkSerialImageProc = SkSerialReturnType (*)(SkImage*, void* ctx);
41 using SkSerialTypefaceProc = SkSerialReturnType (*)(SkTypeface*, void* ctx);
42
43 /**
44 * Called with the encoded form of a picture (previously written with a custom
45 * SkSerialPictureProc proc). Return a picture object, or nullptr indicating failure.
46 */
47 using SkDeserialPictureProc = sk_sp<SkPicture> (*)(const void* data, size_t length, void* ctx);
48
49 /**
50 * Called with the encoded form of an image. The proc can return an image object, or if it
51 * returns nullptr, then Skia will take its default action to try to create an image from the data.
52 *
53 * This will also be used to decode the internal mipmap layers that are saved on some images.
54 *
55 * An explicit SkAlphaType may have been encoded in the bytestream; if not, then the passed in
56 * optional will be not present.
57 *
58 * Clients should set at least SkDeserialImageProc; SkDeserialImageFromDataProc may be called
59 * if the internal implementation has a SkData copy already. Implementations of SkDeserialImageProc
60 * must make a copy of any data they needed after the proc finishes, since the data will go away
61 * after serialization ends.
62 */
63 #if !defined(SK_LEGACY_DESERIAL_IMAGE_PROC)
64 using SkDeserialImageProc = sk_sp<SkImage> (*)(const void* data, size_t length, void* ctx);
65 #else
66 using SkDeserialImageProc = sk_sp<SkImage> (*)(const void* data,
67 size_t length,
68 std::optional<SkAlphaType>,
69 void* ctx);
70 #endif
71 using SkDeserialImageFromDataProc = sk_sp<SkImage> (*)(sk_sp<SkData>,
72 std::optional<SkAlphaType>,
73 void* ctx);
74
75 /**
76 * Slugs are currently only deserializable with a GPU backend. Clients will not be able to
77 * provide a custom mechanism here, but can enable Slug deserialization by calling
78 * sktext::gpu::AddDeserialProcs to add Skia's implementation.
79 */
80 using SkSlugProc = sk_sp<sktext::gpu::Slug> (*)(SkReadBuffer&, void* ctx);
81
82 /**
83 * Called with the encoded form of a typeface (previously written with a custom
84 * SkSerialTypefaceProc proc). Return a typeface object, or nullptr indicating failure.
85 * TODO: Users must not attempt to fork or duplicate the passed stream and hold on to the result.
86 */
87 using SkDeserialTypefaceStreamProc = sk_sp<SkTypeface> (*)(SkStream&, void* ctx);
88 using SkDeserialTypefaceProc = sk_sp<SkTypeface> (*)(const void* data, size_t length, void* ctx);
89
•90 using SkDeserialAllowTagsProc = bool(*)(SkFourByteTag, void* ctx);
91
92 struct SK_API SkSerialProcs {
93 SkSerialPictureProc fPictureProc = nullptr;
94 void* fPictureCtx = nullptr;
95
96 SkSerialImageProc fImageProc = nullptr;
97 void* fImageCtx = nullptr;
98
99 SkSerialTypefaceProc fTypefaceProc = nullptr;
100 void* fTypefaceCtx = nullptr;
101 };
102
103 struct SK_API SkDeserialProcs {
104 SkDeserialPictureProc fPictureProc = nullptr;
105 void* fPictureCtx = nullptr;
106
107 SkDeserialImageProc fImageProc = nullptr;
108 SkDeserialImageFromDataProc fImageDataProc = nullptr;
109 void* fImageCtx = nullptr;
110
111 SkSlugProc fSlugProc = nullptr;
112 void* fSlugCtx = nullptr;
113
114 SkDeserialTypefaceStreamProc fTypefaceStreamProc = nullptr;
115 void* fTypefaceCtx = nullptr;
116
117 // This looks like a flag, but it could be considered a proc as well (one that takes no
118 // parameters and returns a bool). Given that there are only two valid implementations of that
119 // proc, we just insert the bool directly.
120 bool fAllowSkSL = true;
•121
122 // Can be used to restrict the tags that will be deserialized from SkPictures.
123 SkDeserialAllowTagsProc fAllowTagsProc = nullptr;
124 void* fAllowTagsCtx = nullptr;
125 };
126
127 #endif