SkMetaData.cpp revision 80bacfeb4bda06541e8695bd502229727bccfea
180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkMetaData.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkRefCnt.h" 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustruct PtrPair { 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void* fPtr; 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkMetaData::PtrProc fProc; 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid* SkMetaData::RefCntProc(void* ptr, bool doRef) { 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(ptr); 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkRefCnt* refcnt = reinterpret_cast<SkRefCnt*>(ptr); 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (doRef) { 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru refcnt->ref(); 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } else { 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru refcnt->unref(); 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return ptr; 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkMetaData::SkMetaData() : fRec(NULL) 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkMetaData::SkMetaData(const SkMetaData& src) : fRec(NULL) 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *this = src; 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkMetaData::~SkMetaData() 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->reset(); 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkMetaData::reset() 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Rec* rec = fRec; 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (rec) { 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (kPtr_Type == rec->fType) { 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru PtrPair* pair = (PtrPair*)rec->data(); 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (pair->fProc && pair->fPtr) { 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru pair->fPtr = pair->fProc(pair->fPtr, false); 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Rec* next = rec->fNext; 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Rec::Free(rec); 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru rec = next; 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRec = NULL; 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkMetaData& SkMetaData::operator=(const SkMetaData& src) 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->reset(); 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const Rec* rec = src.fRec; 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (rec) 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->set(rec->name(), rec->data(), rec->fDataLen, (Type)rec->fType, rec->fDataCount); 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru rec = rec->fNext; 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return *this; 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkMetaData::setS32(const char name[], int32_t value) 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)this->set(name, &value, sizeof(int32_t), kS32_Type, 1); 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkMetaData::setScalar(const char name[], SkScalar value) 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)this->set(name, &value, sizeof(SkScalar), kScalar_Type, 1); 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkScalar* SkMetaData::setScalars(const char name[], int count, const SkScalar values[]) 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(count > 0); 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (count > 0) 8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return (SkScalar*)this->set(name, values, sizeof(SkScalar), kScalar_Type, count); 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkMetaData::setString(const char name[], const char value[]) 9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)this->set(name, value, sizeof(char), kString_Type, strlen(value) + 1); 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkMetaData::setPtr(const char name[], void* ptr, PtrProc proc) { 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru PtrPair pair = { ptr, proc }; 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)this->set(name, &pair, sizeof(PtrPair), kPtr_Type, 1); 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkMetaData::setBool(const char name[], bool value) 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)this->set(name, &value, sizeof(bool), kBool_Type, 1); 10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkMetaData::setData(const char name[], const void* data, size_t byteCount) { 10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)this->set(name, data, sizeof(char), kData_Type, byteCount); 10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid* SkMetaData::set(const char name[], const void* data, size_t dataSize, Type type, int count) 11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(name); 11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(dataSize); 11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(count > 0); 11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)this->remove(name, type); 11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru size_t len = strlen(name); 12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Rec* rec = Rec::Alloc(sizeof(Rec) + dataSize * count + len + 1); 12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SK_DEBUG 12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru rec->fType = SkToU8(type); 12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#else 12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru rec->fType = type; 12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru rec->fDataLen = SkToU8(dataSize); 12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru rec->fDataCount = SkToU16(count); 12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (data) 13080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru memcpy(rec->data(), data, dataSize * count); 13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru memcpy(rec->name(), name, len + 1); 13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (kPtr_Type == type) { 13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru PtrPair* pair = (PtrPair*)rec->data(); 13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (pair->fProc && pair->fPtr) { 13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru pair->fPtr = pair->fProc(pair->fPtr, true); 13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru rec->fNext = fRec; 14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRec = rec; 14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return rec->data(); 14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 14480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkMetaData::findS32(const char name[], int32_t* value) const 14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const Rec* rec = this->find(name, kS32_Type); 14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (rec) 14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(rec->fDataCount == 1); 15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (value) 15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *value = *(const int32_t*)rec->data(); 15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 15680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 15880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkMetaData::findScalar(const char name[], SkScalar* value) const 15980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 16080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const Rec* rec = this->find(name, kScalar_Type); 16180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (rec) 16280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(rec->fDataCount == 1); 16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (value) 16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *value = *(const SkScalar*)rec->data(); 16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 16880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 16980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 17180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkScalar* SkMetaData::findScalars(const char name[], int* count, SkScalar values[]) const 17280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 17380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const Rec* rec = this->find(name, kScalar_Type); 17480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (rec) 17580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (count) 17780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *count = rec->fDataCount; 17880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (values) 17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru memcpy(values, rec->data(), rec->fDataCount * rec->fDataLen); 18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return (const SkScalar*)rec->data(); 18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 18280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 18380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkMetaData::findPtr(const char name[], void** ptr, PtrProc* proc) const { 18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const Rec* rec = this->find(name, kPtr_Type); 18780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (rec) { 18880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(rec->fDataCount == 1); 18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const PtrPair* pair = (const PtrPair*)rec->data(); 19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (ptr) { 19180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *ptr = pair->fPtr; 19280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 19380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (proc) { 19480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *proc = pair->fProc; 19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 19780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 19880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 19980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 20080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* SkMetaData::findString(const char name[]) const 20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const Rec* rec = this->find(name, kString_Type); 20480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(rec == NULL || rec->fDataLen == sizeof(char)); 20580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return rec ? (const char*)rec->data() : NULL; 20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 20780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 20880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkMetaData::findBool(const char name[], bool* value) const 20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 21080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const Rec* rec = this->find(name, kBool_Type); 21180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (rec) 21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(rec->fDataCount == 1); 21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (value) 21580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *value = *(const bool*)rec->data(); 21680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 21780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 21880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 21980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 22080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 22180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst void* SkMetaData::findData(const char name[], size_t* length) const { 22280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const Rec* rec = this->find(name, kData_Type); 22380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (rec) { 22480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(rec->fDataLen == sizeof(char)); 22580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (length) { 22680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *length = rec->fDataCount; 22780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 22880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return rec->data(); 22980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 23080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 23180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 23280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 23380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMetaData::Rec* SkMetaData::find(const char name[], Type type) const 23480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 23580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const Rec* rec = fRec; 23680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (rec) 23780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 23880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (rec->fType == type && !strcmp(rec->name(), name)) 23980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return rec; 24080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru rec = rec->fNext; 24180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 24280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 24380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 24480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 24580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkMetaData::remove(const char name[], Type type) { 24680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Rec* rec = fRec; 24780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Rec* prev = NULL; 24880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru while (rec) { 24980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Rec* next = rec->fNext; 25080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (rec->fType == type && !strcmp(rec->name(), name)) { 25180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (prev) { 25280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru prev->fNext = next; 25380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } else { 25480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRec = next; 25580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 25680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 25780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (kPtr_Type == type) { 25880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru PtrPair* pair = (PtrPair*)rec->data(); 25980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (pair->fProc && pair->fPtr) { 26080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (void)pair->fProc(pair->fPtr, false); 26180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 26280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 26380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Rec::Free(rec); 26480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 26580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 26680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru prev = rec; 26780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru rec = next; 26880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 26980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 27080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 27180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 27280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkMetaData::removeS32(const char name[]) 27380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 27480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this->remove(name, kS32_Type); 27580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 27680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 27780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkMetaData::removeScalar(const char name[]) 27880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 27980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this->remove(name, kScalar_Type); 28080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 28180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 28280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkMetaData::removeString(const char name[]) 28380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 28480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this->remove(name, kString_Type); 28580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 28680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 28780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkMetaData::removePtr(const char name[]) 28880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 28980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this->remove(name, kPtr_Type); 29080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 29180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 29280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkMetaData::removeBool(const char name[]) 29380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru{ 29480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this->remove(name, kBool_Type); 29580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 29680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 29780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkMetaData::removeData(const char name[]) { 29880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this->remove(name, kData_Type); 29980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 30080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 30180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/////////////////////////////////////////////////////////////////////////////// 30280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 30380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkMetaData::Iter::Iter(const SkMetaData& metadata) { 30480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRec = metadata.fRec; 30580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 30680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 30780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkMetaData::Iter::reset(const SkMetaData& metadata) { 30880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRec = metadata.fRec; 30980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 31080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 31180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst char* SkMetaData::Iter::next(SkMetaData::Type* t, int* count) { 31280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const char* name = NULL; 31380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 31480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fRec) { 31580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (t) { 31680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *t = (SkMetaData::Type)fRec->fType; 31780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 31880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (count) { 31980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *count = fRec->fDataCount; 32080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 32180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru name = fRec->name(); 32280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 32380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRec = fRec->fNext; 32480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 32580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return name; 32680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 32780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 32880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/////////////////////////////////////////////////////////////////////////////// 32980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 33080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkMetaData::Rec* SkMetaData::Rec::Alloc(size_t size) { 33180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return (Rec*)sk_malloc_throw(size); 33280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 33380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 33480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkMetaData::Rec::Free(Rec* rec) { 33580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru sk_free(rec); 33680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 33780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 338