OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrGpuResource.h" | 9 #include "GrGpuResource.h" |
10 #include "GrResourceCache.h" | 10 #include "GrResourceCache.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 return; | 98 return; |
99 } | 99 } |
100 | 100 |
101 if (this->wasDestroyed()) { | 101 if (this->wasDestroyed()) { |
102 return; | 102 return; |
103 } | 103 } |
104 | 104 |
105 get_resource_cache(fGpu)->resourceAccess().changeUniqueKey(this, key); | 105 get_resource_cache(fGpu)->resourceAccess().changeUniqueKey(this, key); |
106 } | 106 } |
107 | 107 |
108 void GrGpuResource::notifyIsPurgeable() const { | 108 void GrGpuResource::notifyAllCntsAreZero(CntType lastCntTypeToReachZero) const { |
109 if (this->wasDestroyed()) { | 109 if (this->wasDestroyed()) { |
110 // We've already been removed from the cache. Goodbye cruel world! | 110 // We've already been removed from the cache. Goodbye cruel world! |
111 SkDELETE(this); | 111 SkDELETE(this); |
112 } else { | 112 return; |
113 GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this); | |
114 get_resource_cache(fGpu)->resourceAccess().notifyPurgeable(mutableThis); | |
115 } | 113 } |
| 114 |
| 115 // We should have already handled this fully in notifyRefCntIsZero(). |
| 116 SkASSERT(kRef_CntType != lastCntTypeToReachZero); |
| 117 |
| 118 GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this); |
| 119 static const uint32_t kFlag = |
| 120 GrResourceCache::ResourceAccess::kAllCntsReachedZero_RefNotificationFlag
; |
| 121 get_resource_cache(fGpu)->resourceAccess().notifyCntReachedZero(mutableThis,
kFlag); |
| 122 } |
| 123 |
| 124 bool GrGpuResource::notifyRefCountIsZero() const { |
| 125 if (this->wasDestroyed()) { |
| 126 // handle this in notifyAllCntsAreZero(). |
| 127 return true; |
| 128 } |
| 129 |
| 130 GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this); |
| 131 uint32_t flags = |
| 132 GrResourceCache::ResourceAccess::kRefCntReachedZero_RefNotificationFlag; |
| 133 if (!this->internalHasPendingIO()) { |
| 134 flags |= GrResourceCache::ResourceAccess::kAllCntsReachedZero_RefNotific
ationFlag; |
| 135 } |
| 136 get_resource_cache(fGpu)->resourceAccess().notifyCntReachedZero(mutableThis,
flags); |
| 137 |
| 138 // There is no need to call our notifyAllCntsAreZero function at this point
since we already |
| 139 // told the cache about the state of cnts. |
| 140 return false; |
116 } | 141 } |
117 | 142 |
118 void GrGpuResource::setScratchKey(const GrScratchKey& scratchKey) { | 143 void GrGpuResource::setScratchKey(const GrScratchKey& scratchKey) { |
119 SkASSERT(!fScratchKey.isValid()); | 144 SkASSERT(!fScratchKey.isValid()); |
120 SkASSERT(scratchKey.isValid()); | 145 SkASSERT(scratchKey.isValid()); |
121 // Wrapped resources can never have a scratch key. | 146 // Wrapped resources can never have a scratch key. |
122 if (this->isWrapped()) { | 147 if (this->isWrapped()) { |
123 return; | 148 return; |
124 } | 149 } |
125 fScratchKey = scratchKey; | 150 fScratchKey = scratchKey; |
(...skipping 21 matching lines...) Expand all Loading... |
147 } | 172 } |
148 | 173 |
149 uint32_t GrGpuResource::CreateUniqueID() { | 174 uint32_t GrGpuResource::CreateUniqueID() { |
150 static int32_t gUniqueID = SK_InvalidUniqueID; | 175 static int32_t gUniqueID = SK_InvalidUniqueID; |
151 uint32_t id; | 176 uint32_t id; |
152 do { | 177 do { |
153 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 178 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
154 } while (id == SK_InvalidUniqueID); | 179 } while (id == SK_InvalidUniqueID); |
155 return id; | 180 return id; |
156 } | 181 } |
OLD | NEW |