aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/gpu/GrProgramResource.h40
-rw-r--r--include/gpu/GrTextureAccess.h13
-rw-r--r--src/gpu/GrDrawState.h2
-rw-r--r--src/gpu/GrEffect.cpp2
-rw-r--r--src/gpu/GrRODrawState.h3
-rw-r--r--src/gpu/GrTextureAccess.cpp8
6 files changed, 44 insertions, 24 deletions
diff --git a/include/gpu/GrProgramResource.h b/include/gpu/GrProgramResource.h
index 61e71ded19..18cf4a70b7 100644
--- a/include/gpu/GrProgramResource.h
+++ b/include/gpu/GrProgramResource.h
@@ -19,6 +19,8 @@ class GrGpuResource;
*/
class GrProgramResource : SkNoncopyable {
public:
+ SK_DECLARE_INST_COUNT_ROOT(GrProgramResource);
+
enum IOType {
kRead_IOType,
kWrite_IOType,
@@ -27,21 +29,10 @@ public:
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 @@ public:
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 @@ private:
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 3d44d9e44f..2fd17375b0 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 @@ public:
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 @@ public:
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 4869658b4f..f04d592713 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -405,7 +405,7 @@ public:
* @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 b8d945edc6..50a198002f 100644
--- a/src/gpu/GrEffect.cpp
+++ b/src/gpu/GrEffect.cpp
@@ -72,7 +72,7 @@ void GrEffect::addCoordTransform(const GrCoordTransform* transform) {
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 eea6f9b98a..7e57b089b0 100644
--- a/src/gpu/GrRODrawState.h
+++ b/src/gpu/GrRODrawState.h
@@ -397,8 +397,9 @@ protected:
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 0886db411a..c4cde3dbaf 100644
--- a/src/gpu/GrTextureAccess.cpp
+++ b/src/gpu/GrTextureAccess.cpp
@@ -46,7 +46,7 @@ void GrTextureAccess::reset(GrTexture* texture,
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 @@ void GrTextureAccess::reset(GrTexture* texture,
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 @@ void GrTextureAccess::reset(GrTexture* texture,
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;