epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SkFlattenable.h" |
| 9 | #include "SkTypeface.h" |
| 10 | |
reed@google.com | f2eb5ab | 2011-05-10 22:56:42 +0000 | [diff] [blame] | 11 | #include "SkMatrix.h" |
| 12 | #include "SkRegion.h" |
| 13 | |
| 14 | void SkReadMatrix(SkReader32* reader, SkMatrix* matrix) { |
| 15 | size_t size = matrix->unflatten(reader->peek()); |
| 16 | SkASSERT(SkAlign4(size) == size); |
| 17 | (void)reader->skip(size); |
| 18 | } |
| 19 | |
| 20 | void SkWriteMatrix(SkWriter32* writer, const SkMatrix& matrix) { |
| 21 | size_t size = matrix.flatten(NULL); |
| 22 | SkASSERT(SkAlign4(size) == size); |
| 23 | matrix.flatten(writer->reserve(size)); |
| 24 | } |
| 25 | |
| 26 | void SkReadRegion(SkReader32* reader, SkRegion* rgn) { |
| 27 | size_t size = rgn->unflatten(reader->peek()); |
| 28 | SkASSERT(SkAlign4(size) == size); |
| 29 | (void)reader->skip(size); |
| 30 | } |
| 31 | |
| 32 | void SkWriteRegion(SkWriter32* writer, const SkRegion& rgn) { |
| 33 | size_t size = rgn.flatten(NULL); |
| 34 | SkASSERT(SkAlign4(size) == size); |
| 35 | rgn.flatten(writer->reserve(size)); |
| 36 | } |
| 37 | |
| 38 | /////////////////////////////////////////////////////////////////////////////// |
| 39 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | void SkFlattenable::flatten(SkFlattenableWriteBuffer&) |
| 41 | { |
| 42 | /* we don't write anything at the moment, but this allows our subclasses |
| 43 | to not know that, since we want them to always call INHERITED::flatten() |
| 44 | in their code. |
| 45 | */ |
| 46 | } |
| 47 | |
| 48 | /////////////////////////////////////////////////////////////////////////////// |
| 49 | /////////////////////////////////////////////////////////////////////////////// |
| 50 | |
| 51 | SkFlattenableReadBuffer::SkFlattenableReadBuffer() { |
| 52 | fRCArray = NULL; |
| 53 | fRCCount = 0; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 54 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | fTFArray = NULL; |
| 56 | fTFCount = 0; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 57 | |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 58 | fFactoryTDArray = NULL; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 59 | fFactoryArray = NULL; |
| 60 | fFactoryCount = 0; |
| 61 | } |
| 62 | |
| 63 | SkFlattenableReadBuffer::SkFlattenableReadBuffer(const void* data) : |
| 64 | INHERITED(data, 1024 * 1024) { |
| 65 | fRCArray = NULL; |
| 66 | fRCCount = 0; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 67 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 68 | fTFArray = NULL; |
| 69 | fTFCount = 0; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 70 | |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 71 | fFactoryTDArray = NULL; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 72 | fFactoryArray = NULL; |
| 73 | fFactoryCount = 0; |
| 74 | } |
| 75 | |
| 76 | SkFlattenableReadBuffer::SkFlattenableReadBuffer(const void* data, size_t size) |
| 77 | : INHERITED(data, size) { |
| 78 | fRCArray = NULL; |
| 79 | fRCCount = 0; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 80 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 81 | fTFArray = NULL; |
| 82 | fTFCount = 0; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 83 | |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 84 | fFactoryTDArray = NULL; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 85 | fFactoryArray = NULL; |
| 86 | fFactoryCount = 0; |
| 87 | } |
| 88 | |
| 89 | SkTypeface* SkFlattenableReadBuffer::readTypeface() { |
| 90 | uint32_t index = this->readU32(); |
| 91 | if (0 == index || index > (unsigned)fTFCount) { |
| 92 | if (index) { |
| 93 | SkDebugf("====== typeface index %d\n", index); |
| 94 | } |
| 95 | return NULL; |
| 96 | } else { |
| 97 | SkASSERT(fTFArray); |
| 98 | return fTFArray[index - 1]; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | SkRefCnt* SkFlattenableReadBuffer::readRefCnt() { |
| 103 | uint32_t index = this->readU32(); |
| 104 | if (0 == index || index > (unsigned)fRCCount) { |
| 105 | return NULL; |
| 106 | } else { |
| 107 | SkASSERT(fRCArray); |
| 108 | return fRCArray[index - 1]; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | SkFlattenable* SkFlattenableReadBuffer::readFlattenable() { |
| 113 | SkFlattenable::Factory factory = NULL; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 114 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 115 | if (fFactoryCount > 0) { |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 116 | int32_t index = this->readU32(); |
| 117 | if (0 == index) { |
| 118 | return NULL; // writer failed to give us the flattenable |
| 119 | } |
| 120 | index = -index; // we stored the negative of the index |
| 121 | index -= 1; // we stored the index-base-1 |
reed@google.com | 13649ce | 2011-06-28 12:02:58 +0000 | [diff] [blame] | 122 | SkASSERT(index < fFactoryCount); |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 123 | factory = fFactoryArray[index]; |
| 124 | } else if (fFactoryTDArray) { |
| 125 | const int32_t* peek = (const int32_t*)this->peek(); |
| 126 | if (*peek <= 0) { |
| 127 | int32_t index = this->readU32(); |
| 128 | if (0 == index) { |
| 129 | return NULL; // writer failed to give us the flattenable |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 130 | } |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 131 | index = -index; // we stored the negative of the index |
| 132 | index -= 1; // we stored the index-base-1 |
| 133 | factory = (*fFactoryTDArray)[index]; |
| 134 | } else { |
| 135 | const char* name = this->readString(); |
| 136 | factory = SkFlattenable::NameToFactory(name); |
| 137 | if (factory) { |
| 138 | SkASSERT(fFactoryTDArray->find(factory) < 0); |
| 139 | *fFactoryTDArray->append() = factory; |
| 140 | } else { |
| 141 | // SkDebugf("can't find factory for [%s]\n", name); |
| 142 | } |
| 143 | // if we didn't find a factory, that's our failure, not the writer's, |
| 144 | // so we fall through, so we can skip the sizeRecorded data. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 145 | } |
| 146 | } else { |
| 147 | factory = (SkFlattenable::Factory)readFunctionPtr(); |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 148 | if (NULL == factory) { |
| 149 | return NULL; // writer failed to give us the flattenable |
| 150 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 151 | } |
| 152 | |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 153 | // if we get here, factory may still be null, but if that is the case, the |
| 154 | // failure was ours, not the writer. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 155 | SkFlattenable* obj = NULL; |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 156 | uint32_t sizeRecorded = this->readU32(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 157 | if (factory) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 158 | uint32_t offset = this->offset(); |
| 159 | obj = (*factory)(*this); |
| 160 | // check that we read the amount we expected |
| 161 | uint32_t sizeRead = this->offset() - offset; |
| 162 | if (sizeRecorded != sizeRead) { |
| 163 | // we could try to fix up the offset... |
| 164 | sk_throw(); |
| 165 | } |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 166 | } else { |
| 167 | // we must skip the remaining data |
| 168 | this->skip(sizeRecorded); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 169 | } |
| 170 | return obj; |
| 171 | } |
| 172 | |
| 173 | void* SkFlattenableReadBuffer::readFunctionPtr() { |
| 174 | void* proc; |
| 175 | this->read(&proc, sizeof(proc)); |
| 176 | return proc; |
| 177 | } |
| 178 | |
| 179 | /////////////////////////////////////////////////////////////////////////////// |
| 180 | |
| 181 | SkFlattenableWriteBuffer::SkFlattenableWriteBuffer(size_t minSize) : |
| 182 | INHERITED(minSize) { |
| 183 | fFlags = (Flags)0; |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 184 | fRCSet = NULL; |
| 185 | fTFSet = NULL; |
| 186 | fFactorySet = NULL; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | SkFlattenableWriteBuffer::~SkFlattenableWriteBuffer() { |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 190 | SkSafeUnref(fRCSet); |
| 191 | SkSafeUnref(fTFSet); |
| 192 | SkSafeUnref(fFactorySet); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 193 | } |
| 194 | |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 195 | SkRefCntSet* SkFlattenableWriteBuffer::setRefCntRecorder(SkRefCntSet* rec) { |
| 196 | SkRefCnt_SafeAssign(fRCSet, rec); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 197 | return rec; |
| 198 | } |
| 199 | |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 200 | SkRefCntSet* SkFlattenableWriteBuffer::setTypefaceRecorder(SkRefCntSet* rec) { |
| 201 | SkRefCnt_SafeAssign(fTFSet, rec); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 202 | return rec; |
| 203 | } |
| 204 | |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 205 | SkFactorySet* SkFlattenableWriteBuffer::setFactoryRecorder(SkFactorySet* rec) { |
| 206 | SkRefCnt_SafeAssign(fFactorySet, rec); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 207 | return rec; |
| 208 | } |
| 209 | |
| 210 | void SkFlattenableWriteBuffer::writeTypeface(SkTypeface* obj) { |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 211 | if (NULL == obj || NULL == fTFSet) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 212 | this->write32(0); |
| 213 | } else { |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 214 | this->write32(fTFSet->add(obj)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
| 218 | void SkFlattenableWriteBuffer::writeRefCnt(SkRefCnt* obj) { |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 219 | if (NULL == obj || NULL == fRCSet) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 220 | this->write32(0); |
| 221 | } else { |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 222 | this->write32(fRCSet->add(obj)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
| 226 | void SkFlattenableWriteBuffer::writeFlattenable(SkFlattenable* flattenable) { |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 227 | /* |
| 228 | * If we have a factoryset, then the first 32bits tell us... |
| 229 | * 0: failure to write the flattenable |
| 230 | * <0: we store the negative of the (1-based) index |
| 231 | * >0: the length of the name |
| 232 | * If we don't have a factoryset, then the first "ptr" is either the |
| 233 | * factory, or null for failure. |
| 234 | * |
| 235 | * The distinction is important, since 0-index is 32bits (always), but a |
| 236 | * 0-functionptr might be 32 or 64 bits. |
| 237 | */ |
| 238 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 239 | SkFlattenable::Factory factory = NULL; |
| 240 | if (flattenable) { |
| 241 | factory = flattenable->getFactory(); |
| 242 | } |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 243 | if (NULL == factory) { |
| 244 | if (fFactorySet) { |
| 245 | this->write32(0); |
| 246 | } else { |
| 247 | this->writeFunctionPtr(NULL); |
| 248 | } |
| 249 | return; |
| 250 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 251 | |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 252 | /* |
| 253 | * We can write 1 of 3 versions of the flattenable: |
| 254 | * 1. function-ptr : this is the fastest for the reader, but assumes that |
| 255 | * the writer and reader are in the same process. |
| 256 | * 2. index into fFactorySet : This is assumes the writer will later |
| 257 | * resolve the function-ptrs into strings for its reader. SkPicture |
| 258 | * does exactly this, by writing a table of names (matching the indices) |
| 259 | * up front in its serialized form. |
| 260 | * 3. names : Reuse fFactorySet to store indices, but only after we've |
| 261 | * written the name the first time. SkGPipe uses this technique, as it |
| 262 | * doesn't require the reader to be told to know the table of names |
| 263 | * up front. |
| 264 | */ |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 265 | if (fFactorySet) { |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 266 | if (this->inlineFactoryNames()) { |
| 267 | int index = fFactorySet->find(factory); |
| 268 | if (index) { |
| 269 | // we write the negative of the index, to distinguish it from |
| 270 | // the length of a string |
| 271 | this->write32(-index); |
| 272 | } else { |
| 273 | const char* name = SkFlattenable::FactoryToName(factory); |
| 274 | if (NULL == name) { |
| 275 | this->write32(0); |
| 276 | return; |
| 277 | } |
| 278 | this->writeString(name); |
| 279 | index = fFactorySet->add(factory); |
| 280 | } |
| 281 | } else { |
| 282 | // we write the negative of the index, to distinguish it from |
| 283 | // the length of a string |
reed@google.com | 13649ce | 2011-06-28 12:02:58 +0000 | [diff] [blame] | 284 | this->write32(-(int)fFactorySet->add(factory)); |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 285 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 286 | } else { |
| 287 | this->writeFunctionPtr((void*)factory); |
| 288 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 289 | |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 290 | // make room for the size of the flatttened object |
| 291 | (void)this->reserve(sizeof(uint32_t)); |
| 292 | // record the current size, so we can subtract after the object writes. |
| 293 | uint32_t offset = this->size(); |
| 294 | // now flatten the object |
| 295 | flattenable->flatten(*this); |
| 296 | uint32_t objSize = this->size() - offset; |
| 297 | // record the obj's size |
| 298 | *this->peek32(offset - sizeof(uint32_t)) = objSize; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | void SkFlattenableWriteBuffer::writeFunctionPtr(void* proc) { |
| 302 | *(void**)this->reserve(sizeof(void*)) = proc; |
| 303 | } |
| 304 | |
| 305 | /////////////////////////////////////////////////////////////////////////////// |
| 306 | |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 307 | SkRefCntSet::~SkRefCntSet() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 308 | // call this now, while our decPtr() is sill in scope |
| 309 | this->reset(); |
| 310 | } |
| 311 | |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 312 | void SkRefCntSet::incPtr(void* ptr) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 313 | ((SkRefCnt*)ptr)->ref(); |
| 314 | } |
| 315 | |
mike@reedtribe.org | e9e08cc | 2011-04-29 01:44:52 +0000 | [diff] [blame] | 316 | void SkRefCntSet::decPtr(void* ptr) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 317 | ((SkRefCnt*)ptr)->unref(); |
| 318 | } |
| 319 | |
| 320 | /////////////////////////////////////////////////////////////////////////////// |
| 321 | /////////////////////////////////////////////////////////////////////////////// |
| 322 | /////////////////////////////////////////////////////////////////////////////// |
| 323 | |
| 324 | #define MAX_PAIR_COUNT 64 |
| 325 | |
| 326 | struct Pair { |
| 327 | const char* fName; |
| 328 | SkFlattenable::Factory fFactory; |
| 329 | }; |
| 330 | |
| 331 | static int gCount; |
| 332 | static Pair gPairs[MAX_PAIR_COUNT]; |
| 333 | |
| 334 | void SkFlattenable::Register(const char name[], Factory factory) { |
| 335 | SkASSERT(name); |
| 336 | SkASSERT(factory); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 337 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 338 | static bool gOnce; |
| 339 | if (!gOnce) { |
| 340 | gCount = 0; |
| 341 | gOnce = true; |
| 342 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 343 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 344 | SkASSERT(gCount < MAX_PAIR_COUNT); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 345 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 346 | gPairs[gCount].fName = name; |
| 347 | gPairs[gCount].fFactory = factory; |
| 348 | gCount += 1; |
| 349 | } |
| 350 | |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 351 | #if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS && defined(SK_DEBUG) |
| 352 | static void report_no_entries(const char* functionName) { |
| 353 | if (!gCount) { |
| 354 | SkDebugf("%s has no registered name/factory pairs." |
caryclark@google.com | 9245498 | 2011-12-16 16:54:07 +0000 | [diff] [blame] | 355 | " Call SkGraphics::Init() at process initialization time.", |
| 356 | functionName); |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | #endif |
| 360 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 361 | SkFlattenable::Factory SkFlattenable::NameToFactory(const char name[]) { |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 362 | #if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS && defined(SK_DEBUG) |
| 363 | report_no_entries(__FUNCTION__); |
| 364 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 365 | const Pair* pairs = gPairs; |
| 366 | for (int i = gCount - 1; i >= 0; --i) { |
| 367 | if (strcmp(pairs[i].fName, name) == 0) { |
| 368 | return pairs[i].fFactory; |
| 369 | } |
| 370 | } |
| 371 | return NULL; |
| 372 | } |
| 373 | |
| 374 | const char* SkFlattenable::FactoryToName(Factory fact) { |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 375 | #if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS && defined(SK_DEBUG) |
| 376 | report_no_entries(__FUNCTION__); |
| 377 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 378 | const Pair* pairs = gPairs; |
| 379 | for (int i = gCount - 1; i >= 0; --i) { |
| 380 | if (pairs[i].fFactory == fact) { |
| 381 | return pairs[i].fName; |
| 382 | } |
| 383 | } |
| 384 | return NULL; |
| 385 | } |