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

Side by Side Diff: cc/CCPrioritizedTextureManager.cpp

Issue 11048004: Only recycle and evict textures not in-use on the impl thread. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « cc/CCPrioritizedTextureManager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 166 }
167 167
168 void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTex ture* texture, CCResourceProvider* resourceProvider) 168 void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTex ture* texture, CCResourceProvider* resourceProvider)
169 { 169 {
170 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 170 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
171 ASSERT(!texture->isSelfManaged()); 171 ASSERT(!texture->isSelfManaged());
172 ASSERT(texture->isAbovePriorityCutoff()); 172 ASSERT(texture->isAbovePriorityCutoff());
173 if (texture->backing() || !texture->isAbovePriorityCutoff()) 173 if (texture->backing() || !texture->isAbovePriorityCutoff())
174 return; 174 return;
175 175
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. 176 // Find a backing below, by either recycling or allocating.
180 CCPrioritizedTexture::Backing* backing = 0; 177 CCPrioritizedTexture::Backing* backing = 0;
181 178
182 // First try to recycle 179 // First try to recycle
183 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) { 180 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) {
184 if ((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePriorityCuto ffAtLastPriorityUpdate()) 181 if ((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePriorityCuto ffAtLastPriorityUpdate())
185 break; 182 break;
186 if ((*it)->size() == texture->size() && (*it)->format() == texture->form at()) { 183 if ((*it)->size() == texture->size() && (*it)->format() == texture->form at()) {
187 backing = (*it); 184 backing = (*it);
188 break; 185 break;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 if (backing->hadOwnerAtLastPriorityUpdate() && backing->wasAbovePrio rityCutoffAtLastPriorityUpdate()) 217 if (backing->hadOwnerAtLastPriorityUpdate() && backing->wasAbovePrio rityCutoffAtLastPriorityUpdate())
221 break; 218 break;
222 evictBackingResource(backing, resourceProvider); 219 evictBackingResource(backing, resourceProvider);
223 } 220 }
224 } 221 }
225 222
226 void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvi der) 223 void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvi der)
227 { 224 {
228 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 225 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
229 226
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); 227 evictBackingsToReduceMemory(m_memoryAvailableBytes, RespectManagerPriorityCu toff, resourceProvider);
234 ASSERT(memoryUseBytes() <= maxMemoryLimitBytes()); 228 ASSERT(memoryUseBytes() <= maxMemoryLimitBytes());
235 229
236 // We currently collect backings from deleted textures for later recycling. 230 // 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 231 // 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 232 // 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 233 // limit externally, but until then this just does some "clean up" of unused
240 // backing textures (any more than 10%). 234 // backing textures (any more than 10%).
241 size_t wastedMemory = 0; 235 size_t wastedMemory = 0;
242 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) { 236 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) {
243 if ((*it)->owner()) 237 if ((*it)->hadOwnerAtLastPriorityUpdate())
244 break; 238 break;
245 wastedMemory += (*it)->bytes(); 239 wastedMemory += (*it)->bytes();
246 } 240 }
247 size_t tenPercentOfMemory = m_memoryAvailableBytes / 10; 241 size_t tenPercentOfMemory = m_memoryAvailableBytes / 10;
248 if (wastedMemory > tenPercentOfMemory) 242 if (wastedMemory > tenPercentOfMemory)
249 evictBackingsToReduceMemory(memoryUseBytes() - (wastedMemory - tenPercen tOfMemory), RespectManagerPriorityCutoff, resourceProvider); 243 evictBackingsToReduceMemory(memoryUseBytes() - (wastedMemory - tenPercen tOfMemory), RespectManagerPriorityCutoff, resourceProvider);
250 244
251 deleteEvictedBackings(); 245 deleteEvictedBackings();
252 } 246 }
253 247
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 if (reachedAboveCutoff) { 394 if (reachedAboveCutoff) {
401 ASSERT((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePrior ityCutoffAtLastPriorityUpdate()); 395 ASSERT((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePrior ityCutoffAtLastPriorityUpdate());
402 ASSERT(reachedOwned); 396 ASSERT(reachedOwned);
403 } 397 }
404 } 398 }
405 } 399 }
406 #endif 400 #endif
407 401
408 402
409 } // namespace cc 403 } // namespace cc
OLDNEW
« no previous file with comments | « cc/CCPrioritizedTextureManager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698