| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #ifndef SkResourceCache_DEFINED | 8 #ifndef SkResourceCache_DEFINED |
| 9 #define SkResourceCache_DEFINED | 9 #define SkResourceCache_DEFINED |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * As a convenience, a global instance is also defined, which can be safely | 24 * As a convenience, a global instance is also defined, which can be safely |
| 25 * access across threads via the static methods (e.g. FindAndLock, etc.). | 25 * access across threads via the static methods (e.g. FindAndLock, etc.). |
| 26 */ | 26 */ |
| 27 class SkResourceCache { | 27 class SkResourceCache { |
| 28 public: | 28 public: |
| 29 struct Key { | 29 struct Key { |
| 30 // Call this to access your private contents. Must not use the address a
fter calling init() | 30 // Call this to access your private contents. Must not use the address a
fter calling init() |
| 31 void* writableContents() { return this + 1; } | 31 void* writableContents() { return this + 1; } |
| 32 | 32 |
| 33 // must call this after your private data has been written. | 33 // must call this after your private data has been written. |
| 34 // nameSpace must be unique per Key subclass. |
| 34 // length must be a multiple of 4 | 35 // length must be a multiple of 4 |
| 35 void init(size_t length); | 36 void init(void* nameSpace, size_t length); |
| 36 | 37 |
| 37 // This is only valid after having called init(). | 38 // This is only valid after having called init(). |
| 38 uint32_t hash() const { return fHash; } | 39 uint32_t hash() const { return fHash; } |
| 39 | 40 |
| 40 bool operator==(const Key& other) const { | 41 bool operator==(const Key& other) const { |
| 41 const uint32_t* a = this->as32(); | 42 const uint32_t* a = this->as32(); |
| 42 const uint32_t* b = other.as32(); | 43 const uint32_t* b = other.as32(); |
| 43 for (int i = 0; i < fCount32; ++i) { // (This checks fCount == othe
r.fCount first.) | 44 for (int i = 0; i < fCount32; ++i) { // (This checks fCount == othe
r.fCount first.) |
| 44 if (a[i] != b[i]) { | 45 if (a[i] != b[i]) { |
| 45 return false; | 46 return false; |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 return true; | 49 return true; |
| 49 } | 50 } |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 int32_t fCount32; // 2 + user contents count32 | 53 int32_t fCount32; // local + user contents count32 |
| 53 uint32_t fHash; | 54 uint32_t fHash; |
| 55 void* fNamespace; // A unique namespace tag. This is hashed. |
| 54 /* uint32_t fContents32[] */ | 56 /* uint32_t fContents32[] */ |
| 55 | 57 |
| 56 const uint32_t* as32() const { return (const uint32_t*)this; } | 58 const uint32_t* as32() const { return (const uint32_t*)this; } |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 struct Rec { | 61 struct Rec { |
| 60 typedef SkResourceCache::Key Key; | 62 typedef SkResourceCache::Key Key; |
| 61 | 63 |
| 62 Rec() {} | 64 Rec() {} |
| 63 virtual ~Rec() {} | 65 virtual ~Rec() {} |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 231 |
| 230 void init(); // called by constructors | 232 void init(); // called by constructors |
| 231 | 233 |
| 232 #ifdef SK_DEBUG | 234 #ifdef SK_DEBUG |
| 233 void validate() const; | 235 void validate() const; |
| 234 #else | 236 #else |
| 235 void validate() const {} | 237 void validate() const {} |
| 236 #endif | 238 #endif |
| 237 }; | 239 }; |
| 238 #endif | 240 #endif |
| OLD | NEW |