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

Side by Side Diff: cc/prioritized_texture_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698