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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 GrGpuResource(GrGpu*, bool isWrapped); | 201 GrGpuResource(GrGpu*, bool isWrapped); |
202 virtual ~GrGpuResource(); | 202 virtual ~GrGpuResource(); |
203 | 203 |
204 GrGpu* getGpu() const { return fGpu; } | 204 GrGpu* getGpu() const { return fGpu; } |
205 | 205 |
206 // Derived classes should always call their parent class' onRelease | 206 // Derived classes should always call their parent class' onRelease |
207 // and onAbandon methods in their overrides. | 207 // and onAbandon methods in their overrides. |
208 virtual void onRelease() {}; | 208 virtual void onRelease() {}; |
209 virtual void onAbandon() {}; | 209 virtual void onAbandon() {}; |
210 | 210 |
211 bool isWrapped() const { return kWrapped_FlagBit & fFlags; } | 211 bool isWrapped() const { return SkToBool(kWrapped_Flag & fFlags); } |
212 | 212 |
213 /** | 213 /** |
214 * This entry point should be called whenever gpuMemorySize() should report a different size. | 214 * This entry point should be called whenever gpuMemorySize() should report a different size. |
215 * The cache will call gpuMemorySize() to update the current size of the res ource. | 215 * The cache will call gpuMemorySize() to update the current size of the res ource. |
216 */ | 216 */ |
217 void didChangeGpuMemorySize() const; | 217 void didChangeGpuMemorySize() const; |
218 | 218 |
219 /** | 219 /** |
220 * Optionally called by the GrGpuResource subclass if the resource can be us ed as scratch. | 220 * Optionally called by the GrGpuResource subclass if the resource can be us ed as scratch. |
221 * By default resources are not usable as scratch. This should only be calle d once. | 221 * By default resources are not usable as scratch. This should only be calle d once. |
222 **/ | 222 **/ |
223 void setScratchKey(const GrResourceKey& scratchKey); | 223 void setScratchKey(const GrResourceKey& scratchKey); |
224 | 224 |
225 private: | 225 private: |
226 virtual size_t onGpuMemorySize() const = 0; | 226 virtual size_t onGpuMemorySize() const = 0; |
227 | 227 |
228 // See comments in CacheAccess. | 228 // See comments in CacheAccess. |
229 bool setContentKey(const GrResourceKey& contentKey); | 229 bool setContentKey(const GrResourceKey& contentKey); |
230 | 230 void setBudgeted(bool countsAgainstBudget); |
231 void notifyIsPurgable() const; | 231 void notifyIsPurgable() const; |
232 | 232 |
233 #ifdef SK_DEBUG | 233 #ifdef SK_DEBUG |
234 friend class GrGpu; // for assert in GrGpu to access getGpu | 234 friend class GrGpu; // for assert in GrGpu to access getGpu |
235 #endif | 235 #endif |
236 | 236 |
237 static uint32_t CreateUniqueID(); | 237 static uint32_t CreateUniqueID(); |
238 | 238 |
239 // We're in an internal doubly linked list owned by GrResourceCache2 | 239 // We're in an internal doubly linked list owned by GrResourceCache2 |
240 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); | 240 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); |
241 | 241 |
242 // This is not ref'ed but abandon() or release() will be called before the G rGpu object | |
243 // is destroyed. Those calls set will this to NULL. | |
244 GrGpu* fGpu; | |
245 | 242 |
243 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); | |
246 enum Flags { | 244 enum Flags { |
247 /** | 245 /** |
248 * This object wraps a GPU object given to us by the user. | 246 * The resource counts against the resource cache's budget. |
249 * Lifetime management is left up to the user (i.e., we will not | |
250 * free it). | |
251 */ | 247 */ |
252 kWrapped_FlagBit = 0x1, | 248 kBudgeted_Flag = 0x1, |
249 | |
250 /** | |
251 * This object wraps a GPU object given to us by Skia's client. Skia wil l not free the | |
252 * underlying backend API GPU resources when the GrGpuResource is destro yed. This also | |
253 * implies that kBudgeted_Flag is not set. | |
254 */ | |
255 kWrapped_Flag = 0x2, | |
256 | |
257 /** | |
258 * If set then fContentKey is valid and the resource is cached based on its content. | |
259 */ | |
260 kContentKeySet_Flag = 0x4, | |
253 }; | 261 }; |
254 | 262 |
255 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); | |
256 | |
257 uint32_t fFlags; | |
258 | |
259 mutable size_t fGpuMemorySize; | |
260 const uint32_t fUniqueID; | |
261 | |
262 // TODO(bsalomon): Remove GrResourceKey and use different simpler types for content and scratch | 263 // TODO(bsalomon): Remove GrResourceKey and use different simpler types for content and scratch |
263 // keys. | 264 // keys. |
264 GrResourceKey fScratchKey; | 265 GrResourceKey fScratchKey; |
265 GrResourceKey fContentKey; | 266 GrResourceKey fContentKey; |
266 bool fContentKeySet; | 267 |
268 // This is not ref'ed but abandon() or release() will be called before the G rGpu object | |
bsalomon
2014/11/13 19:20:54
Mostly shuffling order and removed fContentKeySet
| |
269 // is destroyed. Those calls set will this to NULL. | |
270 GrGpu* fGpu; | |
271 mutable size_t fGpuMemorySize; | |
272 | |
273 uint32_t fFlags; | |
274 const uint32_t fUniqueID; | |
267 | 275 |
268 typedef GrIORef<GrGpuResource> INHERITED; | 276 typedef GrIORef<GrGpuResource> INHERITED; |
269 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. | 277 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. |
270 }; | 278 }; |
271 | 279 |
272 #endif | 280 #endif |
OLD | NEW |