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