Debian Codegraph @

include/core/SkSerialProcs.h

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