OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "GrResourceCache2.h" | 10 #include "GrResourceCache2.h" |
11 #include "GrGpuResource.h" | 11 #include "GrGpuResource.h" |
12 | 12 |
13 GrResourceCache2::~GrResourceCache2() { | 13 GrResourceCache2::~GrResourceCache2() { |
14 this->releaseAll(); | 14 this->releaseAll(); |
15 } | 15 } |
16 | 16 |
17 void GrResourceCache2::insertResource(GrGpuResource* resource) { | 17 void GrResourceCache2::insertResource(GrGpuResource* resource) { |
18 SkASSERT(NULL != resource); | 18 SkASSERT(NULL != resource); |
19 SkASSERT(!resource->wasDestroyed()); | 19 SkASSERT(!resource->wasDestroyed()); |
| 20 SkASSERT(!this->isInCache(resource)); |
20 fResources.addToHead(resource); | 21 fResources.addToHead(resource); |
21 ++fCount; | 22 ++fCount; |
22 } | 23 } |
23 | 24 |
24 void GrResourceCache2::removeResource(GrGpuResource* resource) { | 25 void GrResourceCache2::removeResource(GrGpuResource* resource) { |
| 26 SkASSERT(this->isInCache(resource)); |
25 fResources.remove(resource); | 27 fResources.remove(resource); |
26 --fCount; | 28 --fCount; |
27 } | 29 } |
28 | 30 |
29 void GrResourceCache2::abandonAll() { | 31 void GrResourceCache2::abandonAll() { |
30 while (GrGpuResource* head = fResources.head()) { | 32 while (GrGpuResource* head = fResources.head()) { |
31 SkASSERT(!head->wasDestroyed()); | 33 SkASSERT(!head->wasDestroyed()); |
32 head->abandon(); | 34 head->abandon(); |
33 // abandon should have already removed this from the list. | 35 // abandon should have already removed this from the list. |
34 SkASSERT(head != fResources.head()); | 36 SkASSERT(head != fResources.head()); |
35 } | 37 } |
36 SkASSERT(!fCount); | 38 SkASSERT(!fCount); |
37 } | 39 } |
38 | 40 |
39 void GrResourceCache2::releaseAll() { | 41 void GrResourceCache2::releaseAll() { |
40 while (GrGpuResource* head = fResources.head()) { | 42 while (GrGpuResource* head = fResources.head()) { |
41 SkASSERT(!head->wasDestroyed()); | 43 SkASSERT(!head->wasDestroyed()); |
42 head->release(); | 44 head->release(); |
43 // release should have already removed this from the list. | 45 // release should have already removed this from the list. |
44 SkASSERT(head != fResources.head()); | 46 SkASSERT(head != fResources.head()); |
45 } | 47 } |
46 SkASSERT(!fCount); | 48 SkASSERT(!fCount); |
47 } | 49 } |
OLD | NEW |