Chromium Code Reviews| Index: src/gpu/GrResourceCache2.cpp |
| diff --git a/src/gpu/GrResourceCache2.cpp b/src/gpu/GrResourceCache2.cpp |
| index e0ba26ae83516c54d4e87937bef28607f760b64d..74926eccb4938253bd5f579cfe935e616fa42221 100644 |
| --- a/src/gpu/GrResourceCache2.cpp |
| +++ b/src/gpu/GrResourceCache2.cpp |
| @@ -8,7 +8,8 @@ |
| #include "GrResourceCache2.h" |
| -#include "GrGpuResource.h" |
| +#include "GrGpuResource.h" |
| +#include "SkRefCnt.h" |
| GrResourceCache2::~GrResourceCache2() { |
| this->releaseAll(); |
| @@ -55,3 +56,31 @@ void GrResourceCache2::releaseAll() { |
| SkASSERT(!fScratchMap.count()); |
| SkASSERT(!fCount); |
| } |
| + |
| +class GrResourceCache2::AvailableForScratchUse { |
| +public: |
| + AvailableForScratchUse(uint32_t internalFlags) : fFlags(internalFlags) { } |
| + |
| + bool operator()(const GrGpuResource* resource) const { |
| + if (fFlags) { |
|
robertphillips
2014/10/07 13:59:34
f;ush ?
bsalomon
2014/10/07 14:20:13
Rewrote the comment. Changed from uint32_t fFlags
|
| + // If flags is set then this request is coming during draw buffer f;ush, in which |
| + // case no refs, either by drawing code or for pending io operations, are allowed. |
|
robertphillips
2014/10/07 13:59:34
Flags -> fFlags ?
bsalomon
2014/10/07 14:20:13
done (comment rewritten).
|
| + // Flags will be removed when flush no longer creates resources. |
| + return resource->reffedOnlyByCache() && !resource->internalHasPendingIO() && |
| + GrIORef::kYes_IsScratch == resource->fIsScratch; |
| + } else { |
| + // Because duties are currently shared between GrResourceCache and GrResourceCache2, the |
| + // current interpretation of this rule is that only GrResourceCache has a ref but that |
| + // it has been marked as a scratch resource. |
| + return resource->reffedOnlyByCache() && GrIORef::kYes_IsScratch == resource->fIsScratch; |
| + } |
| + } |
| +private: |
| + uint32_t fFlags; |
| +}; |
| + |
| +GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey& scratchKey, |
| + uint32_t internalFlags) { |
| + SkASSERT(scratchKey.isScratch()); |
| + return SkSafeRef(fScratchMap.find(scratchKey, AvailableForScratchUse(internalFlags))); |
| +} |