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 | 9 |
10 #include "GrGpuResource.h" | 10 #include "GrGpuResource.h" |
11 #include "GrResourceCache2.h" | 11 #include "GrResourceCache2.h" |
12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
13 | 13 |
14 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) { | 14 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) { |
15 SkASSERT(gpu); | 15 SkASSERT(gpu); |
16 SkASSERT(gpu->getContext()); | 16 SkASSERT(gpu->getContext()); |
17 SkASSERT(gpu->getContext()->getResourceCache2()); | 17 SkASSERT(gpu->getContext()->getResourceCache2()); |
18 return gpu->getContext()->getResourceCache2(); | 18 return gpu->getContext()->getResourceCache2(); |
19 } | 19 } |
20 | 20 |
21 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) | 21 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) |
22 : fScratchKey(GrResourceKey::NullScratchKey()) | 22 : fGpu(gpu) |
23 , fGpu(gpu) | |
24 , fGpuMemorySize(kInvalidGpuMemorySize) | 23 , fGpuMemorySize(kInvalidGpuMemorySize) |
25 , fUniqueID(CreateUniqueID()) { | 24 , fUniqueID(CreateUniqueID()) { |
26 if (isWrapped) { | 25 if (isWrapped) { |
27 fFlags = kWrapped_Flag; | 26 fFlags = kWrapped_Flag; |
28 } else { | 27 } else { |
29 // By default all non-wrapped resources are budgeted. | 28 // By default all non-wrapped resources are budgeted. |
30 fFlags = kBudgeted_Flag; | 29 fFlags = kBudgeted_Flag; |
31 } | 30 } |
32 } | 31 } |
33 | 32 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 83 } |
85 | 84 |
86 size_t oldSize = fGpuMemorySize; | 85 size_t oldSize = fGpuMemorySize; |
87 SkASSERT(kInvalidGpuMemorySize != oldSize); | 86 SkASSERT(kInvalidGpuMemorySize != oldSize); |
88 fGpuMemorySize = kInvalidGpuMemorySize; | 87 fGpuMemorySize = kInvalidGpuMemorySize; |
89 get_resource_cache2(fGpu)->resourceAccess().didChangeGpuMemorySize(this, old
Size); | 88 get_resource_cache2(fGpu)->resourceAccess().didChangeGpuMemorySize(this, old
Size); |
90 } | 89 } |
91 | 90 |
92 bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) { | 91 bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) { |
93 // Currently this can only be called once and can't be called when the resou
rce is scratch. | 92 // Currently this can only be called once and can't be called when the resou
rce is scratch. |
94 SkASSERT(!contentKey.isScratch()); | |
95 SkASSERT(this->internalHasRef()); | 93 SkASSERT(this->internalHasRef()); |
96 | 94 |
97 // Wrapped resources can never have a key. | 95 // Wrapped resources can never have a key. |
98 if (this->isWrapped()) { | 96 if (this->isWrapped()) { |
99 return false; | 97 return false; |
100 } | 98 } |
101 | 99 |
102 if ((fFlags & kContentKeySet_Flag) || this->wasDestroyed()) { | 100 if ((fFlags & kContentKeySet_Flag) || this->wasDestroyed()) { |
103 return false; | 101 return false; |
104 } | 102 } |
(...skipping 11 matching lines...) Expand all Loading... |
116 void GrGpuResource::notifyIsPurgable() const { | 114 void GrGpuResource::notifyIsPurgable() const { |
117 if (this->wasDestroyed()) { | 115 if (this->wasDestroyed()) { |
118 // We've already been removed from the cache. Goodbye cruel world! | 116 // We've already been removed from the cache. Goodbye cruel world! |
119 SkDELETE(this); | 117 SkDELETE(this); |
120 } else { | 118 } else { |
121 GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this); | 119 GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this); |
122 get_resource_cache2(fGpu)->resourceAccess().notifyPurgable(mutableThis); | 120 get_resource_cache2(fGpu)->resourceAccess().notifyPurgable(mutableThis); |
123 } | 121 } |
124 } | 122 } |
125 | 123 |
126 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { | 124 void GrGpuResource::setScratchKey(const GrScratchKey& scratchKey) { |
127 SkASSERT(fScratchKey.isNullScratch()); | 125 SkASSERT(!fScratchKey.isValid()); |
128 SkASSERT(scratchKey.isScratch()); | 126 SkASSERT(scratchKey.isValid()); |
129 SkASSERT(!scratchKey.isNullScratch()); | 127 // Wrapped resources can never have a scratch key. |
130 // Wrapped resources can never have a key. | |
131 if (this->isWrapped()) { | 128 if (this->isWrapped()) { |
132 return; | 129 return; |
133 } | 130 } |
134 fScratchKey = scratchKey; | 131 fScratchKey = scratchKey; |
135 } | 132 } |
136 | 133 |
137 void GrGpuResource::removeScratchKey() { | 134 void GrGpuResource::removeScratchKey() { |
138 if (!this->wasDestroyed() && !fScratchKey.isNullScratch()) { | 135 if (!this->wasDestroyed() && fScratchKey.isValid()) { |
139 get_resource_cache2(fGpu)->resourceAccess().willRemoveScratchKey(this); | 136 get_resource_cache2(fGpu)->resourceAccess().willRemoveScratchKey(this); |
140 fScratchKey = GrResourceKey::NullScratchKey(); | 137 fScratchKey.reset(); |
141 } | 138 } |
142 } | 139 } |
143 | 140 |
144 uint32_t GrGpuResource::CreateUniqueID() { | 141 uint32_t GrGpuResource::CreateUniqueID() { |
145 static int32_t gUniqueID = SK_InvalidUniqueID; | 142 static int32_t gUniqueID = SK_InvalidUniqueID; |
146 uint32_t id; | 143 uint32_t id; |
147 do { | 144 do { |
148 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 145 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
149 } while (id == SK_InvalidUniqueID); | 146 } while (id == SK_InvalidUniqueID); |
150 return id; | 147 return id; |
151 } | 148 } |
152 | 149 |
153 void GrGpuResource::setBudgeted(bool countsAgainstBudget) { | 150 void GrGpuResource::setBudgeted(bool countsAgainstBudget) { |
154 // Wrapped resources never count against the budget, nothing to do. No point
in changing the | 151 // Wrapped resources never count against the budget, nothing to do. No point
in changing the |
155 // budgeting of destroyed resources. | 152 // budgeting of destroyed resources. |
156 if (this->isWrapped() || this->wasDestroyed()) { | 153 if (this->isWrapped() || this->wasDestroyed()) { |
157 return; | 154 return; |
158 } | 155 } |
159 | 156 |
160 uint32_t oldFlags = fFlags; | 157 uint32_t oldFlags = fFlags; |
161 if (countsAgainstBudget) { | 158 if (countsAgainstBudget) { |
162 fFlags |= kBudgeted_Flag; | 159 fFlags |= kBudgeted_Flag; |
163 } else { | 160 } else { |
164 fFlags &= ~kBudgeted_Flag; | 161 fFlags &= ~kBudgeted_Flag; |
165 } | 162 } |
166 if (fFlags != oldFlags) { | 163 if (fFlags != oldFlags) { |
167 get_resource_cache2(fGpu)->resourceAccess().didChangeBudgetStatus(this); | 164 get_resource_cache2(fGpu)->resourceAccess().didChangeBudgetStatus(this); |
168 } | 165 } |
169 } | 166 } |
OLD | NEW |