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" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 head->release(); | 52 head->release(); |
53 // release should have already removed this from the list. | 53 // release should have already removed this from the list. |
54 SkASSERT(head != fResources.head()); | 54 SkASSERT(head != fResources.head()); |
55 } | 55 } |
56 SkASSERT(!fScratchMap.count()); | 56 SkASSERT(!fScratchMap.count()); |
57 SkASSERT(!fCount); | 57 SkASSERT(!fCount); |
58 } | 58 } |
59 | 59 |
60 class GrResourceCache2::AvailableForScratchUse { | 60 class GrResourceCache2::AvailableForScratchUse { |
61 public: | 61 public: |
62 AvailableForScratchUse(bool calledDuringFlush) : fFlushing(calledDuringFlush
) { } | 62 AvailableForScratchUse(bool rejectPendingIO) : fRejectPendingIO(rejectPendin
gIO) { } |
63 | 63 |
64 bool operator()(const GrGpuResource* resource) const { | 64 bool operator()(const GrGpuResource* resource) const { |
65 if (fFlushing) { | 65 if (!resource->reffedOnlyByCache() || !resource->isScratch()) { |
66 // If this request is coming during draw buffer flush then no refs a
re allowed | 66 return false; |
67 // either by drawing code or for pending io operations. | |
68 // This will be removed when flush no longer creates resources. | |
69 return resource->reffedOnlyByCache() && !resource->internalHasPendin
gIO() && | |
70 resource->isScratch(); | |
71 } else { | |
72 // Because duties are currently shared between GrResourceCache and G
rResourceCache2, the | |
73 // current interpretation of this rule is that only GrResourceCache
has a ref but that | |
74 // it has been marked as a scratch resource. | |
75 return resource->reffedOnlyByCache() && resource->isScratch(); | |
76 } | 67 } |
| 68 |
| 69 return !fRejectPendingIO || !resource->internalHasPendingIO(); |
77 } | 70 } |
78 | 71 |
79 private: | 72 private: |
80 bool fFlushing; | 73 bool fRejectPendingIO; |
81 }; | 74 }; |
82 | 75 |
83 GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey&
scratchKey, | 76 GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey&
scratchKey, |
84 bool calledDuringFlus
h) { | 77 uint32_t flags) { |
85 SkASSERT(scratchKey.isScratch()); | 78 SkASSERT(scratchKey.isScratch()); |
86 return SkSafeRef(fScratchMap.find(scratchKey, AvailableForScratchUse(calledD
uringFlush))); | 79 |
| 80 if (flags & (kPreferNoPendingIO_ScratchFlag | kRequireNoPendingIO_ScratchFla
g)) { |
| 81 GrGpuResource* resource = fScratchMap.find(scratchKey, AvailableForScrat
chUse(true)); |
| 82 if (resource) { |
| 83 return SkRef(resource); |
| 84 } else if (flags & kRequireNoPendingIO_ScratchFlag) { |
| 85 return NULL; |
| 86 } |
| 87 // TODO: fail here when kPrefer is specified, we didn't find a resource
without pending io, |
| 88 // but there is still space in our budget for the resource. |
| 89 } |
| 90 return SkSafeRef(fScratchMap.find(scratchKey, AvailableForScratchUse(false))
); |
87 } | 91 } |
OLD | NEW |