Flutter Engine
The Flutter Engine
SkFlattenable.h
Go to the documentation of this file.
1/*
2 * Copyright 2006 The Android Open Source Project
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 SkFlattenable_DEFINED
9#define SkFlattenable_DEFINED
10
13
14#include <cstddef>
15
16class SkData;
17class SkReadBuffer;
18class SkWriteBuffer;
19struct SkDeserialProcs;
20struct SkSerialProcs;
21
22/** \class SkFlattenable
23
24 SkFlattenable is the base class for objects that need to be flattened
25 into a data stream for either transport or as part of the key to the
26 font cache.
27 */
29public:
30 enum Type {
34 kSkDrawLooper_Type, // no longer supported by Skia
39 };
40
42
44
45 /** Implement this to return a factory function pointer that can be called
46 to recreate your class given a buffer (previously written to by your
47 override of flatten().
48 */
49 virtual Factory getFactory() const = 0;
50
51 /**
52 * Returns the name of the object's class.
53 */
54 virtual const char* getTypeName() const = 0;
55
56 static Factory NameToFactory(const char name[]);
57 static const char* FactoryToName(Factory);
58
59 static void Register(const char name[], Factory);
60
61 /**
62 * Override this if your subclass needs to record data that it will need to recreate itself
63 * from its CreateProc (returned by getFactory()).
64 *
65 * DEPRECATED public : will move to protected ... use serialize() instead
66 */
67 virtual void flatten(SkWriteBuffer&) const {}
68
69 virtual Type getFlattenableType() const = 0;
70
71 //
72 // public ways to serialize / deserialize
73 //
74 sk_sp<SkData> serialize(const SkSerialProcs* = nullptr) const;
75 size_t serialize(void* memory, size_t memory_size,
76 const SkSerialProcs* = nullptr) const;
77 static sk_sp<SkFlattenable> Deserialize(Type, const void* data, size_t length,
78 const SkDeserialProcs* procs = nullptr);
79
80protected:
82 public:
83 static void InitEffects();
84 static void InitImageFilters();
85 };
86
87private:
88 static void RegisterFlattenablesIfNeeded();
89 static void Finalize();
90
91 friend class SkGraphics;
92
93 using INHERITED = SkRefCnt;
94};
95
96#if defined(SK_DISABLE_EFFECT_DESERIALIZATION)
97 #define SK_REGISTER_FLATTENABLE(type) do{}while(false)
98
99 #define SK_FLATTENABLE_HOOKS(type) \
100 static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&); \
101 friend class SkFlattenable::PrivateInitializer; \
102 Factory getFactory() const override { return nullptr; } \
103 const char* getTypeName() const override { return #type; }
104#else
105 #define SK_REGISTER_FLATTENABLE(type) \
106 SkFlattenable::Register(#type, type::CreateProc)
107
108 #define SK_FLATTENABLE_HOOKS(type) \
109 static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&); \
110 friend class SkFlattenable::PrivateInitializer; \
111 Factory getFactory() const override { return type::CreateProc; } \
112 const char* getTypeName() const override { return #type; }
113#endif
114
115#endif
#define SK_API
Definition: SkAPI.h:35
Definition: SkData.h:25
virtual void flatten(SkWriteBuffer &) const
Definition: SkFlattenable.h:67
virtual Type getFlattenableType() const =0
virtual const char * getTypeName() const =0
virtual Factory getFactory() const =0
size_t length
SKSHAPER_API sk_sp< Factory > Factory()
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63