| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 231 | 231 | 
| 232     GrUniqueKey(const GrUniqueKey& that) { *this = that; } | 232     GrUniqueKey(const GrUniqueKey& that) { *this = that; } | 
| 233 | 233 | 
| 234     /** reset() returns the key to the invalid state. */ | 234     /** reset() returns the key to the invalid state. */ | 
| 235     using INHERITED::reset; | 235     using INHERITED::reset; | 
| 236 | 236 | 
| 237     using INHERITED::isValid; | 237     using INHERITED::isValid; | 
| 238 | 238 | 
| 239     GrUniqueKey& operator=(const GrUniqueKey& that) { | 239     GrUniqueKey& operator=(const GrUniqueKey& that) { | 
| 240         this->INHERITED::operator=(that); | 240         this->INHERITED::operator=(that); | 
| 241         this->setCustomData(that.getCustomData()); | 241         this->setCustomData(sk_ref_sp(that.getCustomData())); | 
| 242         return *this; | 242         return *this; | 
| 243     } | 243     } | 
| 244 | 244 | 
| 245     bool operator==(const GrUniqueKey& that) const { | 245     bool operator==(const GrUniqueKey& that) const { | 
| 246         return this->INHERITED::operator==(that); | 246         return this->INHERITED::operator==(that); | 
| 247     } | 247     } | 
| 248     bool operator!=(const GrUniqueKey& that) const { return !(*this == that); } | 248     bool operator!=(const GrUniqueKey& that) const { return !(*this == that); } | 
| 249 | 249 | 
| 250     void setCustomData(const SkData* data) { | 250     void setCustomData(sk_sp<SkData> data) { | 
| 251         SkSafeRef(data); | 251         fData = std::move(data); | 
| 252         fData.reset(data); |  | 
| 253     } | 252     } | 
| 254     const SkData* getCustomData() const { | 253     SkData* getCustomData() const { | 
| 255         return fData.get(); | 254         return fData.get(); | 
| 256     } | 255     } | 
| 257 | 256 | 
| 258     class Builder : public INHERITED::Builder { | 257     class Builder : public INHERITED::Builder { | 
| 259     public: | 258     public: | 
| 260         Builder(GrUniqueKey* key, Domain domain, int data32Count) | 259         Builder(GrUniqueKey* key, Domain domain, int data32Count) | 
| 261             : INHERITED::Builder(key, domain, data32Count) {} | 260             : INHERITED::Builder(key, domain, data32Count) {} | 
| 262 | 261 | 
| 263         /** Used to build a key that wraps another key and adds additional data.
      */ | 262         /** Used to build a key that wraps another key and adds additional data.
      */ | 
| 264         Builder(GrUniqueKey* key, const GrUniqueKey& innerKey, Domain domain, | 263         Builder(GrUniqueKey* key, const GrUniqueKey& innerKey, Domain domain, | 
| 265                 int extraData32Cnt) | 264                 int extraData32Cnt) | 
| 266             : INHERITED::Builder(key, domain, Data32CntForInnerKey(innerKey) + e
     xtraData32Cnt) { | 265             : INHERITED::Builder(key, domain, Data32CntForInnerKey(innerKey) + e
     xtraData32Cnt) { | 
| 267             SkASSERT(&innerKey != key); | 266             SkASSERT(&innerKey != key); | 
| 268             // add the inner key to the end of the key so that op[] can be index
     ed normally. | 267             // add the inner key to the end of the key so that op[] can be index
     ed normally. | 
| 269             uint32_t* innerKeyData = &this->operator[](extraData32Cnt); | 268             uint32_t* innerKeyData = &this->operator[](extraData32Cnt); | 
| 270             const uint32_t* srcData = innerKey.data(); | 269             const uint32_t* srcData = innerKey.data(); | 
| 271             (*innerKeyData++) = innerKey.domain(); | 270             (*innerKeyData++) = innerKey.domain(); | 
| 272             memcpy(innerKeyData, srcData, innerKey.dataSize()); | 271             memcpy(innerKeyData, srcData, innerKey.dataSize()); | 
| 273         } | 272         } | 
| 274 | 273 | 
| 275     private: | 274     private: | 
| 276         static int Data32CntForInnerKey(const GrUniqueKey& innerKey) { | 275         static int Data32CntForInnerKey(const GrUniqueKey& innerKey) { | 
| 277             // key data + domain | 276             // key data + domain | 
| 278             return SkToInt((innerKey.dataSize() >> 2) + 1); | 277             return SkToInt((innerKey.dataSize() >> 2) + 1); | 
| 279         } | 278         } | 
| 280     }; | 279     }; | 
| 281 | 280 | 
| 282 private: | 281 private: | 
| 283     SkAutoTUnref<const SkData> fData; | 282     sk_sp<SkData> fData; | 
| 284 }; | 283 }; | 
| 285 | 284 | 
| 286 /** | 285 /** | 
| 287  * It is common to need a frequently reused GrUniqueKey where the only requireme
     nt is that the key | 286  * 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 | 287  * 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. | 288  * and only constructed once. | 
| 290  */ | 289  */ | 
| 291 | 290 | 
| 292 /** Place outside of function/class definitions. */ | 291 /** Place outside of function/class definitions. */ | 
| 293 #define GR_DECLARE_STATIC_UNIQUE_KEY(name) static SkOnce name##_once | 292 #define GR_DECLARE_STATIC_UNIQUE_KEY(name) static SkOnce name##_once | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 314         fKey = that.fKey; | 313         fKey = that.fKey; | 
| 315         return *this; | 314         return *this; | 
| 316     } | 315     } | 
| 317 | 316 | 
| 318     const GrUniqueKey& key() const { return fKey; } | 317     const GrUniqueKey& key() const { return fKey; } | 
| 319 | 318 | 
| 320 private: | 319 private: | 
| 321     GrUniqueKey fKey; | 320     GrUniqueKey fKey; | 
| 322 }; | 321 }; | 
| 323 #endif | 322 #endif | 
| OLD | NEW | 
|---|