| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // not intended to cross thread boundaries. | 51 // not intended to cross thread boundaries. |
| 52 void ref() const { | 52 void ref() const { |
| 53 this->validate(); | 53 this->validate(); |
| 54 ++fRefCnt; | 54 ++fRefCnt; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void unref() const { | 57 void unref() const { |
| 58 this->validate(); | 58 this->validate(); |
| 59 | 59 |
| 60 if (!(--fRefCnt)) { | 60 if (!(--fRefCnt)) { |
| 61 SkASSERT(fRefCnt >= 0); |
| 61 if (!static_cast<const DERIVED*>(this)->notifyRefCountIsZero()) { | 62 if (!static_cast<const DERIVED*>(this)->notifyRefCountIsZero()) { |
| 62 return; | 63 return; |
| 63 } | 64 } |
| 64 } | 65 } |
| 65 | 66 |
| 66 this->didRemoveRefOrPendingIO(kRef_CntType); | 67 this->didRemoveRefOrPendingIO(kRef_CntType); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void validate() const { | 70 void validate() const { |
| 70 #ifdef SK_DEBUG | 71 #ifdef SK_DEBUG |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 111 } |
| 111 | 112 |
| 112 void completedWrite() const { | 113 void completedWrite() const { |
| 113 this->validate(); | 114 this->validate(); |
| 114 --fPendingWrites; | 115 --fPendingWrites; |
| 115 this->didRemoveRefOrPendingIO(kPendingWrite_CntType); | 116 this->didRemoveRefOrPendingIO(kPendingWrite_CntType); |
| 116 } | 117 } |
| 117 | 118 |
| 118 private: | 119 private: |
| 119 void didRemoveRefOrPendingIO(CntType cntTypeRemoved) const { | 120 void didRemoveRefOrPendingIO(CntType cntTypeRemoved) const { |
| 121 this->validate(); |
| 120 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) { | 122 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) { |
| 121 static_cast<const DERIVED*>(this)->notifyAllCntsAreZero(cntTypeRemov
ed); | 123 static_cast<const DERIVED*>(this)->notifyAllCntsAreZero(cntTypeRemov
ed); |
| 122 } | 124 } |
| 123 } | 125 } |
| 124 | 126 |
| 125 mutable int32_t fRefCnt; | 127 mutable int32_t fRefCnt; |
| 126 mutable int32_t fPendingReads; | 128 mutable int32_t fPendingReads; |
| 127 mutable int32_t fPendingWrites; | 129 mutable int32_t fPendingWrites; |
| 128 | 130 |
| 129 // This class is used to manage conversion of refs to pending reads/writes. | 131 // This class is used to manage conversion of refs to pending reads/writes. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 302 |
| 301 SkBudgeted fBudgeted; | 303 SkBudgeted fBudgeted; |
| 302 bool fRefsWrappedObjects; | 304 bool fRefsWrappedObjects; |
| 303 const uint32_t fUniqueID; | 305 const uint32_t fUniqueID; |
| 304 | 306 |
| 305 typedef GrIORef<GrGpuResource> INHERITED; | 307 typedef GrIORef<GrGpuResource> INHERITED; |
| 306 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n
otifyRefCntIsZero. | 308 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n
otifyRefCntIsZero. |
| 307 }; | 309 }; |
| 308 | 310 |
| 309 #endif | 311 #endif |
| OLD | NEW |