2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
#ifndef SkMetaData_DEFINED
|
|
|
|
#define SkMetaData_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkScalar.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2019-07-24 13:44:43 +00:00
|
|
|
/** A map from c-string keys to arrays of POD (int32_t, kScalar, void*, or bool)
|
|
|
|
values.
|
|
|
|
*/
|
|
|
|
class SkMetaData {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2019-07-24 13:44:43 +00:00
|
|
|
/** Used to manage the life-cycle of a ptr in the metadata. This is option
|
|
|
|
in setPtr, and is invoked when the metadata is destroyed.
|
|
|
|
*/
|
2011-03-30 18:23:21 +00:00
|
|
|
typedef void* (*PtrProc)(void* ptr, bool doRef);
|
|
|
|
|
2019-07-24 13:44:43 +00:00
|
|
|
SkMetaData() {}
|
|
|
|
~SkMetaData() { if (fRec) { this->reset(); } }
|
2011-03-30 18:23:21 +00:00
|
|
|
void reset();
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-08-28 14:34:05 +00:00
|
|
|
bool findS32(const char name[], int32_t* value = nullptr) const;
|
|
|
|
bool findScalar(const char name[], SkScalar* value = nullptr) const;
|
2011-03-30 18:23:21 +00:00
|
|
|
const SkScalar* findScalars(const char name[], int* count,
|
2017-08-28 14:34:05 +00:00
|
|
|
SkScalar values[] = nullptr) const;
|
|
|
|
bool findPtr(const char name[], void** value = nullptr, PtrProc* = nullptr) const;
|
|
|
|
bool findBool(const char name[], bool* value = nullptr) const;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-03-30 18:23:21 +00:00
|
|
|
bool hasS32(const char name[], int32_t value) const {
|
2008-12-17 15:59:43 +00:00
|
|
|
int32_t v;
|
|
|
|
return this->findS32(name, &v) && v == value;
|
|
|
|
}
|
2011-03-30 18:23:21 +00:00
|
|
|
bool hasScalar(const char name[], SkScalar value) const {
|
|
|
|
SkScalar v;
|
2008-12-17 15:59:43 +00:00
|
|
|
return this->findScalar(name, &v) && v == value;
|
|
|
|
}
|
2011-03-30 18:23:21 +00:00
|
|
|
bool hasPtr(const char name[], void* value) const {
|
|
|
|
void* v;
|
2008-12-17 15:59:43 +00:00
|
|
|
return this->findPtr(name, &v) && v == value;
|
|
|
|
}
|
2011-03-30 18:23:21 +00:00
|
|
|
bool hasBool(const char name[], bool value) const {
|
2008-12-17 15:59:43 +00:00
|
|
|
bool v;
|
|
|
|
return this->findBool(name, &v) && v == value;
|
|
|
|
}
|
|
|
|
|
2011-03-30 18:23:21 +00:00
|
|
|
void setS32(const char name[], int32_t value);
|
|
|
|
void setScalar(const char name[], SkScalar value);
|
2017-08-28 14:34:05 +00:00
|
|
|
SkScalar* setScalars(const char name[], int count, const SkScalar values[] = nullptr);
|
|
|
|
void setPtr(const char name[], void* value, PtrProc proc = nullptr);
|
2011-03-30 18:23:21 +00:00
|
|
|
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[]);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
enum Type {
|
|
|
|
kS32_Type,
|
|
|
|
kScalar_Type,
|
|
|
|
kPtr_Type,
|
|
|
|
kBool_Type,
|
|
|
|
|
|
|
|
kTypeCount
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Rec;
|
|
|
|
class Iter;
|
|
|
|
friend class Iter;
|
|
|
|
|
|
|
|
class Iter {
|
|
|
|
public:
|
2017-08-28 14:34:05 +00:00
|
|
|
Iter() : fRec(nullptr) {}
|
2008-12-17 15:59:43 +00:00
|
|
|
Iter(const SkMetaData&);
|
|
|
|
|
|
|
|
/** Reset the iterator, so that calling next() will return the first
|
|
|
|
data element. This is done implicitly in the constructor.
|
|
|
|
*/
|
2011-03-30 18:23:21 +00:00
|
|
|
void reset(const SkMetaData&);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Each time next is called, it returns the name of the next data element,
|
|
|
|
or null when there are no more elements. If non-null is returned, then the
|
|
|
|
element's type is returned (if not null), and the number of data values
|
|
|
|
is returned in count (if not null).
|
|
|
|
*/
|
|
|
|
const char* next(Type*, int* count);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Rec* fRec;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct Rec {
|
|
|
|
Rec* fNext;
|
|
|
|
uint16_t fDataCount; // number of elements
|
|
|
|
uint8_t fDataLen; // sizeof a single element
|
|
|
|
uint8_t fType;
|
|
|
|
|
|
|
|
const void* data() const { return (this + 1); }
|
|
|
|
void* data() { return (this + 1); }
|
|
|
|
const char* name() const { return (const char*)this->data() + fDataLen * fDataCount; }
|
|
|
|
char* name() { return (char*)this->data() + fDataLen * fDataCount; }
|
|
|
|
|
|
|
|
static Rec* Alloc(size_t);
|
|
|
|
static void Free(Rec*);
|
|
|
|
};
|
2019-07-24 13:44:43 +00:00
|
|
|
Rec* fRec = nullptr;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
const Rec* find(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);
|
2019-07-24 13:44:43 +00:00
|
|
|
|
|
|
|
SkMetaData(const SkMetaData&) = delete;
|
|
|
|
SkMetaData& operator=(const SkMetaData&) = delete;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|