Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Unified Diff: src/gpu/GrResourceCache2.cpp

Issue 481443002: Add GrResourceCache2. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix leaks Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrResourceCache2.h ('k') | src/gpu/gl/GrGpuGL.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrResourceCache2.cpp
diff --git a/src/gpu/GrResourceCache2.cpp b/src/gpu/GrResourceCache2.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0b6944ee856306f8a3983a82b87b5ab823aa91e2
--- /dev/null
+++ b/src/gpu/GrResourceCache2.cpp
@@ -0,0 +1,47 @@
+
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#include "GrResourceCache2.h"
+#include "GrGpuResource.h"
+
+GrResourceCache2::~GrResourceCache2() {
+ this->releaseAll();
+}
+
+void GrResourceCache2::insertResource(GrGpuResource* resource) {
+ SkASSERT(NULL != resource);
+ SkASSERT(!resource->wasDestroyed());
+ fResources.addToHead(resource);
+ ++fCount;
+}
+
+void GrResourceCache2::removeResource(GrGpuResource* resource) {
+ fResources.remove(resource);
+ --fCount;
+}
+
+void GrResourceCache2::abandonAll() {
+ while (GrGpuResource* head = fResources.head()) {
+ SkASSERT(!head->wasDestroyed());
+ head->abandon();
+ // abandon should have already removed this from the list.
+ SkASSERT(head != fResources.head());
+ }
+ SkASSERT(!fCount);
+}
+
+void GrResourceCache2::releaseAll() {
+ while (GrGpuResource* head = fResources.head()) {
+ SkASSERT(!head->wasDestroyed());
+ head->release();
+ // release should have already removed this from the list.
+ SkASSERT(head != fResources.head());
+ }
+ SkASSERT(!fCount);
+}
« no previous file with comments | « src/gpu/GrResourceCache2.h ('k') | src/gpu/gl/GrGpuGL.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698