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 "GrContext.h" | 10 #include "GrContext.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 void GrGpuResource::release() { | 40 void GrGpuResource::release() { |
41 SkASSERT(fGpu); | 41 SkASSERT(fGpu); |
42 this->onRelease(); | 42 this->onRelease(); |
43 get_resource_cache(fGpu)->resourceAccess().removeResource(this); | 43 get_resource_cache(fGpu)->resourceAccess().removeResource(this); |
44 fGpu = nullptr; | 44 fGpu = nullptr; |
45 fGpuMemorySize = 0; | 45 fGpuMemorySize = 0; |
46 } | 46 } |
47 | 47 |
48 void GrGpuResource::abandon() { | 48 void GrGpuResource::abandon() { |
| 49 if (this->wasDestroyed()) { |
| 50 return; |
| 51 } |
49 SkASSERT(fGpu); | 52 SkASSERT(fGpu); |
50 this->onAbandon(); | 53 this->onAbandon(); |
51 get_resource_cache(fGpu)->resourceAccess().removeResource(this); | 54 get_resource_cache(fGpu)->resourceAccess().removeResource(this); |
52 fGpu = nullptr; | 55 fGpu = nullptr; |
53 fGpuMemorySize = 0; | 56 fGpuMemorySize = 0; |
54 } | 57 } |
55 | 58 |
56 void GrGpuResource::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) con
st { | 59 void GrGpuResource::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) con
st { |
57 // Dump resource as "skia/gpu_resources/resource_#". | 60 // Dump resource as "skia/gpu_resources/resource_#". |
58 SkString dumpName("skia/gpu_resources/resource_"); | 61 SkString dumpName("skia/gpu_resources/resource_"); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return; | 100 return; |
98 } | 101 } |
99 | 102 |
100 size_t oldSize = fGpuMemorySize; | 103 size_t oldSize = fGpuMemorySize; |
101 SkASSERT(kInvalidGpuMemorySize != oldSize); | 104 SkASSERT(kInvalidGpuMemorySize != oldSize); |
102 fGpuMemorySize = kInvalidGpuMemorySize; | 105 fGpuMemorySize = kInvalidGpuMemorySize; |
103 get_resource_cache(fGpu)->resourceAccess().didChangeGpuMemorySize(this, oldS
ize); | 106 get_resource_cache(fGpu)->resourceAccess().didChangeGpuMemorySize(this, oldS
ize); |
104 } | 107 } |
105 | 108 |
106 void GrGpuResource::removeUniqueKey() { | 109 void GrGpuResource::removeUniqueKey() { |
| 110 if (this->wasDestroyed()) { |
| 111 return; |
| 112 } |
107 SkASSERT(fUniqueKey.isValid()); | 113 SkASSERT(fUniqueKey.isValid()); |
108 get_resource_cache(fGpu)->resourceAccess().removeUniqueKey(this); | 114 get_resource_cache(fGpu)->resourceAccess().removeUniqueKey(this); |
109 } | 115 } |
110 | 116 |
111 void GrGpuResource::setUniqueKey(const GrUniqueKey& key) { | 117 void GrGpuResource::setUniqueKey(const GrUniqueKey& key) { |
112 SkASSERT(this->internalHasRef()); | 118 SkASSERT(this->internalHasRef()); |
113 SkASSERT(key.isValid()); | 119 SkASSERT(key.isValid()); |
114 | 120 |
115 // Wrapped and uncached resources can never have a unique key. | 121 // Wrapped and uncached resources can never have a unique key. |
116 if (!this->resourcePriv().isBudgeted()) { | 122 if (!this->resourcePriv().isBudgeted()) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 176 } |
171 | 177 |
172 void GrGpuResource::removeScratchKey() { | 178 void GrGpuResource::removeScratchKey() { |
173 if (!this->wasDestroyed() && fScratchKey.isValid()) { | 179 if (!this->wasDestroyed() && fScratchKey.isValid()) { |
174 get_resource_cache(fGpu)->resourceAccess().willRemoveScratchKey(this); | 180 get_resource_cache(fGpu)->resourceAccess().willRemoveScratchKey(this); |
175 fScratchKey.reset(); | 181 fScratchKey.reset(); |
176 } | 182 } |
177 } | 183 } |
178 | 184 |
179 void GrGpuResource::makeBudgeted() { | 185 void GrGpuResource::makeBudgeted() { |
180 if (GrGpuResource::kUncached_LifeCycle == fLifeCycle) { | 186 if (!this->wasDestroyed() && GrGpuResource::kUncached_LifeCycle == fLifeCycl
e) { |
181 fLifeCycle = kCached_LifeCycle; | 187 fLifeCycle = kCached_LifeCycle; |
182 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); | 188 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); |
183 } | 189 } |
184 } | 190 } |
185 | 191 |
186 void GrGpuResource::makeUnbudgeted() { | 192 void GrGpuResource::makeUnbudgeted() { |
187 if (GrGpuResource::kCached_LifeCycle == fLifeCycle && !fUniqueKey.isValid())
{ | 193 if (!this->wasDestroyed() && GrGpuResource::kCached_LifeCycle == fLifeCycle
&& |
| 194 !fUniqueKey.isValid()) { |
188 fLifeCycle = kUncached_LifeCycle; | 195 fLifeCycle = kUncached_LifeCycle; |
189 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); | 196 get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); |
190 } | 197 } |
191 } | 198 } |
192 | 199 |
193 uint32_t GrGpuResource::CreateUniqueID() { | 200 uint32_t GrGpuResource::CreateUniqueID() { |
194 static int32_t gUniqueID = SK_InvalidUniqueID; | 201 static int32_t gUniqueID = SK_InvalidUniqueID; |
195 uint32_t id; | 202 uint32_t id; |
196 do { | 203 do { |
197 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 204 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
198 } while (id == SK_InvalidUniqueID); | 205 } while (id == SK_InvalidUniqueID); |
199 return id; | 206 return id; |
200 } | 207 } |
OLD | NEW |