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 "SkData.h" |
13 #include "SkOnce.h" | 14 #include "SkOnce.h" |
14 #include "SkTemplates.h" | 15 #include "SkTemplates.h" |
15 | 16 |
16 uint32_t GrResourceKeyHash(const uint32_t* data, size_t size); | 17 uint32_t GrResourceKeyHash(const uint32_t* data, size_t size); |
17 | 18 |
18 /** | 19 /** |
19 * Base class for all GrGpuResource cache keys. There are two types of cache key
s. Refer to the | 20 * Base class for all GrGpuResource cache keys. There are two types of cache key
s. Refer to the |
20 * comments for each key type below. | 21 * comments for each key type below. |
21 */ | 22 */ |
22 class GrResourceKey { | 23 class GrResourceKey { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 231 |
231 GrUniqueKey(const GrUniqueKey& that) { *this = that; } | 232 GrUniqueKey(const GrUniqueKey& that) { *this = that; } |
232 | 233 |
233 /** reset() returns the key to the invalid state. */ | 234 /** reset() returns the key to the invalid state. */ |
234 using INHERITED::reset; | 235 using INHERITED::reset; |
235 | 236 |
236 using INHERITED::isValid; | 237 using INHERITED::isValid; |
237 | 238 |
238 GrUniqueKey& operator=(const GrUniqueKey& that) { | 239 GrUniqueKey& operator=(const GrUniqueKey& that) { |
239 this->INHERITED::operator=(that); | 240 this->INHERITED::operator=(that); |
| 241 this->setCustomData(that.getCustomData()); |
240 return *this; | 242 return *this; |
241 } | 243 } |
242 | 244 |
243 bool operator==(const GrUniqueKey& that) const { | 245 bool operator==(const GrUniqueKey& that) const { |
244 return this->INHERITED::operator==(that); | 246 return this->INHERITED::operator==(that); |
245 } | 247 } |
246 bool operator!=(const GrUniqueKey& that) const { return !(*this == that); } | 248 bool operator!=(const GrUniqueKey& that) const { return !(*this == that); } |
247 | 249 |
| 250 void setCustomData(const SkData* data) { |
| 251 SkSafeRef(data); |
| 252 fData.reset(data); |
| 253 } |
| 254 const SkData* getCustomData() const { |
| 255 return fData.get(); |
| 256 } |
| 257 |
248 class Builder : public INHERITED::Builder { | 258 class Builder : public INHERITED::Builder { |
249 public: | 259 public: |
250 Builder(GrUniqueKey* key, Domain domain, int data32Count) | 260 Builder(GrUniqueKey* key, Domain domain, int data32Count) |
251 : INHERITED::Builder(key, domain, data32Count) {} | 261 : INHERITED::Builder(key, domain, data32Count) {} |
252 | 262 |
253 /** Used to build a key that wraps another key and adds additional data.
*/ | 263 /** Used to build a key that wraps another key and adds additional data.
*/ |
254 Builder(GrUniqueKey* key, const GrUniqueKey& innerKey, Domain domain, | 264 Builder(GrUniqueKey* key, const GrUniqueKey& innerKey, Domain domain, |
255 int extraData32Cnt) | 265 int extraData32Cnt) |
256 : INHERITED::Builder(key, domain, Data32CntForInnerKey(innerKey) + e
xtraData32Cnt) { | 266 : INHERITED::Builder(key, domain, Data32CntForInnerKey(innerKey) + e
xtraData32Cnt) { |
257 SkASSERT(&innerKey != key); | 267 SkASSERT(&innerKey != key); |
258 // add the inner key to the end of the key so that op[] can be index
ed normally. | 268 // add the inner key to the end of the key so that op[] can be index
ed normally. |
259 uint32_t* innerKeyData = &this->operator[](extraData32Cnt); | 269 uint32_t* innerKeyData = &this->operator[](extraData32Cnt); |
260 const uint32_t* srcData = innerKey.data(); | 270 const uint32_t* srcData = innerKey.data(); |
261 (*innerKeyData++) = innerKey.domain(); | 271 (*innerKeyData++) = innerKey.domain(); |
262 memcpy(innerKeyData, srcData, innerKey.dataSize()); | 272 memcpy(innerKeyData, srcData, innerKey.dataSize()); |
263 } | 273 } |
264 | 274 |
265 private: | 275 private: |
266 static int Data32CntForInnerKey(const GrUniqueKey& innerKey) { | 276 static int Data32CntForInnerKey(const GrUniqueKey& innerKey) { |
267 // key data + domain | 277 // key data + domain |
268 return SkToInt((innerKey.dataSize() >> 2) + 1); | 278 return SkToInt((innerKey.dataSize() >> 2) + 1); |
269 } | 279 } |
270 }; | 280 }; |
| 281 |
| 282 private: |
| 283 SkAutoTUnref<const SkData> fData; |
271 }; | 284 }; |
272 | 285 |
273 /** | 286 /** |
274 * 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 |
275 * 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 |
276 * and only constructed once. | 289 * and only constructed once. |
277 */ | 290 */ |
278 | 291 |
279 /** Place outside of function/class definitions. */ | 292 /** Place outside of function/class definitions. */ |
280 #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) |
(...skipping 18 matching lines...) Expand all Loading... |
299 fKey = that.fKey; | 312 fKey = that.fKey; |
300 return *this; | 313 return *this; |
301 } | 314 } |
302 | 315 |
303 const GrUniqueKey& key() const { return fKey; } | 316 const GrUniqueKey& key() const { return fKey; } |
304 | 317 |
305 private: | 318 private: |
306 GrUniqueKey fKey; | 319 GrUniqueKey fKey; |
307 }; | 320 }; |
308 #endif | 321 #endif |
OLD | NEW |