Chromium Code Reviews| 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 #ifndef GrGpuResourceCacheAccess_DEFINED | 9 #ifndef GrGpuResourceCacheAccess_DEFINED |
| 10 #define GrGpuResourceCacheAccess_DEFINED | 10 #define GrGpuResourceCacheAccess_DEFINED |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 * be converted to a content resource. Currently this may only be called onc e per resource. It | 22 * be converted to a content resource. Currently this may only be called onc e per resource. It |
| 23 * fails if there is already a resource with the same content key. TODO: mak e this supplant the | 23 * fails if there is already a resource with the same content key. TODO: mak e this supplant the |
| 24 * resource that currently is using the content key, allow resources' conten t keys to change, | 24 * resource that currently is using the content key, allow resources' conten t keys to change, |
| 25 * and allow removal of a content key to convert a resource back to scratch. | 25 * and allow removal of a content key to convert a resource back to scratch. |
| 26 */ | 26 */ |
| 27 bool setContentKey(const GrResourceKey& contentKey) { | 27 bool setContentKey(const GrResourceKey& contentKey) { |
| 28 return fResource->setContentKey(contentKey); | 28 return fResource->setContentKey(contentKey); |
| 29 } | 29 } |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * Changes whether the resource counts against the resource cache budget. | |
| 33 */ | |
| 34 void setBudgeted(bool countsAgainstBudget) { fResource->setBudgeted(countsAg ainstBudget); } | |
|
bsalomon
2014/11/13 19:20:54
This class provides privileged access the parts of
| |
| 35 | |
| 36 /** | |
| 32 * Is the resource currently cached as scratch? This means it has a valid sc ratch key and does | 37 * Is the resource currently cached as scratch? This means it has a valid sc ratch key and does |
| 33 * not have a content key. | 38 * not have a content key. |
| 34 */ | 39 */ |
| 35 bool isScratch() const { | 40 bool isScratch() const { |
| 36 SkASSERT(fResource->fScratchKey.isScratch()); | 41 SkASSERT(fResource->fScratchKey.isScratch()); |
| 37 return NULL == this->getContentKey() && !fResource->fScratchKey.isNullSc ratch(); | 42 return NULL == this->getContentKey() && !fResource->fScratchKey.isNullSc ratch(); |
| 38 } | 43 } |
| 39 | 44 |
| 40 /** | 45 /** |
| 41 * If this resource can be used as a scratch resource this returns a valid s cratch key. | 46 * If this resource can be used as a scratch resource this returns a valid s cratch key. |
| 42 * Otherwise it returns a key for which isNullScratch is true. The resource may currently be | 47 * Otherwise it returns a key for which isNullScratch is true. The resource may currently be |
| 43 * used as content resource rather than scratch. Check isScratch(). | 48 * used as content resource rather than scratch. Check isScratch(). |
| 44 */ | 49 */ |
| 45 const GrResourceKey& getScratchKey() const { return fResource->fScratchKey; } | 50 const GrResourceKey& getScratchKey() const { return fResource->fScratchKey; } |
| 46 | 51 |
| 47 /** | 52 /** |
| 48 * If the resource is currently cached by a content key, the key is returned , otherwise NULL. | 53 * If the resource is currently cached by a content key, the key is returned , otherwise NULL. |
| 49 */ | 54 */ |
| 50 const GrResourceKey* getContentKey() const { | 55 const GrResourceKey* getContentKey() const { |
| 51 if (fResource->fContentKeySet) { | 56 if (fResource->fFlags & GrGpuResource::kContentKeySet_Flag) { |
| 52 return &fResource->fContentKey; | 57 return &fResource->fContentKey; |
| 53 } | 58 } |
| 54 return NULL; | 59 return NULL; |
| 55 } | 60 } |
| 56 | 61 |
| 62 /** | |
| 63 * Is the resource object wrapping an externally allocated GPU resource? | |
| 64 */ | |
| 57 bool isWrapped() const { return fResource->isWrapped(); } | 65 bool isWrapped() const { return fResource->isWrapped(); } |
| 58 | 66 |
| 67 /** | |
| 68 * Does the resource count against the resource budget? | |
| 69 */ | |
| 70 bool isBudgeted() const { | |
| 71 bool ret = SkToBool(GrGpuResource::kBudgeted_Flag & fResource->fFlags); | |
| 72 SkASSERT(!(ret && fResource->isWrapped())); | |
| 73 return ret; | |
| 74 } | |
| 75 | |
| 59 private: | 76 private: |
| 60 CacheAccess(GrGpuResource* resource) : fResource(resource) { } | 77 CacheAccess(GrGpuResource* resource) : fResource(resource) { } |
| 61 CacheAccess(const CacheAccess& that) : fResource(that.fResource) { } | 78 CacheAccess(const CacheAccess& that) : fResource(that.fResource) { } |
| 62 CacheAccess& operator=(const CacheAccess&); // unimpl | 79 CacheAccess& operator=(const CacheAccess&); // unimpl |
| 63 | 80 |
| 64 // No taking addresses of this type. | 81 // No taking addresses of this type. |
| 65 const CacheAccess* operator&() const; | 82 const CacheAccess* operator&() const; |
| 66 CacheAccess* operator&(); | 83 CacheAccess* operator&(); |
| 67 | 84 |
| 68 GrGpuResource* fResource; | 85 GrGpuResource* fResource; |
| 69 | 86 |
| 70 friend class GrGpuResource; // to construct/copy this type. | 87 friend class GrGpuResource; // to construct/copy this type. |
| 71 }; | 88 }; |
| 72 | 89 |
| 73 inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAcc ess(this); } | 90 inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAcc ess(this); } |
| 74 | 91 |
| 75 inline const GrGpuResource::CacheAccess GrGpuResource::cacheAccess() const { | 92 inline const GrGpuResource::CacheAccess GrGpuResource::cacheAccess() const { |
| 76 return CacheAccess(const_cast<GrGpuResource*>(this)); | 93 return CacheAccess(const_cast<GrGpuResource*>(this)); |
| 77 } | 94 } |
| 78 | 95 |
| 79 #endif | 96 #endif |
| OLD | NEW |