Switch GrGpu's GrResource list over to using SkTDLinkedList
https://codereview.appspot.com/6500062/ git-svn-id: http://skia.googlecode.com/svn/trunk@5379 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
b78765e63b
commit
9474ed0617
@ -48,6 +48,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void remove(T* entry) {
|
void remove(T* entry) {
|
||||||
|
SkASSERT(NULL != fHead && NULL != fTail);
|
||||||
SkASSERT(this->isInList(entry));
|
SkASSERT(this->isInList(entry));
|
||||||
|
|
||||||
T* prev = entry->fPrev;
|
T* prev = entry->fPrev;
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include "GrRefCnt.h"
|
#include "GrRefCnt.h"
|
||||||
|
|
||||||
|
#include "SkTDLinkedList.h"
|
||||||
|
|
||||||
class GrGpu;
|
class GrGpu;
|
||||||
class GrContext;
|
class GrContext;
|
||||||
class GrResourceEntry;
|
class GrResourceEntry;
|
||||||
@ -80,14 +82,17 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend class GrGpu; // GrGpu manages list of resources.
|
#if GR_DEBUG
|
||||||
|
friend class GrGpu; // for assert in GrGpu to access getGpu
|
||||||
|
#endif
|
||||||
|
|
||||||
GrGpu* fGpu; // not reffed. The GrGpu can be deleted while there
|
GrGpu* fGpu; // not reffed. The GrGpu can be deleted while there
|
||||||
// are still live GrResources. It will call
|
// are still live GrResources. It will call
|
||||||
// release() on all such resources in its
|
// release() on all such resources in its
|
||||||
// destructor.
|
// destructor.
|
||||||
GrResource* fNext; // dl-list of resources per-GrGpu
|
|
||||||
GrResource* fPrevious;
|
// we're a dlinklist
|
||||||
|
SK_DEFINE_DLINKEDLIST_INTERFACE(GrResource);
|
||||||
|
|
||||||
GrResourceEntry* fCacheEntry; // NULL if not in cache
|
GrResourceEntry* fCacheEntry; // NULL if not in cache
|
||||||
|
|
||||||
|
@ -37,8 +37,7 @@ GrGpu::GrGpu()
|
|||||||
, fIndexPoolUseCnt(0)
|
, fIndexPoolUseCnt(0)
|
||||||
, fQuadIndexBuffer(NULL)
|
, fQuadIndexBuffer(NULL)
|
||||||
, fUnitSquareVertexBuffer(NULL)
|
, fUnitSquareVertexBuffer(NULL)
|
||||||
, fContextIsDirty(true)
|
, fContextIsDirty(true) {
|
||||||
, fResourceHead(NULL) {
|
|
||||||
|
|
||||||
fClipMaskManager.setGpu(this);
|
fClipMaskManager.setGpu(this);
|
||||||
|
|
||||||
@ -68,8 +67,8 @@ void GrGpu::abandonResources() {
|
|||||||
|
|
||||||
fClipMaskManager.releaseResources();
|
fClipMaskManager.releaseResources();
|
||||||
|
|
||||||
while (NULL != fResourceHead) {
|
while (NULL != fResourceList.head()) {
|
||||||
fResourceHead->abandon();
|
fResourceList.head()->abandon();
|
||||||
}
|
}
|
||||||
|
|
||||||
GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
|
GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
|
||||||
@ -87,8 +86,8 @@ void GrGpu::releaseResources() {
|
|||||||
|
|
||||||
fClipMaskManager.releaseResources();
|
fClipMaskManager.releaseResources();
|
||||||
|
|
||||||
while (NULL != fResourceHead) {
|
while (NULL != fResourceList.head()) {
|
||||||
fResourceHead->release();
|
fResourceList.head()->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
|
GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
|
||||||
@ -105,33 +104,15 @@ void GrGpu::releaseResources() {
|
|||||||
void GrGpu::insertResource(GrResource* resource) {
|
void GrGpu::insertResource(GrResource* resource) {
|
||||||
GrAssert(NULL != resource);
|
GrAssert(NULL != resource);
|
||||||
GrAssert(this == resource->getGpu());
|
GrAssert(this == resource->getGpu());
|
||||||
GrAssert(NULL == resource->fNext);
|
|
||||||
GrAssert(NULL == resource->fPrevious);
|
|
||||||
|
|
||||||
resource->fNext = fResourceHead;
|
fResourceList.addToHead(resource);
|
||||||
if (NULL != fResourceHead) {
|
|
||||||
GrAssert(NULL == fResourceHead->fPrevious);
|
|
||||||
fResourceHead->fPrevious = resource;
|
|
||||||
}
|
|
||||||
fResourceHead = resource;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGpu::removeResource(GrResource* resource) {
|
void GrGpu::removeResource(GrResource* resource) {
|
||||||
GrAssert(NULL != resource);
|
GrAssert(NULL != resource);
|
||||||
GrAssert(NULL != fResourceHead);
|
GrAssert(this == resource->getGpu());
|
||||||
|
|
||||||
if (fResourceHead == resource) {
|
fResourceList.remove(resource);
|
||||||
GrAssert(NULL == resource->fPrevious);
|
|
||||||
fResourceHead = resource->fNext;
|
|
||||||
} else {
|
|
||||||
GrAssert(NULL != fResourceHead);
|
|
||||||
resource->fPrevious->fNext = resource->fNext;
|
|
||||||
}
|
|
||||||
if (NULL != resource->fNext) {
|
|
||||||
resource->fNext->fPrevious = resource->fPrevious;
|
|
||||||
}
|
|
||||||
resource->fNext = NULL;
|
|
||||||
resource->fPrevious = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -554,7 +554,8 @@ private:
|
|||||||
|
|
||||||
bool fContextIsDirty;
|
bool fContextIsDirty;
|
||||||
|
|
||||||
GrResource* fResourceHead;
|
typedef SkTDLinkedList<GrResource> ResourceList;
|
||||||
|
ResourceList fResourceList;
|
||||||
|
|
||||||
// Given a rt, find or create a stencil buffer and attach it
|
// Given a rt, find or create a stencil buffer and attach it
|
||||||
bool attachStencilBufferToRenderTarget(GrRenderTarget* target);
|
bool attachStencilBufferToRenderTarget(GrRenderTarget* target);
|
||||||
|
@ -14,8 +14,6 @@ SK_DEFINE_INST_COUNT(GrResource)
|
|||||||
|
|
||||||
GrResource::GrResource(GrGpu* gpu) {
|
GrResource::GrResource(GrGpu* gpu) {
|
||||||
fGpu = gpu;
|
fGpu = gpu;
|
||||||
fNext = NULL;
|
|
||||||
fPrevious = NULL;
|
|
||||||
fCacheEntry = NULL;
|
fCacheEntry = NULL;
|
||||||
fGpu->insertResource(this);
|
fGpu->insertResource(this);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user