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

Side by Side Diff: cc/prioritized_resource_manager.cc

Issue 11232051: Remove static thread pointers from CC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Apply code review comments Created 8 years, 1 month 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/prioritized_resource_manager.h ('k') | cc/prioritized_resource_unittest.cc » ('j') | 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 "cc/prioritized_resource_manager.h" 7 #include "cc/prioritized_resource_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_resource.h" 11 #include "cc/prioritized_resource.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 PrioritizedResourceManager::PrioritizedResourceManager(size_t maxMemoryLimitByte s, int, int pool) 20 PrioritizedResourceManager::PrioritizedResourceManager(size_t maxMemoryLimitByte s, int, int pool, const Proxy* proxy)
21 : m_maxMemoryLimitBytes(maxMemoryLimitBytes) 21 : m_proxy(proxy)
22 , m_maxMemoryLimitBytes(maxMemoryLimitBytes)
22 , m_externalPriorityCutoff(PriorityCalculator::allowEverythingCutoff()) 23 , m_externalPriorityCutoff(PriorityCalculator::allowEverythingCutoff())
23 , m_memoryUseBytes(0) 24 , m_memoryUseBytes(0)
24 , m_memoryAboveCutoffBytes(0) 25 , m_memoryAboveCutoffBytes(0)
25 , m_memoryAvailableBytes(0) 26 , m_memoryAvailableBytes(0)
26 , m_pool(pool) 27 , m_pool(pool)
27 , m_backingsTailNotSorted(false) 28 , m_backingsTailNotSorted(false)
28 , m_memoryVisibleBytes(0) 29 , m_memoryVisibleBytes(0)
29 , m_memoryVisibleAndNearbyBytes(0) 30 , m_memoryVisibleAndNearbyBytes(0)
30 , m_memoryVisibleLastPushedBytes(0) 31 , m_memoryVisibleLastPushedBytes(0)
31 , m_memoryVisibleAndNearbyLastPushedBytes(0) 32 , m_memoryVisibleAndNearbyLastPushedBytes(0)
32 { 33 {
33 } 34 }
34 35
35 PrioritizedResourceManager::~PrioritizedResourceManager() 36 PrioritizedResourceManager::~PrioritizedResourceManager()
36 { 37 {
37 while (m_textures.size() > 0) 38 while (m_textures.size() > 0)
38 unregisterTexture(*m_textures.begin()); 39 unregisterTexture(*m_textures.begin());
39 40
40 deleteUnlinkedEvictedBackings(); 41 deleteUnlinkedEvictedBackings();
41 DCHECK(m_evictedBackings.empty()); 42 DCHECK(m_evictedBackings.empty());
42 43
43 // Each remaining backing is a leaked opengl texture. There should be none. 44 // Each remaining backing is a leaked opengl texture. There should be none.
44 DCHECK(m_backings.empty()); 45 DCHECK(m_backings.empty());
45 } 46 }
46 47
47 size_t PrioritizedResourceManager::memoryVisibleBytes() const 48 size_t PrioritizedResourceManager::memoryVisibleBytes() const
48 { 49 {
49 DCHECK(Proxy::isImplThread()); 50 DCHECK(m_proxy->isImplThread());
50 return m_memoryVisibleLastPushedBytes; 51 return m_memoryVisibleLastPushedBytes;
51 } 52 }
52 53
53 size_t PrioritizedResourceManager::memoryVisibleAndNearbyBytes() const 54 size_t PrioritizedResourceManager::memoryVisibleAndNearbyBytes() const
54 { 55 {
55 DCHECK(Proxy::isImplThread()); 56 DCHECK(m_proxy->isImplThread());
56 return m_memoryVisibleAndNearbyLastPushedBytes; 57 return m_memoryVisibleAndNearbyLastPushedBytes;
57 } 58 }
58 59
59 void PrioritizedResourceManager::prioritizeTextures() 60 void PrioritizedResourceManager::prioritizeTextures()
60 { 61 {
61 TRACE_EVENT0("cc", "PrioritizedResourceManager::prioritizeTextures"); 62 TRACE_EVENT0("cc", "PrioritizedResourceManager::prioritizeTextures");
62 DCHECK(Proxy::isMainThread()); 63 DCHECK(m_proxy->isMainThread());
63 64
64 // Sorting textures in this function could be replaced by a slightly 65 // Sorting textures in this function could be replaced by a slightly
65 // modified O(n) quick-select to partition textures rather than 66 // modified O(n) quick-select to partition textures rather than
66 // sort them (if performance of the sort becomes an issue). 67 // sort them (if performance of the sort becomes an issue).
67 68
68 TextureVector& sortedTextures = m_tempTextureVector; 69 TextureVector& sortedTextures = m_tempTextureVector;
69 sortedTextures.clear(); 70 sortedTextures.clear();
70 71
71 // Copy all textures into a vector, sort them, and collect memory requiremen ts statistics. 72 // Copy all textures into a vector, sort them, and collect memory requiremen ts statistics.
72 m_memoryVisibleBytes = 0; 73 m_memoryVisibleBytes = 0;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 129 }
129 sortedTextures.clear(); 130 sortedTextures.clear();
130 131
131 DCHECK(m_memoryAboveCutoffBytes <= m_memoryAvailableBytes); 132 DCHECK(m_memoryAboveCutoffBytes <= m_memoryAvailableBytes);
132 DCHECK(memoryAboveCutoffBytes() <= maxMemoryLimitBytes()); 133 DCHECK(memoryAboveCutoffBytes() <= maxMemoryLimitBytes());
133 } 134 }
134 135
135 void PrioritizedResourceManager::pushTexturePrioritiesToBackings() 136 void PrioritizedResourceManager::pushTexturePrioritiesToBackings()
136 { 137 {
137 TRACE_EVENT0("cc", "PrioritizedResourceManager::pushTexturePrioritiesToBacki ngs"); 138 TRACE_EVENT0("cc", "PrioritizedResourceManager::pushTexturePrioritiesToBacki ngs");
138 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); 139 DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked());
139 140
140 assertInvariants(); 141 assertInvariants();
141 for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) 142 for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it)
142 (*it)->updatePriority(); 143 (*it)->updatePriority();
143 sortBackings(); 144 sortBackings();
144 assertInvariants(); 145 assertInvariants();
145 146
146 // Push memory requirements to the impl thread structure. 147 // Push memory requirements to the impl thread structure.
147 m_memoryVisibleLastPushedBytes = m_memoryVisibleBytes; 148 m_memoryVisibleLastPushedBytes = m_memoryVisibleBytes;
148 m_memoryVisibleAndNearbyLastPushedBytes = m_memoryVisibleAndNearbyBytes; 149 m_memoryVisibleAndNearbyLastPushedBytes = m_memoryVisibleAndNearbyBytes;
149 } 150 }
150 151
151 void PrioritizedResourceManager::updateBackingsInDrawingImplTree() 152 void PrioritizedResourceManager::updateBackingsInDrawingImplTree()
152 { 153 {
153 TRACE_EVENT0("cc", "PrioritizedResourceManager::updateBackingsInDrawingImplT ree"); 154 TRACE_EVENT0("cc", "PrioritizedResourceManager::updateBackingsInDrawingImplT ree");
154 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); 155 DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked());
155 156
156 assertInvariants(); 157 assertInvariants();
157 for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) { 158 for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) {
158 PrioritizedResource::Backing* backing = (*it); 159 PrioritizedResource::Backing* backing = (*it);
159 backing->updateInDrawingImplTree(); 160 backing->updateInDrawingImplTree();
160 } 161 }
161 sortBackings(); 162 sortBackings();
162 assertInvariants(); 163 assertInvariants();
163 } 164 }
164 165
165 void PrioritizedResourceManager::sortBackings() 166 void PrioritizedResourceManager::sortBackings()
166 { 167 {
167 TRACE_EVENT0("cc", "PrioritizedResourceManager::sortBackings"); 168 TRACE_EVENT0("cc", "PrioritizedResourceManager::sortBackings");
168 DCHECK(Proxy::isImplThread()); 169 DCHECK(m_proxy->isImplThread());
169 170
170 // Put backings in eviction/recycling order. 171 // Put backings in eviction/recycling order.
171 m_backings.sort(compareBackings); 172 m_backings.sort(compareBackings);
172 m_backingsTailNotSorted = false; 173 m_backingsTailNotSorted = false;
173 } 174 }
174 175
175 void PrioritizedResourceManager::clearPriorities() 176 void PrioritizedResourceManager::clearPriorities()
176 { 177 {
177 DCHECK(Proxy::isMainThread()); 178 DCHECK(m_proxy->isMainThread());
178 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); + +it) { 179 for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); + +it) {
179 // FIXME: We should remove this and just set all priorities to 180 // FIXME: We should remove this and just set all priorities to
180 // PriorityCalculator::lowestPriority() once we have priorities 181 // PriorityCalculator::lowestPriority() once we have priorities
181 // for all textures (we can't currently calculate distances for 182 // for all textures (we can't currently calculate distances for
182 // off-screen textures). 183 // off-screen textures).
183 (*it)->setRequestPriority(PriorityCalculator::lingeringPriority((*it)->r equestPriority())); 184 (*it)->setRequestPriority(PriorityCalculator::lingeringPriority((*it)->r equestPriority()));
184 } 185 }
185 } 186 }
186 187
187 bool PrioritizedResourceManager::requestLate(PrioritizedResource* texture) 188 bool PrioritizedResourceManager::requestLate(PrioritizedResource* texture)
188 { 189 {
189 DCHECK(Proxy::isMainThread()); 190 DCHECK(m_proxy->isMainThread());
190 191
191 // This is already above cutoff, so don't double count it's memory below. 192 // This is already above cutoff, so don't double count it's memory below.
192 if (texture->isAbovePriorityCutoff()) 193 if (texture->isAbovePriorityCutoff())
193 return true; 194 return true;
194 195
195 // Allow textures that have priority equal to the cutoff, but not strictly l ower. 196 // Allow textures that have priority equal to the cutoff, but not strictly l ower.
196 if (PriorityCalculator::priorityIsLower(texture->requestPriority(), m_priori tyCutoff)) 197 if (PriorityCalculator::priorityIsLower(texture->requestPriority(), m_priori tyCutoff))
197 return false; 198 return false;
198 199
199 // Disallow textures that do not have a priority strictly higher than the ex ternal cutoff. 200 // Disallow textures that do not have a priority strictly higher than the ex ternal cutoff.
200 if (!PriorityCalculator::priorityIsHigher(texture->requestPriority(), m_exte rnalPriorityCutoff)) 201 if (!PriorityCalculator::priorityIsHigher(texture->requestPriority(), m_exte rnalPriorityCutoff))
201 return false; 202 return false;
202 203
203 size_t newMemoryBytes = m_memoryAboveCutoffBytes + texture->bytes(); 204 size_t newMemoryBytes = m_memoryAboveCutoffBytes + texture->bytes();
204 if (newMemoryBytes > m_memoryAvailableBytes) 205 if (newMemoryBytes > m_memoryAvailableBytes)
205 return false; 206 return false;
206 207
207 m_memoryAboveCutoffBytes = newMemoryBytes; 208 m_memoryAboveCutoffBytes = newMemoryBytes;
208 texture->setAbovePriorityCutoff(true); 209 texture->setAbovePriorityCutoff(true);
209 return true; 210 return true;
210 } 211 }
211 212
212 void PrioritizedResourceManager::acquireBackingTextureIfNeeded(PrioritizedResour ce* texture, ResourceProvider* resourceProvider) 213 void PrioritizedResourceManager::acquireBackingTextureIfNeeded(PrioritizedResour ce* texture, ResourceProvider* resourceProvider)
213 { 214 {
214 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); 215 DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked());
215 DCHECK(!texture->isSelfManaged()); 216 DCHECK(!texture->isSelfManaged());
216 DCHECK(texture->isAbovePriorityCutoff()); 217 DCHECK(texture->isAbovePriorityCutoff());
217 if (texture->backing() || !texture->isAbovePriorityCutoff()) 218 if (texture->backing() || !texture->isAbovePriorityCutoff())
218 return; 219 return;
219 220
220 // Find a backing below, by either recycling or allocating. 221 // Find a backing below, by either recycling or allocating.
221 PrioritizedResource::Backing* backing = 0; 222 PrioritizedResource::Backing* backing = 0;
222 223
223 // First try to recycle 224 // First try to recycle
224 for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) { 225 for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) {
(...skipping 19 matching lines...) Expand all
244 texture->link(backing); 245 texture->link(backing);
245 m_backings.push_back(backing); 246 m_backings.push_back(backing);
246 m_backingsTailNotSorted = true; 247 m_backingsTailNotSorted = true;
247 248
248 // Update the backing's priority from its new owner. 249 // Update the backing's priority from its new owner.
249 backing->updatePriority(); 250 backing->updatePriority();
250 } 251 }
251 252
252 bool PrioritizedResourceManager::evictBackingsToReduceMemory(size_t limitBytes, int priorityCutoff, EvictionPolicy evictionPolicy, ResourceProvider* resourcePro vider) 253 bool PrioritizedResourceManager::evictBackingsToReduceMemory(size_t limitBytes, int priorityCutoff, EvictionPolicy evictionPolicy, ResourceProvider* resourcePro vider)
253 { 254 {
254 DCHECK(Proxy::isImplThread()); 255 DCHECK(m_proxy->isImplThread());
255 if (memoryUseBytes() <= limitBytes && PriorityCalculator::allowEverythingCut off() == priorityCutoff) 256 if (memoryUseBytes() <= limitBytes && PriorityCalculator::allowEverythingCut off() == priorityCutoff)
256 return false; 257 return false;
257 258
258 // Destroy backings until we are below the limit, 259 // Destroy backings until we are below the limit,
259 // or until all backings remaining are above the cutoff. 260 // or until all backings remaining are above the cutoff.
260 while (m_backings.size() > 0) { 261 while (m_backings.size() > 0) {
261 PrioritizedResource::Backing* backing = m_backings.front(); 262 PrioritizedResource::Backing* backing = m_backings.front();
262 if (memoryUseBytes() <= limitBytes && 263 if (memoryUseBytes() <= limitBytes &&
263 PriorityCalculator::priorityIsHigher(backing->requestPriorityAtLastP riorityUpdate(), priorityCutoff)) 264 PriorityCalculator::priorityIsHigher(backing->requestPriorityAtLastP riorityUpdate(), priorityCutoff))
264 break; 265 break;
265 if (evictionPolicy == EvictOnlyRecyclable && !backing->canBeRecycled()) 266 if (evictionPolicy == EvictOnlyRecyclable && !backing->canBeRecycled())
266 break; 267 break;
267 evictFirstBackingResource(resourceProvider); 268 evictFirstBackingResource(resourceProvider);
268 } 269 }
269 return true; 270 return true;
270 } 271 }
271 272
272 void PrioritizedResourceManager::reduceMemory(ResourceProvider* resourceProvider ) 273 void PrioritizedResourceManager::reduceMemory(ResourceProvider* resourceProvider )
273 { 274 {
274 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); 275 DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked());
275 276
276 // Note that it will not always be the case that memoryUseBytes() <= maxMemo ryLimitBytes(), 277 // Note that it will not always be the case that memoryUseBytes() <= maxMemo ryLimitBytes(),
277 // because we are not at liberty to delete textures that are referenced by t he impl tree to 278 // because we are not at liberty to delete textures that are referenced by t he impl tree to
278 // get more space. 279 // get more space.
279 280
280 evictBackingsToReduceMemory(m_memoryAvailableBytes, PriorityCalculator::allo wEverythingCutoff(), EvictOnlyRecyclable, resourceProvider); 281 evictBackingsToReduceMemory(m_memoryAvailableBytes, PriorityCalculator::allo wEverythingCutoff(), EvictOnlyRecyclable, resourceProvider);
281 282
282 // We currently collect backings from deleted textures for later recycling. 283 // We currently collect backings from deleted textures for later recycling.
283 // However, if we do that forever we will always use the max limit even if 284 // However, if we do that forever we will always use the max limit even if
284 // we really need very little memory. This should probably be solved by redu cing the 285 // we really need very little memory. This should probably be solved by redu cing the
(...skipping 14 matching lines...) Expand all
299 if ((*it)->owner()) 300 if ((*it)->owner())
300 (*it)->owner()->unlink(); 301 (*it)->owner()->unlink();
301 } 302 }
302 303
303 // And clear the list of evicted backings 304 // And clear the list of evicted backings
304 deleteUnlinkedEvictedBackings(); 305 deleteUnlinkedEvictedBackings();
305 } 306 }
306 307
307 void PrioritizedResourceManager::clearAllMemory(ResourceProvider* resourceProvid er) 308 void PrioritizedResourceManager::clearAllMemory(ResourceProvider* resourceProvid er)
308 { 309 {
309 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); 310 DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked());
310 DCHECK(resourceProvider); 311 DCHECK(resourceProvider);
311 evictBackingsToReduceMemory(0, PriorityCalculator::allowEverythingCutoff(), EvictAnything, resourceProvider); 312 evictBackingsToReduceMemory(0, PriorityCalculator::allowEverythingCutoff(), EvictAnything, resourceProvider);
312 } 313 }
313 314
314 bool PrioritizedResourceManager::reduceMemoryOnImplThread(size_t limitBytes, int priorityCutoff, ResourceProvider* resourceProvider) 315 bool PrioritizedResourceManager::reduceMemoryOnImplThread(size_t limitBytes, int priorityCutoff, ResourceProvider* resourceProvider)
315 { 316 {
316 DCHECK(Proxy::isImplThread()); 317 DCHECK(m_proxy->isImplThread());
317 DCHECK(resourceProvider); 318 DCHECK(resourceProvider);
318 // If we are in the process of uploading a new frame then the backings at th e very end of 319 // If we are in the process of uploading a new frame then the backings at th e very end of
319 // the list are not sorted by priority. Sort them before doing the eviction. 320 // the list are not sorted by priority. Sort them before doing the eviction.
320 if (m_backingsTailNotSorted) 321 if (m_backingsTailNotSorted)
321 sortBackings(); 322 sortBackings();
322 return evictBackingsToReduceMemory(limitBytes, priorityCutoff, EvictAnything , resourceProvider); 323 return evictBackingsToReduceMemory(limitBytes, priorityCutoff, EvictAnything , resourceProvider);
323 } 324 }
324 325
325 void PrioritizedResourceManager::getEvictedBackings(BackingList& evictedBackings ) 326 void PrioritizedResourceManager::getEvictedBackings(BackingList& evictedBackings )
326 { 327 {
327 DCHECK(Proxy::isImplThread()); 328 DCHECK(m_proxy->isImplThread());
328 evictedBackings.clear(); 329 evictedBackings.clear();
329 evictedBackings.insert(evictedBackings.begin(), m_evictedBackings.begin(), m _evictedBackings.end()); 330 evictedBackings.insert(evictedBackings.begin(), m_evictedBackings.begin(), m _evictedBackings.end());
330 } 331 }
331 332
332 void PrioritizedResourceManager::unlinkEvictedBackings(const BackingList& evicte dBackings) 333 void PrioritizedResourceManager::unlinkEvictedBackings(const BackingList& evicte dBackings)
333 { 334 {
334 DCHECK(Proxy::isMainThread()); 335 DCHECK(m_proxy->isMainThread());
335 for (BackingList::const_iterator it = evictedBackings.begin(); it != evicted Backings.end(); ++it) { 336 for (BackingList::const_iterator it = evictedBackings.begin(); it != evicted Backings.end(); ++it) {
336 PrioritizedResource::Backing* backing = (*it); 337 PrioritizedResource::Backing* backing = (*it);
337 if (backing->owner()) 338 if (backing->owner())
338 backing->owner()->unlink(); 339 backing->owner()->unlink();
339 } 340 }
340 } 341 }
341 342
342 void PrioritizedResourceManager::deleteUnlinkedEvictedBackings() 343 void PrioritizedResourceManager::deleteUnlinkedEvictedBackings()
343 { 344 {
344 DCHECK(Proxy::isMainThread() || (Proxy::isImplThread() && Proxy::isMainThrea dBlocked())); 345 DCHECK(m_proxy->isMainThread() || (m_proxy->isImplThread() && m_proxy->isMai nThreadBlocked()));
345 BackingList newEvictedBackings; 346 BackingList newEvictedBackings;
346 for (BackingList::const_iterator it = m_evictedBackings.begin(); it != m_evi ctedBackings.end(); ++it) { 347 for (BackingList::const_iterator it = m_evictedBackings.begin(); it != m_evi ctedBackings.end(); ++it) {
347 PrioritizedResource::Backing* backing = (*it); 348 PrioritizedResource::Backing* backing = (*it);
348 if (backing->owner()) 349 if (backing->owner())
349 newEvictedBackings.push_back(backing); 350 newEvictedBackings.push_back(backing);
350 else 351 else
351 delete backing; 352 delete backing;
352 } 353 }
353 m_evictedBackings.swap(newEvictedBackings); 354 m_evictedBackings.swap(newEvictedBackings);
354 } 355 }
355 356
356 bool PrioritizedResourceManager::linkedEvictedBackingsExist() const 357 bool PrioritizedResourceManager::linkedEvictedBackingsExist() const
357 { 358 {
358 for (BackingList::const_iterator it = m_evictedBackings.begin(); it != m_evi ctedBackings.end(); ++it) { 359 for (BackingList::const_iterator it = m_evictedBackings.begin(); it != m_evi ctedBackings.end(); ++it) {
359 if ((*it)->owner()) 360 if ((*it)->owner())
360 return true; 361 return true;
361 } 362 }
362 return false; 363 return false;
363 } 364 }
364 365
365 void PrioritizedResourceManager::registerTexture(PrioritizedResource* texture) 366 void PrioritizedResourceManager::registerTexture(PrioritizedResource* texture)
366 { 367 {
367 DCHECK(Proxy::isMainThread()); 368 DCHECK(m_proxy->isMainThread());
368 DCHECK(texture); 369 DCHECK(texture);
369 DCHECK(!texture->resourceManager()); 370 DCHECK(!texture->resourceManager());
370 DCHECK(!texture->backing()); 371 DCHECK(!texture->backing());
371 DCHECK(!ContainsKey(m_textures, texture)); 372 DCHECK(!ContainsKey(m_textures, texture));
372 373
373 texture->setManagerInternal(this); 374 texture->setManagerInternal(this);
374 m_textures.insert(texture); 375 m_textures.insert(texture);
375 376
376 } 377 }
377 378
378 void PrioritizedResourceManager::unregisterTexture(PrioritizedResource* texture) 379 void PrioritizedResourceManager::unregisterTexture(PrioritizedResource* texture)
379 { 380 {
380 DCHECK(Proxy::isMainThread() || (Proxy::isImplThread() && Proxy::isMainThrea dBlocked())); 381 DCHECK(m_proxy->isMainThread() || (m_proxy->isImplThread() && m_proxy->isMai nThreadBlocked()));
381 DCHECK(texture); 382 DCHECK(texture);
382 DCHECK(ContainsKey(m_textures, texture)); 383 DCHECK(ContainsKey(m_textures, texture));
383 384
384 returnBackingTexture(texture); 385 returnBackingTexture(texture);
385 texture->setManagerInternal(0); 386 texture->setManagerInternal(0);
386 m_textures.erase(texture); 387 m_textures.erase(texture);
387 texture->setAbovePriorityCutoff(false); 388 texture->setAbovePriorityCutoff(false);
388 } 389 }
389 390
390 void PrioritizedResourceManager::returnBackingTexture(PrioritizedResource* textu re) 391 void PrioritizedResourceManager::returnBackingTexture(PrioritizedResource* textu re)
391 { 392 {
392 DCHECK(Proxy::isMainThread() || (Proxy::isImplThread() && Proxy::isMainThrea dBlocked())); 393 DCHECK(m_proxy->isMainThread() || (m_proxy->isImplThread() && m_proxy->isMai nThreadBlocked()));
393 if (texture->backing()) 394 if (texture->backing())
394 texture->unlink(); 395 texture->unlink();
395 } 396 }
396 397
397 PrioritizedResource::Backing* PrioritizedResourceManager::createBacking(gfx::Siz e size, GLenum format, ResourceProvider* resourceProvider) 398 PrioritizedResource::Backing* PrioritizedResourceManager::createBacking(gfx::Siz e size, GLenum format, ResourceProvider* resourceProvider)
398 { 399 {
399 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); 400 DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked());
400 DCHECK(resourceProvider); 401 DCHECK(resourceProvider);
401 ResourceProvider::ResourceId resourceId = resourceProvider->createResource(m _pool, size, format, ResourceProvider::TextureUsageAny); 402 ResourceProvider::ResourceId resourceId = resourceProvider->createResource(m _pool, size, format, ResourceProvider::TextureUsageAny);
402 PrioritizedResource::Backing* backing = new PrioritizedResource::Backing(res ourceId, resourceProvider, size, format); 403 PrioritizedResource::Backing* backing = new PrioritizedResource::Backing(res ourceId, resourceProvider, size, format);
403 m_memoryUseBytes += backing->bytes(); 404 m_memoryUseBytes += backing->bytes();
404 return backing; 405 return backing;
405 } 406 }
406 407
407 void PrioritizedResourceManager::evictFirstBackingResource(ResourceProvider* res ourceProvider) 408 void PrioritizedResourceManager::evictFirstBackingResource(ResourceProvider* res ourceProvider)
408 { 409 {
409 DCHECK(Proxy::isImplThread()); 410 DCHECK(m_proxy->isImplThread());
410 DCHECK(resourceProvider); 411 DCHECK(resourceProvider);
411 DCHECK(!m_backings.empty()); 412 DCHECK(!m_backings.empty());
412 PrioritizedResource::Backing* backing = m_backings.front(); 413 PrioritizedResource::Backing* backing = m_backings.front();
413 414
414 // Note that we create a backing and its resource at the same time, but we 415 // Note that we create a backing and its resource at the same time, but we
415 // delete the backing structure and its resource in two steps. This is becau se 416 // delete the backing structure and its resource in two steps. This is becau se
416 // we can delete the resource while the main thread is running, but we canno t 417 // we can delete the resource while the main thread is running, but we canno t
417 // unlink backings while the main thread is running. 418 // unlink backings while the main thread is running.
418 backing->deleteResource(resourceProvider); 419 backing->deleteResource(resourceProvider);
419 m_memoryUseBytes -= backing->bytes(); 420 m_memoryUseBytes -= backing->bytes();
420 m_backings.pop_front(); 421 m_backings.pop_front();
421 m_evictedBackings.push_back(backing); 422 m_evictedBackings.push_back(backing);
422 } 423 }
423 424
424 void PrioritizedResourceManager::assertInvariants() 425 void PrioritizedResourceManager::assertInvariants()
425 { 426 {
426 #ifndef NDEBUG 427 #ifndef NDEBUG
427 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); 428 DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked());
428 429
429 // If we hit any of these asserts, there is a bug in this class. To see 430 // If we hit any of these asserts, there is a bug in this class. To see
430 // where the bug is, call this function at the beginning and end of 431 // where the bug is, call this function at the beginning and end of
431 // every public function. 432 // every public function.
432 433
433 // Backings/textures must be doubly-linked and only to other backings/textur es in this manager. 434 // Backings/textures must be doubly-linked and only to other backings/textur es in this manager.
434 for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) { 435 for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) {
435 if ((*it)->owner()) { 436 if ((*it)->owner()) {
436 DCHECK(ContainsKey(m_textures, (*it)->owner())); 437 DCHECK(ContainsKey(m_textures, (*it)->owner()));
437 DCHECK((*it)->owner()->backing() == (*it)); 438 DCHECK((*it)->owner()->backing() == (*it));
(...skipping 27 matching lines...) Expand all
465 reachedUnrecyclable = true; 466 reachedUnrecyclable = true;
466 if (reachedUnrecyclable) 467 if (reachedUnrecyclable)
467 DCHECK(!backing->canBeRecycled()); 468 DCHECK(!backing->canBeRecycled());
468 else 469 else
469 DCHECK(backing->canBeRecycled()); 470 DCHECK(backing->canBeRecycled());
470 previous_backing = backing; 471 previous_backing = backing;
471 } 472 }
472 #endif 473 #endif
473 } 474 }
474 475
476 const Proxy* PrioritizedResourceManager::proxyForDebug() const
477 {
478 return m_proxy;
479 }
480
475 } // namespace cc 481 } // namespace cc
OLDNEW
« no previous file with comments | « cc/prioritized_resource_manager.h ('k') | cc/prioritized_resource_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698