OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrGpuResource_DEFINED | 8 #ifndef GrGpuResource_DEFINED |
9 #define GrGpuResource_DEFINED | 9 #define GrGpuResource_DEFINED |
10 | 10 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 /** | 120 /** |
121 * Base class for objects that can be kept in the GrResourceCache. | 121 * Base class for objects that can be kept in the GrResourceCache. |
122 */ | 122 */ |
123 class SK_API GrGpuResource : public GrIORef<GrGpuResource> { | 123 class SK_API GrGpuResource : public GrIORef<GrGpuResource> { |
124 public: | 124 public: |
125 SK_DECLARE_INST_COUNT(GrGpuResource) | 125 SK_DECLARE_INST_COUNT(GrGpuResource) |
126 | 126 |
127 enum LifeCycle { | 127 enum LifeCycle { |
128 /** | 128 /** |
129 * The resource is cached and owned by Skia. Resources with this status
may be kept alive | 129 * The resource is cached and owned by Skia. Resources with this status
may be kept alive |
130 * by the cache as either scratch or content resources even when there a
re no refs to them. | 130 * by the cache as either scratch or unique resources even when there ar
e no refs to them. |
131 * The cache may release them whenever there are no refs. | 131 * The cache may release them whenever there are no refs. |
132 */ | 132 */ |
133 kCached_LifeCycle, | 133 kCached_LifeCycle, |
134 /** | 134 /** |
135 * The resource is uncached. As soon as there are no more refs to it, it
is released. Under | 135 * The resource is uncached. As soon as there are no more refs to it, it
is released. Under |
136 * the hood the cache may opaquely recycle it as a cached resource. | 136 * the hood the cache may opaquely recycle it as a cached resource. |
137 */ | 137 */ |
138 kUncached_LifeCycle, | 138 kUncached_LifeCycle, |
139 /** | 139 /** |
140 * Similar to uncached, but Skia does not manage the lifetime of the und
erlying backend | 140 * Similar to uncached, but Skia does not manage the lifetime of the und
erlying backend |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 return fGpuMemorySize; | 180 return fGpuMemorySize; |
181 } | 181 } |
182 | 182 |
183 /** | 183 /** |
184 * Gets an id that is unique for this GrGpuResource object. It is static in
that it does | 184 * Gets an id that is unique for this GrGpuResource object. It is static in
that it does |
185 * not change when the content of the GrGpuResource object changes. This wil
l never return | 185 * not change when the content of the GrGpuResource object changes. This wil
l never return |
186 * 0. | 186 * 0. |
187 */ | 187 */ |
188 uint32_t getUniqueID() const { return fUniqueID; } | 188 uint32_t getUniqueID() const { return fUniqueID; } |
189 | 189 |
190 /** Returns the current content key for the resource. It will be invalid if
the resource has not | 190 /** Returns the current unique key for the resource. It will be invalid if t
he resource has no |
191 been cached by its contents. */ | 191 associated unique key. */ |
192 const GrContentKey& getContentKey() const { return fContentKey; } | 192 const GrUniqueKey& getUniqueKey() const { return fUniqueKey; } |
193 | 193 |
194 /** | 194 /** |
195 * Attach a custom data object to this resource. The data will remain attach
ed | 195 * Attach a custom data object to this resource. The data will remain attach
ed |
196 * for the lifetime of this resource (until it is abandoned or released). | 196 * for the lifetime of this resource (until it is abandoned or released). |
197 * Takes a ref on data. Previously attached data, if any, is unrefed. | 197 * Takes a ref on data. Previously attached data, if any, is unrefed. |
198 * Returns the data argument, for convenience. | 198 * Returns the data argument, for convenience. |
199 */ | 199 */ |
200 const SkData* setCustomData(const SkData* data); | 200 const SkData* setCustomData(const SkData* data); |
201 | 201 |
202 /** | 202 /** |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 262 |
263 private: | 263 private: |
264 /** | 264 /** |
265 * Frees the object in the underlying 3D API. Called by CacheAccess. | 265 * Frees the object in the underlying 3D API. Called by CacheAccess. |
266 */ | 266 */ |
267 void release(); | 267 void release(); |
268 | 268 |
269 virtual size_t onGpuMemorySize() const = 0; | 269 virtual size_t onGpuMemorySize() const = 0; |
270 | 270 |
271 // See comments in CacheAccess and ResourcePriv. | 271 // See comments in CacheAccess and ResourcePriv. |
272 bool setContentKey(const GrContentKey& contentKey); | 272 bool setUniqueKey(const GrUniqueKey&); |
273 void removeContentKey(); | 273 void removeUniqueKey(); |
274 void notifyIsPurgeable() const; | 274 void notifyIsPurgeable() const; |
275 void removeScratchKey(); | 275 void removeScratchKey(); |
276 void makeBudgeted(); | 276 void makeBudgeted(); |
277 void makeUnbudgeted(); | 277 void makeUnbudgeted(); |
278 | 278 |
279 #ifdef SK_DEBUG | 279 #ifdef SK_DEBUG |
280 friend class GrGpu; // for assert in GrGpu to access getGpu | 280 friend class GrGpu; // for assert in GrGpu to access getGpu |
281 #endif | 281 #endif |
282 | 282 |
283 static uint32_t CreateUniqueID(); | 283 static uint32_t CreateUniqueID(); |
284 | 284 |
285 // An index into a heap when this resource is purgeable or an array when not
. This is maintained | 285 // An index into a heap when this resource is purgeable or an array when not
. This is maintained |
286 // by the cache. | 286 // by the cache. |
287 int fCacheArrayIndex; | 287 int fCacheArrayIndex; |
288 // This value reflects how recently this resource was accessed in the cache.
This is maintained | 288 // This value reflects how recently this resource was accessed in the cache.
This is maintained |
289 // by the cache. | 289 // by the cache. |
290 uint32_t fTimestamp; | 290 uint32_t fTimestamp; |
291 | 291 |
292 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); | 292 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); |
293 GrScratchKey fScratchKey; | 293 GrScratchKey fScratchKey; |
294 GrContentKey fContentKey; | 294 GrUniqueKey fUniqueKey; |
295 | 295 |
296 // This is not ref'ed but abandon() or release() will be called before the G
rGpu object | 296 // This is not ref'ed but abandon() or release() will be called before the G
rGpu object |
297 // is destroyed. Those calls set will this to NULL. | 297 // is destroyed. Those calls set will this to NULL. |
298 GrGpu* fGpu; | 298 GrGpu* fGpu; |
299 mutable size_t fGpuMemorySize; | 299 mutable size_t fGpuMemorySize; |
300 | 300 |
301 LifeCycle fLifeCycle; | 301 LifeCycle fLifeCycle; |
302 const uint32_t fUniqueID; | 302 const uint32_t fUniqueID; |
303 | 303 |
304 SkAutoTUnref<const SkData> fData; | 304 SkAutoTUnref<const SkData> fData; |
305 | 305 |
306 typedef GrIORef<GrGpuResource> INHERITED; | 306 typedef GrIORef<GrGpuResource> INHERITED; |
307 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgeable. | 307 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgeable. |
308 }; | 308 }; |
309 | 309 |
310 #endif | 310 #endif |
OLD | NEW |