Index: src/gpu/GrResourceHandle.h |
diff --git a/src/gpu/GrResourceHandle.h b/src/gpu/GrResourceHandle.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..97a6ec73814ac5c3c77c4c71431942667c462473 |
--- /dev/null |
+++ b/src/gpu/GrResourceHandle.h |
@@ -0,0 +1,46 @@ |
+/* |
+ * 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 |
+class GrResourceHandle { |
+public: |
+ GrResourceHandle(int value) : fValue(value) { |
+ SkASSERT(this->isValid()); |
+ } |
+ |
+ GrResourceHandle() : fValue(kInvalid_ResourceHandle) {} |
+protected: |
+ 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 resource handle class with the name, name, which exposes the protected functions of the |
+// handle class to be used on the sub class |
+#define GR_CREATE_RESOURCE_HANDLE_CLASS(name) \ |
bsalomon
2016/05/06 17:37:54
What do you think about simplifying this by making
|
+ class name : public GrResourceHandle { \ |
+ private: \ |
+ typedef GrResourceHandle INHERITED; \ |
+ public: \ |
+ using INHERITED::INHERITED; \ |
+ using INHERITED::operator==; \ |
+ using INHERITED::isValid; \ |
+ using INHERITED::toIndex; \ |
+ } |
+ |
+ |
+ |
+#endif |