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

Side by Side Diff: cc/prioritized_texture_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698