aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-09-04 13:34:32 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-09-04 13:34:32 +0000
commit9474ed06176fe24c77091b0d75f35442e851073f (patch)
tree8af93b0a79523f4fcea4b10f9e14053c6434a63b
parentb78765e63b5de5a7dfe5f9f6813f6df81cae14ae (diff)
Switch GrGpu's GrResource list over to using SkTDLinkedList
-rw-r--r--include/core/SkTDLinkedList.h1
-rw-r--r--include/gpu/GrResource.h11
-rw-r--r--src/gpu/GrGpu.cpp35
-rw-r--r--src/gpu/GrGpu.h3
-rw-r--r--src/gpu/GrResource.cpp2
5 files changed, 19 insertions, 33 deletions
diff --git a/include/core/SkTDLinkedList.h b/include/core/SkTDLinkedList.h
index 88bf96d347..92478121bb 100644
--- a/include/core/SkTDLinkedList.h
+++ b/include/core/SkTDLinkedList.h
@@ -48,6 +48,7 @@ public:
}
void remove(T* entry) {
+ SkASSERT(NULL != fHead && NULL != fTail);
SkASSERT(this->isInList(entry));
T* prev = entry->fPrev;
diff --git a/include/gpu/GrResource.h b/include/gpu/GrResource.h
index 6b85729b54..5c3e24aac7 100644
--- a/include/gpu/GrResource.h
+++ b/include/gpu/GrResource.h
@@ -12,6 +12,8 @@
#include "GrRefCnt.h"
+#include "SkTDLinkedList.h"
+
class GrGpu;
class GrContext;
class GrResourceEntry;
@@ -80,14 +82,17 @@ protected:
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
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index b6f5bb7839..148d572ddd 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -37,8 +37,7 @@ GrGpu::GrGpu()
, fIndexPoolUseCnt(0)
, fQuadIndexBuffer(NULL)
, fUnitSquareVertexBuffer(NULL)
- , fContextIsDirty(true)
- , fResourceHead(NULL) {
+ , fContextIsDirty(true) {
fClipMaskManager.setGpu(this);
@@ -68,8 +67,8 @@ void GrGpu::abandonResources() {
fClipMaskManager.releaseResources();
- while (NULL != fResourceHead) {
- fResourceHead->abandon();
+ while (NULL != fResourceList.head()) {
+ fResourceList.head()->abandon();
}
GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
@@ -87,8 +86,8 @@ void GrGpu::releaseResources() {
fClipMaskManager.releaseResources();
- while (NULL != fResourceHead) {
- fResourceHead->release();
+ while (NULL != fResourceList.head()) {
+ fResourceList.head()->release();
}
GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
@@ -105,33 +104,15 @@ void GrGpu::releaseResources() {
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);
}
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index fb5c1f59c0..60e49e7c9e 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -554,7 +554,8 @@ private:
bool fContextIsDirty;
- GrResource* fResourceHead;
+ typedef SkTDLinkedList<GrResource> ResourceList;
+ ResourceList fResourceList;
// Given a rt, find or create a stencil buffer and attach it
bool attachStencilBufferToRenderTarget(GrRenderTarget* target);
diff --git a/src/gpu/GrResource.cpp b/src/gpu/GrResource.cpp
index 74fc63d471..2ff7df61cb 100644
--- a/src/gpu/GrResource.cpp
+++ b/src/gpu/GrResource.cpp
@@ -14,8 +14,6 @@ SK_DEFINE_INST_COUNT(GrResource)
GrResource::GrResource(GrGpu* gpu) {
fGpu = gpu;
- fNext = NULL;
- fPrevious = NULL;
fCacheEntry = NULL;
fGpu->insertResource(this);
}