| 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 GrResourceCache2_DEFINED | 9 #ifndef GrResourceCache2_DEFINED |
| 10 #define GrResourceCache2_DEFINED | 10 #define GrResourceCache2_DEFINED |
| 11 | 11 |
| 12 #include "GrGpuResource.h" | 12 #include "GrGpuResource.h" |
| 13 #include "GrGpuResourceCacheAccess.h" | 13 #include "GrGpuResourceCacheAccess.h" |
| 14 #include "GrResourceKey.h" | 14 #include "GrResourceKey.h" |
| 15 #include "SkRefCnt.h" | 15 #include "SkRefCnt.h" |
| 16 #include "SkTInternalLList.h" | 16 #include "SkTInternalLList.h" |
| 17 #include "SkTMultiMap.h" | 17 #include "SkTMultiMap.h" |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Manages the lifetime of all GrGpuResource instances. | 20 * Manages the lifetime of all GrGpuResource instances. |
| 21 * | 21 * |
| 22 * Resources may have optionally have two types of keys: | 22 * Resources may have optionally have two types of keys: |
| 23 * 1) A scratch key. This is for resources whose allocations are cached but
not their contents. | 23 * 1) A scratch key. This is for resources whose allocations are cached but
not their contents. |
| 24 * Multiple resources can share the same scratch key. This is so a calle
r can have two | 24 * Multiple resources can share the same scratch key. This is so a calle
r can have two |
| 25 * resource instances with the same properties (e.g. multipass rendering
that ping pongs | 25 * resource instances with the same properties (e.g. multipass rendering
that ping-pongs |
| 26 * between two temporary surfaces. The scratch key is set at resource cr
eation time and | 26 * between two temporary surfaces. The scratch key is set at resource cr
eation time and |
| 27 * should never change. Resources need not have a scratch key. | 27 * should never change. Resources need not have a scratch key. |
| 28 * 2) A content key. This key represents the contents of the resource rathe
r than just its | 28 * 2) A content key. This key represents the contents of the resource rathe
r than just its |
| 29 * allocation properties. They may not collide. The content key can be s
et after resource | 29 * allocation properties. They may not collide. The content key can be s
et after resource |
| 30 * creation. Currently it may only be set once and cannot be cleared. Th
is restriction will | 30 * creation. Currently it may only be set once and cannot be cleared. Th
is restriction will |
| 31 * be removed. | 31 * be removed. |
| 32 * If a resource has neither key type then it will be deleted as soon as the las
t reference to it | 32 * If a resource has neither key type then it will be deleted as soon as the las
t reference to it |
| 33 * is dropped. If a key has both keys the content key takes precedence. | 33 * is dropped. If a key has both keys the content key takes precedence. |
| 34 */ | 34 */ |
| 35 class GrResourceCache2 { | 35 class GrResourceCache2 { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 154 |
| 155 private: | 155 private: |
| 156 /////////////////////////////////////////////////////////////////////////// | 156 /////////////////////////////////////////////////////////////////////////// |
| 157 /// @name Methods accessible via ResourceAccess | 157 /// @name Methods accessible via ResourceAccess |
| 158 //// | 158 //// |
| 159 void insertResource(GrGpuResource*); | 159 void insertResource(GrGpuResource*); |
| 160 void removeResource(GrGpuResource*); | 160 void removeResource(GrGpuResource*); |
| 161 void notifyPurgable(GrGpuResource*); | 161 void notifyPurgable(GrGpuResource*); |
| 162 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize); | 162 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize); |
| 163 bool didSetContentKey(GrGpuResource*); | 163 bool didSetContentKey(GrGpuResource*); |
| 164 void didChangeBudgetStatus(GrGpuResource*); |
| 164 void makeResourceMRU(GrGpuResource*); | 165 void makeResourceMRU(GrGpuResource*); |
| 165 /// @} | 166 /// @} |
| 166 | 167 |
| 167 void purgeAsNeeded() { | 168 void purgeAsNeeded() { |
| 168 if (fPurging || (fBudgetedCount <= fMaxCount && fBudgetedBytes < fMaxByt
es)) { | 169 if (fPurging || (fBudgetedCount <= fMaxCount && fBudgetedBytes < fMaxByt
es)) { |
| 169 return; | 170 return; |
| 170 } | 171 } |
| 171 this->internalPurgeAsNeeded(); | 172 this->internalPurgeAsNeeded(); |
| 172 } | 173 } |
| 173 | 174 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 /** | 270 /** |
| 270 * Called by GrGpuResources when their content keys change. | 271 * Called by GrGpuResources when their content keys change. |
| 271 * | 272 * |
| 272 * This currently returns a bool and fails when an existing resource has a k
ey that collides | 273 * This currently returns a bool and fails when an existing resource has a k
ey that collides |
| 273 * with the new content key. In the future it will null out the content key
for the existing | 274 * with the new content key. In the future it will null out the content key
for the existing |
| 274 * resource. The failure is a temporary measure taken because duties are spl
it between two | 275 * resource. The failure is a temporary measure taken because duties are spl
it between two |
| 275 * cache objects currently. | 276 * cache objects currently. |
| 276 */ | 277 */ |
| 277 bool didSetContentKey(GrGpuResource* resource) { return fCache->didSetConten
tKey(resource); } | 278 bool didSetContentKey(GrGpuResource* resource) { return fCache->didSetConten
tKey(resource); } |
| 278 | 279 |
| 280 |
| 281 /** |
| 282 * Called by GrGpuResources when they change from budgeted to unbudgeted or
vice versa. |
| 283 */ |
| 284 void didChangeBudgetStatus(GrGpuResource* resource) { fCache->didChangeBudge
tStatus(resource); } |
| 285 |
| 279 // No taking addresses of this type. | 286 // No taking addresses of this type. |
| 280 const ResourceAccess* operator&() const; | 287 const ResourceAccess* operator&() const; |
| 281 ResourceAccess* operator&(); | 288 ResourceAccess* operator&(); |
| 282 | 289 |
| 283 GrResourceCache2* fCache; | 290 GrResourceCache2* fCache; |
| 284 | 291 |
| 285 friend class GrGpuResource; // To access all the proxy inline methods. | 292 friend class GrGpuResource; // To access all the proxy inline methods. |
| 286 friend class GrResourceCache2; // To create this type. | 293 friend class GrResourceCache2; // To create this type. |
| 287 }; | 294 }; |
| 288 | 295 |
| 289 inline GrResourceCache2::ResourceAccess GrResourceCache2::resourceAccess() { | 296 inline GrResourceCache2::ResourceAccess GrResourceCache2::resourceAccess() { |
| 290 return ResourceAccess(this); | 297 return ResourceAccess(this); |
| 291 } | 298 } |
| 292 | 299 |
| 293 #endif | 300 #endif |
| OLD | NEW |