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" |
11 #include "GrResourceCache.h" | 11 #include "GrResourceCache.h" |
12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
13 #include "GrGpuResourcePriv.h" | 13 #include "GrGpuResourcePriv.h" |
14 #include "SkTraceMemoryDump.h" | 14 #include "SkTraceMemoryDump.h" |
15 | 15 |
16 static inline GrResourceCache* get_resource_cache(GrGpu* gpu) { | 16 static inline GrResourceCache* get_resource_cache(GrGpu* gpu) { |
17 SkASSERT(gpu); | 17 SkASSERT(gpu); |
18 SkASSERT(gpu->getContext()); | 18 SkASSERT(gpu->getContext()); |
19 SkASSERT(gpu->getContext()->getResourceCache()); | 19 SkASSERT(gpu->getContext()->getResourceCache()); |
20 return gpu->getContext()->getResourceCache(); | 20 return gpu->getContext()->getResourceCache(); |
21 } | 21 } |
22 | 22 |
23 GrGpuResource::GrGpuResource(GrGpu* gpu, LifeCycle lifeCycle) | 23 GrGpuResource::GrGpuResource(GrGpu* gpu, LifeCycle lifeCycle, Type2 type) |
24 : fGpu(gpu) | 24 : fGpu(gpu) |
25 , fGpuMemorySize(kInvalidGpuMemorySize) | 25 , fGpuMemorySize(kInvalidGpuMemorySize) |
26 , fLifeCycle(lifeCycle) | 26 , fLifeCycle(lifeCycle) |
27 , fUniqueID(CreateUniqueID()) { | 27 , fUniqueID(CreateUniqueID()) |
| 28 , fType1(type) |
| 29 , fFromRawPixels2(false) |
| 30 , fException(false) |
| 31 , fException2(false) { |
28 SkDEBUGCODE(fCacheArrayIndex = -1); | 32 SkDEBUGCODE(fCacheArrayIndex = -1); |
29 } | 33 } |
30 | 34 |
31 void GrGpuResource::registerWithCache() { | 35 void GrGpuResource::registerWithCache() { |
32 get_resource_cache(fGpu)->resourceAccess().insertResource(this); | 36 get_resource_cache(fGpu)->resourceAccess().insertResource(this); |
33 } | 37 } |
34 | 38 |
35 GrGpuResource::~GrGpuResource() { | 39 GrGpuResource::~GrGpuResource() { |
36 // The cache should have released or destroyed this resource. | 40 // The cache should have released or destroyed this resource. |
37 SkASSERT(this->wasDestroyed()); | 41 SkASSERT(this->wasDestroyed()); |
38 } | 42 } |
39 | 43 |
40 void GrGpuResource::release() { | 44 void GrGpuResource::release() { |
41 SkASSERT(fGpu); | 45 SkASSERT(fGpu); |
42 this->onRelease(); | 46 this->onRelease(); |
43 get_resource_cache(fGpu)->resourceAccess().removeResource(this); | 47 get_resource_cache(fGpu)->resourceAccess().removeResource(this); |
44 fGpu = nullptr; | 48 fGpu = nullptr; |
45 fGpuMemorySize = 0; | 49 fGpuMemorySize = 0; |
| 50 fFromRawPixels2 = false; |
| 51 fException = false; |
| 52 fException2 = false; |
46 } | 53 } |
47 | 54 |
48 void GrGpuResource::abandon() { | 55 void GrGpuResource::abandon() { |
49 if (this->wasDestroyed()) { | 56 if (this->wasDestroyed()) { |
50 return; | 57 return; |
51 } | 58 } |
52 SkASSERT(fGpu); | 59 SkASSERT(fGpu); |
53 this->onAbandon(); | 60 this->onAbandon(); |
54 get_resource_cache(fGpu)->resourceAccess().removeResource(this); | 61 get_resource_cache(fGpu)->resourceAccess().removeResource(this); |
55 fGpu = nullptr; | 62 fGpu = nullptr; |
56 fGpuMemorySize = 0; | 63 fGpuMemorySize = 0; |
| 64 fFromRawPixels2 = false; |
| 65 fException = false; |
| 66 fException2 = false; |
57 } | 67 } |
58 | 68 |
59 void GrGpuResource::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) con
st { | 69 void GrGpuResource::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) con
st { |
60 // Dump resource as "skia/gpu_resources/resource_#". | 70 // Dump resource as "skia/gpu_resources/resource_#". |
61 SkString dumpName("skia/gpu_resources/resource_"); | 71 SkString dumpName("skia/gpu_resources/resource_"); |
62 dumpName.appendS32(this->getUniqueID()); | 72 dumpName.appendS32(this->getUniqueID()); |
63 | 73 |
64 traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", this->g
puMemorySize()); | 74 traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", this->g
puMemorySize()); |
65 | 75 |
66 if (this->isPurgeable()) { | 76 if (this->isPurgeable()) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 SkASSERT(kInvalidGpuMemorySize != oldSize); | 114 SkASSERT(kInvalidGpuMemorySize != oldSize); |
105 fGpuMemorySize = kInvalidGpuMemorySize; | 115 fGpuMemorySize = kInvalidGpuMemorySize; |
106 get_resource_cache(fGpu)->resourceAccess().didChangeGpuMemorySize(this, oldS
ize); | 116 get_resource_cache(fGpu)->resourceAccess().didChangeGpuMemorySize(this, oldS
ize); |
107 } | 117 } |
108 | 118 |
109 void GrGpuResource::removeUniqueKey() { | 119 void GrGpuResource::removeUniqueKey() { |
110 if (this->wasDestroyed()) { | 120 if (this->wasDestroyed()) { |
111 return; | 121 return; |
112 } | 122 } |
113 SkASSERT(fUniqueKey.isValid()); | 123 SkASSERT(fUniqueKey.isValid()); |
| 124 |
| 125 if (fType1 == kSurface) { |
| 126 SkASSERT(this->fromRawPixels2() || this->fException2); |
| 127 this->setFromRawPixels(false); |
| 128 fException = false; |
| 129 fException2 = false; |
| 130 } |
114 get_resource_cache(fGpu)->resourceAccess().removeUniqueKey(this); | 131 get_resource_cache(fGpu)->resourceAccess().removeUniqueKey(this); |
115 } | 132 } |
116 | 133 |
117 void GrGpuResource::setUniqueKey(const GrUniqueKey& key) { | 134 void GrGpuResource::setUniqueKey(const GrUniqueKey& key) { |
118 SkASSERT(this->internalHasRef()); | 135 SkASSERT(this->internalHasRef()); |
119 SkASSERT(key.isValid()); | 136 SkASSERT(key.isValid()); |
120 | 137 |
121 // Wrapped and uncached resources can never have a unique key. | 138 // Wrapped and uncached resources can never have a unique key. |
122 if (!this->resourcePriv().isBudgeted()) { | 139 if (!this->resourcePriv().isBudgeted()) { |
123 return; | 140 return; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 215 } |
199 | 216 |
200 uint32_t GrGpuResource::CreateUniqueID() { | 217 uint32_t GrGpuResource::CreateUniqueID() { |
201 static int32_t gUniqueID = SK_InvalidUniqueID; | 218 static int32_t gUniqueID = SK_InvalidUniqueID; |
202 uint32_t id; | 219 uint32_t id; |
203 do { | 220 do { |
204 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 221 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
205 } while (id == SK_InvalidUniqueID); | 222 } while (id == SK_InvalidUniqueID); |
206 return id; | 223 return id; |
207 } | 224 } |
OLD | NEW |