Make templated GrProgramTResource subclass of GrProgramResource
R=robertphillips@google.com
Author: bsalomon@google.com
Review URL: https://codereview.chromium.org/563963004
diff --git a/include/gpu/GrProgramResource.h b/include/gpu/GrProgramResource.h
index 61e71de..18cf4a7 100644
--- a/include/gpu/GrProgramResource.h
+++ b/include/gpu/GrProgramResource.h
@@ -19,6 +19,8 @@
*/
class GrProgramResource : SkNoncopyable {
public:
+ SK_DECLARE_INST_COUNT_ROOT(GrProgramResource);
+
enum IOType {
kRead_IOType,
kWrite_IOType,
@@ -27,21 +29,10 @@
kNone_IOType, // For internal use only, don't specify to constructor or setResource().
};
- SK_DECLARE_INST_COUNT_ROOT(GrProgramResource);
- GrProgramResource();
-
- /** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as
- pending on the resource when markPendingIO is called. */
- explicit GrProgramResource(GrGpuResource*, IOType ioType);
-
~GrProgramResource();
GrGpuResource* getResource() const { return fResource; }
- /** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as
- pending on the resource when markPendingIO is called. */
- void setResource(GrGpuResource*, IOType ioType);
-
/** Does this object own a pending read or write on the resource it is wrapping. */
bool ownsPendingIO() const { return fPendingIO; }
@@ -49,6 +40,17 @@
is called. */
void reset();
+protected:
+ GrProgramResource();
+
+ /** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as
+ pending on the resource when markPendingIO is called. */
+ GrProgramResource(GrGpuResource*, IOType);
+
+ /** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as
+ pending on the resource when markPendingIO is called. */
+ void setResource(GrGpuResource*, IOType);
+
private:
/** Called by owning GrProgramElement when the program element is first scheduled for
execution. */
@@ -76,4 +78,20 @@
typedef SkNoncopyable INHERITED;
};
+template <typename T> class GrProgramTResource : public GrProgramResource {
+public:
+ GrProgramTResource() {}
+
+ /** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as
+ pending on the resource when markPendingIO is called. */
+ GrProgramTResource(T* resource, IOType ioType) : GrProgramResource(resource, ioType) {}
+
+ T* get() const { return static_cast<T*>(this->getResource()); }
+
+ /** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as
+ pending on the resource when markPendingIO is called. */
+ void set(T* resource, IOType ioType) { this->setResource(resource, ioType); }
+};
+
+
#endif
diff --git a/include/gpu/GrTextureAccess.h b/include/gpu/GrTextureAccess.h
index 3d44d9e..2fd1737 100644
--- a/include/gpu/GrTextureAccess.h
+++ b/include/gpu/GrTextureAccess.h
@@ -8,11 +8,10 @@
#ifndef GrTextureAccess_DEFINED
#define GrTextureAccess_DEFINED
+#include "GrProgramResource.h"
+#include "GrTexture.h"
#include "SkRefCnt.h"
#include "SkShader.h"
-#include "GrProgramResource.h"
-
-class GrTexture;
/**
* Represents the filtering and tile modes used to access a texture. It is mostly used with
@@ -163,12 +162,12 @@
bool operator!= (const GrTextureAccess& other) const { return !(*this == other); }
- GrTexture* getTexture() const { return (GrTexture*)fTexture.getResource(); }
+ GrTexture* getTexture() const { return fTexture.get(); }
/**
* For internal use by GrEffect.
*/
- const GrProgramResource* getTextureProgramResource() const { return &fTexture; }
+ const GrProgramResource* getProgramTexture() const { return &fTexture; }
/**
* Returns a string representing the swizzle. The string is is null-terminated.
@@ -184,7 +183,9 @@
private:
void setSwizzle(const char*);
- GrProgramResource fTexture;
+ typedef GrProgramTResource<GrTexture> ProgramTexture;
+
+ ProgramTexture fTexture;
GrTextureParams fParams;
uint32_t fSwizzleMask;
char fSwizzle[5];
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 4869658..f04d592 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -405,7 +405,7 @@
* @param target The render target to set.
*/
void setRenderTarget(GrRenderTarget* target) {
- fRenderTarget.setResource(SkSafeRef(target), GrProgramResource::kWrite_IOType);
+ fRenderTarget.set(SkSafeRef(target), GrProgramResource::kWrite_IOType);
this->invalidateOptState();
}
diff --git a/src/gpu/GrEffect.cpp b/src/gpu/GrEffect.cpp
index b8d945e..50a1980 100644
--- a/src/gpu/GrEffect.cpp
+++ b/src/gpu/GrEffect.cpp
@@ -72,7 +72,7 @@
void GrEffect::addTextureAccess(const GrTextureAccess* access) {
fTextureAccesses.push_back(access);
- this->addProgramResource(access->getTextureProgramResource());
+ this->addProgramResource(access->getProgramTexture());
}
void* GrEffect::operator new(size_t size) {
diff --git a/src/gpu/GrRODrawState.h b/src/gpu/GrRODrawState.h
index eea6f9b..7e57b08 100644
--- a/src/gpu/GrRODrawState.h
+++ b/src/gpu/GrRODrawState.h
@@ -397,8 +397,9 @@
GrBlendCoeff* srcCoeff = NULL,
GrBlendCoeff* dstCoeff = NULL) const;
+ typedef GrProgramTResource<GrRenderTarget> ProgramRenderTarget;
// These fields are roughly sorted by decreasing likelihood of being different in op==
- GrProgramResource fRenderTarget;
+ ProgramRenderTarget fRenderTarget;
GrColor fColor;
SkMatrix fViewMatrix;
GrColor fBlendConstant;
diff --git a/src/gpu/GrTextureAccess.cpp b/src/gpu/GrTextureAccess.cpp
index 0886db4..c4cde3d 100644
--- a/src/gpu/GrTextureAccess.cpp
+++ b/src/gpu/GrTextureAccess.cpp
@@ -46,7 +46,7 @@
SkASSERT(strlen(swizzle) >= 1 && strlen(swizzle) <= 4);
fParams = params;
- fTexture.setResource(SkRef(texture), GrProgramResource::kRead_IOType);
+ fTexture.set(SkRef(texture), GrProgramResource::kRead_IOType);
this->setSwizzle(swizzle);
}
@@ -58,14 +58,14 @@
SkASSERT(strlen(swizzle) >= 1 && strlen(swizzle) <= 4);
fParams.reset(tileXAndY, filterMode);
- fTexture.setResource(SkRef(texture), GrProgramResource::kRead_IOType);
+ fTexture.set(SkRef(texture), GrProgramResource::kRead_IOType);
this->setSwizzle(swizzle);
}
void GrTextureAccess::reset(GrTexture* texture,
const GrTextureParams& params) {
SkASSERT(texture);
- fTexture.setResource(SkRef(texture), GrProgramResource::kRead_IOType);
+ fTexture.set(SkRef(texture), GrProgramResource::kRead_IOType);
fParams = params;
memcpy(fSwizzle, "rgba", 5);
fSwizzleMask = kRGBA_GrColorComponentFlags;
@@ -75,7 +75,7 @@
GrTextureParams::FilterMode filterMode,
SkShader::TileMode tileXAndY) {
SkASSERT(texture);
- fTexture.setResource(SkRef(texture), GrProgramResource::kRead_IOType);
+ fTexture.set(SkRef(texture), GrProgramResource::kRead_IOType);
fParams.reset(tileXAndY, filterMode);
memcpy(fSwizzle, "rgba", 5);
fSwizzleMask = kRGBA_GrColorComponentFlags;