Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Public Attributes | Friends | List of all members
SkMetaData Class Reference

#include <SkMetaData.h>

Classes

class  Iter
 
struct  Rec
 

Public Types

enum  Type {
  kS32_Type , kScalar_Type , kPtr_Type , kBool_Type ,
  kTypeCount
}
 

Public Member Functions

 SkMetaData ()
 
 ~SkMetaData ()
 
void reset ()
 
bool findS32 (const char name[], int32_t *value=nullptr) const
 
bool findScalar (const char name[], SkScalar *value=nullptr) const
 
const SkScalarfindScalars (const char name[], int *count, SkScalar values[]=nullptr) const
 
bool findPtr (const char name[], void **value=nullptr) const
 
bool findBool (const char name[], bool *value=nullptr) const
 
bool hasS32 (const char name[], int32_t value) const
 
bool hasScalar (const char name[], SkScalar value) const
 
bool hasPtr (const char name[], void *value) const
 
bool hasBool (const char name[], bool value) const
 
void setS32 (const char name[], int32_t value)
 
void setScalar (const char name[], SkScalar value)
 
SkScalarsetScalars (const char name[], int count, const SkScalar values[]=nullptr)
 
void setPtr (const char name[], void *value)
 
void setBool (const char name[], bool value)
 
bool removeS32 (const char name[])
 
bool removeScalar (const char name[])
 
bool removePtr (const char name[])
 
bool removeBool (const char name[])
 
const Recfind (const char name[], Type) const
 
void * set (const char name[], const void *data, size_t len, Type, int count)
 
bool remove (const char name[], Type)
 
 SkMetaData (const SkMetaData &)=delete
 
SkMetaDataoperator= (const SkMetaData &)=delete
 

Public Attributes

RecfRec = nullptr
 

Friends

class Iter
 

Detailed Description

A map from c-string keys to arrays of POD (int32_t, kScalar, void*, or bool) values.

Definition at line 15 of file SkMetaData.h.

Member Enumeration Documentation

◆ Type

Enumerator
kS32_Type 
kScalar_Type 
kPtr_Type 
kBool_Type 
kTypeCount 

Definition at line 56 of file SkMetaData.h.

56 {
61
63 };
@ kScalar_Type
Definition: SkMetaData.h:58

Constructor & Destructor Documentation

◆ SkMetaData() [1/2]

SkMetaData::SkMetaData ( )
inline

Definition at line 17 of file SkMetaData.h.

17{}

◆ ~SkMetaData()

SkMetaData::~SkMetaData ( )
inline

Definition at line 18 of file SkMetaData.h.

18{ if (fRec) { this->reset(); } }
void reset()
Definition: SkMetaData.cpp:13
Rec * fRec
Definition: SkMetaData.h:105

◆ SkMetaData() [2/2]

SkMetaData::SkMetaData ( const SkMetaData )
delete

Member Function Documentation

◆ find()

const SkMetaData::Rec * SkMetaData::find ( const char  name[],
Type  type 
) const

Definition at line 174 of file SkMetaData.cpp.

174 {
175 return this->findWithPrev(name, type).rec;
176}
GLenum type
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ findBool()

bool SkMetaData::findBool ( const char  name[],
bool *  value = nullptr 
) const

Definition at line 149 of file SkMetaData.cpp.

150{
151 const Rec* rec = this->find(name, kBool_Type);
152 if (rec)
153 {
154 SkASSERT(rec->fDataCount == 1);
155 if (value)
156 *value = *(const bool*)rec->data();
157 return true;
158 }
159 return false;
160}
#define SkASSERT(cond)
Definition: SkAssert.h:116
const Rec * find(const char name[], Type) const
Definition: SkMetaData.cpp:174
uint8_t value

◆ findPtr()

bool SkMetaData::findPtr ( const char  name[],
void **  value = nullptr 
) const

Definition at line 136 of file SkMetaData.cpp.

136 {
137 const Rec* rec = this->find(name, kPtr_Type);
138 if (rec) {
139 SkASSERT(rec->fDataCount == 1);
140 void* const* found = (void* const*)rec->data();
141 if (ptr) {
142 *ptr = *found;
143 }
144 return true;
145 }
146 return false;
147}

◆ findS32()

bool SkMetaData::findS32 ( const char  name[],
int32_t *  value = nullptr 
) const

Definition at line 96 of file SkMetaData.cpp.

97{
98 const Rec* rec = this->find(name, kS32_Type);
99 if (rec)
100 {
101 SkASSERT(rec->fDataCount == 1);
102 if (value)
103 *value = *(const int32_t*)rec->data();
104 return true;
105 }
106 return false;
107}

◆ findScalar()

bool SkMetaData::findScalar ( const char  name[],
SkScalar value = nullptr 
) const

Definition at line 109 of file SkMetaData.cpp.

110{
111 const Rec* rec = this->find(name, kScalar_Type);
112 if (rec)
113 {
114 SkASSERT(rec->fDataCount == 1);
115 if (value)
116 *value = *(const SkScalar*)rec->data();
117 return true;
118 }
119 return false;
120}
float SkScalar
Definition: extension.cpp:12

◆ findScalars()

const SkScalar * SkMetaData::findScalars ( const char  name[],
int count,
SkScalar  values[] = nullptr 
) const

Definition at line 122 of file SkMetaData.cpp.

123{
124 const Rec* rec = this->find(name, kScalar_Type);
125 if (rec)
126 {
127 if (count)
128 *count = rec->fDataCount;
129 if (values)
130 memcpy(values, rec->data(), rec->fDataCount * rec->fDataLen);
131 return (const SkScalar*)rec->data();
132 }
133 return nullptr;
134}
int count
Definition: FontMgrTest.cpp:50

◆ hasBool()

bool SkMetaData::hasBool ( const char  name[],
bool  value 
) const
inline

Definition at line 40 of file SkMetaData.h.

40 {
41 bool v;
42 return this->findBool(name, &v) && v == value;
43 }
bool findBool(const char name[], bool *value=nullptr) const
Definition: SkMetaData.cpp:149

◆ hasPtr()

bool SkMetaData::hasPtr ( const char  name[],
void *  value 
) const
inline

Definition at line 36 of file SkMetaData.h.

36 {
37 void* v;
38 return this->findPtr(name, &v) && v == value;
39 }
bool findPtr(const char name[], void **value=nullptr) const
Definition: SkMetaData.cpp:136

◆ hasS32()

bool SkMetaData::hasS32 ( const char  name[],
int32_t  value 
) const
inline

Definition at line 28 of file SkMetaData.h.

28 {
29 int32_t v;
30 return this->findS32(name, &v) && v == value;
31 }
bool findS32(const char name[], int32_t *value=nullptr) const
Definition: SkMetaData.cpp:96

◆ hasScalar()

bool SkMetaData::hasScalar ( const char  name[],
SkScalar  value 
) const
inline

Definition at line 32 of file SkMetaData.h.

32 {
33 SkScalar v;
34 return this->findScalar(name, &v) && v == value;
35 }
bool findScalar(const char name[], SkScalar *value=nullptr) const
Definition: SkMetaData.cpp:109

◆ operator=()

SkMetaData & SkMetaData::operator= ( const SkMetaData )
delete

◆ remove()

bool SkMetaData::remove ( const char  name[],
Type  type 
)

Definition at line 188 of file SkMetaData.cpp.

188 {
189 FindResult result = this->findWithPrev(name, type);
190 if (!result.rec) {
191 return false;
192 }
193 this->remove(result);
194 return true;
195}
bool remove(const char name[], Type)
Definition: SkMetaData.cpp:188
GAsyncResult * result

◆ removeBool()

bool SkMetaData::removeBool ( const char  name[])

Definition at line 212 of file SkMetaData.cpp.

213{
214 return this->remove(name, kBool_Type);
215}

◆ removePtr()

bool SkMetaData::removePtr ( const char  name[])

Definition at line 207 of file SkMetaData.cpp.

208{
209 return this->remove(name, kPtr_Type);
210}

◆ removeS32()

bool SkMetaData::removeS32 ( const char  name[])

Definition at line 197 of file SkMetaData.cpp.

198{
199 return this->remove(name, kS32_Type);
200}

◆ removeScalar()

bool SkMetaData::removeScalar ( const char  name[])

Definition at line 202 of file SkMetaData.cpp.

203{
204 return this->remove(name, kScalar_Type);
205}

◆ reset()

void SkMetaData::reset ( )

Definition at line 13 of file SkMetaData.cpp.

14{
15 Rec* rec = fRec;
16 while (rec) {
17 Rec* next = rec->fNext;
18 Rec::Free(rec);
19 rec = next;
20 }
21 fRec = nullptr;
22}
static float next(float f)
static void Free(Rec *)
Definition: SkMetaData.cpp:250

◆ set()

void * SkMetaData::set ( const char  name[],
const void *  data,
size_t  len,
Type  type,
int  count 
)

Definition at line 51 of file SkMetaData.cpp.

52{
54 SkASSERT(dataSize);
55 SkASSERT(count > 0);
56
57 FindResult result = this->findWithPrev(name, type);
58
59 Rec* rec;
60 bool reuseRec = result.rec &&
61 result.rec->fDataLen == dataSize &&
62 result.rec->fDataCount == count;
63 if (reuseRec) {
64 rec = result.rec;
65 } else {
66 size_t len = strlen(name);
67 rec = Rec::Alloc(sizeof(Rec) + dataSize * count + len + 1);
68 rec->fType = SkToU8(type);
69 rec->fDataLen = SkToU8(dataSize);
70 rec->fDataCount = SkToU16(count);
71
72 memcpy(rec->name(), name, len + 1);
73 }
74 if (data) {
75 memcpy(rec->data(), data, dataSize * count);
76 }
77
78 if (reuseRec) {
79 // Do nothing, reused
80 } else if (result.rec) {
81 // Had one, but had to create a new one. Invalidates iterators.
82 // Delayed removal since name or data may have been in the result.rec.
83 this->remove(result);
84 if (result.prev) {
85 rec->fNext = result.prev->fNext;
86 result.prev->fNext = rec;
87 }
88 } else {
89 // Adding a new one, stick it at head.
90 rec->fNext = fRec;
91 fRec = rec;
92 }
93 return rec->data();
94}
constexpr uint16_t SkToU16(S x)
Definition: SkTo.h:24
constexpr uint8_t SkToU8(S x)
Definition: SkTo.h:22
const void * data() const
Definition: SkMetaData.h:97
static Rec * Alloc(size_t)
Definition: SkMetaData.cpp:246
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ setBool()

void SkMetaData::setBool ( const char  name[],
bool  value 
)

Definition at line 46 of file SkMetaData.cpp.

47{
48 (void)this->set(name, &value, sizeof(bool), kBool_Type, 1);
49}
void * set(const char name[], const void *data, size_t len, Type, int count)
Definition: SkMetaData.cpp:51

◆ setPtr()

void SkMetaData::setPtr ( const char  name[],
void *  value 
)

Definition at line 42 of file SkMetaData.cpp.

42 {
43 (void)this->set(name, &ptr, sizeof(void*), kPtr_Type, 1);
44}

◆ setS32()

void SkMetaData::setS32 ( const char  name[],
int32_t  value 
)

Definition at line 24 of file SkMetaData.cpp.

25{
26 (void)this->set(name, &value, sizeof(int32_t), kS32_Type, 1);
27}

◆ setScalar()

void SkMetaData::setScalar ( const char  name[],
SkScalar  value 
)

Definition at line 29 of file SkMetaData.cpp.

30{
31 (void)this->set(name, &value, sizeof(SkScalar), kScalar_Type, 1);
32}

◆ setScalars()

SkScalar * SkMetaData::setScalars ( const char  name[],
int  count,
const SkScalar  values[] = nullptr 
)

Definition at line 34 of file SkMetaData.cpp.

35{
36 SkASSERT(count > 0);
37 if (count > 0)
38 return (SkScalar*)this->set(name, values, sizeof(SkScalar), kScalar_Type, count);
39 return nullptr;
40}

Friends And Related Function Documentation

◆ Iter

friend class Iter
friend

Definition at line 67 of file SkMetaData.h.

Member Data Documentation

◆ fRec

Rec* SkMetaData::fRec = nullptr

Definition at line 105 of file SkMetaData.h.


The documentation for this class was generated from the following files: