Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: cc/CCPrioritizedTextureManager.cpp

Issue 11079007: Fix issue incremental upload can evict textures being drawn (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporate review feedback Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "CCPrioritizedTexture.h" 9 #include "CCPrioritizedTexture.h"
10 #include "CCPriorityCalculator.h" 10 #include "CCPriorityCalculator.h"
11 #include "CCProxy.h" 11 #include "CCProxy.h"
12 #include "TraceEvent.h" 12 #include "TraceEvent.h"
13 #include <algorithm> 13 #include <algorithm>
14 14
15 using namespace std; 15 using namespace std;
16 16
17 namespace cc { 17 namespace cc {
18 18
19 CCPrioritizedTextureManager::CCPrioritizedTextureManager(size_t maxMemoryLimitBy tes, int, int pool) 19 CCPrioritizedTextureManager::CCPrioritizedTextureManager(size_t maxMemoryLimitBy tes, int, int pool)
20 : m_maxMemoryLimitBytes(maxMemoryLimitBytes) 20 : m_maxMemoryLimitBytes(maxMemoryLimitBytes)
21 , m_memoryUseBytes(0) 21 , m_memoryUseBytes(0)
22 , m_memoryAboveCutoffBytes(0) 22 , m_memoryAboveCutoffBytes(0)
23 , m_memoryAvailableBytes(0) 23 , m_memoryAvailableBytes(0)
24 , m_pool(pool) 24 , m_pool(pool)
25 , m_needsUpdateBackingsPrioritites(false)
26 { 25 {
27 } 26 }
28 27
29 CCPrioritizedTextureManager::~CCPrioritizedTextureManager() 28 CCPrioritizedTextureManager::~CCPrioritizedTextureManager()
30 { 29 {
31 while (m_textures.size() > 0) 30 while (m_textures.size() > 0)
32 unregisterTexture(*m_textures.begin()); 31 unregisterTexture(*m_textures.begin());
33 32
34 deleteEvictedBackings(); 33 deleteUnlinkedEvictedBackings();
34 ASSERT(m_evictedBackings.isEmpty());
35 35
36 // Each remaining backing is a leaked opengl texture. There should be none. 36 // Each remaining backing is a leaked opengl texture. There should be none.
37 ASSERT(m_backings.isEmpty()); 37 ASSERT(m_backings.isEmpty());
38 } 38 }
39 39
40 void CCPrioritizedTextureManager::prioritizeTextures() 40 void CCPrioritizedTextureManager::prioritizeTextures()
41 { 41 {
42 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::prioritizeTextures"); 42 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::prioritizeTextures");
43 ASSERT(CCProxy::isMainThread()); 43 ASSERT(CCProxy::isMainThread());
44 44
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // being partially allowed randomly. 86 // being partially allowed randomly.
87 m_memoryAboveCutoffBytes = 0; 87 m_memoryAboveCutoffBytes = 0;
88 for (TextureVector::iterator it = sortedTextures.begin(); it != sortedTextur es.end(); ++it) { 88 for (TextureVector::iterator it = sortedTextures.begin(); it != sortedTextur es.end(); ++it) {
89 bool isAbovePriorityCutoff = CCPriorityCalculator::priorityIsHigher((*it )->requestPriority(), m_priorityCutoff); 89 bool isAbovePriorityCutoff = CCPriorityCalculator::priorityIsHigher((*it )->requestPriority(), m_priorityCutoff);
90 (*it)->setAbovePriorityCutoff(isAbovePriorityCutoff); 90 (*it)->setAbovePriorityCutoff(isAbovePriorityCutoff);
91 if (isAbovePriorityCutoff && !(*it)->isSelfManaged()) 91 if (isAbovePriorityCutoff && !(*it)->isSelfManaged())
92 m_memoryAboveCutoffBytes += (*it)->bytes(); 92 m_memoryAboveCutoffBytes += (*it)->bytes();
93 } 93 }
94 sortedTextures.clear(); 94 sortedTextures.clear();
95 95
96 m_needsUpdateBackingsPrioritites = true;
97
98 ASSERT(m_memoryAboveCutoffBytes <= m_memoryAvailableBytes); 96 ASSERT(m_memoryAboveCutoffBytes <= m_memoryAvailableBytes);
99 ASSERT(memoryAboveCutoffBytes() <= maxMemoryLimitBytes()); 97 ASSERT(memoryAboveCutoffBytes() <= maxMemoryLimitBytes());
100 } 98 }
101 99
102 void CCPrioritizedTextureManager::updateBackingsPriorities() 100 void CCPrioritizedTextureManager::pushTexturePrioritiesToBackings()
101 {
102 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::pushTexturePrioritiesToBack ings");
103 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
104
105 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it)
106 (*it)->updatePriority();
107
108 sortBackings();
109 }
110
111 void CCPrioritizedTextureManager::updateBackingsInDrawingImplTree()
112 {
113 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsInDrawingImpl Tree");
114 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
115
116 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) {
117 CCPrioritizedTexture::Backing* backing = (*it);
118 backing->updateInDrawingImplTree();
119 }
120
121 sortBackings();
122 }
123
124 void CCPrioritizedTextureManager::sortBackings()
103 { 125 {
104 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsPriorities"); 126 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsPriorities");
105 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 127 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
106 128
107 if (!m_needsUpdateBackingsPrioritites)
108 return;
109
110 #if !ASSERT_DISABLED
111 assertInvariants();
112 #endif
113
114 // Update backings' priorities and put backings in eviction/recycling order. 129 // Update backings' priorities and put backings in eviction/recycling order.
115 BackingVector& sortedBackings = m_tempBackingVector; 130 BackingVector& sortedBackings = m_tempBackingVector;
116 sortedBackings.clear(); 131 sortedBackings.clear();
117 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) { 132 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it)
118 (*it)->updatePriority();
119 sortedBackings.append(*it); 133 sortedBackings.append(*it);
120 }
121 std::sort(sortedBackings.begin(), sortedBackings.end(), compareBackings); 134 std::sort(sortedBackings.begin(), sortedBackings.end(), compareBackings);
122 135
123 for (BackingVector::iterator it = sortedBackings.begin(); it != sortedBackin gs.end(); ++it) { 136 for (BackingVector::iterator it = sortedBackings.begin(); it != sortedBackin gs.end(); ++it) {
124 m_backings.remove(*it); 137 m_backings.remove(*it);
125 m_backings.add(*it); 138 m_backings.add(*it);
126 } 139 }
127 sortedBackings.clear(); 140 sortedBackings.clear();
128 m_needsUpdateBackingsPrioritites = false;
129 141
130 #if !ASSERT_DISABLED 142 #if !ASSERT_DISABLED
131 assertInvariants(); 143 assertInvariants();
132 #endif 144 #endif
133 } 145 }
134 146
135 void CCPrioritizedTextureManager::clearPriorities() 147 void CCPrioritizedTextureManager::clearPriorities()
136 { 148 {
137 ASSERT(CCProxy::isMainThread()); 149 ASSERT(CCProxy::isMainThread());
138 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); + +it) { 150 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); + +it) {
(...skipping 15 matching lines...) Expand all
154 166
155 if (CCPriorityCalculator::priorityIsLower(texture->requestPriority(), m_prio rityCutoff)) 167 if (CCPriorityCalculator::priorityIsLower(texture->requestPriority(), m_prio rityCutoff))
156 return false; 168 return false;
157 169
158 size_t newMemoryBytes = m_memoryAboveCutoffBytes + texture->bytes(); 170 size_t newMemoryBytes = m_memoryAboveCutoffBytes + texture->bytes();
159 if (newMemoryBytes > m_memoryAvailableBytes) 171 if (newMemoryBytes > m_memoryAvailableBytes)
160 return false; 172 return false;
161 173
162 m_memoryAboveCutoffBytes = newMemoryBytes; 174 m_memoryAboveCutoffBytes = newMemoryBytes;
163 texture->setAbovePriorityCutoff(true); 175 texture->setAbovePriorityCutoff(true);
164 m_needsUpdateBackingsPrioritites = true;
165 return true; 176 return true;
166 } 177 }
167 178
168 void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTex ture* texture, CCResourceProvider* resourceProvider) 179 void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTex ture* texture, CCResourceProvider* resourceProvider)
169 { 180 {
170 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 181 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
171 ASSERT(!texture->isSelfManaged()); 182 ASSERT(!texture->isSelfManaged());
172 ASSERT(texture->isAbovePriorityCutoff()); 183 ASSERT(texture->isAbovePriorityCutoff());
173 if (texture->backing() || !texture->isAbovePriorityCutoff()) 184 if (texture->backing() || !texture->isAbovePriorityCutoff())
174 return; 185 return;
175 186
176 // Make sure that the backings list is up to date and sorted before traversi ng it.
177 updateBackingsPriorities();
178
179 // Find a backing below, by either recycling or allocating. 187 // Find a backing below, by either recycling or allocating.
180 CCPrioritizedTexture::Backing* backing = 0; 188 CCPrioritizedTexture::Backing* backing = 0;
181 189
182 // First try to recycle 190 // First try to recycle
183 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) { 191 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) {
184 if ((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePriorityCuto ffAtLastPriorityUpdate()) 192 if (!(*it)->canBeRecycled())
185 break; 193 break;
186 if ((*it)->size() == texture->size() && (*it)->format() == texture->form at()) { 194 if ((*it)->size() == texture->size() && (*it)->format() == texture->form at()) {
187 backing = (*it); 195 backing = (*it);
188 break; 196 break;
189 } 197 }
190 } 198 }
191 199
192 // Otherwise reduce memory and just allocate a new backing texures. 200 // Otherwise reduce memory and just allocate a new backing texures.
193 if (!backing) { 201 if (!backing) {
194 evictBackingsToReduceMemory(m_memoryAvailableBytes - texture->bytes(), R espectManagerPriorityCutoff, resourceProvider); 202 evictBackingsToReduceMemory(m_memoryAvailableBytes - texture->bytes(), R espectManagerPriorityCutoff, resourceProvider);
(...skipping 15 matching lines...) Expand all
210 { 218 {
211 ASSERT(CCProxy::isImplThread()); 219 ASSERT(CCProxy::isImplThread());
212 if (memoryUseBytes() <= limitBytes) 220 if (memoryUseBytes() <= limitBytes)
213 return; 221 return;
214 222
215 // Destroy backings until we are below the limit, 223 // Destroy backings until we are below the limit,
216 // or until all backings remaining are above the cutoff. 224 // or until all backings remaining are above the cutoff.
217 while (memoryUseBytes() > limitBytes && m_backings.size() > 0) { 225 while (memoryUseBytes() > limitBytes && m_backings.size() > 0) {
218 CCPrioritizedTexture::Backing* backing = *m_backings.begin(); 226 CCPrioritizedTexture::Backing* backing = *m_backings.begin();
219 if (evictionPolicy == RespectManagerPriorityCutoff) 227 if (evictionPolicy == RespectManagerPriorityCutoff)
220 if (backing->hadOwnerAtLastPriorityUpdate() && backing->wasAbovePrio rityCutoffAtLastPriorityUpdate()) 228 if (backing->wasAbovePriorityCutoffAtLastPriorityUpdate())
221 break; 229 break;
222 evictBackingResource(backing, resourceProvider); 230 evictBackingResource(backing, resourceProvider);
223 } 231 }
224 } 232 }
225 233
226 void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvi der) 234 void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvi der)
227 { 235 {
228 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 236 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
229 237
230 // Make sure that the backings list is up to date and sorted before traversi ng it.
231 updateBackingsPriorities();
232
233 evictBackingsToReduceMemory(m_memoryAvailableBytes, RespectManagerPriorityCu toff, resourceProvider); 238 evictBackingsToReduceMemory(m_memoryAvailableBytes, RespectManagerPriorityCu toff, resourceProvider);
234 ASSERT(memoryUseBytes() <= maxMemoryLimitBytes()); 239 ASSERT(memoryUseBytes() <= maxMemoryLimitBytes());
235 240
236 // We currently collect backings from deleted textures for later recycling. 241 // We currently collect backings from deleted textures for later recycling.
237 // However, if we do that forever we will always use the max limit even if 242 // However, if we do that forever we will always use the max limit even if
238 // we really need very little memory. This should probably be solved by redu cing the 243 // we really need very little memory. This should probably be solved by redu cing the
239 // limit externally, but until then this just does some "clean up" of unused 244 // limit externally, but until then this just does some "clean up" of unused
240 // backing textures (any more than 10%). 245 // backing textures (any more than 10%).
241 size_t wastedMemory = 0; 246 size_t wastedMemory = 0;
242 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) { 247 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) {
243 if ((*it)->owner()) 248 if ((*it)->owner())
244 break; 249 break;
245 wastedMemory += (*it)->bytes(); 250 wastedMemory += (*it)->bytes();
246 } 251 }
247 size_t tenPercentOfMemory = m_memoryAvailableBytes / 10; 252 size_t tenPercentOfMemory = m_memoryAvailableBytes / 10;
248 if (wastedMemory > tenPercentOfMemory) 253 if (wastedMemory > tenPercentOfMemory)
249 evictBackingsToReduceMemory(memoryUseBytes() - (wastedMemory - tenPercen tOfMemory), RespectManagerPriorityCutoff, resourceProvider); 254 evictBackingsToReduceMemory(memoryUseBytes() - (wastedMemory - tenPercen tOfMemory), RespectManagerPriorityCutoff, resourceProvider);
250 255
251 deleteEvictedBackings(); 256 // Unlink all evicted backings
257 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e victedBackings.end(); ++it) {
258 if ((*it)->owner())
259 (*it)->owner()->unlink();
260 }
261
262 // And clear the list of evicted backings
263 deleteUnlinkedEvictedBackings();
252 } 264 }
253 265
254 void CCPrioritizedTextureManager::clearAllMemory(CCResourceProvider* resourcePro vider) 266 void CCPrioritizedTextureManager::clearAllMemory(CCResourceProvider* resourcePro vider)
255 { 267 {
256 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 268 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
257 ASSERT(resourceProvider); 269 ASSERT(resourceProvider);
258 evictBackingsToReduceMemory(0, DoNotRespectManagerPriorityCutoff, resourcePr ovider); 270 evictBackingsToReduceMemory(0, DoNotRespectManagerPriorityCutoff, resourcePr ovider);
259 deleteEvictedBackings();
260 } 271 }
261 272
262 void CCPrioritizedTextureManager::reduceMemoryOnImplThread(size_t limitBytes, CC ResourceProvider* resourceProvider) 273 void CCPrioritizedTextureManager::reduceMemoryOnImplThread(size_t limitBytes, CC ResourceProvider* resourceProvider)
263 { 274 {
264 ASSERT(CCProxy::isImplThread()); 275 ASSERT(CCProxy::isImplThread());
265 ASSERT(resourceProvider); 276 ASSERT(resourceProvider);
266 evictBackingsToReduceMemory(limitBytes, DoNotRespectManagerPriorityCutoff, r esourceProvider); 277 evictBackingsToReduceMemory(limitBytes, DoNotRespectManagerPriorityCutoff, r esourceProvider);
267 } 278 }
268 279
269 void CCPrioritizedTextureManager::getEvictedBackings(BackingVector& evictedBacki ngs) 280 void CCPrioritizedTextureManager::getEvictedBackings(BackingVector& evictedBacki ngs)
270 { 281 {
271 ASSERT(CCProxy::isImplThread()); 282 ASSERT(CCProxy::isImplThread());
272 evictedBackings.clear(); 283 evictedBackings.clear();
273 evictedBackings.append(m_evictedBackings); 284 evictedBackings.append(m_evictedBackings);
274 } 285 }
275 286
276 void CCPrioritizedTextureManager::unlinkEvictedBackings(const BackingVector& evi ctedBackings) 287 void CCPrioritizedTextureManager::unlinkEvictedBackings(const BackingVector& evi ctedBackings)
277 { 288 {
278 ASSERT(CCProxy::isMainThread()); 289 ASSERT(CCProxy::isMainThread());
279 for (BackingVector::const_iterator it = evictedBackings.begin(); it != evict edBackings.end(); ++it) { 290 for (BackingVector::const_iterator it = evictedBackings.begin(); it != evict edBackings.end(); ++it) {
280 CCPrioritizedTexture::Backing* backing = (*it); 291 CCPrioritizedTexture::Backing* backing = (*it);
281 if (backing->owner()) 292 if (backing->owner())
282 backing->owner()->unlink(); 293 backing->owner()->unlink();
283 } 294 }
284 } 295 }
285 296
286 bool CCPrioritizedTextureManager::deleteEvictedBackings() 297 void CCPrioritizedTextureManager::deleteUnlinkedEvictedBackings()
287 { 298 {
288 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai nThreadBlocked())); 299 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai nThreadBlocked()));
289 bool linkedEvictedBackingsExisted = false; 300 BackingVector newEvictedBackings;
290 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e victedBackings.end(); ++it) { 301 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e victedBackings.end(); ++it) {
291 CCPrioritizedTexture::Backing* backing = (*it); 302 CCPrioritizedTexture::Backing* backing = (*it);
292 if (backing->owner()) { 303 if (backing->owner())
293 linkedEvictedBackingsExisted = true; 304 newEvictedBackings.append(backing);
294 backing->owner()->unlink(); 305 else
295 } 306 delete backing;
296 delete backing;
297 } 307 }
298 m_evictedBackings.clear(); 308 m_evictedBackings.swap(newEvictedBackings);
299 return linkedEvictedBackingsExisted; 309 }
310
311 bool CCPrioritizedTextureManager::linkedEvictedBackingsExist() const
312 {
313 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e victedBackings.end(); ++it) {
314 if ((*it)->owner())
315 return true;
316 }
317 return false;
300 } 318 }
301 319
302 void CCPrioritizedTextureManager::registerTexture(CCPrioritizedTexture* texture) 320 void CCPrioritizedTextureManager::registerTexture(CCPrioritizedTexture* texture)
303 { 321 {
304 ASSERT(CCProxy::isMainThread()); 322 ASSERT(CCProxy::isMainThread());
305 ASSERT(texture); 323 ASSERT(texture);
306 ASSERT(!texture->textureManager()); 324 ASSERT(!texture->textureManager());
307 ASSERT(!texture->backing()); 325 ASSERT(!texture->backing());
308 ASSERT(m_textures.find(texture) == m_textures.end()); 326 ASSERT(m_textures.find(texture) == m_textures.end());
309 327
(...skipping 10 matching lines...) Expand all
320 338
321 returnBackingTexture(texture); 339 returnBackingTexture(texture);
322 texture->setManagerInternal(0); 340 texture->setManagerInternal(0);
323 m_textures.remove(texture); 341 m_textures.remove(texture);
324 texture->setAbovePriorityCutoff(false); 342 texture->setAbovePriorityCutoff(false);
325 } 343 }
326 344
327 void CCPrioritizedTextureManager::returnBackingTexture(CCPrioritizedTexture* tex ture) 345 void CCPrioritizedTextureManager::returnBackingTexture(CCPrioritizedTexture* tex ture)
328 { 346 {
329 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai nThreadBlocked())); 347 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai nThreadBlocked()));
330 if (texture->backing()) { 348 if (texture->backing())
331 texture->unlink(); 349 texture->unlink();
332 m_needsUpdateBackingsPrioritites = true;
333 }
334 } 350 }
335 351
336 CCPrioritizedTexture::Backing* CCPrioritizedTextureManager::createBacking(IntSiz e size, GC3Denum format, CCResourceProvider* resourceProvider) 352 CCPrioritizedTexture::Backing* CCPrioritizedTextureManager::createBacking(IntSiz e size, GC3Denum format, CCResourceProvider* resourceProvider)
337 { 353 {
338 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 354 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
339 ASSERT(resourceProvider); 355 ASSERT(resourceProvider);
340 CCResourceProvider::ResourceId resourceId = resourceProvider->createResource (m_pool, size, format, CCResourceProvider::TextureUsageAny); 356 CCResourceProvider::ResourceId resourceId = resourceProvider->createResource (m_pool, size, format, CCResourceProvider::TextureUsageAny);
341 CCPrioritizedTexture::Backing* backing = new CCPrioritizedTexture::Backing(r esourceId, resourceProvider, size, format); 357 CCPrioritizedTexture::Backing* backing = new CCPrioritizedTexture::Backing(r esourceId, resourceProvider, size, format);
342 m_memoryUseBytes += backing->bytes(); 358 m_memoryUseBytes += backing->bytes();
343 // Put backing texture at the front for eviction, since it isn't in use yet. 359 // Put backing texture at the front for eviction, since it isn't in use yet.
(...skipping 28 matching lines...) Expand all
372 // every public function. 388 // every public function.
373 389
374 // Backings/textures must be doubly-linked and only to other backings/textur es in this manager. 390 // Backings/textures must be doubly-linked and only to other backings/textur es in this manager.
375 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) { 391 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) {
376 if ((*it)->owner()) { 392 if ((*it)->owner()) {
377 ASSERT(m_textures.find((*it)->owner()) != m_textures.end()); 393 ASSERT(m_textures.find((*it)->owner()) != m_textures.end());
378 ASSERT((*it)->owner()->backing() == (*it)); 394 ASSERT((*it)->owner()->backing() == (*it));
379 } 395 }
380 } 396 }
381 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); + +it) { 397 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); + +it) {
382 if ((*it)->backing()) { 398 CCPrioritizedTexture* texture = (*it);
383 ASSERT(m_backings.find((*it)->backing()) != m_backings.end()); 399 CCPrioritizedTexture::Backing* backing = texture->backing();
384 ASSERT((*it)->backing()->owner() == (*it)); 400 if (backing) {
401 if (backing->resourceHasBeenDeleted())
402 ASSERT(m_backings.find(backing) == m_backings.end());
epenner 2012/10/09 17:25:04 Maybe ASSERT that it's in the evicted list?
ccameron 2012/10/09 21:03:56 Done.
403 else
404 ASSERT(m_backings.find(backing) != m_backings.end());
405 ASSERT(backing->owner() == texture);
385 } 406 }
386 } 407 }
387 408
388 // At all times, backings that can be evicted must always come before 409 // At all times, backings that can be evicted must always come before
389 // backings that can't be evicted in the backing texture list (otherwise 410 // backings that can't be evicted in the backing texture list (otherwise
390 // reduceMemory will not find all textures available for eviction/recycling) . 411 // reduceMemory will not find all textures available for eviction/recycling) .
391 bool reachedOwned = false; 412 bool reachedUnrecyclable = false;
392 bool reachedAboveCutoff = false;
393 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) { 413 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) {
394 if ((*it)->hadOwnerAtLastPriorityUpdate()) 414 if (!(*it)->canBeRecycled())
epenner 2012/10/09 17:25:04 This is good to have for if we enable more recycli
395 reachedOwned = true; 415 reachedUnrecyclable = true;
396 if ((*it)->wasAbovePriorityCutoffAtLastPriorityUpdate()) 416 if (reachedUnrecyclable)
397 reachedAboveCutoff = true; 417 ASSERT(!(*it)->canBeRecycled());
398 if (reachedOwned) 418 else
399 ASSERT((*it)->hadOwnerAtLastPriorityUpdate()); 419 ASSERT((*it)->canBeRecycled());
400 if (reachedAboveCutoff) {
401 ASSERT((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePrior ityCutoffAtLastPriorityUpdate());
402 ASSERT(reachedOwned);
403 }
404 } 420 }
405 } 421 }
406 #endif 422 #endif
407 423
408 424
409 } // namespace cc 425 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698