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 |
11 | 11 |
12 #include "GrTypes.h" | 12 #include "GrTypes.h" |
13 #include "SkOnce.h" | |
13 #include "SkTemplates.h" | 14 #include "SkTemplates.h" |
14 | 15 |
15 uint32_t GrResourceKeyHash(const uint32_t* data, size_t size); | 16 uint32_t GrResourceKeyHash(const uint32_t* data, size_t size); |
16 | 17 |
17 /** | 18 /** |
18 * Base class for all GrGpuResource cache keys. There are two types of cache key s. Refer to the | 19 * Base class for all GrGpuResource cache keys. There are two types of cache key s. Refer to the |
19 * comments for each key type below. | 20 * comments for each key type below. |
20 */ | 21 */ |
21 class GrResourceKey { | 22 class GrResourceKey { |
22 public: | 23 public: |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 } | 260 } |
260 | 261 |
261 private: | 262 private: |
262 static int Data32CntForInnerKey(const GrUniqueKey& innerKey) { | 263 static int Data32CntForInnerKey(const GrUniqueKey& innerKey) { |
263 // key data + domain | 264 // key data + domain |
264 return SkToInt((innerKey.dataSize() >> 2) + 1); | 265 return SkToInt((innerKey.dataSize() >> 2) + 1); |
265 } | 266 } |
266 }; | 267 }; |
267 }; | 268 }; |
268 | 269 |
270 /** | |
271 * It is common to need a frequently reused GrUniqueKey where the only requireme nt is that the key | |
272 * is unique. These macros create such a key in a thread safe manner so the key can be truly global | |
273 * and only constructed once. | |
274 */ | |
275 | |
276 /** Place outside of function/class definitions. */ | |
robertphillips
2015/05/04 13:15:59
single line - maybe ?
bsalomon
2015/05/04 15:01:09
Done.
| |
277 #define GR_DECLARE_STATIC_UNIQUE_KEY(name) \ | |
278 SK_DECLARE_STATIC_ONCE(name##_once) | |
279 | |
280 /** Place inside function where the key is used. */ | |
281 #define GR_DEFINE_STATIC_UNIQUE_KEY(name) \ | |
282 static GrUniqueKey name; \ | |
283 SkOnce(&name##_once, gr_init_static_unique_key_once, &name) | |
284 | |
285 static inline void gr_init_static_unique_key_once(GrUniqueKey* key) { | |
286 GrUniqueKey::Builder builder(key, GrUniqueKey::GenerateDomain(), 0); | |
287 } | |
288 | |
269 // The cache listens for these messages to purge junk resources proactively. | 289 // The cache listens for these messages to purge junk resources proactively. |
270 class GrUniqueKeyInvalidatedMessage { | 290 class GrUniqueKeyInvalidatedMessage { |
271 public: | 291 public: |
272 explicit GrUniqueKeyInvalidatedMessage(const GrUniqueKey& key) : fKey(key) { } | 292 explicit GrUniqueKeyInvalidatedMessage(const GrUniqueKey& key) : fKey(key) { } |
273 | 293 |
274 GrUniqueKeyInvalidatedMessage(const GrUniqueKeyInvalidatedMessage& that) : f Key(that.fKey) {} | 294 GrUniqueKeyInvalidatedMessage(const GrUniqueKeyInvalidatedMessage& that) : f Key(that.fKey) {} |
275 | 295 |
276 GrUniqueKeyInvalidatedMessage& operator=(const GrUniqueKeyInvalidatedMessage & that) { | 296 GrUniqueKeyInvalidatedMessage& operator=(const GrUniqueKeyInvalidatedMessage & that) { |
277 fKey = that.fKey; | 297 fKey = that.fKey; |
278 return *this; | 298 return *this; |
279 } | 299 } |
280 | 300 |
281 const GrUniqueKey& key() const { return fKey; } | 301 const GrUniqueKey& key() const { return fKey; } |
282 | 302 |
283 private: | 303 private: |
284 GrUniqueKey fKey; | 304 GrUniqueKey fKey; |
285 }; | 305 }; |
286 #endif | 306 #endif |
OLD | NEW |