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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) SK_DECLARE_STATIC_ONCE(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 GrUniqueKey name; \ | 297 static SkAlignedSTStorage<1, GrUniqueKey> name##_storage;
\ |
298 SkOnce(&name##_once, gr_init_static_unique_key_once, &name) | 298 SkOnce(&name##_once, gr_init_static_unique_key_once, &name##_storage);
\ |
| 299 static const GrUniqueKey& name = *reinterpret_cast<GrUniqueKey*>(name##_stor
age.get()); |
299 | 300 |
300 static inline void gr_init_static_unique_key_once(GrUniqueKey* key) { | 301 static inline void gr_init_static_unique_key_once(SkAlignedSTStorage<1,GrUniqueK
ey>* keyStorage) { |
| 302 GrUniqueKey* key = new (keyStorage->get()) GrUniqueKey; |
301 GrUniqueKey::Builder builder(key, GrUniqueKey::GenerateDomain(), 0); | 303 GrUniqueKey::Builder builder(key, GrUniqueKey::GenerateDomain(), 0); |
302 } | 304 } |
303 | 305 |
304 // The cache listens for these messages to purge junk resources proactively. | 306 // The cache listens for these messages to purge junk resources proactively. |
305 class GrUniqueKeyInvalidatedMessage { | 307 class GrUniqueKeyInvalidatedMessage { |
306 public: | 308 public: |
307 explicit GrUniqueKeyInvalidatedMessage(const GrUniqueKey& key) : fKey(key) {
} | 309 explicit GrUniqueKeyInvalidatedMessage(const GrUniqueKey& key) : fKey(key) {
} |
308 | 310 |
309 GrUniqueKeyInvalidatedMessage(const GrUniqueKeyInvalidatedMessage& that) : f
Key(that.fKey) {} | 311 GrUniqueKeyInvalidatedMessage(const GrUniqueKeyInvalidatedMessage& that) : f
Key(that.fKey) {} |
310 | 312 |
311 GrUniqueKeyInvalidatedMessage& operator=(const GrUniqueKeyInvalidatedMessage
& that) { | 313 GrUniqueKeyInvalidatedMessage& operator=(const GrUniqueKeyInvalidatedMessage
& that) { |
312 fKey = that.fKey; | 314 fKey = that.fKey; |
313 return *this; | 315 return *this; |
314 } | 316 } |
315 | 317 |
316 const GrUniqueKey& key() const { return fKey; } | 318 const GrUniqueKey& key() const { return fKey; } |
317 | 319 |
318 private: | 320 private: |
319 GrUniqueKey fKey; | 321 GrUniqueKey fKey; |
320 }; | 322 }; |
321 #endif | 323 #endif |
OLD | NEW |