OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
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 #ifndef GrResourceKey_DEFINED | 9 #ifndef GrResourceKey_DEFINED |
10 #define GrResourceKey_DEFINED | 10 #define GrResourceKey_DEFINED |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 return *this; | 65 return *this; |
66 } | 66 } |
67 | 67 |
68 bool isValid() const { return kInvalidDomain != this->domain(); } | 68 bool isValid() const { return kInvalidDomain != this->domain(); } |
69 | 69 |
70 uint32_t domain() const { return fKey[kDomainAndSize_MetaDataIdx] & 0xffff;
} | 70 uint32_t domain() const { return fKey[kDomainAndSize_MetaDataIdx] & 0xffff;
} |
71 | 71 |
72 /** size of the key data, excluding meta-data (hash, domain, etc). */ | 72 /** size of the key data, excluding meta-data (hash, domain, etc). */ |
73 size_t dataSize() const { return this->size() - 4 * kMetaDataCnt; } | 73 size_t dataSize() const { return this->size() - 4 * kMetaDataCnt; } |
74 | 74 |
75 /** ptr to the key data, excluding meta-data (hash, domain, etc). */ | 75 /** ptr to the key data, excluding meta-data (hash, domain, etc). */ |
76 const uint32_t* data() const { | 76 const uint32_t* data() const { |
77 this->validate(); | 77 this->validate(); |
78 return &fKey[kMetaDataCnt]; | 78 return &fKey[kMetaDataCnt]; |
79 } | 79 } |
80 | 80 |
81 /** Used to initialize a key. */ | 81 /** Used to initialize a key. */ |
82 class Builder { | 82 class Builder { |
83 public: | 83 public: |
84 Builder(GrResourceKey* key, uint32_t domain, int data32Count) : fKey(key
) { | 84 Builder(GrResourceKey* key, uint32_t domain, int data32Count) : fKey(key
) { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 SkAutoTUnref<const SkData> fData; | 283 SkAutoTUnref<const SkData> fData; |
284 }; | 284 }; |
285 | 285 |
286 /** | 286 /** |
287 * It is common to need a frequently reused GrUniqueKey where the only requireme
nt is that the key | 287 * It is common to need a frequently reused GrUniqueKey where the only requireme
nt is that the key |
288 * is unique. These macros create such a key in a thread safe manner so the key
can be truly global | 288 * is unique. These macros create such a key in a thread safe manner so the key
can be truly global |
289 * and only constructed once. | 289 * and only constructed once. |
290 */ | 290 */ |
291 | 291 |
292 /** Place outside of function/class definitions. */ | 292 /** Place outside of function/class definitions. */ |
293 #define GR_DECLARE_STATIC_UNIQUE_KEY(name) SK_DECLARE_STATIC_ONCE(name##_once) | 293 #define GR_DECLARE_STATIC_UNIQUE_KEY(name) static SkOnce name##_once |
294 | 294 |
295 /** Place inside function where the key is used. */ | 295 /** Place inside function where the key is used. */ |
296 #define GR_DEFINE_STATIC_UNIQUE_KEY(name)
\ | 296 #define GR_DEFINE_STATIC_UNIQUE_KEY(name)
\ |
297 static SkAlignedSTStorage<1, GrUniqueKey> name##_storage;
\ | 297 static SkAlignedSTStorage<1, GrUniqueKey> name##_storage;
\ |
298 SkOnce(&name##_once, gr_init_static_unique_key_once, &name##_storage);
\ | 298 name##_once(gr_init_static_unique_key_once, &name##_storage);
\ |
299 static const GrUniqueKey& name = *reinterpret_cast<GrUniqueKey*>(name##_stor
age.get()); | 299 static const GrUniqueKey& name = *reinterpret_cast<GrUniqueKey*>(name##_stor
age.get()); |
300 | 300 |
301 static inline void gr_init_static_unique_key_once(SkAlignedSTStorage<1,GrUniqueK
ey>* keyStorage) { | 301 static inline void gr_init_static_unique_key_once(SkAlignedSTStorage<1,GrUniqueK
ey>* keyStorage) { |
302 GrUniqueKey* key = new (keyStorage->get()) GrUniqueKey; | 302 GrUniqueKey* key = new (keyStorage->get()) GrUniqueKey; |
303 GrUniqueKey::Builder builder(key, GrUniqueKey::GenerateDomain(), 0); | 303 GrUniqueKey::Builder builder(key, GrUniqueKey::GenerateDomain(), 0); |
304 } | 304 } |
305 | 305 |
306 // The cache listens for these messages to purge junk resources proactively. | 306 // The cache listens for these messages to purge junk resources proactively. |
307 class GrUniqueKeyInvalidatedMessage { | 307 class GrUniqueKeyInvalidatedMessage { |
308 public: | 308 public: |
309 explicit GrUniqueKeyInvalidatedMessage(const GrUniqueKey& key) : fKey(key) {
} | 309 explicit GrUniqueKeyInvalidatedMessage(const GrUniqueKey& key) : fKey(key) {
} |
310 | 310 |
311 GrUniqueKeyInvalidatedMessage(const GrUniqueKeyInvalidatedMessage& that) : f
Key(that.fKey) {} | 311 GrUniqueKeyInvalidatedMessage(const GrUniqueKeyInvalidatedMessage& that) : f
Key(that.fKey) {} |
312 | 312 |
313 GrUniqueKeyInvalidatedMessage& operator=(const GrUniqueKeyInvalidatedMessage
& that) { | 313 GrUniqueKeyInvalidatedMessage& operator=(const GrUniqueKeyInvalidatedMessage
& that) { |
314 fKey = that.fKey; | 314 fKey = that.fKey; |
315 return *this; | 315 return *this; |
316 } | 316 } |
317 | 317 |
318 const GrUniqueKey& key() const { return fKey; } | 318 const GrUniqueKey& key() const { return fKey; } |
319 | 319 |
320 private: | 320 private: |
321 GrUniqueKey fKey; | 321 GrUniqueKey fKey; |
322 }; | 322 }; |
323 #endif | 323 #endif |
OLD | NEW |