diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index 462ef1c266..03bf48ffad 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -26,7 +26,7 @@ '<(skia_include_path)/gpu/GrPathRendererChain.h', '<(skia_include_path)/gpu/GrProgramElement.h', '<(skia_include_path)/gpu/GrProgramElementRef.h', - '<(skia_include_path)/gpu/GrProgramResource.h', + '<(skia_include_path)/gpu/GrGpuResourceRef.h', '<(skia_include_path)/gpu/GrRect.h', '<(skia_include_path)/gpu/GrRenderTarget.h', '<(skia_include_path)/gpu/GrResourceKey.h', @@ -111,7 +111,7 @@ '<(skia_src_path)/gpu/GrPathUtils.cpp', '<(skia_src_path)/gpu/GrPathUtils.h', '<(skia_src_path)/gpu/GrProgramElement.cpp', - '<(skia_src_path)/gpu/GrProgramResource.cpp', + '<(skia_src_path)/gpu/GrGpuResourceRef.cpp', '<(skia_src_path)/gpu/GrPictureUtils.h', '<(skia_src_path)/gpu/GrPictureUtils.cpp', '<(skia_src_path)/gpu/GrPlotMgr.h', diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h index 626f027ff3..911ee3985b 100644 --- a/include/gpu/GrGpuResource.h +++ b/include/gpu/GrGpuResource.h @@ -110,7 +110,7 @@ private: mutable int32_t fPendingWrites; // This class is used to manage conversion of refs to pending reads/writes. - friend class GrProgramResource; + friend class GrGpuResourceRef; }; /** diff --git a/include/gpu/GrProgramResource.h b/include/gpu/GrGpuResourceRef.h similarity index 82% rename from include/gpu/GrProgramResource.h rename to include/gpu/GrGpuResourceRef.h index 18cf4a70b7..28299f2b11 100644 --- a/include/gpu/GrProgramResource.h +++ b/include/gpu/GrGpuResourceRef.h @@ -5,8 +5,8 @@ * found in the LICENSE file. */ -#ifndef GrProgramResource_DEFINED -#define GrProgramResource_DEFINED +#ifndef GrGpuResourceRef_DEFINED +#define GrGpuResourceRef_DEFINED #include "SkRefCnt.h" @@ -17,9 +17,9 @@ class GrGpuResource; * converting refs to pending io operations. Like SkAutoTUnref, its constructor and setter adopt * a ref from their caller. This class is intended only for internal use in core Gr code. */ -class GrProgramResource : SkNoncopyable { +class GrGpuResourceRef : SkNoncopyable { public: - SK_DECLARE_INST_COUNT_ROOT(GrProgramResource); + SK_DECLARE_INST_COUNT_ROOT(GrGpuResourceRef); enum IOType { kRead_IOType, @@ -29,7 +29,7 @@ public: kNone_IOType, // For internal use only, don't specify to constructor or setResource(). }; - ~GrProgramResource(); + ~GrGpuResourceRef(); GrGpuResource* getResource() const { return fResource; } @@ -41,11 +41,11 @@ public: void reset(); protected: - GrProgramResource(); + GrGpuResourceRef(); /** 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); + GrGpuResourceRef(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. */ @@ -62,7 +62,7 @@ private: void removeRef() const; /** Called to indicate that the previous pending IO is complete. Useful when the owning object - still has refs, so it is not about to destroy this GrProgramResource, but its previously + still has refs, so it is not about to destroy this GrGpuResourceRef, but its previously pending executions have been complete. */ void pendingIOComplete() const; @@ -78,19 +78,22 @@ private: typedef SkNoncopyable INHERITED; }; -template class GrProgramTResource : public GrProgramResource { +template class GrTGpuResourceRef : public GrGpuResourceRef { public: - GrProgramTResource() {} + GrTGpuResourceRef() {} /** 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) {} + GrTGpuResourceRef(T* resource, IOType ioType) : INHERITED(resource, ioType) {} T* get() const { return static_cast(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); } + +private: + typedef GrGpuResourceRef INHERITED; }; diff --git a/include/gpu/GrProgramElement.h b/include/gpu/GrProgramElement.h index 5f88a2a68f..8d23ba2035 100644 --- a/include/gpu/GrProgramElement.h +++ b/include/gpu/GrProgramElement.h @@ -11,7 +11,7 @@ #include "SkRefCnt.h" #include "SkTArray.h" -class GrProgramResource; +class GrGpuResourceRef; /** * Base class for GrEffect (and future GrGeometryProcessor). GrDrawState uses this to manage @@ -19,8 +19,8 @@ class GrProgramResource; * converts resources owned by the effect from being ref'ed to having pending reads/writes. * * All GrGpuResource objects owned by a GrProgramElement or derived classes (either directly or - * indirectly) must be wrapped in a GrProgramResource and registered with the GrProgramElement using - * addGrProgramResource(). This allows the regular refs to be converted to pending IO events + * indirectly) must be wrapped in a GrGpuResourceRef and registered with the GrProgramElement using + * addGpuResource(). This allows the regular refs to be converted to pending IO events * when the program element is scheduled for deferred execution. */ class GrProgramElement : public SkNoncopyable { @@ -67,10 +67,10 @@ protected: /** Subclasses registers their resources using this function. It is assumed the GrProgramResouce is and will remain owned by the subclass and this function will retain a raw ptr. Once a - GrProgramResource is registered its setResource must not be called. + GrGpuResourceRef is registered its setResource must not be called. */ - void addProgramResource(const GrProgramResource* res) { - fProgramResources.push_back(res); + void addGpuResource(const GrGpuResourceRef* res) { + fGpuResources.push_back(res); } private: @@ -85,7 +85,7 @@ private: mutable int32_t fPendingExecutions; uint32_t fUniqueID; - SkSTArray<4, const GrProgramResource*, true> fProgramResources; + SkSTArray<4, const GrGpuResourceRef*, true> fGpuResources; // Only this class can access convertRefToPendingExecution() and completedExecution(). template friend class GrProgramElementRef; diff --git a/include/gpu/GrTextureAccess.h b/include/gpu/GrTextureAccess.h index 2fd17375b0..d552e440ca 100644 --- a/include/gpu/GrTextureAccess.h +++ b/include/gpu/GrTextureAccess.h @@ -8,7 +8,7 @@ #ifndef GrTextureAccess_DEFINED #define GrTextureAccess_DEFINED -#include "GrProgramResource.h" +#include "GrGpuResourceRef.h" #include "GrTexture.h" #include "SkRefCnt.h" #include "SkShader.h" @@ -167,7 +167,7 @@ public: /** * For internal use by GrEffect. */ - const GrProgramResource* getProgramTexture() const { return &fTexture; } + const GrGpuResourceRef* getProgramTexture() const { return &fTexture; } /** * Returns a string representing the swizzle. The string is is null-terminated. @@ -183,7 +183,7 @@ public: private: void setSwizzle(const char*); - typedef GrProgramTResource ProgramTexture; + typedef GrTGpuResourceRef ProgramTexture; ProgramTexture fTexture; GrTextureParams fParams; diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h index f04d592713..4d720624aa 100644 --- a/src/gpu/GrDrawState.h +++ b/src/gpu/GrDrawState.h @@ -9,7 +9,7 @@ #define GrDrawState_DEFINED #include "GrBlend.h" -#include "GrProgramResource.h" +#include "GrGpuResourceRef.h" #include "GrRODrawState.h" #include "effects/GrSimpleTextureEffect.h" @@ -405,7 +405,7 @@ public: * @param target The render target to set. */ void setRenderTarget(GrRenderTarget* target) { - fRenderTarget.set(SkSafeRef(target), GrProgramResource::kWrite_IOType); + fRenderTarget.set(SkSafeRef(target), GrGpuResourceRef::kWrite_IOType); this->invalidateOptState(); } diff --git a/src/gpu/GrEffect.cpp b/src/gpu/GrEffect.cpp index 50a198002f..28c23d7da6 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->getProgramTexture()); + this->addGpuResource(access->getProgramTexture()); } void* GrEffect::operator new(size_t size) { diff --git a/src/gpu/GrProgramResource.cpp b/src/gpu/GrGpuResourceRef.cpp similarity index 83% rename from src/gpu/GrProgramResource.cpp rename to src/gpu/GrGpuResourceRef.cpp index 482caff7ee..74b1ef0eba 100644 --- a/src/gpu/GrProgramResource.cpp +++ b/src/gpu/GrGpuResourceRef.cpp @@ -5,24 +5,24 @@ * found in the LICENSE file. */ -#include "GrProgramResource.h" +#include "GrGpuResourceRef.h" #include "GrGpuResource.h" -GrProgramResource::GrProgramResource() { +GrGpuResourceRef::GrGpuResourceRef() { fResource = NULL; fOwnRef = false; fPendingIO = false; fIOType = kNone_IOType; } -GrProgramResource::GrProgramResource(GrGpuResource* resource, IOType ioType) { +GrGpuResourceRef::GrGpuResourceRef(GrGpuResource* resource, IOType ioType) { fResource = NULL; fOwnRef = false; fPendingIO = false; this->setResource(resource, ioType); } -GrProgramResource::~GrProgramResource() { +GrGpuResourceRef::~GrGpuResourceRef() { if (fOwnRef) { SkASSERT(fResource); fResource->unref(); @@ -46,7 +46,7 @@ GrProgramResource::~GrProgramResource() { } } -void GrProgramResource::reset() { +void GrGpuResourceRef::reset() { SkASSERT(!fPendingIO); SkASSERT(SkToBool(fResource) == fOwnRef); if (fOwnRef) { @@ -57,7 +57,7 @@ void GrProgramResource::reset() { } } -void GrProgramResource::setResource(GrGpuResource* resource, IOType ioType) { +void GrGpuResourceRef::setResource(GrGpuResource* resource, IOType ioType) { SkASSERT(!fPendingIO); SkASSERT(SkToBool(fResource) == fOwnRef); SkSafeUnref(fResource); @@ -73,7 +73,7 @@ void GrProgramResource::setResource(GrGpuResource* resource, IOType ioType) { } } -void GrProgramResource::markPendingIO() const { +void GrGpuResourceRef::markPendingIO() const { // This should only be called when the owning GrProgramElement gets its first // pendingExecution ref. SkASSERT(!fPendingIO); @@ -81,7 +81,7 @@ void GrProgramResource::markPendingIO() const { fPendingIO = true; switch (fIOType) { case kNone_IOType: - SkFAIL("GrProgramResource with neither reads nor writes?"); + SkFAIL("GrGpuResourceRef with neither reads nor writes?"); break; case kRead_IOType: fResource->addPendingRead(); @@ -97,14 +97,14 @@ void GrProgramResource::markPendingIO() const { } } -void GrProgramResource::pendingIOComplete() const { +void GrGpuResourceRef::pendingIOComplete() const { // This should only be called when the owner's pending executions have ocurred but it is still // reffed. SkASSERT(fOwnRef); SkASSERT(fPendingIO); switch (fIOType) { case kNone_IOType: - SkFAIL("GrProgramResource with neither reads nor writes?"); + SkFAIL("GrGpuResourceRef with neither reads nor writes?"); break; case kRead_IOType: fResource->completedRead(); @@ -121,7 +121,7 @@ void GrProgramResource::pendingIOComplete() const { fPendingIO = false; } -void GrProgramResource::removeRef() const { +void GrGpuResourceRef::removeRef() const { // This should only be called once, when the owners last ref goes away and // there is a pending execution. SkASSERT(fOwnRef); diff --git a/src/gpu/GrProgramElement.cpp b/src/gpu/GrProgramElement.cpp index 20a957f7c7..2c3085f7e4 100644 --- a/src/gpu/GrProgramElement.cpp +++ b/src/gpu/GrProgramElement.cpp @@ -6,7 +6,7 @@ */ #include "GrProgramElement.h" -#include "GrProgramResource.h" +#include "GrGpuResourceRef.h" uint32_t GrProgramElement::CreateUniqueID() { static int32_t gUniqueID = SK_InvalidUniqueID; @@ -18,21 +18,21 @@ uint32_t GrProgramElement::CreateUniqueID() { } void GrProgramElement::convertRefToPendingExecution() const { - // This function makes it so that all the GrProgramResources own a single ref to their + // This function makes it so that all the GrGpuResourceRefs own a single ref to their // underlying GrGpuResource if there are any refs to the GrProgramElement and a single // pending read/write if there are any pending executions of the GrProgramElement. The - // GrProgramResource will give up its single ref and/or pending read/write in its destructor. + // GrGpuResourceRef will give up its single ref and/or pending read/write in its destructor. SkASSERT(fRefCnt > 0); if (0 == fPendingExecutions) { - for (int i = 0; i < fProgramResources.count(); ++i) { - fProgramResources[i]->markPendingIO(); + for (int i = 0; i < fGpuResources.count(); ++i) { + fGpuResources[i]->markPendingIO(); } } ++fPendingExecutions; this->unref(); if (0 == fRefCnt) { - for (int i = 0; i < fProgramResources.count(); ++i) { - fProgramResources[i]->removeRef(); + for (int i = 0; i < fGpuResources.count(); ++i) { + fGpuResources[i]->removeRef(); } } } @@ -46,8 +46,8 @@ void GrProgramElement::completedExecution() const { } else { // Now our pending executions have ocurred and we still have refs. Convert // ownership of our resources back to regular refs. - for (int i = 0; i < fProgramResources.count(); ++i) { - fProgramResources[i]->pendingIOComplete(); + for (int i = 0; i < fGpuResources.count(); ++i) { + fGpuResources[i]->pendingIOComplete(); } } diff --git a/src/gpu/GrRODrawState.cpp b/src/gpu/GrRODrawState.cpp index 26edb18c06..4d35684e5c 100644 --- a/src/gpu/GrRODrawState.cpp +++ b/src/gpu/GrRODrawState.cpp @@ -14,7 +14,7 @@ GrRODrawState::GrRODrawState(const GrRODrawState& drawState) : INHERITED() { fRenderTarget.setResource(SkSafeRef(drawState.fRenderTarget.getResource()), - GrProgramResource::kWrite_IOType); + GrGpuResourceRef::kWrite_IOType); } bool GrRODrawState::isEqual(const GrRODrawState& that) const { diff --git a/src/gpu/GrRODrawState.h b/src/gpu/GrRODrawState.h index 7e57b089b0..75e36a6ab0 100644 --- a/src/gpu/GrRODrawState.h +++ b/src/gpu/GrRODrawState.h @@ -397,7 +397,7 @@ protected: GrBlendCoeff* srcCoeff = NULL, GrBlendCoeff* dstCoeff = NULL) const; - typedef GrProgramTResource ProgramRenderTarget; + typedef GrTGpuResourceRef ProgramRenderTarget; // These fields are roughly sorted by decreasing likelihood of being different in op== ProgramRenderTarget fRenderTarget; GrColor fColor; diff --git a/src/gpu/GrTextureAccess.cpp b/src/gpu/GrTextureAccess.cpp index c4cde3dbaf..3e543ca75f 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.set(SkRef(texture), GrProgramResource::kRead_IOType); + fTexture.set(SkRef(texture), GrGpuResourceRef::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.set(SkRef(texture), GrProgramResource::kRead_IOType); + fTexture.set(SkRef(texture), GrGpuResourceRef::kRead_IOType); this->setSwizzle(swizzle); } void GrTextureAccess::reset(GrTexture* texture, const GrTextureParams& params) { SkASSERT(texture); - fTexture.set(SkRef(texture), GrProgramResource::kRead_IOType); + fTexture.set(SkRef(texture), GrGpuResourceRef::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.set(SkRef(texture), GrProgramResource::kRead_IOType); + fTexture.set(SkRef(texture), GrGpuResourceRef::kRead_IOType); fParams.reset(tileXAndY, filterMode); memcpy(fSwizzle, "rgba", 5); fSwizzleMask = kRGBA_GrColorComponentFlags;