| 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 #include "SkRefCnt.h" | |
| 13 | 12 |
| 14 GrResourceCache2::~GrResourceCache2() { | 13 GrResourceCache2::~GrResourceCache2() { |
| 15 this->releaseAll(); | 14 this->releaseAll(); |
| 16 } | 15 } |
| 17 | 16 |
| 18 void GrResourceCache2::insertResource(GrGpuResource* resource) { | 17 void GrResourceCache2::insertResource(GrGpuResource* resource) { |
| 19 SkASSERT(resource); | 18 SkASSERT(resource); |
| 20 SkASSERT(!resource->wasDestroyed()); | 19 SkASSERT(!resource->wasDestroyed()); |
| 21 SkASSERT(!this->isInCache(resource)); | 20 SkASSERT(!this->isInCache(resource)); |
| 22 fResources.addToHead(resource); | 21 fResources.addToHead(resource); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 49 void GrResourceCache2::releaseAll() { | 48 void GrResourceCache2::releaseAll() { |
| 50 while (GrGpuResource* head = fResources.head()) { | 49 while (GrGpuResource* head = fResources.head()) { |
| 51 SkASSERT(!head->wasDestroyed()); | 50 SkASSERT(!head->wasDestroyed()); |
| 52 head->release(); | 51 head->release(); |
| 53 // release should have already removed this from the list. | 52 // release should have already removed this from the list. |
| 54 SkASSERT(head != fResources.head()); | 53 SkASSERT(head != fResources.head()); |
| 55 } | 54 } |
| 56 SkASSERT(!fScratchMap.count()); | 55 SkASSERT(!fScratchMap.count()); |
| 57 SkASSERT(!fCount); | 56 SkASSERT(!fCount); |
| 58 } | 57 } |
| 59 | |
| 60 class GrResourceCache2::AvailableForScratchUse { | |
| 61 public: | |
| 62 bool operator()(const GrGpuResource* resource) const { | |
| 63 // Because duties are currently shared between GrResourceCache and GrRes
ourceCache2, the | |
| 64 // current interpretation of this rule is that only GrResourceCache has
a ref but that | |
| 65 // it has been marked as a scratch resource. | |
| 66 return resource->reffedOnlyByCache() && GrIORef::kYes_IsScratch == resou
rce->fIsScratch; | |
| 67 } | |
| 68 }; | |
| 69 | |
| 70 GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey&
scratchKey) { | |
| 71 SkASSERT(scratchKey.isScratch()); | |
| 72 return SkSafeRef(fScratchMap.find(scratchKey, AvailableForScratchUse())); | |
| 73 } | |
| OLD | NEW |