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
This commit is contained in:
egdaniel 2016-05-09 11:03:48 -07:00 committed by Commit bot
parent fe8a839221
commit 167ab91980
3 changed files with 40 additions and 24 deletions

View File

@ -165,6 +165,7 @@
'<(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',

View File

@ -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

View File

@ -8,6 +8,7 @@
#ifndef GrGLSLProgramDataManager_DEFINED
#define GrGLSLProgramDataManager_DEFINED
#include "GrResourceHandle.h"
#include "SkTypes.h"
class SkMatrix;
@ -18,28 +19,7 @@ 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() {}
@ -67,7 +47,7 @@ public:
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;
@ -75,7 +55,6 @@ protected:
GrGLSLProgramDataManager() {}
private:
typedef SkNoncopyable INHERITED;
};