| 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 |
| 11 #include "GrResourceKey.h" | 11 #include "GrResourceKey.h" |
| 12 #include "GrTypesPriv.h" | 12 #include "GrTypesPriv.h" |
| 13 #include "SkData.h" | 13 #include "SkData.h" |
| 14 #include "SkInstCnt.h" | 14 #include "SkInstCnt.h" |
| 15 #include "SkTInternalLList.h" | 15 #include "SkTInternalLList.h" |
| 16 | 16 |
| 17 class GrContext; | 17 class GrContext; |
| 18 class GrGpu; | 18 class GrGpu; |
| 19 class GrResourceCache2; | 19 class GrResourceCache; |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Base class for GrGpuResource. Handles the various types of refs we need. Sepa
rated out as a base | 22 * Base class for GrGpuResource. Handles the various types of refs we need. Sepa
rated out as a base |
| 23 * class to isolate the ref-cnting behavior and provide friendship without expos
ing all of | 23 * class to isolate the ref-cnting behavior and provide friendship without expos
ing all of |
| 24 * GrGpuResource. | 24 * GrGpuResource. |
| 25 * | 25 * |
| 26 * Gpu resources can have three types of refs: | 26 * Gpu resources can have three types of refs: |
| 27 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is is
suing draw calls | 27 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is is
suing draw calls |
| 28 * that read and write the resource via GrDrawTarget and by any object that
must own a | 28 * that read and write the resource via GrDrawTarget and by any object that
must own a |
| 29 * GrGpuResource and is itself owned (directly or indirectly) by Skia-clien
t code. | 29 * GrGpuResource and is itself owned (directly or indirectly) by Skia-clien
t code. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 static_cast<const DERIVED*>(this)->notifyIsPurgeable(); | 106 static_cast<const DERIVED*>(this)->notifyIsPurgeable(); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 mutable int32_t fRefCnt; | 110 mutable int32_t fRefCnt; |
| 111 mutable int32_t fPendingReads; | 111 mutable int32_t fPendingReads; |
| 112 mutable int32_t fPendingWrites; | 112 mutable int32_t fPendingWrites; |
| 113 | 113 |
| 114 // This class is used to manage conversion of refs to pending reads/writes. | 114 // This class is used to manage conversion of refs to pending reads/writes. |
| 115 friend class GrGpuResourceRef; | 115 friend class GrGpuResourceRef; |
| 116 friend class GrResourceCache2; // to check IO ref counts. | 116 friend class GrResourceCache; // to check IO ref counts. |
| 117 | 117 |
| 118 template <typename, GrIOType> friend class GrPendingIOResource; | 118 template <typename, GrIOType> friend class GrPendingIOResource; |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 /** | 121 /** |
| 122 * Base class for objects that can be kept in the GrResourceCache2. | 122 * Base class for objects that can be kept in the GrResourceCache. |
| 123 */ | 123 */ |
| 124 class SK_API GrGpuResource : public GrIORef<GrGpuResource> { | 124 class SK_API GrGpuResource : public GrIORef<GrGpuResource> { |
| 125 public: | 125 public: |
| 126 SK_DECLARE_INST_COUNT(GrGpuResource) | 126 SK_DECLARE_INST_COUNT(GrGpuResource) |
| 127 | 127 |
| 128 enum LifeCycle { | 128 enum LifeCycle { |
| 129 /** | 129 /** |
| 130 * The resource is cached and owned by Skia. Resources with this status
may be kept alive | 130 * The resource is cached and owned by Skia. Resources with this status
may be kept alive |
| 131 * by the cache as either scratch or content resources even when there a
re no refs to them. | 131 * by the cache as either scratch or content resources even when there a
re no refs to them. |
| 132 * The cache may release them whenever there are no refs. | 132 * The cache may release them whenever there are no refs. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 void removeScratchKey(); | 269 void removeScratchKey(); |
| 270 void makeBudgeted(); | 270 void makeBudgeted(); |
| 271 void makeUnbudgeted(); | 271 void makeUnbudgeted(); |
| 272 | 272 |
| 273 #ifdef SK_DEBUG | 273 #ifdef SK_DEBUG |
| 274 friend class GrGpu; // for assert in GrGpu to access getGpu | 274 friend class GrGpu; // for assert in GrGpu to access getGpu |
| 275 #endif | 275 #endif |
| 276 | 276 |
| 277 static uint32_t CreateUniqueID(); | 277 static uint32_t CreateUniqueID(); |
| 278 | 278 |
| 279 // We're in an internal doubly linked list owned by GrResourceCache2 | 279 // We're in an internal doubly linked list owned by GrResourceCache |
| 280 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); | 280 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); |
| 281 | 281 |
| 282 | 282 |
| 283 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); | 283 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); |
| 284 GrScratchKey fScratchKey; | 284 GrScratchKey fScratchKey; |
| 285 GrContentKey fContentKey; | 285 GrContentKey fContentKey; |
| 286 | 286 |
| 287 // This is not ref'ed but abandon() or release() will be called before the G
rGpu object | 287 // This is not ref'ed but abandon() or release() will be called before the G
rGpu object |
| 288 // is destroyed. Those calls set will this to NULL. | 288 // is destroyed. Those calls set will this to NULL. |
| 289 GrGpu* fGpu; | 289 GrGpu* fGpu; |
| 290 mutable size_t fGpuMemorySize; | 290 mutable size_t fGpuMemorySize; |
| 291 | 291 |
| 292 LifeCycle fLifeCycle; | 292 LifeCycle fLifeCycle; |
| 293 const uint32_t fUniqueID; | 293 const uint32_t fUniqueID; |
| 294 | 294 |
| 295 SkAutoTUnref<const SkData> fData; | 295 SkAutoTUnref<const SkData> fData; |
| 296 | 296 |
| 297 typedef GrIORef<GrGpuResource> INHERITED; | 297 typedef GrIORef<GrGpuResource> INHERITED; |
| 298 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgeable. | 298 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgeable. |
| 299 }; | 299 }; |
| 300 | 300 |
| 301 #endif | 301 #endif |
| OLD | NEW |