Skia
2D Graphics Library
SkSerialProcs.h
Go to the documentation of 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 enum SkAlphaType : int;
23 namespace sktext::gpu {
24  class Slug;
25 }
26 
37 using SkSerialPictureProc = sk_sp<SkData> (*)(SkPicture*, void* ctx);
38 using SkSerialImageProc = sk_sp<SkData> (*)(SkImage*, void* ctx);
40 
45 using SkDeserialPictureProc = sk_sp<SkPicture> (*)(const void* data, size_t length, void* ctx);
46 
61 #if !defined(SK_LEGACY_DESERIAL_IMAGE_PROC)
62 using SkDeserialImageProc = sk_sp<SkImage> (*)(const void* data, size_t length, void* ctx);
63 #else
64 using SkDeserialImageProc = sk_sp<SkImage> (*)(const void* data,
65  size_t length,
66  std::optional<SkAlphaType>,
67  void* ctx);
68 #endif
70  std::optional<SkAlphaType>,
71  void* ctx);
72 
78 using SkSlugProc = sk_sp<sktext::gpu::Slug> (*)(SkReadBuffer&, void* ctx);
79 
84 using SkDeserialTypefaceProc = sk_sp<SkTypeface> (*)(const void* data, size_t length, void* ctx);
85 
86 struct SK_API SkSerialProcs {
87  SkSerialPictureProc fPictureProc = nullptr;
88  void* fPictureCtx = nullptr;
89 
90  SkSerialImageProc fImageProc = nullptr;
91  void* fImageCtx = nullptr;
92 
93  SkSerialTypefaceProc fTypefaceProc = nullptr;
94  void* fTypefaceCtx = nullptr;
95 };
96 
97 struct SK_API SkDeserialProcs {
98  SkDeserialPictureProc fPictureProc = nullptr;
99  void* fPictureCtx = nullptr;
100 
101  SkDeserialImageProc fImageProc = nullptr;
102  SkDeserialImageFromDataProc fImageDataProc = nullptr;
103  void* fImageCtx = nullptr;
104 
105  SkSlugProc fSlugProc = nullptr;
106  void* fSlugCtx = nullptr;
107 
108  SkDeserialTypefaceProc fTypefaceProc = nullptr;
109  void* fTypefaceCtx = nullptr;
110 
111  // This looks like a flag, but it could be considered a proc as well (one that takes no
112  // parameters and returns a bool). Given that there are only two valid implementations of that
113  // proc, we just insert the bool directly.
114  bool fAllowSkSL = true;
115 };
116 
117 #endif
SkAlphaType
Describes how to interpret the alpha component of a pixel.
Definition: SkAlphaType.h:26
sk_sp< SkImage >(*)(sk_sp< SkData >, std::optional< SkAlphaType >, void *ctx) SkDeserialImageFromDataProc
Definition: SkSerialProcs.h:71
sk_sp< sktext::gpu::Slug >(*)(SkReadBuffer &, void *ctx) SkSlugProc
Slugs are currently only deserializable with a GPU backend.
Definition: SkSerialProcs.h:78
SkData holds an immutable data buffer.
Definition: SkData.h:25
SkImage describes a two dimensional array of pixels to draw.
Definition: SkImage.h:270
SkPicture records drawing commands made to SkCanvas.
Definition: SkPicture.h:44
The SkTypeface class specifies the typeface and intrinsic style of a font.
Definition: SkTypeface.h:52
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:220
Definition: SkCanvas.h:74
Definition: SkSerialProcs.h:97
Definition: SkSerialProcs.h:86