| 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); } |
| 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 |
| 59 /** | 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 |
| 76 /** |
| 60 * Called by the cache to delete the resource under normal circumstances. | 77 * Called by the cache to delete the resource under normal circumstances. |
| 61 */ | 78 */ |
| 62 void release() { | 79 void release() { |
| 63 fResource->release(); | 80 fResource->release(); |
| 64 if (fResource->isPurgable()) { | 81 if (fResource->isPurgable()) { |
| 65 SkDELETE(fResource); | 82 SkDELETE(fResource); |
| 66 } | 83 } |
| 67 } | 84 } |
| 68 | 85 |
| 69 /** | 86 /** |
| (...skipping 20 matching lines...) Expand all Loading... |
| 90 friend class GrGpuResource; // to construct/copy this type. | 107 friend class GrGpuResource; // to construct/copy this type. |
| 91 }; | 108 }; |
| 92 | 109 |
| 93 inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAcc
ess(this); } | 110 inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAcc
ess(this); } |
| 94 | 111 |
| 95 inline const GrGpuResource::CacheAccess GrGpuResource::cacheAccess() const { | 112 inline const GrGpuResource::CacheAccess GrGpuResource::cacheAccess() const { |
| 96 return CacheAccess(const_cast<GrGpuResource*>(this)); | 113 return CacheAccess(const_cast<GrGpuResource*>(this)); |
| 97 } | 114 } |
| 98 | 115 |
| 99 #endif | 116 #endif |
| OLD | NEW |