Chromium Code Reviews| Index: src/gpu/GrResourceHandle.h |
| diff --git a/src/gpu/GrResourceHandle.h b/src/gpu/GrResourceHandle.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..47de8a16e6e6397d65a4fa6c55b308fa83c60ff8 |
| --- /dev/null |
| +++ b/src/gpu/GrResourceHandle.h |
| @@ -0,0 +1,37 @@ |
| +/* |
| + * Copyright 2016 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| +*/ |
| + |
| +#ifndef GrResourceHandle_DEFINED |
| +#define GrResourcehandle_DEFINED |
| + |
| +#include "SkTypes.h" |
| + |
| +// Opaque handle to a resource. Users should always use the macro below to create a specific indexed |
| +// 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
|
| +// a specific type indexed one. |
| +template <typename kind> class GrResourceHandle { |
| +public: |
| + GrResourceHandle(int value) : fValue(value) { |
| + SkASSERT(this->isValid()); |
| + } |
| + |
| + GrResourceHandle() : fValue(kInvalid_ResourceHandle) {} |
| + |
| + bool operator==(const GrResourceHandle& other) const { return other.fValue == fValue; } |
| + bool isValid() const { return kInvalid_ResourceHandle != fValue; } |
| + int toIndex() const { SkASSERT(this->isValid()); return fValue; } |
| + |
| +private: |
| + static const int kInvalid_ResourceHandle = -1; |
| + int fValue; |
| +}; |
| + |
| +// Creates a type "name" that is a specfic type index of GrResourceHandle. |
| +#define GR_DEFINE_RESOURCE_HANDLE_CLASS(name) \ |
| + struct name##Kind {}; \ |
| + using name = GrResourceHandle<name##Kind>; |
| +#endif |