| 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 15 matching lines...) Expand all Loading... |
| 26 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is is
suing draw calls | 26 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is is
suing draw calls |
| 27 * that read and write the resource via GrDrawTarget and by any object that
must own a | 27 * that read and write the resource via GrDrawTarget and by any object that
must own a |
| 28 * GrGpuResource and is itself owned (directly or indirectly) by Skia-clien
t code. | 28 * GrGpuResource and is itself owned (directly or indirectly) by Skia-clien
t code. |
| 29 * 2) Pending read (+ by addPendingRead(), - by readCompleted()): GrContext ha
s scheduled a read | 29 * 2) Pending read (+ by addPendingRead(), - by readCompleted()): GrContext ha
s scheduled a read |
| 30 * of the resource by the GPU as a result of a skia API call but hasn't exe
cuted it yet. | 30 * of the resource by the GPU as a result of a skia API call but hasn't exe
cuted it yet. |
| 31 * 3) Pending write (+ by addPendingWrite(), - by writeCompleted()): GrContext
has scheduled a | 31 * 3) Pending write (+ by addPendingWrite(), - by writeCompleted()): GrContext
has scheduled a |
| 32 * write to the resource by the GPU as a result of a skia API call but hasn
't executed it yet. | 32 * write to the resource by the GPU as a result of a skia API call but hasn
't executed it yet. |
| 33 * | 33 * |
| 34 * The latter two ref types are private and intended only for Gr core code. | 34 * The latter two ref types are private and intended only for Gr core code. |
| 35 */ | 35 */ |
| 36 class GrGpuRef : public SkNoncopyable { | 36 class GrIORef : public SkNoncopyable { |
| 37 public: | 37 public: |
| 38 SK_DECLARE_INST_COUNT_ROOT(GrGpuRef) | 38 SK_DECLARE_INST_COUNT_ROOT(GrIORef) |
| 39 | 39 |
| 40 virtual ~GrGpuRef(); | 40 enum IOType { |
| 41 kRead_IOType, |
| 42 kWrite_IOType, |
| 43 kRW_IOType |
| 44 }; |
| 45 |
| 46 virtual ~GrIORef(); |
| 41 | 47 |
| 42 // Some of the signatures are written to mirror SkRefCnt so that GrGpuResour
ce can work with | 48 // Some of the signatures are written to mirror SkRefCnt so that GrGpuResour
ce can work with |
| 43 // templated helper classes (e.g. SkAutoTUnref). However, we have different
categories of | 49 // templated helper classes (e.g. SkAutoTUnref). However, we have different
categories of |
| 44 // refs (e.g. pending reads). We also don't require thread safety as GrCache
able objects are | 50 // refs (e.g. pending reads). We also don't require thread safety as GrCache
able objects are |
| 45 // not intended to cross thread boundaries. | 51 // not intended to cross thread boundaries. |
| 46 // internal_dispose() exists because of GrTexture's reliance on it. It will
be removed | 52 // internal_dispose() exists because of GrTexture's reliance on it. It will
be removed |
| 47 // soon. | 53 // soon. |
| 48 void ref() const { | 54 void ref() const { |
| 49 ++fRefCnt; | 55 ++fRefCnt; |
| 50 // pre-validate once internal_dispose is removed (and therefore 0 ref cn
t is not allowed). | 56 // pre-validate once internal_dispose is removed (and therefore 0 ref cn
t is not allowed). |
| (...skipping 17 matching lines...) Expand all Loading... |
| 68 void validate() const { | 74 void validate() const { |
| 69 #ifdef SK_DEBUG | 75 #ifdef SK_DEBUG |
| 70 SkASSERT(fRefCnt >= 0); | 76 SkASSERT(fRefCnt >= 0); |
| 71 SkASSERT(fPendingReads >= 0); | 77 SkASSERT(fPendingReads >= 0); |
| 72 SkASSERT(fPendingWrites >= 0); | 78 SkASSERT(fPendingWrites >= 0); |
| 73 SkASSERT(fRefCnt + fPendingReads + fPendingWrites > 0); | 79 SkASSERT(fRefCnt + fPendingReads + fPendingWrites > 0); |
| 74 #endif | 80 #endif |
| 75 } | 81 } |
| 76 | 82 |
| 77 protected: | 83 protected: |
| 78 GrGpuRef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) {} | 84 GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) {} |
| 79 | 85 |
| 80 private: | 86 private: |
| 81 void addPendingRead() const { | 87 void addPendingRead() const { |
| 82 this->validate(); | 88 this->validate(); |
| 83 ++fPendingReads; | 89 ++fPendingReads; |
| 84 } | 90 } |
| 85 | 91 |
| 86 void completedRead() const { | 92 void completedRead() const { |
| 87 this->validate(); | 93 this->validate(); |
| 88 --fPendingReads; | 94 --fPendingReads; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 104 } | 110 } |
| 105 } | 111 } |
| 106 | 112 |
| 107 private: | 113 private: |
| 108 mutable int32_t fRefCnt; | 114 mutable int32_t fRefCnt; |
| 109 mutable int32_t fPendingReads; | 115 mutable int32_t fPendingReads; |
| 110 mutable int32_t fPendingWrites; | 116 mutable int32_t fPendingWrites; |
| 111 | 117 |
| 112 // This class is used to manage conversion of refs to pending reads/writes. | 118 // This class is used to manage conversion of refs to pending reads/writes. |
| 113 friend class GrGpuResourceRef; | 119 friend class GrGpuResourceRef; |
| 114 template <typename T> friend class GrPendingIOResource; | 120 template <typename, IOType> friend class GrPendingIOResource; |
| 115 }; | 121 }; |
| 116 | 122 |
| 117 /** | 123 /** |
| 118 * Base class for objects that can be kept in the GrResourceCache. | 124 * Base class for objects that can be kept in the GrResourceCache. |
| 119 */ | 125 */ |
| 120 class GrGpuResource : public GrGpuRef { | 126 class GrGpuResource : public GrIORef { |
| 121 public: | 127 public: |
| 122 SK_DECLARE_INST_COUNT(GrGpuResource) | 128 SK_DECLARE_INST_COUNT(GrGpuResource) |
| 123 | 129 |
| 124 /** | 130 /** |
| 125 * Frees the object in the underlying 3D API. It must be safe to call this | 131 * Frees the object in the underlying 3D API. It must be safe to call this |
| 126 * when the object has been previously abandoned. | 132 * when the object has been previously abandoned. |
| 127 */ | 133 */ |
| 128 void release(); | 134 void release(); |
| 129 | 135 |
| 130 /** | 136 /** |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 kWrapped_FlagBit = 0x1, | 241 kWrapped_FlagBit = 0x1, |
| 236 }; | 242 }; |
| 237 | 243 |
| 238 uint32_t fFlags; | 244 uint32_t fFlags; |
| 239 | 245 |
| 240 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache | 246 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache |
| 241 const uint32_t fUniqueID; | 247 const uint32_t fUniqueID; |
| 242 | 248 |
| 243 GrResourceKey fScratchKey; | 249 GrResourceKey fScratchKey; |
| 244 | 250 |
| 245 typedef GrGpuRef INHERITED; | 251 typedef GrIORef INHERITED; |
| 246 }; | 252 }; |
| 247 | 253 |
| 248 #endif | 254 #endif |
| OLD | NEW |