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:
parent
5e5f948b6b
commit
d68b3e491b
@ -27,6 +27,7 @@ public:
|
||||
StencilResource(GrGpu* gpu, int id)
|
||||
: INHERITED(gpu, false)
|
||||
, fID(id) {
|
||||
this->registerWithCache();
|
||||
}
|
||||
|
||||
virtual ~StencilResource() { this->release(); }
|
||||
@ -51,6 +52,7 @@ public:
|
||||
TextureResource(GrGpu* gpu, int id)
|
||||
: INHERITED(gpu, false)
|
||||
, fID(id) {
|
||||
this->registerWithCache();
|
||||
}
|
||||
|
||||
virtual ~TextureResource() { this->release(); }
|
||||
|
@ -90,6 +90,11 @@ public:
|
||||
uint32_t getUniqueID() const { return fUniqueID; }
|
||||
|
||||
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);
|
||||
virtual ~GrGpuResource();
|
||||
|
||||
|
@ -28,6 +28,9 @@ GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped)
|
||||
} else {
|
||||
fFlags = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void GrGpuResource::registerWithCache() {
|
||||
get_resource_cache2(fGpu)->insertResource(this);
|
||||
}
|
||||
|
||||
@ -37,7 +40,7 @@ GrGpuResource::~GrGpuResource() {
|
||||
SkASSERT(this->wasDestroyed());
|
||||
}
|
||||
|
||||
void GrGpuResource::release() {
|
||||
void GrGpuResource::release() {
|
||||
if (NULL != fGpu) {
|
||||
this->onRelease();
|
||||
get_resource_cache2(fGpu)->removeResource(this);
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
: INHERITED(gpu, kIsWrapped),
|
||||
fSize(size),
|
||||
fStroke(stroke) {
|
||||
this->registerWithCache();
|
||||
}
|
||||
|
||||
size_t getSize() const { return fSize; }
|
||||
|
@ -17,11 +17,13 @@ GrResourceCache2::~GrResourceCache2() {
|
||||
void GrResourceCache2::insertResource(GrGpuResource* resource) {
|
||||
SkASSERT(NULL != resource);
|
||||
SkASSERT(!resource->wasDestroyed());
|
||||
SkASSERT(!this->isInCache(resource));
|
||||
fResources.addToHead(resource);
|
||||
++fCount;
|
||||
}
|
||||
|
||||
void GrResourceCache2::removeResource(GrGpuResource* resource) {
|
||||
SkASSERT(this->isInCache(resource));
|
||||
fResources.remove(resource);
|
||||
--fCount;
|
||||
}
|
||||
|
@ -33,6 +33,12 @@ public:
|
||||
void releaseAll();
|
||||
|
||||
private:
|
||||
#ifdef SK_DEBUG
|
||||
bool isInCache(const GrGpuResource* r) const {
|
||||
return fResources.isInList(r);
|
||||
}
|
||||
#endif
|
||||
|
||||
int fCount;
|
||||
SkTInternalLList<GrGpuResource> fResources;
|
||||
};
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
glyphs.reset(SkNEW_ARGS(GlyphPathRange, (context, cache->getDescriptor(), stroke)));
|
||||
context->addResourceToCache(resourceKey, glyphs);
|
||||
}
|
||||
glyphs->registerWithCache();
|
||||
|
||||
return glyphs.detach();
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
GrGLIndexBuffer::GrGLIndexBuffer(GrGpuGL* gpu, const Desc& desc)
|
||||
: INHERITED(gpu, desc.fIsWrapped, desc.fSizeInBytes, desc.fDynamic, 0 == desc.fID)
|
||||
, fImpl(gpu, desc, GR_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
this->registerWithCache();
|
||||
}
|
||||
|
||||
void GrGLIndexBuffer::onRelease() {
|
||||
|
@ -136,6 +136,7 @@ GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke)
|
||||
// FIXME: try to account for stroking, without rasterizing the stroke.
|
||||
fBounds.outset(stroke.getWidth(), stroke.getWidth());
|
||||
}
|
||||
this->registerWithCache();
|
||||
}
|
||||
|
||||
GrGLPath::~GrGLPath() {
|
||||
|
@ -21,6 +21,7 @@ void GrGLRenderTarget::init(const Desc& desc,
|
||||
fMSColorRenderbufferID = desc.fMSColorRenderbufferID;
|
||||
fViewport = viewport;
|
||||
fTexIDObj.reset(SkSafeRef(texID));
|
||||
this->registerWithCache();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
: GrStencilBuffer(gpu, isWrapped, width, height, format.fStencilBits, sampleCnt)
|
||||
, fFormat(format)
|
||||
, fRenderbufferID(rbid) {
|
||||
this->registerWithCache();
|
||||
}
|
||||
|
||||
virtual ~GrGLStencilBuffer();
|
||||
|
@ -33,6 +33,7 @@ void GrGLTexture::init(GrGpuGL* gpu,
|
||||
|
||||
fRenderTarget.reset(SkNEW_ARGS(GrGLRenderTarget, (gpu, *rtDesc, vp, fTexIDObj, this)));
|
||||
}
|
||||
this->registerWithCache();
|
||||
}
|
||||
|
||||
GrGLTexture::GrGLTexture(GrGpuGL* gpu,
|
||||
|
@ -73,6 +73,7 @@ GrGLVertexArray::GrGLVertexArray(GrGpuGL* gpu, GrGLint id, int attribCount)
|
||||
, fID(id)
|
||||
, fAttribArrays(attribCount)
|
||||
, fIndexBufferIDIsValid(false) {
|
||||
this->registerWithCache();
|
||||
}
|
||||
|
||||
void GrGLVertexArray::onAbandon() {
|
||||
|
@ -11,6 +11,7 @@
|
||||
GrGLVertexBuffer::GrGLVertexBuffer(GrGpuGL* gpu, const Desc& desc)
|
||||
: INHERITED(gpu, desc.fIsWrapped, desc.fSizeInBytes, desc.fDynamic, 0 == desc.fID)
|
||||
, fImpl(gpu, desc, GR_GL_ARRAY_BUFFER) {
|
||||
this->registerWithCache();
|
||||
}
|
||||
|
||||
void GrGLVertexBuffer::onRelease() {
|
||||
|
@ -69,6 +69,7 @@ public:
|
||||
, fToDelete(NULL)
|
||||
, fSize(size) {
|
||||
++fAlive;
|
||||
this->registerWithCache();
|
||||
}
|
||||
|
||||
~TestResource() {
|
||||
|
Loading…
Reference in New Issue
Block a user