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

Side by Side Diff: cc/CCPrioritizedTextureManager.cpp

Issue 11048044: cc: Switch to Chromium DCHECKs and LOGs (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
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 "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "CCPrioritizedTexture.h" 10 #include "CCPrioritizedTexture.h"
(...skipping 17 matching lines...) Expand all
28 } 28 }
29 29
30 CCPrioritizedTextureManager::~CCPrioritizedTextureManager() 30 CCPrioritizedTextureManager::~CCPrioritizedTextureManager()
31 { 31 {
32 while (m_textures.size() > 0) 32 while (m_textures.size() > 0)
33 unregisterTexture(*m_textures.begin()); 33 unregisterTexture(*m_textures.begin());
34 34
35 deleteEvictedBackings(); 35 deleteEvictedBackings();
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 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 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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; 97 m_needsUpdateBackingsPrioritites = true;
98 98
99 ASSERT(m_memoryAboveCutoffBytes <= m_memoryAvailableBytes); 99 DCHECK(m_memoryAboveCutoffBytes <= m_memoryAvailableBytes);
100 ASSERT(memoryAboveCutoffBytes() <= maxMemoryLimitBytes()); 100 DCHECK(memoryAboveCutoffBytes() <= maxMemoryLimitBytes());
101 } 101 }
102 102
103 void CCPrioritizedTextureManager::updateBackingsPriorities() 103 void CCPrioritizedTextureManager::updateBackingsPriorities()
104 { 104 {
105 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsPriorities"); 105 TRACE_EVENT0("cc", "CCPrioritizedTextureManager::updateBackingsPriorities");
106 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 106 DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
107 107
108 if (!m_needsUpdateBackingsPrioritites) 108 if (!m_needsUpdateBackingsPrioritites)
109 return; 109 return;
110 110
111 #if !ASSERT_DISABLED
112 assertInvariants(); 111 assertInvariants();
113 #endif
114 112
115 // Update backings' priorities and put backings in eviction/recycling order. 113 // Update backings' priorities and put backings in eviction/recycling order.
116 BackingVector& sortedBackings = m_tempBackingVector; 114 BackingVector& sortedBackings = m_tempBackingVector;
117 sortedBackings.clear(); 115 sortedBackings.clear();
118 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) { 116 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) {
119 (*it)->updatePriority(); 117 (*it)->updatePriority();
120 sortedBackings.append(*it); 118 sortedBackings.append(*it);
121 } 119 }
122 std::sort(sortedBackings.begin(), sortedBackings.end(), compareBackings); 120 std::sort(sortedBackings.begin(), sortedBackings.end(), compareBackings);
123 121
124 for (BackingVector::iterator it = sortedBackings.begin(); it != sortedBackin gs.end(); ++it) { 122 for (BackingVector::iterator it = sortedBackings.begin(); it != sortedBackin gs.end(); ++it) {
125 m_backings.remove(*it); 123 m_backings.remove(*it);
126 m_backings.add(*it); 124 m_backings.add(*it);
127 } 125 }
128 sortedBackings.clear(); 126 sortedBackings.clear();
129 m_needsUpdateBackingsPrioritites = false; 127 m_needsUpdateBackingsPrioritites = false;
130 128
131 #if !ASSERT_DISABLED
132 assertInvariants(); 129 assertInvariants();
133 #endif
134 } 130 }
135 131
136 void CCPrioritizedTextureManager::clearPriorities() 132 void CCPrioritizedTextureManager::clearPriorities()
137 { 133 {
138 ASSERT(CCProxy::isMainThread()); 134 DCHECK(CCProxy::isMainThread());
139 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); + +it) { 135 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); + +it) {
140 // FIXME: We should remove this and just set all priorities to 136 // FIXME: We should remove this and just set all priorities to
141 // CCPriorityCalculator::lowestPriority() once we have priorities 137 // CCPriorityCalculator::lowestPriority() once we have priorities
142 // for all textures (we can't currently calculate distances for 138 // for all textures (we can't currently calculate distances for
143 // off-screen textures). 139 // off-screen textures).
144 (*it)->setRequestPriority(CCPriorityCalculator::lingeringPriority((*it)- >requestPriority())); 140 (*it)->setRequestPriority(CCPriorityCalculator::lingeringPriority((*it)- >requestPriority()));
145 } 141 }
146 } 142 }
147 143
148 bool CCPrioritizedTextureManager::requestLate(CCPrioritizedTexture* texture) 144 bool CCPrioritizedTextureManager::requestLate(CCPrioritizedTexture* texture)
149 { 145 {
150 ASSERT(CCProxy::isMainThread()); 146 DCHECK(CCProxy::isMainThread());
151 147
152 // This is already above cutoff, so don't double count it's memory below. 148 // This is already above cutoff, so don't double count it's memory below.
153 if (texture->isAbovePriorityCutoff()) 149 if (texture->isAbovePriorityCutoff())
154 return true; 150 return true;
155 151
156 if (CCPriorityCalculator::priorityIsLower(texture->requestPriority(), m_prio rityCutoff)) 152 if (CCPriorityCalculator::priorityIsLower(texture->requestPriority(), m_prio rityCutoff))
157 return false; 153 return false;
158 154
159 size_t newMemoryBytes = m_memoryAboveCutoffBytes + texture->bytes(); 155 size_t newMemoryBytes = m_memoryAboveCutoffBytes + texture->bytes();
160 if (newMemoryBytes > m_memoryAvailableBytes) 156 if (newMemoryBytes > m_memoryAvailableBytes)
161 return false; 157 return false;
162 158
163 m_memoryAboveCutoffBytes = newMemoryBytes; 159 m_memoryAboveCutoffBytes = newMemoryBytes;
164 texture->setAbovePriorityCutoff(true); 160 texture->setAbovePriorityCutoff(true);
165 m_needsUpdateBackingsPrioritites = true; 161 m_needsUpdateBackingsPrioritites = true;
166 return true; 162 return true;
167 } 163 }
168 164
169 void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTex ture* texture, CCResourceProvider* resourceProvider) 165 void CCPrioritizedTextureManager::acquireBackingTextureIfNeeded(CCPrioritizedTex ture* texture, CCResourceProvider* resourceProvider)
170 { 166 {
171 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 167 DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
172 ASSERT(!texture->isSelfManaged()); 168 DCHECK(!texture->isSelfManaged());
173 ASSERT(texture->isAbovePriorityCutoff()); 169 DCHECK(texture->isAbovePriorityCutoff());
174 if (texture->backing() || !texture->isAbovePriorityCutoff()) 170 if (texture->backing() || !texture->isAbovePriorityCutoff())
175 return; 171 return;
176 172
177 // Make sure that the backings list is up to date and sorted before traversi ng it. 173 // Make sure that the backings list is up to date and sorted before traversi ng it.
178 updateBackingsPriorities(); 174 updateBackingsPriorities();
179 175
180 // Find a backing below, by either recycling or allocating. 176 // Find a backing below, by either recycling or allocating.
181 CCPrioritizedTexture::Backing* backing = 0; 177 CCPrioritizedTexture::Backing* backing = 0;
182 178
183 // First try to recycle 179 // First try to recycle
(...skipping 18 matching lines...) Expand all
202 texture->link(backing); 198 texture->link(backing);
203 m_backings.remove(backing); 199 m_backings.remove(backing);
204 m_backings.add(backing); 200 m_backings.add(backing);
205 201
206 // Update the backing's priority from its new owner. 202 // Update the backing's priority from its new owner.
207 backing->updatePriority(); 203 backing->updatePriority();
208 } 204 }
209 205
210 void CCPrioritizedTextureManager::evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy evictionPolicy, CCResourceProvider* resourceProvider) 206 void CCPrioritizedTextureManager::evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy evictionPolicy, CCResourceProvider* resourceProvider)
211 { 207 {
212 ASSERT(CCProxy::isImplThread()); 208 DCHECK(CCProxy::isImplThread());
213 if (memoryUseBytes() <= limitBytes) 209 if (memoryUseBytes() <= limitBytes)
214 return; 210 return;
215 211
216 // Destroy backings until we are below the limit, 212 // Destroy backings until we are below the limit,
217 // or until all backings remaining are above the cutoff. 213 // or until all backings remaining are above the cutoff.
218 while (memoryUseBytes() > limitBytes && m_backings.size() > 0) { 214 while (memoryUseBytes() > limitBytes && m_backings.size() > 0) {
219 CCPrioritizedTexture::Backing* backing = *m_backings.begin(); 215 CCPrioritizedTexture::Backing* backing = *m_backings.begin();
220 if (evictionPolicy == RespectManagerPriorityCutoff) 216 if (evictionPolicy == RespectManagerPriorityCutoff)
221 if (backing->hadOwnerAtLastPriorityUpdate() && backing->wasAbovePrio rityCutoffAtLastPriorityUpdate()) 217 if (backing->hadOwnerAtLastPriorityUpdate() && backing->wasAbovePrio rityCutoffAtLastPriorityUpdate())
222 break; 218 break;
223 evictBackingResource(backing, resourceProvider); 219 evictBackingResource(backing, resourceProvider);
224 } 220 }
225 } 221 }
226 222
227 void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvi der) 223 void CCPrioritizedTextureManager::reduceMemory(CCResourceProvider* resourceProvi der)
228 { 224 {
229 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 225 DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
230 226
231 // Make sure that the backings list is up to date and sorted before traversi ng it. 227 // Make sure that the backings list is up to date and sorted before traversi ng it.
232 updateBackingsPriorities(); 228 updateBackingsPriorities();
233 229
234 evictBackingsToReduceMemory(m_memoryAvailableBytes, RespectManagerPriorityCu toff, resourceProvider); 230 evictBackingsToReduceMemory(m_memoryAvailableBytes, RespectManagerPriorityCu toff, resourceProvider);
235 ASSERT(memoryUseBytes() <= maxMemoryLimitBytes()); 231 DCHECK(memoryUseBytes() <= maxMemoryLimitBytes());
236 232
237 // We currently collect backings from deleted textures for later recycling. 233 // 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 234 // 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 235 // 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 236 // limit externally, but until then this just does some "clean up" of unused
241 // backing textures (any more than 10%). 237 // backing textures (any more than 10%).
242 size_t wastedMemory = 0; 238 size_t wastedMemory = 0;
243 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) { 239 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) {
244 if ((*it)->owner()) 240 if ((*it)->owner())
245 break; 241 break;
246 wastedMemory += (*it)->bytes(); 242 wastedMemory += (*it)->bytes();
247 } 243 }
248 size_t tenPercentOfMemory = m_memoryAvailableBytes / 10; 244 size_t tenPercentOfMemory = m_memoryAvailableBytes / 10;
249 if (wastedMemory > tenPercentOfMemory) 245 if (wastedMemory > tenPercentOfMemory)
250 evictBackingsToReduceMemory(memoryUseBytes() - (wastedMemory - tenPercen tOfMemory), RespectManagerPriorityCutoff, resourceProvider); 246 evictBackingsToReduceMemory(memoryUseBytes() - (wastedMemory - tenPercen tOfMemory), RespectManagerPriorityCutoff, resourceProvider);
251 247
252 deleteEvictedBackings(); 248 deleteEvictedBackings();
253 } 249 }
254 250
255 void CCPrioritizedTextureManager::clearAllMemory(CCResourceProvider* resourcePro vider) 251 void CCPrioritizedTextureManager::clearAllMemory(CCResourceProvider* resourcePro vider)
256 { 252 {
257 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 253 DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
258 ASSERT(resourceProvider); 254 DCHECK(resourceProvider);
259 evictBackingsToReduceMemory(0, DoNotRespectManagerPriorityCutoff, resourcePr ovider); 255 evictBackingsToReduceMemory(0, DoNotRespectManagerPriorityCutoff, resourcePr ovider);
260 deleteEvictedBackings(); 256 deleteEvictedBackings();
261 } 257 }
262 258
263 void CCPrioritizedTextureManager::reduceMemoryOnImplThread(size_t limitBytes, CC ResourceProvider* resourceProvider) 259 void CCPrioritizedTextureManager::reduceMemoryOnImplThread(size_t limitBytes, CC ResourceProvider* resourceProvider)
264 { 260 {
265 ASSERT(CCProxy::isImplThread()); 261 DCHECK(CCProxy::isImplThread());
266 ASSERT(resourceProvider); 262 DCHECK(resourceProvider);
267 evictBackingsToReduceMemory(limitBytes, DoNotRespectManagerPriorityCutoff, r esourceProvider); 263 evictBackingsToReduceMemory(limitBytes, DoNotRespectManagerPriorityCutoff, r esourceProvider);
268 } 264 }
269 265
270 void CCPrioritizedTextureManager::getEvictedBackings(BackingVector& evictedBacki ngs) 266 void CCPrioritizedTextureManager::getEvictedBackings(BackingVector& evictedBacki ngs)
271 { 267 {
272 ASSERT(CCProxy::isImplThread()); 268 DCHECK(CCProxy::isImplThread());
273 evictedBackings.clear(); 269 evictedBackings.clear();
274 evictedBackings.append(m_evictedBackings); 270 evictedBackings.append(m_evictedBackings);
275 } 271 }
276 272
277 void CCPrioritizedTextureManager::unlinkEvictedBackings(const BackingVector& evi ctedBackings) 273 void CCPrioritizedTextureManager::unlinkEvictedBackings(const BackingVector& evi ctedBackings)
278 { 274 {
279 ASSERT(CCProxy::isMainThread()); 275 DCHECK(CCProxy::isMainThread());
280 for (BackingVector::const_iterator it = evictedBackings.begin(); it != evict edBackings.end(); ++it) { 276 for (BackingVector::const_iterator it = evictedBackings.begin(); it != evict edBackings.end(); ++it) {
281 CCPrioritizedTexture::Backing* backing = (*it); 277 CCPrioritizedTexture::Backing* backing = (*it);
282 if (backing->owner()) 278 if (backing->owner())
283 backing->owner()->unlink(); 279 backing->owner()->unlink();
284 } 280 }
285 } 281 }
286 282
287 bool CCPrioritizedTextureManager::deleteEvictedBackings() 283 bool CCPrioritizedTextureManager::deleteEvictedBackings()
288 { 284 {
289 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai nThreadBlocked())); 285 DCHECK(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai nThreadBlocked()));
290 bool linkedEvictedBackingsExisted = false; 286 bool linkedEvictedBackingsExisted = false;
291 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e victedBackings.end(); ++it) { 287 for (BackingVector::const_iterator it = m_evictedBackings.begin(); it != m_e victedBackings.end(); ++it) {
292 CCPrioritizedTexture::Backing* backing = (*it); 288 CCPrioritizedTexture::Backing* backing = (*it);
293 if (backing->owner()) { 289 if (backing->owner()) {
294 linkedEvictedBackingsExisted = true; 290 linkedEvictedBackingsExisted = true;
295 backing->owner()->unlink(); 291 backing->owner()->unlink();
296 } 292 }
297 delete backing; 293 delete backing;
298 } 294 }
299 m_evictedBackings.clear(); 295 m_evictedBackings.clear();
300 return linkedEvictedBackingsExisted; 296 return linkedEvictedBackingsExisted;
301 } 297 }
302 298
303 void CCPrioritizedTextureManager::registerTexture(CCPrioritizedTexture* texture) 299 void CCPrioritizedTextureManager::registerTexture(CCPrioritizedTexture* texture)
304 { 300 {
305 ASSERT(CCProxy::isMainThread()); 301 DCHECK(CCProxy::isMainThread());
306 ASSERT(texture); 302 DCHECK(texture);
307 ASSERT(!texture->textureManager()); 303 DCHECK(!texture->textureManager());
308 ASSERT(!texture->backing()); 304 DCHECK(!texture->backing());
309 ASSERT(!ContainsKey(m_textures, texture)); 305 DCHECK(!ContainsKey(m_textures, texture));
310 306
311 texture->setManagerInternal(this); 307 texture->setManagerInternal(this);
312 m_textures.insert(texture); 308 m_textures.insert(texture);
313 309
314 } 310 }
315 311
316 void CCPrioritizedTextureManager::unregisterTexture(CCPrioritizedTexture* textur e) 312 void CCPrioritizedTextureManager::unregisterTexture(CCPrioritizedTexture* textur e)
317 { 313 {
318 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai nThreadBlocked())); 314 DCHECK(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai nThreadBlocked()));
319 ASSERT(texture); 315 DCHECK(texture);
320 ASSERT(ContainsKey(m_textures, texture)); 316 DCHECK(ContainsKey(m_textures, texture));
321 317
322 returnBackingTexture(texture); 318 returnBackingTexture(texture);
323 texture->setManagerInternal(0); 319 texture->setManagerInternal(0);
324 m_textures.erase(texture); 320 m_textures.erase(texture);
325 texture->setAbovePriorityCutoff(false); 321 texture->setAbovePriorityCutoff(false);
326 } 322 }
327 323
328 void CCPrioritizedTextureManager::returnBackingTexture(CCPrioritizedTexture* tex ture) 324 void CCPrioritizedTextureManager::returnBackingTexture(CCPrioritizedTexture* tex ture)
329 { 325 {
330 ASSERT(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai nThreadBlocked())); 326 DCHECK(CCProxy::isMainThread() || (CCProxy::isImplThread() && CCProxy::isMai nThreadBlocked()));
331 if (texture->backing()) { 327 if (texture->backing()) {
332 texture->unlink(); 328 texture->unlink();
333 m_needsUpdateBackingsPrioritites = true; 329 m_needsUpdateBackingsPrioritites = true;
334 } 330 }
335 } 331 }
336 332
337 CCPrioritizedTexture::Backing* CCPrioritizedTextureManager::createBacking(IntSiz e size, GC3Denum format, CCResourceProvider* resourceProvider) 333 CCPrioritizedTexture::Backing* CCPrioritizedTextureManager::createBacking(IntSiz e size, GC3Denum format, CCResourceProvider* resourceProvider)
338 { 334 {
339 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 335 DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
340 ASSERT(resourceProvider); 336 DCHECK(resourceProvider);
341 CCResourceProvider::ResourceId resourceId = resourceProvider->createResource (m_pool, size, format, CCResourceProvider::TextureUsageAny); 337 CCResourceProvider::ResourceId resourceId = resourceProvider->createResource (m_pool, size, format, CCResourceProvider::TextureUsageAny);
342 CCPrioritizedTexture::Backing* backing = new CCPrioritizedTexture::Backing(r esourceId, resourceProvider, size, format); 338 CCPrioritizedTexture::Backing* backing = new CCPrioritizedTexture::Backing(r esourceId, resourceProvider, size, format);
343 m_memoryUseBytes += backing->bytes(); 339 m_memoryUseBytes += backing->bytes();
344 // Put backing texture at the front for eviction, since it isn't in use yet. 340 // Put backing texture at the front for eviction, since it isn't in use yet.
345 m_backings.insertBefore(m_backings.begin(), backing); 341 m_backings.insertBefore(m_backings.begin(), backing);
346 return backing; 342 return backing;
347 } 343 }
348 344
349 void CCPrioritizedTextureManager::evictBackingResource(CCPrioritizedTexture::Bac king* backing, CCResourceProvider* resourceProvider) 345 void CCPrioritizedTextureManager::evictBackingResource(CCPrioritizedTexture::Bac king* backing, CCResourceProvider* resourceProvider)
350 { 346 {
351 ASSERT(CCProxy::isImplThread()); 347 DCHECK(CCProxy::isImplThread());
352 ASSERT(backing); 348 DCHECK(backing);
353 ASSERT(resourceProvider); 349 DCHECK(resourceProvider);
354 ASSERT(m_backings.find(backing) != m_backings.end()); 350 DCHECK(m_backings.find(backing) != m_backings.end());
355 351
356 // Note that we create a backing and its resource at the same time, but we 352 // Note that we create a backing and its resource at the same time, but we
357 // delete the backing structure and its resource in two steps. This is becau se 353 // delete the backing structure and its resource in two steps. This is becau se
358 // we can delete the resource while the main thread is running, but we canno t 354 // we can delete the resource while the main thread is running, but we canno t
359 // unlink backings while the main thread is running. 355 // unlink backings while the main thread is running.
360 backing->deleteResource(resourceProvider); 356 backing->deleteResource(resourceProvider);
361 m_memoryUseBytes -= backing->bytes(); 357 m_memoryUseBytes -= backing->bytes();
362 m_backings.remove(backing); 358 m_backings.remove(backing);
363 m_evictedBackings.append(backing); 359 m_evictedBackings.append(backing);
364 } 360 }
365 361
366 #if !ASSERT_DISABLED
367 void CCPrioritizedTextureManager::assertInvariants() 362 void CCPrioritizedTextureManager::assertInvariants()
368 { 363 {
369 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); 364 if (!DCHECK_IS_ON())
365 return;
366
367 DCHECK(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked());
370 368
371 // If we hit any of these asserts, there is a bug in this class. To see 369 // If we hit any of these asserts, there is a bug in this class. To see
372 // where the bug is, call this function at the beginning and end of 370 // where the bug is, call this function at the beginning and end of
373 // every public function. 371 // every public function.
374 372
375 // Backings/textures must be doubly-linked and only to other backings/textur es in this manager. 373 // 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) { 374 for (BackingSet::iterator it = m_backings.begin(); it != m_backings.end(); + +it) {
377 if ((*it)->owner()) { 375 if ((*it)->owner()) {
378 ASSERT(ContainsKey(m_textures, (*it)->owner())); 376 DCHECK(ContainsKey(m_textures, (*it)->owner()));
379 ASSERT((*it)->owner()->backing() == (*it)); 377 DCHECK((*it)->owner()->backing() == (*it));
380 } 378 }
381 } 379 }
382 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); + +it) { 380 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); + +it) {
383 if ((*it)->backing()) { 381 if ((*it)->backing()) {
384 ASSERT(m_backings.find((*it)->backing()) != m_backings.end()); 382 DCHECK(m_backings.find((*it)->backing()) != m_backings.end());
385 ASSERT((*it)->backing()->owner() == (*it)); 383 DCHECK((*it)->backing()->owner() == (*it));
386 } 384 }
387 } 385 }
388 386
389 // At all times, backings that can be evicted must always come before 387 // 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 388 // backings that can't be evicted in the backing texture list (otherwise
391 // reduceMemory will not find all textures available for eviction/recycling) . 389 // reduceMemory will not find all textures available for eviction/recycling) .
392 bool reachedOwned = false; 390 bool reachedOwned = false;
393 bool reachedAboveCutoff = false; 391 bool reachedAboveCutoff = false;
394 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) {
395 if ((*it)->hadOwnerAtLastPriorityUpdate()) 393 if ((*it)->hadOwnerAtLastPriorityUpdate())
396 reachedOwned = true; 394 reachedOwned = true;
397 if ((*it)->wasAbovePriorityCutoffAtLastPriorityUpdate()) 395 if ((*it)->wasAbovePriorityCutoffAtLastPriorityUpdate())
398 reachedAboveCutoff = true; 396 reachedAboveCutoff = true;
399 if (reachedOwned) 397 if (reachedOwned)
400 ASSERT((*it)->hadOwnerAtLastPriorityUpdate()); 398 DCHECK((*it)->hadOwnerAtLastPriorityUpdate());
401 if (reachedAboveCutoff) { 399 if (reachedAboveCutoff) {
402 ASSERT((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePrior ityCutoffAtLastPriorityUpdate()); 400 DCHECK((*it)->hadOwnerAtLastPriorityUpdate() && (*it)->wasAbovePrior ityCutoffAtLastPriorityUpdate());
403 ASSERT(reachedOwned); 401 DCHECK(reachedOwned);
404 } 402 }
405 } 403 }
406 } 404 }
407 #endif
408 405
409 406
410 } // namespace cc 407 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698