From 167ab9198025e577efe033612d2e009633abb54b Mon Sep 17 00:00:00 2001 From: egdaniel Date: Mon, 9 May 2016 11:03:48 -0700 Subject: [PATCH] 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 --- gyp/gpu.gypi | 1 + src/gpu/GrResourceHandle.h | 36 +++++++++++++++++++++++++ src/gpu/glsl/GrGLSLProgramDataManager.h | 27 +++---------------- 3 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 src/gpu/GrResourceHandle.h diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index f0bb333e94..6b4837a992 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -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', 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 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; +#endif diff --git a/src/gpu/glsl/GrGLSLProgramDataManager.h b/src/gpu/glsl/GrGLSLProgramDataManager.h index e578e11808..5d502cfd75 100644 --- a/src/gpu/glsl/GrGLSLProgramDataManager.h +++ b/src/gpu/glsl/GrGLSLProgramDataManager.h @@ -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; }; -- 2.34.1