OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkDescriptor_DEFINED | 10 #ifndef SkDescriptor_DEFINED |
(...skipping 19 matching lines...) Expand all Loading... |
30 sk_free(desc); | 30 sk_free(desc); |
31 } | 31 } |
32 | 32 |
33 void init() { | 33 void init() { |
34 fLength = sizeof(SkDescriptor); | 34 fLength = sizeof(SkDescriptor); |
35 fCount = 0; | 35 fCount = 0; |
36 } | 36 } |
37 | 37 |
38 uint32_t getLength() const { return fLength; } | 38 uint32_t getLength() const { return fLength; } |
39 | 39 |
40 void* addEntry(uint32_t tag, size_t length, const void* data = NULL) { | 40 void* addEntry(uint32_t tag, size_t length, const void* data = nullptr) { |
41 SkASSERT(tag); | 41 SkASSERT(tag); |
42 SkASSERT(SkAlign4(length) == length); | 42 SkASSERT(SkAlign4(length) == length); |
43 SkASSERT(this->findEntry(tag, NULL) == NULL); | 43 SkASSERT(this->findEntry(tag, nullptr) == nullptr); |
44 | 44 |
45 Entry* entry = (Entry*)((char*)this + fLength); | 45 Entry* entry = (Entry*)((char*)this + fLength); |
46 entry->fTag = tag; | 46 entry->fTag = tag; |
47 entry->fLen = SkToU32(length); | 47 entry->fLen = SkToU32(length); |
48 if (data) { | 48 if (data) { |
49 memcpy(entry + 1, data, length); | 49 memcpy(entry + 1, data, length); |
50 } | 50 } |
51 | 51 |
52 fCount += 1; | 52 fCount += 1; |
53 fLength = SkToU32(fLength + sizeof(Entry) + length); | 53 fLength = SkToU32(fLength + sizeof(Entry) + length); |
(...skipping 16 matching lines...) Expand all Loading... |
70 | 70 |
71 while (--count >= 0) { | 71 while (--count >= 0) { |
72 if (entry->fTag == tag) { | 72 if (entry->fTag == tag) { |
73 if (length) { | 73 if (length) { |
74 *length = entry->fLen; | 74 *length = entry->fLen; |
75 } | 75 } |
76 return entry + 1; | 76 return entry + 1; |
77 } | 77 } |
78 entry = (const Entry*)((const char*)(entry + 1) + entry->fLen); | 78 entry = (const Entry*)((const char*)(entry + 1) + entry->fLen); |
79 } | 79 } |
80 return NULL; | 80 return nullptr; |
81 } | 81 } |
82 | 82 |
83 SkDescriptor* copy() const { | 83 SkDescriptor* copy() const { |
84 SkDescriptor* desc = SkDescriptor::Alloc(fLength); | 84 SkDescriptor* desc = SkDescriptor::Alloc(fLength); |
85 memcpy(desc, this, fLength); | 85 memcpy(desc, this, fLength); |
86 return desc; | 86 return desc; |
87 } | 87 } |
88 | 88 |
89 bool equals(const SkDescriptor& other) const { | 89 bool equals(const SkDescriptor& other) const { |
90 // probe to see if we have a good checksum algo | 90 // probe to see if we have a good checksum algo |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 127 } |
128 | 128 |
129 // private so no one can create one except our factories | 129 // private so no one can create one except our factories |
130 SkDescriptor() {} | 130 SkDescriptor() {} |
131 }; | 131 }; |
132 | 132 |
133 #include "SkScalerContext.h" | 133 #include "SkScalerContext.h" |
134 | 134 |
135 class SkAutoDescriptor : SkNoncopyable { | 135 class SkAutoDescriptor : SkNoncopyable { |
136 public: | 136 public: |
137 SkAutoDescriptor() : fDesc(NULL) {} | 137 SkAutoDescriptor() : fDesc(nullptr) {} |
138 SkAutoDescriptor(size_t size) : fDesc(NULL) { this->reset(size); } | 138 SkAutoDescriptor(size_t size) : fDesc(nullptr) { this->reset(size); } |
139 SkAutoDescriptor(const SkDescriptor& desc) : fDesc(NULL) { | 139 SkAutoDescriptor(const SkDescriptor& desc) : fDesc(nullptr) { |
140 size_t size = desc.getLength(); | 140 size_t size = desc.getLength(); |
141 this->reset(size); | 141 this->reset(size); |
142 memcpy(fDesc, &desc, size); | 142 memcpy(fDesc, &desc, size); |
143 } | 143 } |
144 | 144 |
145 ~SkAutoDescriptor() { this->free(); } | 145 ~SkAutoDescriptor() { this->free(); } |
146 | 146 |
147 void reset(size_t size) { | 147 void reset(size_t size) { |
148 this->free(); | 148 this->free(); |
149 if (size <= sizeof(fStorage)) { | 149 if (size <= sizeof(fStorage)) { |
(...skipping 17 matching lines...) Expand all Loading... |
167 + sizeof(SkDescriptor::Entry) + sizeof(void*)
// for typeface | 167 + sizeof(SkDescriptor::Entry) + sizeof(void*)
// for typeface |
168 + 32 // slop for occational small extras | 168 + 32 // slop for occational small extras |
169 }; | 169 }; |
170 SkDescriptor* fDesc; | 170 SkDescriptor* fDesc; |
171 uint32_t fStorage[(kStorageSize + 3) >> 2]; | 171 uint32_t fStorage[(kStorageSize + 3) >> 2]; |
172 }; | 172 }; |
173 #define SkAutoDescriptor(...) SK_REQUIRE_LOCAL_VAR(SkAutoDescriptor) | 173 #define SkAutoDescriptor(...) SK_REQUIRE_LOCAL_VAR(SkAutoDescriptor) |
174 | 174 |
175 | 175 |
176 #endif | 176 #endif |
OLD | NEW |