Make GrGpuResources register with GrResourceCache2 after fully constructed.

R=robertphillips@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/504313002
This commit is contained in:
bsalomon 2014-08-26 12:51:20 -07:00 committed by Commit bot
parent 5e5f948b6b
commit d68b3e491b
15 changed files with 29 additions and 1 deletions

View File

@ -27,6 +27,7 @@ public:
StencilResource(GrGpu* gpu, int id) StencilResource(GrGpu* gpu, int id)
: INHERITED(gpu, false) : INHERITED(gpu, false)
, fID(id) { , fID(id) {
this->registerWithCache();
} }
virtual ~StencilResource() { this->release(); } virtual ~StencilResource() { this->release(); }
@ -51,6 +52,7 @@ public:
TextureResource(GrGpu* gpu, int id) TextureResource(GrGpu* gpu, int id)
: INHERITED(gpu, false) : INHERITED(gpu, false)
, fID(id) { , fID(id) {
this->registerWithCache();
} }
virtual ~TextureResource() { this->release(); } virtual ~TextureResource() { this->release(); }

View File

@ -90,6 +90,11 @@ public:
uint32_t getUniqueID() const { return fUniqueID; } uint32_t getUniqueID() const { return fUniqueID; }
protected: protected:
// This must be called by every GrGpuObject. It should be called once the object is fully
// initialized (i.e. not in a base class constructor).
void registerWithCache();
GrGpuResource(GrGpu*, bool isWrapped); GrGpuResource(GrGpu*, bool isWrapped);
virtual ~GrGpuResource(); virtual ~GrGpuResource();

View File

@ -28,6 +28,9 @@ GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped)
} else { } else {
fFlags = 0; fFlags = 0;
} }
}
void GrGpuResource::registerWithCache() {
get_resource_cache2(fGpu)->insertResource(this); get_resource_cache2(fGpu)->insertResource(this);
} }
@ -37,7 +40,7 @@ GrGpuResource::~GrGpuResource() {
SkASSERT(this->wasDestroyed()); SkASSERT(this->wasDestroyed());
} }
void GrGpuResource::release() { void GrGpuResource::release() {
if (NULL != fGpu) { if (NULL != fGpu) {
this->onRelease(); this->onRelease();
get_resource_cache2(fGpu)->removeResource(this); get_resource_cache2(fGpu)->removeResource(this);

View File

@ -38,6 +38,7 @@ public:
: INHERITED(gpu, kIsWrapped), : INHERITED(gpu, kIsWrapped),
fSize(size), fSize(size),
fStroke(stroke) { fStroke(stroke) {
this->registerWithCache();
} }
size_t getSize() const { return fSize; } size_t getSize() const { return fSize; }

View File

@ -17,11 +17,13 @@ GrResourceCache2::~GrResourceCache2() {
void GrResourceCache2::insertResource(GrGpuResource* resource) { void GrResourceCache2::insertResource(GrGpuResource* resource) {
SkASSERT(NULL != resource); SkASSERT(NULL != resource);
SkASSERT(!resource->wasDestroyed()); SkASSERT(!resource->wasDestroyed());
SkASSERT(!this->isInCache(resource));
fResources.addToHead(resource); fResources.addToHead(resource);
++fCount; ++fCount;
} }
void GrResourceCache2::removeResource(GrGpuResource* resource) { void GrResourceCache2::removeResource(GrGpuResource* resource) {
SkASSERT(this->isInCache(resource));
fResources.remove(resource); fResources.remove(resource);
--fCount; --fCount;
} }

View File

@ -33,6 +33,12 @@ public:
void releaseAll(); void releaseAll();
private: private:
#ifdef SK_DEBUG
bool isInCache(const GrGpuResource* r) const {
return fResources.isInList(r);
}
#endif
int fCount; int fCount;
SkTInternalLList<GrGpuResource> fResources; SkTInternalLList<GrGpuResource> fResources;
}; };

View File

@ -43,6 +43,7 @@ public:
glyphs.reset(SkNEW_ARGS(GlyphPathRange, (context, cache->getDescriptor(), stroke))); glyphs.reset(SkNEW_ARGS(GlyphPathRange, (context, cache->getDescriptor(), stroke)));
context->addResourceToCache(resourceKey, glyphs); context->addResourceToCache(resourceKey, glyphs);
} }
glyphs->registerWithCache();
return glyphs.detach(); return glyphs.detach();
} }

View File

@ -11,6 +11,7 @@
GrGLIndexBuffer::GrGLIndexBuffer(GrGpuGL* gpu, const Desc& desc) GrGLIndexBuffer::GrGLIndexBuffer(GrGpuGL* gpu, const Desc& desc)
: INHERITED(gpu, desc.fIsWrapped, desc.fSizeInBytes, desc.fDynamic, 0 == desc.fID) : INHERITED(gpu, desc.fIsWrapped, desc.fSizeInBytes, desc.fDynamic, 0 == desc.fID)
, fImpl(gpu, desc, GR_GL_ELEMENT_ARRAY_BUFFER) { , fImpl(gpu, desc, GR_GL_ELEMENT_ARRAY_BUFFER) {
this->registerWithCache();
} }
void GrGLIndexBuffer::onRelease() { void GrGLIndexBuffer::onRelease() {

View File

@ -136,6 +136,7 @@ GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke)
// FIXME: try to account for stroking, without rasterizing the stroke. // FIXME: try to account for stroking, without rasterizing the stroke.
fBounds.outset(stroke.getWidth(), stroke.getWidth()); fBounds.outset(stroke.getWidth(), stroke.getWidth());
} }
this->registerWithCache();
} }
GrGLPath::~GrGLPath() { GrGLPath::~GrGLPath() {

View File

@ -21,6 +21,7 @@ void GrGLRenderTarget::init(const Desc& desc,
fMSColorRenderbufferID = desc.fMSColorRenderbufferID; fMSColorRenderbufferID = desc.fMSColorRenderbufferID;
fViewport = viewport; fViewport = viewport;
fTexIDObj.reset(SkSafeRef(texID)); fTexIDObj.reset(SkSafeRef(texID));
this->registerWithCache();
} }
namespace { namespace {

View File

@ -32,6 +32,7 @@ public:
: GrStencilBuffer(gpu, isWrapped, width, height, format.fStencilBits, sampleCnt) : GrStencilBuffer(gpu, isWrapped, width, height, format.fStencilBits, sampleCnt)
, fFormat(format) , fFormat(format)
, fRenderbufferID(rbid) { , fRenderbufferID(rbid) {
this->registerWithCache();
} }
virtual ~GrGLStencilBuffer(); virtual ~GrGLStencilBuffer();

View File

@ -33,6 +33,7 @@ void GrGLTexture::init(GrGpuGL* gpu,
fRenderTarget.reset(SkNEW_ARGS(GrGLRenderTarget, (gpu, *rtDesc, vp, fTexIDObj, this))); fRenderTarget.reset(SkNEW_ARGS(GrGLRenderTarget, (gpu, *rtDesc, vp, fTexIDObj, this)));
} }
this->registerWithCache();
} }
GrGLTexture::GrGLTexture(GrGpuGL* gpu, GrGLTexture::GrGLTexture(GrGpuGL* gpu,

View File

@ -73,6 +73,7 @@ GrGLVertexArray::GrGLVertexArray(GrGpuGL* gpu, GrGLint id, int attribCount)
, fID(id) , fID(id)
, fAttribArrays(attribCount) , fAttribArrays(attribCount)
, fIndexBufferIDIsValid(false) { , fIndexBufferIDIsValid(false) {
this->registerWithCache();
} }
void GrGLVertexArray::onAbandon() { void GrGLVertexArray::onAbandon() {

View File

@ -11,6 +11,7 @@
GrGLVertexBuffer::GrGLVertexBuffer(GrGpuGL* gpu, const Desc& desc) GrGLVertexBuffer::GrGLVertexBuffer(GrGpuGL* gpu, const Desc& desc)
: INHERITED(gpu, desc.fIsWrapped, desc.fSizeInBytes, desc.fDynamic, 0 == desc.fID) : INHERITED(gpu, desc.fIsWrapped, desc.fSizeInBytes, desc.fDynamic, 0 == desc.fID)
, fImpl(gpu, desc, GR_GL_ARRAY_BUFFER) { , fImpl(gpu, desc, GR_GL_ARRAY_BUFFER) {
this->registerWithCache();
} }
void GrGLVertexBuffer::onRelease() { void GrGLVertexBuffer::onRelease() {

View File

@ -69,6 +69,7 @@ public:
, fToDelete(NULL) , fToDelete(NULL)
, fSize(size) { , fSize(size) {
++fAlive; ++fAlive;
this->registerWithCache();
} }
~TestResource() { ~TestResource() {