OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCPrioritizedTextureManager.h" | 7 #include "CCPrioritizedTextureManager.h" |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "CCPrioritizedTexture.h" | 10 #include "CCPrioritizedTexture.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 , m_pool(pool) | 25 , m_pool(pool) |
26 { | 26 { |
27 } | 27 } |
28 | 28 |
29 CCPrioritizedTextureManager::~CCPrioritizedTextureManager() | 29 CCPrioritizedTextureManager::~CCPrioritizedTextureManager() |
30 { | 30 { |
31 while (m_textures.size() > 0) | 31 while (m_textures.size() > 0) |
32 unregisterTexture(*m_textures.begin()); | 32 unregisterTexture(*m_textures.begin()); |
33 | 33 |
34 deleteUnlinkedEvictedBackings(); | 34 deleteUnlinkedEvictedBackings(); |
35 ASSERT(m_evictedBackings.isEmpty()); | 35 CC_DCHECK(m_evictedBackings.isEmpty()); |
36 | 36 |
37 // Each remaining backing is a leaked opengl texture. There should be none. | 37 // Each remaining backing is a leaked opengl texture. There should be none. |
38 ASSERT(m_backings.isEmpty()); | 38 CC_DCHECK(m_backings.isEmpty()); |
39 } | 39 } |
40 | 40 |
41 void CCPrioritizedTextureManager::prioritizeTextures() | 41 void CCPrioritizedTextureManager::prioritizeTextures() |
42 { | 42 { |
43 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::prioritizeTextures"); | 43 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::prioritizeTextures"); |
44 ASSERT(CCProxy::isMainThread()); | 44 CC_DCHECK(CCProxy::isMainThread()); |
45 | 45 |
46 // Sorting textures in this function could be replaced by a slightly | 46 // Sorting textures in this function could be replaced by a slightly |
47 // modified O(n) quick-select to partition textures rather than | 47 // modified O(n) quick-select to partition textures rather than |
48 // sort them (if performance of the sort becomes an issue). | 48 // sort them (if performance of the sort becomes an issue). |
49 | 49 |
50 TextureVector& sortedTextures = m_tempTextureVector; | 50 TextureVector& sortedTextures = m_tempTextureVector; |
51 sortedTextures.clear(); | 51 sortedTextures.clear(); |
52 | 52 |
53 // Copy all textures into a vector and sort them. | 53 // Copy all textures into a vector and sort them. |
54 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); +
+it) | 54 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); +
+it) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // being partially allowed randomly. | 87 // being partially allowed randomly. |
88 m_memoryAboveCutoffBytes = 0; | 88 m_memoryAboveCutoffBytes = 0; |
89 for (TextureVector::iterator it = sortedTextures.begin(); it != sortedTextur
es.end(); ++it) { | 89 for (TextureVector::iterator it = sortedTextures.begin(); it != sortedTextur
es.end(); ++it) { |
90 bool isAbovePriorityCutoff = CCPriorityCalculator::priorityIsHigher((*it
)->requestPriority(), m_priorityCutoff); | 90 bool isAbovePriorityCutoff = CCPriorityCalculator::priorityIsHigher((*it
)->requestPriority(), m_priorityCutoff); |
91 (*it)->setAbovePriorityCutoff(isAbovePriorityCutoff); | 91 (*it)->setAbovePriorityCutoff(isAbovePriorityCutoff); |
92 if (isAbovePriorityCutoff && !(*it)->isSelfManaged()) | 92 if (isAbovePriorityCutoff && !(*it)->isSelfManaged()) |
93 m_memoryAboveCutoffBytes += (*it)->bytes(); | 93 m_memoryAboveCutoffBytes += (*it)->bytes(); |
94 } | 94 } |
95 sortedTextures.clear(); | 95 sortedTextures.clear(); |
96 | 96 |
97 ASSERT(m_memoryAboveCutoffBytes <= m_memoryAvailableBytes); | 97 CC_DCHECK(m_memoryAboveCutoffBytes <= m_memoryAvailableBytes); |
98 ASSERT(memoryAboveCutoffBytes() <= maxMemoryLimitBytes()); | 98 CC_DCHECK(memoryAboveCutoffBytes() <= maxMemoryLimitBytes()); |
99 } | 99 } |
100 | 100 |
101 void CCPrioritizedTextureManager::pushTexturePrioritiesToBackings() | 101 void CCPrioritizedTextureManager::pushTexturePrioritiesToBackings() |
102 { | 102 { |
103 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::pushTexturePrioritiesToBack
ings"); | 103 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::pushTexturePrioritiesToBack
ings"); |
104 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 104 CC_DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
105 | 105 |
106 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) | 106 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) |
107 (*it)->updatePriority(); | 107 (*it)->updatePriority(); |
108 | 108 |
109 sortBackings(); | 109 sortBackings(); |
110 } | 110 } |
111 | 111 |
112 void CCPrioritizedTextureManager::updateBackingsInDrawingImplTree() | 112 void CCPrioritizedTextureManager::updateBackingsInDrawingImplTree() |
113 { | 113 { |
114 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsInDrawingImpl
Tree"); | 114 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsInDrawingImpl
Tree"); |
115 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 115 CC_DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
116 | 116 |
117 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) { | 117 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) { |
118 CCPrioritizedTexture::Backing* backing = (*it); | 118 CCPrioritizedTexture::Backing* backing = (*it); |
119 backing->updateInDrawingImplTree(); | 119 backing->updateInDrawingImplTree(); |
120 } | 120 } |
121 | 121 |
122 sortBackings(); | 122 sortBackings(); |
123 } | 123 } |
124 | 124 |
125 void CCPrioritizedTextureManager::sortBackings() | 125 void CCPrioritizedTextureManager::sortBackings() |
126 { | 126 { |
127 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsPriorities"); | 127 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsPriorities"); |
128 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 128 CC_DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
129 | 129 |
130 // Update backings' priorities and put backings in eviction/recycling order. | 130 // Update backings' priorities and put backings in eviction/recycling order. |
131 BackingVector& sortedBackings = m_tempBackingVector; | 131 BackingVector& sortedBackings = m_tempBackingVector; |
132 sortedBackings.clear(); | 132 sortedBackings.clear(); |
133 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) | 133 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) |
134 sortedBackings.append(*it); | 134 sortedBackings.append(*it); |
135 std::sort(sortedBackings.begin(), sortedBackings.end(), compareBackings); | 135 std::sort(sortedBackings.begin(), sortedBackings.end(), compareBackings); |
136 | 136 |
137 for (BackingVector::iterator it = sortedBackings.begin(); it != sortedBackin
gs.end(); ++it) { | 137 for (BackingVector::iterator it = sortedBackings.begin(); it != sortedBackin
gs.end(); ++it) { |
138 m_backings.remove(*it); | 138 m_backings.remove(*it); |
139 m_backings.add(*it); | 139 m_backings.add(*it); |
140 } | 140 } |
141 sortedBackings.clear(); | 141 sortedBackings.clear(); |
142 | 142 |
143 #if !ASSERT_DISABLED | 143 #if CC_DCHECK_ENABLED |
144 assertInvariants(); | 144 assertInvariants(); |
145 #endif | 145 #endif |
146 } | 146 } |
147 | 147 |
148 void CCPrioritizedTextureManager::clearPriorities() | 148 void CCPrioritizedTextureManager::clearPriorities() |
149 { | 149 { |
150 ASSERT(CCProxy::isMainThread()); | 150 CC_DCHECK(CCProxy::isMainThread()); |
151 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); +
+it) { | 151 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); +
+it) { |
152 // FIXME: We should remove this and just set all priorities to | 152 // FIXME: We should remove this and just set all priorities to |
153 // CCPriorityCalculator::lowestPriority() once we have priorities | 153 // CCPriorityCalculator::lowestPriority() once we have priorities |
154 // for all textures (we can't currently calculate distances for | 154 // for all textures (we can't currently calculate distances for |
155 // off-screen textures). | 155 // off-screen textures). |
156 (*it)->setRequestPriority(CCPriorityCalculator::lingeringPriority((*it)-
>requestPriority())); | 156 (*it)->setRequestPriority(CCPriorityCalculator::lingeringPriority((*it)-
>requestPriority())); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 bool CCPrioritizedTextureManager::requestLate(CCPrioritizedTexture* texture) | 160 bool CCPrioritizedTextureManager::requestLate(CCPrioritizedTexture* texture) |
161 { | 161 { |
162 ASSERT(CCProxy::isMainThread()); | 162 CC_DCHECK(CCProxy::isMainThread()); |
163 | 163 |
164 // This is already above cutoff, so don't double count it's memory below. | 164 // This is already above cutoff, so don't double count it's memory below. |
165 if (texture->isAbovePriorityCutoff()) | 165 if (texture->isAbovePriorityCutoff()) |
166 return true; | 166 return true; |
167 | 167 |
168 if (CCPriorityCalculator::priorityIsLower(texture->requestPriority(), m_prio
rityCutoff)) | 168 if (CCPriorityCalculator::priorityIsLower(texture->requestPriority(), m_prio
rityCutoff)) |
169 return false; | 169 return false; |
170 | 170 |
171 size_t newMemoryBytes = m_memoryAboveCutoffBytes + texture->bytes(); | 171 size_t newMemoryBytes = m_memoryAboveCutoffBytes + texture->bytes(); |
172 if (newMemoryBytes > m_memoryAvailableBytes) | 172 if (newMemoryBytes > m_memoryAvailableBytes) |
173 return false; | 173 return false; |
174 | 174 |
175 m_memoryAboveCutoffBytes = newMemoryBytes; | 175 m_memoryAboveCutoffBytes = newMemoryBytes; |
176 texture->setAbovePriorityCutoff(true); | 176 texture->setAbovePriorityCutoff(true); |
177 return true; | 177 return true; |
178 } | 178 } |
179 | 179 |
180 void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTex
ture* texture, CCResourceProvider* resourceProvider) | 180 void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTex
ture* texture, CCResourceProvider* resourceProvider) |
181 { | 181 { |
182 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 182 CC_DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
183 ASSERT(!texture->isSelfManaged()); | 183 CC_DCHECK(!texture->isSelfManaged()); |
184 ASSERT(texture->isAbovePriorityCutoff()); | 184 CC_DCHECK(texture->isAbovePriorityCutoff()); |
185 if (texture->backing() || !texture->isAbovePriorityCutoff()) | 185 if (texture->backing() || !texture->isAbovePriorityCutoff()) |
186 return; | 186 return; |
187 | 187 |
188 // Find a backing below, by either recycling or allocating. | 188 // Find a backing below, by either recycling or allocating. |
189 CCPrioritizedTexture::Backing* backing = 0; | 189 CCPrioritizedTexture::Backing* backing = 0; |
190 | 190 |
191 // First try to recycle | 191 // First try to recycle |
192 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) { | 192 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) { |
193 if (!(*it)->canBeRecycled()) | 193 if (!(*it)->canBeRecycled()) |
194 break; | 194 break; |
(...skipping 15 matching lines...) Expand all Loading... |
210 texture->link(backing); | 210 texture->link(backing); |
211 m_backings.remove(backing); | 211 m_backings.remove(backing); |
212 m_backings.add(backing); | 212 m_backings.add(backing); |
213 | 213 |
214 // Update the backing's priority from its new owner. | 214 // Update the backing's priority from its new owner. |
215 backing->updatePriority(); | 215 backing->updatePriority(); |
216 } | 216 } |
217 | 217 |
218 void CCPrioritizedTextureManager::evictBackingsToReduceMemory(size_t limitBytes,
EvictionPriorityPolicy evictionPolicy, CCResourceProvider* resourceProvider) | 218 void CCPrioritizedTextureManager::evictBackingsToReduceMemory(size_t limitBytes,
EvictionPriorityPolicy evictionPolicy, CCResourceProvider* resourceProvider) |
219 { | 219 { |
220 ASSERT(CCProxy::isImplThread()); | 220 CC_DCHECK(CCProxy::isImplThread()); |
221 if (memoryUseBytes() <= limitBytes) | 221 if (memoryUseBytes() <= limitBytes) |
222 return; | 222 return; |
223 | 223 |
224 // Destroy backings until we are below the limit, | 224 // Destroy backings until we are below the limit, |
225 // or until all backings remaining are above the cutoff. | 225 // or until all backings remaining are above the cutoff. |
226 while (memoryUseBytes() > limitBytes && m_backings.size() > 0) { | 226 while (memoryUseBytes() > limitBytes && m_backings.size() > 0) { |
227 CCPrioritizedTexture::Backing* backing = *m_backings.begin(); | 227 CCPrioritizedTexture::Backing* backing = *m_backings.begin(); |
228 if (evictionPolicy == RespectManagerPriorityCutoff) | 228 if (evictionPolicy == RespectManagerPriorityCutoff) |
229 if (backing->wasAbovePriorityCutoffAtLastPriorityUpdate()) | 229 if (backing->wasAbovePriorityCutoffAtLastPriorityUpdate()) |
230 break; | 230 break; |
231 evictBackingResource(backing, resourceProvider); | 231 evictBackingResource(backing, resourceProvider); |
232 } | 232 } |
233 } | 233 } |
234 | 234 |
235 void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvi
der) | 235 void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvi
der) |
236 { | 236 { |
237 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 237 CC_DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
238 | 238 |
239 evictBackingsToReduceMemory(m_memoryAvailableBytes, RespectManagerPriorityCu
toff, resourceProvider); | 239 evictBackingsToReduceMemory(m_memoryAvailableBytes, RespectManagerPriorityCu
toff, resourceProvider); |
240 ASSERT(memoryUseBytes() <= maxMemoryLimitBytes()); | 240 CC_DCHECK(memoryUseBytes() <= maxMemoryLimitBytes()); |
241 | 241 |
242 // We currently collect backings from deleted textures for later recycling. | 242 // We currently collect backings from deleted textures for later recycling. |
243 // However, if we do that forever we will always use the max limit even if | 243 // However, if we do that forever we will always use the max limit even if |
244 // we really need very little memory. This should probably be solved by redu
cing the | 244 // we really need very little memory. This should probably be solved by redu
cing the |
245 // limit externally, but until then this just does some "clean up" of unused | 245 // limit externally, but until then this just does some "clean up" of unused |
246 // backing textures (any more than 10%). | 246 // backing textures (any more than 10%). |
247 size_t wastedMemory = 0; | 247 size_t wastedMemory = 0; |
248 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) { | 248 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) { |
249 if ((*it)->owner()) | 249 if ((*it)->owner()) |
250 break; | 250 break; |
251 wastedMemory += (*it)->bytes(); | 251 wastedMemory += (*it)->bytes(); |
252 } | 252 } |
253 size_t tenPercentOfMemory = m_memoryAvailableBytes / 10; | 253 size_t tenPercentOfMemory = m_memoryAvailableBytes / 10; |
254 if (wastedMemory > tenPercentOfMemory) | 254 if (wastedMemory > tenPercentOfMemory) |
255 evictBackingsToReduceMemory(memoryUseBytes() - (wastedMemory - tenPercen
tOfMemory), RespectManagerPriorityCutoff, resourceProvider); | 255 evictBackingsToReduceMemory(memoryUseBytes() - (wastedMemory - tenPercen
tOfMemory), RespectManagerPriorityCutoff, resourceProvider); |
256 | 256 |
257 // Unlink all evicted backings | 257 // Unlink all evicted backings |
258 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e
victedBackings.end(); ++it) { | 258 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e
victedBackings.end(); ++it) { |
259 if ((*it)->owner()) | 259 if ((*it)->owner()) |
260 (*it)->owner()->unlink(); | 260 (*it)->owner()->unlink(); |
261 } | 261 } |
262 | 262 |
263 // And clear the list of evicted backings | 263 // And clear the list of evicted backings |
264 deleteUnlinkedEvictedBackings(); | 264 deleteUnlinkedEvictedBackings(); |
265 } | 265 } |
266 | 266 |
267 void CCPrioritizedTextureManager::clearAllMemory(CCResourceProvider* resourcePro
vider) | 267 void CCPrioritizedTextureManager::clearAllMemory(CCResourceProvider* resourcePro
vider) |
268 { | 268 { |
269 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 269 CC_DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
270 ASSERT(resourceProvider); | 270 CC_DCHECK(resourceProvider); |
271 evictBackingsToReduceMemory(0, DoNotRespectManagerPriorityCutoff, resourcePr
ovider); | 271 evictBackingsToReduceMemory(0, DoNotRespectManagerPriorityCutoff, resourcePr
ovider); |
272 } | 272 } |
273 | 273 |
274 void CCPrioritizedTextureManager::reduceMemoryOnImplThread(size_t limitBytes, CC
ResourceProvider* resourceProvider) | 274 void CCPrioritizedTextureManager::reduceMemoryOnImplThread(size_t limitBytes, CC
ResourceProvider* resourceProvider) |
275 { | 275 { |
276 ASSERT(CCProxy::isImplThread()); | 276 CC_DCHECK(CCProxy::isImplThread()); |
277 ASSERT(resourceProvider); | 277 CC_DCHECK(resourceProvider); |
278 evictBackingsToReduceMemory(limitBytes, DoNotRespectManagerPriorityCutoff, r
esourceProvider); | 278 evictBackingsToReduceMemory(limitBytes, DoNotRespectManagerPriorityCutoff, r
esourceProvider); |
279 } | 279 } |
280 | 280 |
281 void CCPrioritizedTextureManager::getEvictedBackings(BackingVector& evictedBacki
ngs) | 281 void CCPrioritizedTextureManager::getEvictedBackings(BackingVector& evictedBacki
ngs) |
282 { | 282 { |
283 ASSERT(CCProxy::isImplThread()); | 283 CC_DCHECK(CCProxy::isImplThread()); |
284 evictedBackings.clear(); | 284 evictedBackings.clear(); |
285 evictedBackings.append(m_evictedBackings); | 285 evictedBackings.append(m_evictedBackings); |
286 } | 286 } |
287 | 287 |
288 void CCPrioritizedTextureManager::unlinkEvictedBackings(const BackingVector& evi
ctedBackings) | 288 void CCPrioritizedTextureManager::unlinkEvictedBackings(const BackingVector& evi
ctedBackings) |
289 { | 289 { |
290 ASSERT(CCProxy::isMainThread()); | 290 CC_DCHECK(CCProxy::isMainThread()); |
291 for (BackingVector::const_iterator it = evictedBackings.begin(); it != evict
edBackings.end(); ++it) { | 291 for (BackingVector::const_iterator it = evictedBackings.begin(); it != evict
edBackings.end(); ++it) { |
292 CCPrioritizedTexture::Backing* backing = (*it); | 292 CCPrioritizedTexture::Backing* backing = (*it); |
293 if (backing->owner()) | 293 if (backing->owner()) |
294 backing->owner()->unlink(); | 294 backing->owner()->unlink(); |
295 } | 295 } |
296 } | 296 } |
297 | 297 |
298 void CCPrioritizedTextureManager::deleteUnlinkedEvictedBackings() | 298 void CCPrioritizedTextureManager::deleteUnlinkedEvictedBackings() |
299 { | 299 { |
300 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai
nThreadBlocked())); | 300 CC_DCHECK(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::is
MainThreadBlocked())); |
301 BackingVector newEvictedBackings; | 301 BackingVector newEvictedBackings; |
302 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e
victedBackings.end(); ++it) { | 302 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e
victedBackings.end(); ++it) { |
303 CCPrioritizedTexture::Backing* backing = (*it); | 303 CCPrioritizedTexture::Backing* backing = (*it); |
304 if (backing->owner()) | 304 if (backing->owner()) |
305 newEvictedBackings.append(backing); | 305 newEvictedBackings.append(backing); |
306 else | 306 else |
307 delete backing; | 307 delete backing; |
308 } | 308 } |
309 m_evictedBackings.swap(newEvictedBackings); | 309 m_evictedBackings.swap(newEvictedBackings); |
310 } | 310 } |
311 | 311 |
312 bool CCPrioritizedTextureManager::linkedEvictedBackingsExist() const | 312 bool CCPrioritizedTextureManager::linkedEvictedBackingsExist() const |
313 { | 313 { |
314 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e
victedBackings.end(); ++it) { | 314 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e
victedBackings.end(); ++it) { |
315 if ((*it)->owner()) | 315 if ((*it)->owner()) |
316 return true; | 316 return true; |
317 } | 317 } |
318 return false; | 318 return false; |
319 } | 319 } |
320 | 320 |
321 void CCPrioritizedTextureManager::registerTexture(CCPrioritizedTexture* texture) | 321 void CCPrioritizedTextureManager::registerTexture(CCPrioritizedTexture* texture) |
322 { | 322 { |
323 ASSERT(CCProxy::isMainThread()); | 323 CC_DCHECK(CCProxy::isMainThread()); |
324 ASSERT(texture); | 324 CC_DCHECK(texture); |
325 ASSERT(!texture->textureManager()); | 325 CC_DCHECK(!texture->textureManager()); |
326 ASSERT(!texture->backing()); | 326 CC_DCHECK(!texture->backing()); |
327 ASSERT(!ContainsKey(m_textures, texture)); | 327 CC_DCHECK(!ContainsKey(m_textures, texture)); |
328 | 328 |
329 texture->setManagerInternal(this); | 329 texture->setManagerInternal(this); |
330 m_textures.insert(texture); | 330 m_textures.insert(texture); |
331 | 331 |
332 } | 332 } |
333 | 333 |
334 void CCPrioritizedTextureManager::unregisterTexture(CCPrioritizedTexture* textur
e) | 334 void CCPrioritizedTextureManager::unregisterTexture(CCPrioritizedTexture* textur
e) |
335 { | 335 { |
336 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai
nThreadBlocked())); | 336 CC_DCHECK(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::is
MainThreadBlocked())); |
337 ASSERT(texture); | 337 CC_DCHECK(texture); |
338 ASSERT(ContainsKey(m_textures, texture)); | 338 CC_DCHECK(ContainsKey(m_textures, texture)); |
339 | 339 |
340 returnBackingTexture(texture); | 340 returnBackingTexture(texture); |
341 texture->setManagerInternal(0); | 341 texture->setManagerInternal(0); |
342 m_textures.erase(texture); | 342 m_textures.erase(texture); |
343 texture->setAbovePriorityCutoff(false); | 343 texture->setAbovePriorityCutoff(false); |
344 } | 344 } |
345 | 345 |
346 void CCPrioritizedTextureManager::returnBackingTexture(CCPrioritizedTexture* tex
ture) | 346 void CCPrioritizedTextureManager::returnBackingTexture(CCPrioritizedTexture* tex
ture) |
347 { | 347 { |
348 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai
nThreadBlocked())); | 348 CC_DCHECK(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::is
MainThreadBlocked())); |
349 if (texture->backing()) | 349 if (texture->backing()) |
350 texture->unlink(); | 350 texture->unlink(); |
351 } | 351 } |
352 | 352 |
353 CCPrioritizedTexture::Backing* CCPrioritizedTextureManager::createBacking(IntSiz
e size, GC3Denum format, CCResourceProvider* resourceProvider) | 353 CCPrioritizedTexture::Backing* CCPrioritizedTextureManager::createBacking(IntSiz
e size, GC3Denum format, CCResourceProvider* resourceProvider) |
354 { | 354 { |
355 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 355 CC_DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
356 ASSERT(resourceProvider); | 356 CC_DCHECK(resourceProvider); |
357 CCResourceProvider::ResourceId resourceId = resourceProvider->createResource
(m_pool, size, format, CCResourceProvider::TextureUsageAny); | 357 CCResourceProvider::ResourceId resourceId = resourceProvider->createResource
(m_pool, size, format, CCResourceProvider::TextureUsageAny); |
358 CCPrioritizedTexture::Backing* backing = new CCPrioritizedTexture::Backing(r
esourceId, resourceProvider, size, format); | 358 CCPrioritizedTexture::Backing* backing = new CCPrioritizedTexture::Backing(r
esourceId, resourceProvider, size, format); |
359 m_memoryUseBytes += backing->bytes(); | 359 m_memoryUseBytes += backing->bytes(); |
360 // Put backing texture at the front for eviction, since it isn't in use yet. | 360 // Put backing texture at the front for eviction, since it isn't in use yet. |
361 m_backings.insertBefore(m_backings.begin(), backing); | 361 m_backings.insertBefore(m_backings.begin(), backing); |
362 return backing; | 362 return backing; |
363 } | 363 } |
364 | 364 |
365 void CCPrioritizedTextureManager::evictBackingResource(CCPrioritizedTexture::Bac
king* backing, CCResourceProvider* resourceProvider) | 365 void CCPrioritizedTextureManager::evictBackingResource(CCPrioritizedTexture::Bac
king* backing, CCResourceProvider* resourceProvider) |
366 { | 366 { |
367 ASSERT(CCProxy::isImplThread()); | 367 CC_DCHECK(CCProxy::isImplThread()); |
368 ASSERT(backing); | 368 CC_DCHECK(backing); |
369 ASSERT(resourceProvider); | 369 CC_DCHECK(resourceProvider); |
370 ASSERT(m_backings.find(backing) != m_backings.end()); | 370 CC_DCHECK(m_backings.find(backing) != m_backings.end()); |
371 | 371 |
372 // Note that we create a backing and its resource at the same time, but we | 372 // Note that we create a backing and its resource at the same time, but we |
373 // delete the backing structure and its resource in two steps. This is becau
se | 373 // delete the backing structure and its resource in two steps. This is becau
se |
374 // we can delete the resource while the main thread is running, but we canno
t | 374 // we can delete the resource while the main thread is running, but we canno
t |
375 // unlink backings while the main thread is running. | 375 // unlink backings while the main thread is running. |
376 backing->deleteResource(resourceProvider); | 376 backing->deleteResource(resourceProvider); |
377 m_memoryUseBytes -= backing->bytes(); | 377 m_memoryUseBytes -= backing->bytes(); |
378 m_backings.remove(backing); | 378 m_backings.remove(backing); |
379 m_evictedBackings.append(backing); | 379 m_evictedBackings.append(backing); |
380 } | 380 } |
381 | 381 |
382 #if !ASSERT_DISABLED | 382 #if CC_DCHECK_ENABLED |
383 void CCPrioritizedTextureManager::assertInvariants() | 383 void CCPrioritizedTextureManager::assertInvariants() |
384 { | 384 { |
385 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 385 CC_DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
386 | 386 |
387 // If we hit any of these asserts, there is a bug in this class. To see | 387 // If we hit any of these asserts, there is a bug in this class. To see |
388 // where the bug is, call this function at the beginning and end of | 388 // where the bug is, call this function at the beginning and end of |
389 // every public function. | 389 // every public function. |
390 | 390 |
391 // Backings/textures must be doubly-linked and only to other backings/textur
es in this manager. | 391 // Backings/textures must be doubly-linked and only to other backings/textur
es in this manager. |
392 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) { | 392 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) { |
393 if ((*it)->owner()) { | 393 if ((*it)->owner()) { |
394 ASSERT(ContainsKey(m_textures, (*it)->owner())); | 394 CC_DCHECK(ContainsKey(m_textures, (*it)->owner())); |
395 ASSERT((*it)->owner()->backing() == (*it)); | 395 CC_DCHECK((*it)->owner()->backing() == (*it)); |
396 } | 396 } |
397 } | 397 } |
398 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); +
+it) { | 398 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); +
+it) { |
399 CCPrioritizedTexture* texture = (*it); | 399 CCPrioritizedTexture* texture = (*it); |
400 CCPrioritizedTexture::Backing* backing = texture->backing(); | 400 CCPrioritizedTexture::Backing* backing = texture->backing(); |
401 if (backing) { | 401 if (backing) { |
402 if (backing->resourceHasBeenDeleted()) { | 402 if (backing->resourceHasBeenDeleted()) { |
403 ASSERT(m_backings.find(backing) == m_backings.end()); | 403 CC_DCHECK(m_backings.find(backing) == m_backings.end()); |
404 ASSERT(m_evictedBackings.contains(backing)); | 404 CC_DCHECK(m_evictedBackings.contains(backing)); |
405 } else { | 405 } else { |
406 ASSERT(m_backings.find(backing) != m_backings.end()); | 406 CC_DCHECK(m_backings.find(backing) != m_backings.end()); |
407 ASSERT(!m_evictedBackings.contains(backing)); | 407 CC_DCHECK(!m_evictedBackings.contains(backing)); |
408 } | 408 } |
409 ASSERT(backing->owner() == texture); | 409 CC_DCHECK(backing->owner() == texture); |
410 } | 410 } |
411 } | 411 } |
412 | 412 |
413 // At all times, backings that can be evicted must always come before | 413 // At all times, backings that can be evicted must always come before |
414 // backings that can't be evicted in the backing texture list (otherwise | 414 // backings that can't be evicted in the backing texture list (otherwise |
415 // reduceMemory will not find all textures available for eviction/recycling)
. | 415 // reduceMemory will not find all textures available for eviction/recycling)
. |
416 bool reachedUnrecyclable = false; | 416 bool reachedUnrecyclable = false; |
417 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) { | 417 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) { |
418 if (!(*it)->canBeRecycled()) | 418 if (!(*it)->canBeRecycled()) |
419 reachedUnrecyclable = true; | 419 reachedUnrecyclable = true; |
420 if (reachedUnrecyclable) | 420 if (reachedUnrecyclable) |
421 ASSERT(!(*it)->canBeRecycled()); | 421 CC_DCHECK(!(*it)->canBeRecycled()); |
422 else | 422 else |
423 ASSERT((*it)->canBeRecycled()); | 423 CC_DCHECK((*it)->canBeRecycled()); |
424 } | 424 } |
425 } | 425 } |
426 #endif | 426 #endif |
427 | 427 |
428 | 428 |
429 } // namespace cc | 429 } // namespace cc |
OLD | NEW |