| 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" |
| 11 #include "CCPriorityCalculator.h" | 11 #include "CCPriorityCalculator.h" |
| 12 #include "CCProxy.h" | 12 #include "CCProxy.h" |
| 13 #include "TraceEvent.h" | 13 #include "TraceEvent.h" |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 | 15 |
| 16 using namespace std; | 16 using namespace std; |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 | 19 |
| 20 CCPrioritizedTextureManager::CCPrioritizedTextureManager(size_t maxMemoryLimitBy
tes, int, int pool) | 20 CCPrioritizedTextureManager::CCPrioritizedTextureManager(size_t maxMemoryLimitBy
tes, int, int pool) |
| 21 : m_maxMemoryLimitBytes(maxMemoryLimitBytes) | 21 : m_maxMemoryLimitBytes(maxMemoryLimitBytes) |
| 22 , m_memoryUseBytes(0) | 22 , m_memoryUseBytes(0) |
| 23 , m_memoryAboveCutoffBytes(0) | 23 , m_memoryAboveCutoffBytes(0) |
| 24 , m_memoryAvailableBytes(0) | 24 , m_memoryAvailableBytes(0) |
| 25 , m_pool(pool) | 25 , m_pool(pool) |
| 26 , m_needsUpdateBackingsPrioritites(false) | |
| 27 { | 26 { |
| 28 } | 27 } |
| 29 | 28 |
| 30 CCPrioritizedTextureManager::~CCPrioritizedTextureManager() | 29 CCPrioritizedTextureManager::~CCPrioritizedTextureManager() |
| 31 { | 30 { |
| 32 while (m_textures.size() > 0) | 31 while (m_textures.size() > 0) |
| 33 unregisterTexture(*m_textures.begin()); | 32 unregisterTexture(*m_textures.begin()); |
| 34 | 33 |
| 35 deleteEvictedBackings(); | 34 deleteUnlinkedEvictedBackings(); |
| 35 ASSERT(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 ASSERT(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 ASSERT(CCProxy::isMainThread()); |
| 45 | 45 |
| (...skipping 41 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 m_needsUpdateBackingsPrioritites = true; | |
| 98 | |
| 99 ASSERT(m_memoryAboveCutoffBytes <= m_memoryAvailableBytes); | 97 ASSERT(m_memoryAboveCutoffBytes <= m_memoryAvailableBytes); |
| 100 ASSERT(memoryAboveCutoffBytes() <= maxMemoryLimitBytes()); | 98 ASSERT(memoryAboveCutoffBytes() <= maxMemoryLimitBytes()); |
| 101 } | 99 } |
| 102 | 100 |
| 103 void CCPrioritizedTextureManager::updateBackingsPriorities() | 101 void CCPrioritizedTextureManager::pushTexturePrioritiesToBackings() |
| 102 { |
| 103 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::pushTexturePrioritiesToBack
ings"); |
| 104 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
| 105 |
| 106 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) |
| 107 (*it)->updatePriority(); |
| 108 |
| 109 sortBackings(); |
| 110 } |
| 111 |
| 112 void CCPrioritizedTextureManager::updateBackingsInDrawingImplTree() |
| 113 { |
| 114 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsInDrawingImpl
Tree"); |
| 115 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
| 116 |
| 117 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); +
+it) { |
| 118 CCPrioritizedTexture::Backing* backing = (*it); |
| 119 backing->updateInDrawingImplTree(); |
| 120 } |
| 121 |
| 122 sortBackings(); |
| 123 } |
| 124 |
| 125 void CCPrioritizedTextureManager::sortBackings() |
| 104 { | 126 { |
| 105 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsPriorities"); | 127 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsPriorities"); |
| 106 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 128 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
| 107 | 129 |
| 108 if (!m_needsUpdateBackingsPrioritites) | |
| 109 return; | |
| 110 | |
| 111 #if !ASSERT_DISABLED | |
| 112 assertInvariants(); | |
| 113 #endif | |
| 114 | |
| 115 // Update backings' priorities and put backings in eviction/recycling order. | 130 // Update backings' priorities and put backings in eviction/recycling order. |
| 116 BackingVector& sortedBackings = m_tempBackingVector; | 131 BackingVector& sortedBackings = m_tempBackingVector; |
| 117 sortedBackings.clear(); | 132 sortedBackings.clear(); |
| 118 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) |
| 119 (*it)->updatePriority(); | |
| 120 sortedBackings.append(*it); | 134 sortedBackings.append(*it); |
| 121 } | |
| 122 std::sort(sortedBackings.begin(), sortedBackings.end(), compareBackings); | 135 std::sort(sortedBackings.begin(), sortedBackings.end(), compareBackings); |
| 123 | 136 |
| 124 for (BackingVector::iterator it = sortedBackings.begin(); it != sortedBackin
gs.end(); ++it) { | 137 for (BackingVector::iterator it = sortedBackings.begin(); it != sortedBackin
gs.end(); ++it) { |
| 125 m_backings.remove(*it); | 138 m_backings.remove(*it); |
| 126 m_backings.add(*it); | 139 m_backings.add(*it); |
| 127 } | 140 } |
| 128 sortedBackings.clear(); | 141 sortedBackings.clear(); |
| 129 m_needsUpdateBackingsPrioritites = false; | |
| 130 | 142 |
| 131 #if !ASSERT_DISABLED | 143 #if !ASSERT_DISABLED |
| 132 assertInvariants(); | 144 assertInvariants(); |
| 133 #endif | 145 #endif |
| 134 } | 146 } |
| 135 | 147 |
| 136 void CCPrioritizedTextureManager::clearPriorities() | 148 void CCPrioritizedTextureManager::clearPriorities() |
| 137 { | 149 { |
| 138 ASSERT(CCProxy::isMainThread()); | 150 ASSERT(CCProxy::isMainThread()); |
| 139 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) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 155 | 167 |
| 156 if (CCPriorityCalculator::priorityIsLower(texture->requestPriority(), m_prio
rityCutoff)) | 168 if (CCPriorityCalculator::priorityIsLower(texture->requestPriority(), m_prio
rityCutoff)) |
| 157 return false; | 169 return false; |
| 158 | 170 |
| 159 size_t newMemoryBytes = m_memoryAboveCutoffBytes + texture->bytes(); | 171 size_t newMemoryBytes = m_memoryAboveCutoffBytes + texture->bytes(); |
| 160 if (newMemoryBytes > m_memoryAvailableBytes) | 172 if (newMemoryBytes > m_memoryAvailableBytes) |
| 161 return false; | 173 return false; |
| 162 | 174 |
| 163 m_memoryAboveCutoffBytes = newMemoryBytes; | 175 m_memoryAboveCutoffBytes = newMemoryBytes; |
| 164 texture->setAbovePriorityCutoff(true); | 176 texture->setAbovePriorityCutoff(true); |
| 165 m_needsUpdateBackingsPrioritites = true; | |
| 166 return true; | 177 return true; |
| 167 } | 178 } |
| 168 | 179 |
| 169 void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTex
ture* texture, CCResourceProvider* resourceProvider) | 180 void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTex
ture* texture, CCResourceProvider* resourceProvider) |
| 170 { | 181 { |
| 171 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 182 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
| 172 ASSERT(!texture->isSelfManaged()); | 183 ASSERT(!texture->isSelfManaged()); |
| 173 ASSERT(texture->isAbovePriorityCutoff()); | 184 ASSERT(texture->isAbovePriorityCutoff()); |
| 174 if (texture->backing() || !texture->isAbovePriorityCutoff()) | 185 if (texture->backing() || !texture->isAbovePriorityCutoff()) |
| 175 return; | 186 return; |
| 176 | 187 |
| 177 // Make sure that the backings list is up to date and sorted before traversi
ng it. | |
| 178 updateBackingsPriorities(); | |
| 179 | |
| 180 // Find a backing below, by either recycling or allocating. | 188 // Find a backing below, by either recycling or allocating. |
| 181 CCPrioritizedTexture::Backing* backing = 0; | 189 CCPrioritizedTexture::Backing* backing = 0; |
| 182 | 190 |
| 183 // First try to recycle | 191 // First try to recycle |
| 184 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) { |
| 185 if ((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePriorityCuto
ffAtLastPriorityUpdate()) | 193 if (!(*it)->canBeRecycled()) |
| 186 break; | 194 break; |
| 187 if ((*it)->size() == texture->size() && (*it)->format() == texture->form
at()) { | 195 if ((*it)->size() == texture->size() && (*it)->format() == texture->form
at()) { |
| 188 backing = (*it); | 196 backing = (*it); |
| 189 break; | 197 break; |
| 190 } | 198 } |
| 191 } | 199 } |
| 192 | 200 |
| 193 // Otherwise reduce memory and just allocate a new backing texures. | 201 // Otherwise reduce memory and just allocate a new backing texures. |
| 194 if (!backing) { | 202 if (!backing) { |
| 195 evictBackingsToReduceMemory(m_memoryAvailableBytes - texture->bytes(), R
espectManagerPriorityCutoff, resourceProvider); | 203 evictBackingsToReduceMemory(m_memoryAvailableBytes - texture->bytes(), R
espectManagerPriorityCutoff, resourceProvider); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 211 { | 219 { |
| 212 ASSERT(CCProxy::isImplThread()); | 220 ASSERT(CCProxy::isImplThread()); |
| 213 if (memoryUseBytes() <= limitBytes) | 221 if (memoryUseBytes() <= limitBytes) |
| 214 return; | 222 return; |
| 215 | 223 |
| 216 // Destroy backings until we are below the limit, | 224 // Destroy backings until we are below the limit, |
| 217 // or until all backings remaining are above the cutoff. | 225 // or until all backings remaining are above the cutoff. |
| 218 while (memoryUseBytes() > limitBytes && m_backings.size() > 0) { | 226 while (memoryUseBytes() > limitBytes && m_backings.size() > 0) { |
| 219 CCPrioritizedTexture::Backing* backing = *m_backings.begin(); | 227 CCPrioritizedTexture::Backing* backing = *m_backings.begin(); |
| 220 if (evictionPolicy == RespectManagerPriorityCutoff) | 228 if (evictionPolicy == RespectManagerPriorityCutoff) |
| 221 if (backing->hadOwnerAtLastPriorityUpdate() && backing->wasAbovePrio
rityCutoffAtLastPriorityUpdate()) | 229 if (backing->wasAbovePriorityCutoffAtLastPriorityUpdate()) |
| 222 break; | 230 break; |
| 223 evictBackingResource(backing, resourceProvider); | 231 evictBackingResource(backing, resourceProvider); |
| 224 } | 232 } |
| 225 } | 233 } |
| 226 | 234 |
| 227 void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvi
der) | 235 void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvi
der) |
| 228 { | 236 { |
| 229 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 237 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
| 230 | 238 |
| 231 // Make sure that the backings list is up to date and sorted before traversi
ng it. | |
| 232 updateBackingsPriorities(); | |
| 233 | |
| 234 evictBackingsToReduceMemory(m_memoryAvailableBytes, RespectManagerPriorityCu
toff, resourceProvider); | 239 evictBackingsToReduceMemory(m_memoryAvailableBytes, RespectManagerPriorityCu
toff, resourceProvider); |
| 235 ASSERT(memoryUseBytes() <= maxMemoryLimitBytes()); | 240 ASSERT(memoryUseBytes() <= maxMemoryLimitBytes()); |
| 236 | 241 |
| 237 // We currently collect backings from deleted textures for later recycling. | 242 // We currently collect backings from deleted textures for later recycling. |
| 238 // 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 |
| 239 // 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 |
| 240 // 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 |
| 241 // backing textures (any more than 10%). | 246 // backing textures (any more than 10%). |
| 242 size_t wastedMemory = 0; | 247 size_t wastedMemory = 0; |
| 243 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) { |
| 244 if ((*it)->owner()) | 249 if ((*it)->owner()) |
| 245 break; | 250 break; |
| 246 wastedMemory += (*it)->bytes(); | 251 wastedMemory += (*it)->bytes(); |
| 247 } | 252 } |
| 248 size_t tenPercentOfMemory = m_memoryAvailableBytes / 10; | 253 size_t tenPercentOfMemory = m_memoryAvailableBytes / 10; |
| 249 if (wastedMemory > tenPercentOfMemory) | 254 if (wastedMemory > tenPercentOfMemory) |
| 250 evictBackingsToReduceMemory(memoryUseBytes() - (wastedMemory - tenPercen
tOfMemory), RespectManagerPriorityCutoff, resourceProvider); | 255 evictBackingsToReduceMemory(memoryUseBytes() - (wastedMemory - tenPercen
tOfMemory), RespectManagerPriorityCutoff, resourceProvider); |
| 251 | 256 |
| 252 deleteEvictedBackings(); | 257 // Unlink all evicted backings |
| 258 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e
victedBackings.end(); ++it) { |
| 259 if ((*it)->owner()) |
| 260 (*it)->owner()->unlink(); |
| 261 } |
| 262 |
| 263 // And clear the list of evicted backings |
| 264 deleteUnlinkedEvictedBackings(); |
| 253 } | 265 } |
| 254 | 266 |
| 255 void CCPrioritizedTextureManager::clearAllMemory(CCResourceProvider* resourcePro
vider) | 267 void CCPrioritizedTextureManager::clearAllMemory(CCResourceProvider* resourcePro
vider) |
| 256 { | 268 { |
| 257 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 269 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
| 258 ASSERT(resourceProvider); | 270 ASSERT(resourceProvider); |
| 259 evictBackingsToReduceMemory(0, DoNotRespectManagerPriorityCutoff, resourcePr
ovider); | 271 evictBackingsToReduceMemory(0, DoNotRespectManagerPriorityCutoff, resourcePr
ovider); |
| 260 deleteEvictedBackings(); | |
| 261 } | 272 } |
| 262 | 273 |
| 263 void CCPrioritizedTextureManager::reduceMemoryOnImplThread(size_t limitBytes, CC
ResourceProvider* resourceProvider) | 274 void CCPrioritizedTextureManager::reduceMemoryOnImplThread(size_t limitBytes, CC
ResourceProvider* resourceProvider) |
| 264 { | 275 { |
| 265 ASSERT(CCProxy::isImplThread()); | 276 ASSERT(CCProxy::isImplThread()); |
| 266 ASSERT(resourceProvider); | 277 ASSERT(resourceProvider); |
| 267 evictBackingsToReduceMemory(limitBytes, DoNotRespectManagerPriorityCutoff, r
esourceProvider); | 278 evictBackingsToReduceMemory(limitBytes, DoNotRespectManagerPriorityCutoff, r
esourceProvider); |
| 268 } | 279 } |
| 269 | 280 |
| 270 void CCPrioritizedTextureManager::getEvictedBackings(BackingVector& evictedBacki
ngs) | 281 void CCPrioritizedTextureManager::getEvictedBackings(BackingVector& evictedBacki
ngs) |
| 271 { | 282 { |
| 272 ASSERT(CCProxy::isImplThread()); | 283 ASSERT(CCProxy::isImplThread()); |
| 273 evictedBackings.clear(); | 284 evictedBackings.clear(); |
| 274 evictedBackings.append(m_evictedBackings); | 285 evictedBackings.append(m_evictedBackings); |
| 275 } | 286 } |
| 276 | 287 |
| 277 void CCPrioritizedTextureManager::unlinkEvictedBackings(const BackingVector& evi
ctedBackings) | 288 void CCPrioritizedTextureManager::unlinkEvictedBackings(const BackingVector& evi
ctedBackings) |
| 278 { | 289 { |
| 279 ASSERT(CCProxy::isMainThread()); | 290 ASSERT(CCProxy::isMainThread()); |
| 280 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) { |
| 281 CCPrioritizedTexture::Backing* backing = (*it); | 292 CCPrioritizedTexture::Backing* backing = (*it); |
| 282 if (backing->owner()) | 293 if (backing->owner()) |
| 283 backing->owner()->unlink(); | 294 backing->owner()->unlink(); |
| 284 } | 295 } |
| 285 } | 296 } |
| 286 | 297 |
| 287 bool CCPrioritizedTextureManager::deleteEvictedBackings() | 298 void CCPrioritizedTextureManager::deleteUnlinkedEvictedBackings() |
| 288 { | 299 { |
| 289 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai
nThreadBlocked())); | 300 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai
nThreadBlocked())); |
| 290 bool linkedEvictedBackingsExisted = false; | 301 BackingVector newEvictedBackings; |
| 291 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) { |
| 292 CCPrioritizedTexture::Backing* backing = (*it); | 303 CCPrioritizedTexture::Backing* backing = (*it); |
| 293 if (backing->owner()) { | 304 if (backing->owner()) |
| 294 linkedEvictedBackingsExisted = true; | 305 newEvictedBackings.append(backing); |
| 295 backing->owner()->unlink(); | 306 else |
| 296 } | 307 delete backing; |
| 297 delete backing; | |
| 298 } | 308 } |
| 299 m_evictedBackings.clear(); | 309 m_evictedBackings.swap(newEvictedBackings); |
| 300 return linkedEvictedBackingsExisted; | 310 } |
| 311 |
| 312 bool CCPrioritizedTextureManager::linkedEvictedBackingsExist() const |
| 313 { |
| 314 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e
victedBackings.end(); ++it) { |
| 315 if ((*it)->owner()) |
| 316 return true; |
| 317 } |
| 318 return false; |
| 301 } | 319 } |
| 302 | 320 |
| 303 void CCPrioritizedTextureManager::registerTexture(CCPrioritizedTexture* texture) | 321 void CCPrioritizedTextureManager::registerTexture(CCPrioritizedTexture* texture) |
| 304 { | 322 { |
| 305 ASSERT(CCProxy::isMainThread()); | 323 ASSERT(CCProxy::isMainThread()); |
| 306 ASSERT(texture); | 324 ASSERT(texture); |
| 307 ASSERT(!texture->textureManager()); | 325 ASSERT(!texture->textureManager()); |
| 308 ASSERT(!texture->backing()); | 326 ASSERT(!texture->backing()); |
| 309 ASSERT(!ContainsKey(m_textures, texture)); | 327 ASSERT(!ContainsKey(m_textures, texture)); |
| 310 | 328 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 321 | 339 |
| 322 returnBackingTexture(texture); | 340 returnBackingTexture(texture); |
| 323 texture->setManagerInternal(0); | 341 texture->setManagerInternal(0); |
| 324 m_textures.erase(texture); | 342 m_textures.erase(texture); |
| 325 texture->setAbovePriorityCutoff(false); | 343 texture->setAbovePriorityCutoff(false); |
| 326 } | 344 } |
| 327 | 345 |
| 328 void CCPrioritizedTextureManager::returnBackingTexture(CCPrioritizedTexture* tex
ture) | 346 void CCPrioritizedTextureManager::returnBackingTexture(CCPrioritizedTexture* tex
ture) |
| 329 { | 347 { |
| 330 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai
nThreadBlocked())); | 348 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai
nThreadBlocked())); |
| 331 if (texture->backing()) { | 349 if (texture->backing()) |
| 332 texture->unlink(); | 350 texture->unlink(); |
| 333 m_needsUpdateBackingsPrioritites = true; | |
| 334 } | |
| 335 } | 351 } |
| 336 | 352 |
| 337 CCPrioritizedTexture::Backing* CCPrioritizedTextureManager::createBacking(IntSiz
e size, GC3Denum format, CCResourceProvider* resourceProvider) | 353 CCPrioritizedTexture::Backing* CCPrioritizedTextureManager::createBacking(IntSiz
e size, GC3Denum format, CCResourceProvider* resourceProvider) |
| 338 { | 354 { |
| 339 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 355 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); |
| 340 ASSERT(resourceProvider); | 356 ASSERT(resourceProvider); |
| 341 CCResourceProvider::ResourceId resourceId = resourceProvider->createResource
(m_pool, size, format, CCResourceProvider::TextureUsageAny); | 357 CCResourceProvider::ResourceId resourceId = resourceProvider->createResource
(m_pool, size, format, CCResourceProvider::TextureUsageAny); |
| 342 CCPrioritizedTexture::Backing* backing = new CCPrioritizedTexture::Backing(r
esourceId, resourceProvider, size, format); | 358 CCPrioritizedTexture::Backing* backing = new CCPrioritizedTexture::Backing(r
esourceId, resourceProvider, size, format); |
| 343 m_memoryUseBytes += backing->bytes(); | 359 m_memoryUseBytes += backing->bytes(); |
| 344 // 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. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 373 // every public function. | 389 // every public function. |
| 374 | 390 |
| 375 // 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. |
| 376 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) { |
| 377 if ((*it)->owner()) { | 393 if ((*it)->owner()) { |
| 378 ASSERT(ContainsKey(m_textures, (*it)->owner())); | 394 ASSERT(ContainsKey(m_textures, (*it)->owner())); |
| 379 ASSERT((*it)->owner()->backing() == (*it)); | 395 ASSERT((*it)->owner()->backing() == (*it)); |
| 380 } | 396 } |
| 381 } | 397 } |
| 382 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) { |
| 383 if ((*it)->backing()) { | 399 CCPrioritizedTexture* texture = (*it); |
| 384 ASSERT(m_backings.find((*it)->backing()) != m_backings.end()); | 400 CCPrioritizedTexture::Backing* backing = texture->backing(); |
| 385 ASSERT((*it)->backing()->owner() == (*it)); | 401 if (backing) { |
| 402 if (backing->resourceHasBeenDeleted()) { |
| 403 ASSERT(m_backings.find(backing) == m_backings.end()); |
| 404 ASSERT(m_evictedBackings.contains(backing)); |
| 405 } else { |
| 406 ASSERT(m_backings.find(backing) != m_backings.end()); |
| 407 ASSERT(!m_evictedBackings.contains(backing)); |
| 408 } |
| 409 ASSERT(backing->owner() == texture); |
| 386 } | 410 } |
| 387 } | 411 } |
| 388 | 412 |
| 389 // 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 |
| 390 // 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 |
| 391 // reduceMemory will not find all textures available for eviction/recycling)
. | 415 // reduceMemory will not find all textures available for eviction/recycling)
. |
| 392 bool reachedOwned = false; | 416 bool reachedUnrecyclable = false; |
| 393 bool reachedAboveCutoff = false; | |
| 394 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) { |
| 395 if ((*it)->hadOwnerAtLastPriorityUpdate()) | 418 if (!(*it)->canBeRecycled()) |
| 396 reachedOwned = true; | 419 reachedUnrecyclable = true; |
| 397 if ((*it)->wasAbovePriorityCutoffAtLastPriorityUpdate()) | 420 if (reachedUnrecyclable) |
| 398 reachedAboveCutoff = true; | 421 ASSERT(!(*it)->canBeRecycled()); |
| 399 if (reachedOwned) | 422 else |
| 400 ASSERT((*it)->hadOwnerAtLastPriorityUpdate()); | 423 ASSERT((*it)->canBeRecycled()); |
| 401 if (reachedAboveCutoff) { | |
| 402 ASSERT((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePrior
ityCutoffAtLastPriorityUpdate()); | |
| 403 ASSERT(reachedOwned); | |
| 404 } | |
| 405 } | 424 } |
| 406 } | 425 } |
| 407 #endif | 426 #endif |
| 408 | 427 |
| 409 | 428 |
| 410 } // namespace cc | 429 } // namespace cc |
| OLD | NEW |