diff options
author | egdaniel <egdaniel@google.com> | 2016-05-09 11:03:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-09 11:03:48 -0700 |
commit | 167ab9198025e577efe033612d2e009633abb54b (patch) | |
tree | 71386614fe8350b9c453d4cec30430e7605e60d3 /src/gpu/GrResourceHandle.h | |
parent | fe8a8392217072fdd5505edc3876a9698608ada1 (diff) |
Allow gpu ResourceHandle class to be shared for multiple purposes
Currently this class was just used for resource handles when building up
a shader. However, I want to now use this class for things like objects
owned/held by the GrVkResourceProvider which are used by other classes.
An example of this will be for GrVkRenderTargets to hold a handle to a
collection of compatible render passes without having to own/hold onto
the render passes themselves.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1955893002
Review-Url: https://codereview.chromium.org/1955893002
Diffstat (limited to 'src/gpu/GrResourceHandle.h')
-rw-r--r-- | src/gpu/GrResourceHandle.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/gpu/GrResourceHandle.h b/src/gpu/GrResourceHandle.h new file mode 100644 index 0000000000..383bbea6c7 --- /dev/null +++ b/src/gpu/GrResourceHandle.h @@ -0,0 +1,36 @@ +/* + * 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 +// template instantiation of GrResourceHandle. +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", which is a specfic template instantiation of GrResourceHandle. +#define GR_DEFINE_RESOURCE_HANDLE_CLASS(name) \ + struct name##Kind {}; \ + using name = GrResourceHandle<name##Kind>; +#endif |