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
'<(skia_src_path)/gpu/GrReducedClip.h',
'<(skia_src_path)/gpu/GrResourceCache.cpp',
'<(skia_src_path)/gpu/GrResourceCache.h',
+ '<(skia_src_path)/gpu/GrResourceHandle.h',
'<(skia_src_path)/gpu/GrResourceProvider.cpp',
'<(skia_src_path)/gpu/GrResourceProvider.h',
'<(skia_src_path)/gpu/GrShape.cpp',
--- /dev/null
+/*
+ * 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
#ifndef GrGLSLProgramDataManager_DEFINED
#define GrGLSLProgramDataManager_DEFINED
+#include "GrResourceHandle.h"
#include "SkTypes.h"
class SkMatrix;
*/
class GrGLSLProgramDataManager : SkNoncopyable {
public:
- // Opaque handle to a resource
- class ShaderResourceHandle {
- public:
- ShaderResourceHandle(int value)
- : fValue(value) {
- SkASSERT(this->isValid());
- }
-
- ShaderResourceHandle()
- : fValue(kInvalid_ShaderResourceHandle) {
- }
-
- bool operator==(const ShaderResourceHandle& other) const { return other.fValue == fValue; }
- bool isValid() const { return kInvalid_ShaderResourceHandle != fValue; }
- int toIndex() const { SkASSERT(this->isValid()); return fValue; }
-
- private:
- static const int kInvalid_ShaderResourceHandle = -1;
- int fValue;
- };
-
- typedef ShaderResourceHandle UniformHandle;
+ GR_DEFINE_RESOURCE_HANDLE_CLASS(UniformHandle);
virtual ~GrGLSLProgramDataManager() {}
void setSkMatrix(UniformHandle, const SkMatrix&) const;
// for nvpr only
- typedef ShaderResourceHandle VaryingHandle;
+ GR_DEFINE_RESOURCE_HANDLE_CLASS(VaryingHandle);
virtual void setPathFragmentInputTransform(VaryingHandle u, int components,
const SkMatrix& matrix) const = 0;
GrGLSLProgramDataManager() {}
private:
-
typedef SkNoncopyable INHERITED;
};