Flutter Engine
The Flutter Engine
SkFlattenable.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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 */
8
17
18#include <algorithm>
19#include <cstdint>
20#include <cstring>
21#include <iterator>
22#include <utility>
23
24SkNamedFactorySet::SkNamedFactorySet() : fNextAddedFactory(0) {}
25
27 uint32_t index = fFactorySet.find(factory);
28 if (index > 0) {
29 return index;
30 }
31 const char* name = SkFlattenable::FactoryToName(factory);
32 if (nullptr == name) {
33 return 0;
34 }
35 *fNames.append() = name;
36 return fFactorySet.add(factory);
37}
38
40 if (fNextAddedFactory < fNames.size()) {
41 return fNames[fNextAddedFactory++];
42 }
43 return nullptr;
44}
45
46///////////////////////////////////////////////////////////////////////////////
47
49 // call this now, while our decPtr() is sill in scope
50 this->reset();
51}
52
53void SkRefCntSet::incPtr(void* ptr) {
54 ((SkRefCnt*)ptr)->ref();
55}
56
57void SkRefCntSet::decPtr(void* ptr) {
58 ((SkRefCnt*)ptr)->unref();
59}
60
61///////////////////////////////////////////////////////////////////////////////
62
63namespace {
64
65struct Entry {
66 const char* fName;
68};
69
70struct EntryComparator {
71 bool operator()(const Entry& a, const Entry& b) const {
72 return strcmp(a.fName, b.fName) < 0;
73 }
74 bool operator()(const Entry& a, const char* b) const {
75 return strcmp(a.fName, b) < 0;
76 }
77 bool operator()(const char* a, const Entry& b) const {
78 return strcmp(a, b.fName) < 0;
79 }
80};
81
82int gCount = 0;
83Entry gEntries[128];
84
85} // namespace
86
87void SkFlattenable::Finalize() {
88 std::sort(gEntries, gEntries + gCount, EntryComparator());
89}
90
91void SkFlattenable::Register(const char name[], Factory factory) {
93 SkASSERT(factory);
94 SkASSERT(gCount < (int)std::size(gEntries));
95
96 gEntries[gCount].fName = name;
97 gEntries[gCount].fFactory = factory;
98 gCount += 1;
99}
100
102 RegisterFlattenablesIfNeeded();
103
104 SkASSERT(std::is_sorted(gEntries, gEntries + gCount, EntryComparator()));
105 auto pair = std::equal_range(gEntries, gEntries + gCount, name, EntryComparator());
106 if (pair.first == pair.second) {
107 return nullptr;
108 }
109 return pair.first->fFactory;
110}
111
113 RegisterFlattenablesIfNeeded();
114
115 const Entry* entries = gEntries;
116 for (int i = gCount - 1; i >= 0; --i) {
117 if (entries[i].fFactory == fact) {
118 return entries[i].fName;
119 }
120 }
121 return nullptr;
122}
123
124///////////////////////////////////////////////////////////////////////////////////////////////////
125
128 if (procs) {
129 p = *procs;
130 }
131 SkBinaryWriteBuffer writer(p);
132
133 writer.writeFlattenable(this);
134 size_t size = writer.bytesWritten();
136 writer.writeToMemory(data->writable_data());
137 return data;
138}
139
140size_t SkFlattenable::serialize(void* memory, size_t memory_size,
141 const SkSerialProcs* procs) const {
143 if (procs) {
144 p = *procs;
145 }
146 SkBinaryWriteBuffer writer(memory, memory_size, p);
147 writer.writeFlattenable(this);
148 return writer.usingInitialStorage() ? writer.bytesWritten() : 0u;
149}
150
152 size_t size, const SkDeserialProcs* procs) {
154 if (procs) {
155 buffer.setDeserialProcs(*procs);
156 }
157 return sk_sp<SkFlattenable>(buffer.readFlattenable(type));
158}
const char * fName
#define SkASSERT(cond)
Definition: SkAssert.h:116
static std::vector< SkPDFIndirectReference > sort(const THashSet< SkPDFIndirectReference > &src)
GLenum type
void writeFlattenable(const SkFlattenable *flattenable) override
size_t bytesWritten() const
bool usingInitialStorage() const
void writeToMemory(void *dst) const
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
sk_sp< SkFlattenable >(* Factory)(SkReadBuffer &)
Definition: SkFlattenable.h:41
static const char * FactoryToName(Factory)
sk_sp< SkData > serialize(const SkSerialProcs *=nullptr) const
static sk_sp< SkFlattenable > Deserialize(Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)
static void Register(const char name[], Factory)
static Factory NameToFactory(const char name[])
const char * getNextAddedFactoryName()
uint32_t find(SkFlattenable::Factory)
void reset()
void incPtr(void *) override
void decPtr(void *) override
~SkRefCntSet() override
int size() const
Definition: SkTDArray.h:138
T * append()
Definition: SkTDArray.h:191
uint32_t find(T ptr)
uint32_t add(T ptr)
static bool b
struct MyStruct a[10]
SKSHAPER_API sk_sp< Factory > Factory()
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63