| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2015 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 GrGpuResourcePriv_DEFINED |
| 10 #define GrGpuResourceCacheAccess_DEFINED | 10 #define GrGpuResourcePriv_DEFINED |
| 11 | 11 |
| 12 #include "GrGpuResource.h" | 12 #include "GrGpuResource.h" |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * This class allows code internal to Skia privileged access to manage the cache
keys of a | 15 * This class allows code internal to Skia privileged access to manage the cache
keys and budget |
| 16 * GrGpuResource object. | 16 * status of a GrGpuResource object. |
| 17 */ | 17 */ |
| 18 class GrGpuResource::CacheAccess { | 18 class GrGpuResource::ResourcePriv { |
| 19 public: | 19 public: |
| 20 /** | 20 /** |
| 21 * Sets a content key for the resource. If the resource was previously cache
d as scratch it will | 21 * Sets a content key for the resource. If the resource was previously cache
d as scratch it will |
| 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 GrContentKey& contentKey) { | 27 bool setContentKey(const GrContentKey& contentKey) { |
| 28 return fResource->setContentKey(contentKey); | 28 return fResource->setContentKey(contentKey); |
| 29 } | 29 } |
| 30 | 30 |
| 31 /** Removes the content key from a resource */ |
| 31 void removeContentKey() { return fResource->removeContentKey(); } | 32 void removeContentKey() { return fResource->removeContentKey(); } |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * Is the resource currently cached as scratch? This means it is cached, has
a valid scratch | 35 * If the resource is uncached make it cached. Has no effect on resources th
at are wrapped or |
| 35 * key, and does not have a content key. | 36 * already cached. |
| 36 */ | 37 */ |
| 37 bool isScratch() const { | 38 void makeBudgeted() { fResource->makeBudgeted(); } |
| 38 return !fResource->getContentKey().isValid() && fResource->fScratchKey.i
sValid() && | |
| 39 this->isBudgeted(); | |
| 40 } | |
| 41 | |
| 42 /** | |
| 43 * If this resource can be used as a scratch resource this returns a valid s
cratch key. | |
| 44 * Otherwise it returns a key for which isNullScratch is true. The resource
may currently be | |
| 45 * used as a content resource rather than scratch. Check isScratch(). | |
| 46 */ | |
| 47 const GrScratchKey& getScratchKey() const { return fResource->fScratchKey; } | |
| 48 | 39 |
| 49 /** | 40 /** |
| 50 * If the resource has a scratch key, the key will be removed. Since scratch
keys are installed | 41 * If the resource is cached make it uncached. Has no effect on resources th
at are wrapped or |
| 51 * at resource creation time, this means the resource will never again be us
ed as scratch. | 42 * already uncached. Furthermore, resources with content keys cannot be made
unbudgeted. |
| 52 */ | 43 */ |
| 53 void removeScratchKey() const { fResource->removeScratchKey(); } | 44 void makeUnbudgeted() { fResource->makeUnbudgeted(); } |
| 54 | |
| 55 /** | |
| 56 * Is the resource object wrapping an externally allocated GPU resource? | |
| 57 */ | |
| 58 bool isWrapped() const { return GrGpuResource::kWrapped_LifeCycle == fResour
ce->fLifeCycle; } | |
| 59 | 45 |
| 60 /** | 46 /** |
| 61 * Does the resource count against the resource budget? | 47 * Does the resource count against the resource budget? |
| 62 */ | 48 */ |
| 63 bool isBudgeted() const { | 49 bool isBudgeted() const { |
| 64 bool ret = GrGpuResource::kCached_LifeCycle == fResource->fLifeCycle; | 50 bool ret = GrGpuResource::kCached_LifeCycle == fResource->fLifeCycle; |
| 65 SkASSERT(ret || !fResource->getContentKey().isValid()); | 51 SkASSERT(ret || !fResource->getContentKey().isValid()); |
| 66 return ret; | 52 return ret; |
| 67 } | 53 } |
| 68 | 54 |
| 69 /** | 55 /** |
| 70 * If the resource is uncached make it cached. Has no effect on resources th
at are wrapped or | 56 * If this resource can be used as a scratch resource this returns a valid s
cratch key. |
| 71 * already cached. | 57 * Otherwise it returns a key for which isNullScratch is true. The resource
may currently be |
| 58 * used as a content resource rather than scratch. Check isScratch(). |
| 72 */ | 59 */ |
| 73 void makeBudgeted() { fResource->makeBudgeted(); } | 60 const GrScratchKey& getScratchKey() const { return fResource->fScratchKey; } |
| 74 | 61 |
| 75 /** | 62 /** |
| 76 * If the resource is cached make it uncached. Has no effect on resources th
at are wrapped or | 63 * If the resource has a scratch key, the key will be removed. Since scratch
keys are installed |
| 77 * already uncached. Furthermore, resources with content keys cannot be made
unbudgeted. | 64 * at resource creation time, this means the resource will never again be us
ed as scratch. |
| 78 */ | 65 */ |
| 79 void makeUnbudgeted() { fResource->makeUnbudgeted(); } | 66 void removeScratchKey() const { fResource->removeScratchKey(); } |
| 80 | 67 |
| 81 /** | 68 protected: |
| 82 * Called by the cache to delete the resource under normal circumstances. | 69 ResourcePriv(GrGpuResource* resource) : fResource(resource) { } |
| 83 */ | 70 ResourcePriv(const ResourcePriv& that) : fResource(that.fResource) {} |
| 84 void release() { | 71 ResourcePriv& operator=(const CacheAccess&); // unimpl |
| 85 fResource->release(); | |
| 86 if (fResource->isPurgeable()) { | |
| 87 SkDELETE(fResource); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 /** | |
| 92 * Called by the cache to delete the resource when the backend 3D context is
no longer valid. | |
| 93 */ | |
| 94 void abandon() { | |
| 95 fResource->abandon(); | |
| 96 if (fResource->isPurgeable()) { | |
| 97 SkDELETE(fResource); | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 private: | |
| 102 CacheAccess(GrGpuResource* resource) : fResource(resource) { } | |
| 103 CacheAccess(const CacheAccess& that) : fResource(that.fResource) { } | |
| 104 CacheAccess& operator=(const CacheAccess&); // unimpl | |
| 105 | 72 |
| 106 // No taking addresses of this type. | 73 // No taking addresses of this type. |
| 107 const CacheAccess* operator&() const; | 74 const ResourcePriv* operator&() const; |
| 108 CacheAccess* operator&(); | 75 ResourcePriv* operator&(); |
| 109 | 76 |
| 110 GrGpuResource* fResource; | 77 GrGpuResource* fResource; |
| 111 | 78 |
| 112 friend class GrGpuResource; // to construct/copy this type. | 79 friend class GrGpuResource; // to construct/copy this type. |
| 113 }; | 80 }; |
| 114 | 81 |
| 115 inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAcc
ess(this); } | 82 inline GrGpuResource::ResourcePriv GrGpuResource::resourcePriv() { return Resour
cePriv(this); } |
| 116 | 83 |
| 117 inline const GrGpuResource::CacheAccess GrGpuResource::cacheAccess() const { | 84 inline const GrGpuResource::ResourcePriv GrGpuResource::resourcePriv() const { |
| 118 return CacheAccess(const_cast<GrGpuResource*>(this)); | 85 return ResourcePriv(const_cast<GrGpuResource*>(this)); |
| 119 } | 86 } |
| 120 | 87 |
| 121 #endif | 88 #endif |
| OLD | NEW |