| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkFlattenable.h" | 8 #include "SkFlattenable.h" |
| 9 #include "SkPtrRecorder.h" | 9 #include "SkPtrRecorder.h" |
| 10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
| 11 | 11 |
| 12 SkNamedFactorySet::SkNamedFactorySet() : fNextAddedFactory(0) {} | 12 SkNamedFactorySet::SkNamedFactorySet() : fNextAddedFactory(0) {} |
| 13 | 13 |
| 14 uint32_t SkNamedFactorySet::find(SkFlattenable::Factory factory) { | 14 uint32_t SkNamedFactorySet::find(SkFlattenable::Factory factory) { |
| 15 uint32_t index = fFactorySet.find(factory); | 15 uint32_t index = fFactorySet.find(factory); |
| 16 if (index > 0) { | 16 if (index > 0) { |
| 17 return index; | 17 return index; |
| 18 } | 18 } |
| 19 const char* name = SkFlattenable::FactoryToName(factory); | 19 const char* name = SkFlattenable::FactoryToName(factory); |
| 20 if (NULL == name) { | 20 if (nullptr == name) { |
| 21 return 0; | 21 return 0; |
| 22 } | 22 } |
| 23 *fNames.append() = name; | 23 *fNames.append() = name; |
| 24 return fFactorySet.add(factory); | 24 return fFactorySet.add(factory); |
| 25 } | 25 } |
| 26 | 26 |
| 27 const char* SkNamedFactorySet::getNextAddedFactoryName() { | 27 const char* SkNamedFactorySet::getNextAddedFactoryName() { |
| 28 if (fNextAddedFactory < fNames.count()) { | 28 if (fNextAddedFactory < fNames.count()) { |
| 29 return fNames[fNextAddedFactory++]; | 29 return fNames[fNextAddedFactory++]; |
| 30 } | 30 } |
| 31 return NULL; | 31 return nullptr; |
| 32 } | 32 } |
| 33 | 33 |
| 34 /////////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////////// |
| 35 | 35 |
| 36 SkRefCntSet::~SkRefCntSet() { | 36 SkRefCntSet::~SkRefCntSet() { |
| 37 // call this now, while our decPtr() is sill in scope | 37 // call this now, while our decPtr() is sill in scope |
| 38 this->reset(); | 38 this->reset(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void SkRefCntSet::incPtr(void* ptr) { | 41 void SkRefCntSet::incPtr(void* ptr) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 InitializeFlattenablesIfNeeded(); | 91 InitializeFlattenablesIfNeeded(); |
| 92 #ifdef SK_DEBUG | 92 #ifdef SK_DEBUG |
| 93 report_no_entries(__FUNCTION__); | 93 report_no_entries(__FUNCTION__); |
| 94 #endif | 94 #endif |
| 95 const Entry* entries = gEntries; | 95 const Entry* entries = gEntries; |
| 96 for (int i = gCount - 1; i >= 0; --i) { | 96 for (int i = gCount - 1; i >= 0; --i) { |
| 97 if (strcmp(entries[i].fName, name) == 0) { | 97 if (strcmp(entries[i].fName, name) == 0) { |
| 98 return entries[i].fFactory; | 98 return entries[i].fFactory; |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 return NULL; | 101 return nullptr; |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool SkFlattenable::NameToType(const char name[], SkFlattenable::Type* type) { | 104 bool SkFlattenable::NameToType(const char name[], SkFlattenable::Type* type) { |
| 105 SkASSERT(type); | 105 SkASSERT(type); |
| 106 InitializeFlattenablesIfNeeded(); | 106 InitializeFlattenablesIfNeeded(); |
| 107 #ifdef SK_DEBUG | 107 #ifdef SK_DEBUG |
| 108 report_no_entries(__FUNCTION__); | 108 report_no_entries(__FUNCTION__); |
| 109 #endif | 109 #endif |
| 110 const Entry* entries = gEntries; | 110 const Entry* entries = gEntries; |
| 111 for (int i = gCount - 1; i >= 0; --i) { | 111 for (int i = gCount - 1; i >= 0; --i) { |
| 112 if (strcmp(entries[i].fName, name) == 0) { | 112 if (strcmp(entries[i].fName, name) == 0) { |
| 113 *type = entries[i].fType; | 113 *type = entries[i].fType; |
| 114 return true; | 114 return true; |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 | 119 |
| 120 const char* SkFlattenable::FactoryToName(Factory fact) { | 120 const char* SkFlattenable::FactoryToName(Factory fact) { |
| 121 InitializeFlattenablesIfNeeded(); | 121 InitializeFlattenablesIfNeeded(); |
| 122 #ifdef SK_DEBUG | 122 #ifdef SK_DEBUG |
| 123 report_no_entries(__FUNCTION__); | 123 report_no_entries(__FUNCTION__); |
| 124 #endif | 124 #endif |
| 125 const Entry* entries = gEntries; | 125 const Entry* entries = gEntries; |
| 126 for (int i = gCount - 1; i >= 0; --i) { | 126 for (int i = gCount - 1; i >= 0; --i) { |
| 127 if (entries[i].fFactory == fact) { | 127 if (entries[i].fFactory == fact) { |
| 128 return entries[i].fName; | 128 return entries[i].fName; |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 return NULL; | 131 return nullptr; |
| 132 } | 132 } |
| OLD | NEW |