Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 #ifndef GrGpuResourceCacheAccess_DEFINED | |
| 10 #define GrGpuResourceCacheAccess_DEFINED | |
| 11 | |
| 12 #include "GrGpuResource.h" | |
| 13 | |
|
robertphillips
2014/11/11 15:20:52
// This class acts as a chokepoint for resource ca
bsalomon
2014/11/11 15:32:26
Done.
| |
| 14 class GrGpuResource::CacheAccess { | |
| 15 public: | |
| 16 /** | |
| 17 * Sets a content key for the resource. If the resource was previously cache d as scratch it will | |
| 18 * be converted to a content resource. Currently this may only be called onc e per resource. It | |
| 19 * fails if there is already a resource with the same content key. TODO: mak e this supplant the | |
| 20 * resource that currently is using the content key, allow resources' conten t keys to change, | |
| 21 * and allow removal of a content key to convert a resource back to scratch. | |
| 22 */ | |
| 23 bool setContentKey(const GrResourceKey& contentKey) { | |
| 24 return fResource->setContentKey(contentKey); | |
| 25 } | |
| 26 | |
| 27 /** | |
| 28 * Used by legacy cache to attach a cache entry. This is to be removed soon. | |
| 29 */ | |
| 30 void setCacheEntry(GrResourceCacheEntry* cacheEntry) { | |
| 31 // GrResourceCache never changes the cacheEntry once one has been added. | |
| 32 SkASSERT(NULL == cacheEntry || NULL == fResource->fCacheEntry); | |
| 33 fResource->fCacheEntry = cacheEntry; | |
| 34 } | |
| 35 | |
| 36 /** | |
| 37 * Is the resource in the legacy cache? This is to be removed soon. | |
| 38 */ | |
| 39 bool isInCache() const { return SkToBool(fResource->fCacheEntry); } | |
| 40 | |
| 41 /** | |
| 42 * Returns the cache entry for the legacy cache. This is to be removed soon. | |
| 43 */ | |
| 44 GrResourceCacheEntry* getCacheEntry() const { return fResource->fCacheEntry; } | |
| 45 | |
| 46 /** | |
| 47 * Is the resource currently cached as scratch? This means it has a valid sc ratch key and does | |
| 48 * not have a content key. | |
| 49 */ | |
| 50 bool isScratch() const { | |
| 51 SkASSERT(fResource->fScratchKey.isScratch()); | |
| 52 return NULL == this->getContentKey() && !fResource->fScratchKey.isNullSc ratch(); | |
| 53 } | |
| 54 | |
|
robertphillips
2014/11/11 15:20:51
extra space ?
bsalomon
2014/11/11 15:32:26
Done.
| |
| 55 /** | |
| 56 * If this resource can be used as a scratch resource this returns a valid s cratch key. | |
| 57 * Otherwise it returns a key for which isNullScratch is true. The resource may currently be | |
| 58 * used as content resource rather than scratch. Check isScratch(). | |
| 59 */ | |
|
robertphillips
2014/11/11 15:20:52
if (fResource->gContentKeySet) {
return nullScra
bsalomon
2014/11/11 15:32:26
We sometimes need to access the scratch key even w
| |
| 60 const GrResourceKey& getScratchKey() const { return fResource->fScratchKey; } | |
| 61 | |
| 62 /** | |
| 63 * If the resource is currently cached by a content key, the key is returned , otherwise NULL. | |
| 64 */ | |
| 65 const GrResourceKey* getContentKey() const { | |
| 66 if (fResource->fContentKeySet) { | |
| 67 return &fResource->fContentKey; | |
| 68 } | |
| 69 return NULL; | |
| 70 } | |
| 71 | |
| 72 private: | |
| 73 CacheAccess(GrGpuResource* resource) : fResource(resource) { } | |
| 74 CacheAccess(const CacheAccess& that) : fResource(that.fResource) { } | |
| 75 CacheAccess& operator=(const CacheAccess&); // unimpl | |
| 76 | |
| 77 // No taking addresses of this type. | |
| 78 const CacheAccess* operator&() const; | |
| 79 CacheAccess* operator&(); | |
| 80 | |
| 81 GrGpuResource* fResource; | |
| 82 | |
| 83 friend class GrGpuResource; // to construct/copy this type. | |
| 84 }; | |
| 85 | |
| 86 inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAcc ess(this); } | |
| 87 | |
| 88 inline const GrGpuResource::CacheAccess GrGpuResource::cacheAccess() const { | |
| 89 return CacheAccess(const_cast<GrGpuResource*>(this)); | |
| 90 } | |
| 91 | |
| 92 #endif | |
| OLD | NEW |