Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2016 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef GrResourceHandle_DEFINED | |
| 9 #define GrResourcehandle_DEFINED | |
| 10 | |
| 11 #include "SkTypes.h" | |
| 12 | |
| 13 // Opaque handle to a resource. Users should always use the macro below to creat e a specific indexed | |
| 14 // version of the class. No function should ever take a generic GrResourceHandle and instead use | |
|
bsalomon
2016/05/06 18:40:56
Maybe remove the last sentence? One of the benefit
| |
| 15 // a specific type indexed one. | |
| 16 template <typename kind> class GrResourceHandle { | |
| 17 public: | |
| 18 GrResourceHandle(int value) : fValue(value) { | |
| 19 SkASSERT(this->isValid()); | |
| 20 } | |
| 21 | |
| 22 GrResourceHandle() : fValue(kInvalid_ResourceHandle) {} | |
| 23 | |
| 24 bool operator==(const GrResourceHandle& other) const { return other.fValue = = fValue; } | |
| 25 bool isValid() const { return kInvalid_ResourceHandle != fValue; } | |
| 26 int toIndex() const { SkASSERT(this->isValid()); return fValue; } | |
| 27 | |
| 28 private: | |
| 29 static const int kInvalid_ResourceHandle = -1; | |
| 30 int fValue; | |
| 31 }; | |
| 32 | |
| 33 // Creates a type "name" that is a specfic type index of GrResourceHandle. | |
| 34 #define GR_DEFINE_RESOURCE_HANDLE_CLASS(name) \ | |
| 35 struct name##Kind {}; \ | |
| 36 using name = GrResourceHandle<name##Kind>; | |
| 37 #endif | |
| OLD | NEW |