StencilResource(GrGpu* gpu, int id)
: INHERITED(gpu, false)
, fID(id) {
+ this->registerWithCache();
}
virtual ~StencilResource() { this->release(); }
TextureResource(GrGpu* gpu, int id)
: INHERITED(gpu, false)
, fID(id) {
+ this->registerWithCache();
}
virtual ~TextureResource() { this->release(); }
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();
} else {
fFlags = 0;
}
+}
+
+void GrGpuResource::registerWithCache() {
get_resource_cache2(fGpu)->insertResource(this);
}
SkASSERT(this->wasDestroyed());
}
-void GrGpuResource::release() {
+void GrGpuResource::release() {
if (NULL != fGpu) {
this->onRelease();
get_resource_cache2(fGpu)->removeResource(this);
: INHERITED(gpu, kIsWrapped),
fSize(size),
fStroke(stroke) {
+ this->registerWithCache();
}
size_t getSize() const { return fSize; }
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;
}
void releaseAll();
private:
+#ifdef SK_DEBUG
+ bool isInCache(const GrGpuResource* r) const {
+ return fResources.isInList(r);
+ }
+#endif
+
int fCount;
SkTInternalLList<GrGpuResource> fResources;
};
glyphs.reset(SkNEW_ARGS(GlyphPathRange, (context, cache->getDescriptor(), stroke)));
context->addResourceToCache(resourceKey, glyphs);
}
+ glyphs->registerWithCache();
return glyphs.detach();
}
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() {
// FIXME: try to account for stroking, without rasterizing the stroke.
fBounds.outset(stroke.getWidth(), stroke.getWidth());
}
+ this->registerWithCache();
}
GrGLPath::~GrGLPath() {
fMSColorRenderbufferID = desc.fMSColorRenderbufferID;
fViewport = viewport;
fTexIDObj.reset(SkSafeRef(texID));
+ this->registerWithCache();
}
namespace {
: GrStencilBuffer(gpu, isWrapped, width, height, format.fStencilBits, sampleCnt)
, fFormat(format)
, fRenderbufferID(rbid) {
+ this->registerWithCache();
}
virtual ~GrGLStencilBuffer();
fRenderTarget.reset(SkNEW_ARGS(GrGLRenderTarget, (gpu, *rtDesc, vp, fTexIDObj, this)));
}
+ this->registerWithCache();
}
GrGLTexture::GrGLTexture(GrGpuGL* gpu,
, fID(id)
, fAttribArrays(attribCount)
, fIndexBufferIDIsValid(false) {
+ this->registerWithCache();
}
void GrGLVertexArray::onAbandon() {
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() {
, fToDelete(NULL)
, fSize(size) {
++fAlive;
+ this->registerWithCache();
}
~TestResource() {