Revert of Add GrResourceCache2. (patchset #4 of https://codereview.chromium.org/481443002/)
Reason for revert:
Likely caused a leak detected in Chromium after last Skia roll.
Original issue's description:
> Add GrResourceCache2.
>
> Currently it just replaces GrGpu as the owner of the linked list of resources.
>
> Committed: https://skia.googlesource.com/skia/+/94ce9ac8624dbb45656b8f5c992fad9c9ff3ee5f
R=mtklein@google.com, robertphillips@google.com
TBR=mtklein@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: bsalomon@google.com
Review URL: https://codereview.chromium.org/477323006
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index bdf6772..0b49e74 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -49,9 +49,62 @@
#endif
}
-GrGpu::~GrGpu() {}
+GrGpu::~GrGpu() {
+ this->releaseResources();
+}
-void GrGpu::contextAbandonded() {}
+void GrGpu::abandonResources() {
+
+ fClipMaskManager.releaseResources();
+
+ while (NULL != fObjectList.head()) {
+ fObjectList.head()->abandon();
+ }
+
+ SkASSERT(NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed());
+ SkSafeSetNull(fQuadIndexBuffer);
+ delete fVertexPool;
+ fVertexPool = NULL;
+ delete fIndexPool;
+ fIndexPool = NULL;
+}
+
+void GrGpu::releaseResources() {
+
+ fClipMaskManager.releaseResources();
+
+ while (NULL != fObjectList.head()) {
+ fObjectList.head()->release();
+ }
+
+ SkASSERT(NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed());
+ SkSafeSetNull(fQuadIndexBuffer);
+ delete fVertexPool;
+ fVertexPool = NULL;
+ delete fIndexPool;
+ fIndexPool = NULL;
+}
+
+void GrGpu::insertObject(GrGpuResource* object) {
+ SkASSERT(NULL != object);
+ SkASSERT(this == object->getGpu());
+
+ fObjectList.addToHead(object);
+}
+
+void GrGpu::removeObject(GrGpuResource* object) {
+ SkASSERT(NULL != object);
+ SkASSERT(this == object->getGpu());
+
+ fObjectList.remove(object);
+}
+
+
+void GrGpu::unimpl(const char msg[]) {
+#ifdef SK_DEBUG
+ GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg);
+#endif
+}
////////////////////////////////////////////////////////////////////////////////
@@ -266,8 +319,7 @@
}
const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const {
- if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) {
- SkSafeUnref(fQuadIndexBuffer);
+ if (NULL == fQuadIndexBuffer) {
static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS;
GrGpu* me = const_cast<GrGpu*>(this);
fQuadIndexBuffer = me->createIndexBuffer(SIZE, false);