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

Side by Side Diff: cc/prioritized_texture_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698