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 /** | |
37 * Is the resource currently cached as scratch? This means it has a valid sc
ratch key and does | 32 * Is the resource currently cached as scratch? This means it has a valid sc
ratch key and does |
38 * not have a content key. | 33 * not have a content key. |
39 */ | 34 */ |
40 bool isScratch() const { | 35 bool isScratch() const { |
41 return NULL == this->getContentKey() && fResource->fScratchKey.isValid()
; | 36 return NULL == this->getContentKey() && fResource->fScratchKey.isValid()
; |
42 } | 37 } |
43 | 38 |
44 /** | 39 /** |
45 * If this resource can be used as a scratch resource this returns a valid s
cratch key. | 40 * If this resource can be used as a scratch resource this returns a valid s
cratch key. |
46 * Otherwise it returns a key for which isNullScratch is true. The resource
may currently be | 41 * Otherwise it returns a key for which isNullScratch is true. The resource
may currently be |
(...skipping 13 matching lines...) Expand all Loading... |
60 const GrResourceKey* getContentKey() const { | 55 const GrResourceKey* getContentKey() const { |
61 if (fResource->fFlags & GrGpuResource::kContentKeySet_Flag) { | 56 if (fResource->fFlags & GrGpuResource::kContentKeySet_Flag) { |
62 return &fResource->fContentKey; | 57 return &fResource->fContentKey; |
63 } | 58 } |
64 return NULL; | 59 return NULL; |
65 } | 60 } |
66 | 61 |
67 /** | 62 /** |
68 * Is the resource object wrapping an externally allocated GPU resource? | 63 * Is the resource object wrapping an externally allocated GPU resource? |
69 */ | 64 */ |
70 bool isWrapped() const { return fResource->isWrapped(); } | 65 bool isWrapped() const { return GrGpuResource::kWrapped_LifeCycle == fResour
ce->fLifeCycle; } |
71 | 66 |
72 /** | 67 /** |
73 * Does the resource count against the resource budget? | 68 * Does the resource count against the resource budget? |
74 */ | 69 */ |
75 bool isBudgeted() const { | 70 bool isBudgeted() const { return GrGpuResource::kCached_LifeCycle == fResour
ce->fLifeCycle; } |
76 bool ret = SkToBool(GrGpuResource::kBudgeted_Flag & fResource->fFlags); | |
77 SkASSERT(!(ret && fResource->isWrapped())); | |
78 return ret; | |
79 } | |
80 | 71 |
81 /** | 72 /** |
82 * Called by the cache to delete the resource under normal circumstances. | 73 * Called by the cache to delete the resource under normal circumstances. |
83 */ | 74 */ |
84 void release() { | 75 void release() { |
85 fResource->release(); | 76 fResource->release(); |
86 if (fResource->isPurgable()) { | 77 if (fResource->isPurgable()) { |
87 SkDELETE(fResource); | 78 SkDELETE(fResource); |
88 } | 79 } |
89 } | 80 } |
(...skipping 22 matching lines...) Expand all Loading... |
112 friend class GrGpuResource; // to construct/copy this type. | 103 friend class GrGpuResource; // to construct/copy this type. |
113 }; | 104 }; |
114 | 105 |
115 inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAcc
ess(this); } | 106 inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAcc
ess(this); } |
116 | 107 |
117 inline const GrGpuResource::CacheAccess GrGpuResource::cacheAccess() const { | 108 inline const GrGpuResource::CacheAccess GrGpuResource::cacheAccess() const { |
118 return CacheAccess(const_cast<GrGpuResource*>(this)); | 109 return CacheAccess(const_cast<GrGpuResource*>(this)); |
119 } | 110 } |
120 | 111 |
121 #endif | 112 #endif |
OLD | NEW |