Rename GrProgramResource to GrGpuResourceRef

BUG=skia:2889
R=robertphillips@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/574333003
This commit is contained in:
bsalomon 2014-09-17 08:05:40 -07:00 committed by Commit bot
parent 4aa6dfc0b7
commit f96ba02513
12 changed files with 56 additions and 53 deletions

View File

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

View File

@ -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;
};
/**

View File

@ -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 <typename T> class GrProgramTResource : public GrProgramResource {
template <typename T> 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<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); }
private:
typedef GrGpuResourceRef INHERITED;
};

View File

@ -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 <typename T> friend class GrProgramElementRef;

View File

@ -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<GrTexture> ProgramTexture;
typedef GrTGpuResourceRef<GrTexture> ProgramTexture;
ProgramTexture fTexture;
GrTextureParams fParams;

View File

@ -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();
}

View File

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

View File

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

View File

@ -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();
}
}

View File

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

View File

@ -397,7 +397,7 @@ protected:
GrBlendCoeff* srcCoeff = NULL,
GrBlendCoeff* dstCoeff = NULL) const;
typedef GrProgramTResource<GrRenderTarget> ProgramRenderTarget;
typedef GrTGpuResourceRef<GrRenderTarget> ProgramRenderTarget;
// These fields are roughly sorted by decreasing likelihood of being different in op==
ProgramRenderTarget fRenderTarget;
GrColor fColor;

View File

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