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