#include "GrRefCnt.h"
+#include "SkTDLinkedList.h"
+
class GrGpu;
class GrContext;
class GrResourceEntry;
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
// are still live GrResources. It will call
// release() on all such resources in its
// 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
, fIndexPoolUseCnt(0)
, fQuadIndexBuffer(NULL)
, fUnitSquareVertexBuffer(NULL)
- , fContextIsDirty(true)
- , fResourceHead(NULL) {
+ , fContextIsDirty(true) {
fClipMaskManager.setGpu(this);
fClipMaskManager.releaseResources();
- while (NULL != fResourceHead) {
- fResourceHead->abandon();
+ while (NULL != fResourceList.head()) {
+ fResourceList.head()->abandon();
}
GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
fClipMaskManager.releaseResources();
- while (NULL != fResourceHead) {
- fResourceHead->release();
+ while (NULL != fResourceList.head()) {
+ fResourceList.head()->release();
}
GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
void GrGpu::insertResource(GrResource* resource) {
GrAssert(NULL != resource);
GrAssert(this == resource->getGpu());
- GrAssert(NULL == resource->fNext);
- GrAssert(NULL == resource->fPrevious);
- resource->fNext = fResourceHead;
- if (NULL != fResourceHead) {
- GrAssert(NULL == fResourceHead->fPrevious);
- fResourceHead->fPrevious = resource;
- }
- fResourceHead = resource;
+ fResourceList.addToHead(resource);
}
void GrGpu::removeResource(GrResource* resource) {
GrAssert(NULL != resource);
- GrAssert(NULL != fResourceHead);
+ GrAssert(this == resource->getGpu());
- if (fResourceHead == 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;
+ fResourceList.remove(resource);
}