| OLD | NEW |
| 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 #ifndef CCPrioritizedTextureManager_h | 5 #ifndef CCPrioritizedTextureManager_h |
| 6 #define CCPrioritizedTextureManager_h | 6 #define CCPrioritizedTextureManager_h |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 size_t memoryUseBytes() const { return m_memoryUseBytes; } | 60 size_t memoryUseBytes() const { return m_memoryUseBytes; } |
| 61 size_t memoryAboveCutoffBytes() const { return m_memoryAboveCutoffBytes; } | 61 size_t memoryAboveCutoffBytes() const { return m_memoryAboveCutoffBytes; } |
| 62 size_t memoryForSelfManagedTextures() const { return m_maxMemoryLimitBytes -
m_memoryAvailableBytes; } | 62 size_t memoryForSelfManagedTextures() const { return m_maxMemoryLimitBytes -
m_memoryAvailableBytes; } |
| 63 | 63 |
| 64 void setMaxMemoryLimitBytes(size_t bytes) { m_maxMemoryLimitBytes = bytes; } | 64 void setMaxMemoryLimitBytes(size_t bytes) { m_maxMemoryLimitBytes = bytes; } |
| 65 size_t maxMemoryLimitBytes() const { return m_maxMemoryLimitBytes; } | 65 size_t maxMemoryLimitBytes() const { return m_maxMemoryLimitBytes; } |
| 66 | 66 |
| 67 void prioritizeTextures(); | 67 void prioritizeTextures(); |
| 68 void clearPriorities(); | 68 void clearPriorities(); |
| 69 | 69 |
| 70 // Delete contents textures' backing resources until they use only bytesLimi
t bytes. This may |
| 71 // be called on the impl thread while the main thread is running. |
| 70 void reduceMemoryOnImplThread(size_t limitBytes, CCResourceProvider*); | 72 void reduceMemoryOnImplThread(size_t limitBytes, CCResourceProvider*); |
| 71 bool evictedBackingsExist() const { return !m_evictedBackings.isEmpty(); } | 73 // Returns true if there exist any textures that are linked to backings that
have had their |
| 74 // resources evicted. Only when we commit a tree that has no textures linked
to evicted backings |
| 75 // may we allow drawing. |
| 76 bool linkedEvictedBackingsExist() const; |
| 77 // Retrieve the list of all contents textures' backings that have been evict
ed, to pass to the |
| 78 // main thread to unlink them from their owning textures. |
| 72 void getEvictedBackings(BackingVector& evictedBackings); | 79 void getEvictedBackings(BackingVector& evictedBackings); |
| 80 // Unlink the list of contents textures' backings from their owning textures
on the main thread |
| 81 // before updating layers. |
| 73 void unlinkEvictedBackings(const BackingVector& evictedBackings); | 82 void unlinkEvictedBackings(const BackingVector& evictedBackings); |
| 74 // Deletes all evicted backings, unlinking them from their owning textures i
f needed. | |
| 75 // Returns true if this function unlinked any backings from their owning tex
ture while | |
| 76 // destroying them. | |
| 77 bool deleteEvictedBackings(); | |
| 78 | 83 |
| 79 bool requestLate(CCPrioritizedTexture*); | 84 bool requestLate(CCPrioritizedTexture*); |
| 80 | 85 |
| 81 void reduceMemory(CCResourceProvider*); | 86 void reduceMemory(CCResourceProvider*); |
| 82 void clearAllMemory(CCResourceProvider*); | 87 void clearAllMemory(CCResourceProvider*); |
| 83 | 88 |
| 84 void acquireBackingTextureIfNeeded(CCPrioritizedTexture*, CCResourceProvider
*); | 89 void acquireBackingTextureIfNeeded(CCPrioritizedTexture*, CCResourceProvider
*); |
| 85 | 90 |
| 86 void registerTexture(CCPrioritizedTexture*); | 91 void registerTexture(CCPrioritizedTexture*); |
| 87 void unregisterTexture(CCPrioritizedTexture*); | 92 void unregisterTexture(CCPrioritizedTexture*); |
| 88 void returnBackingTexture(CCPrioritizedTexture*); | 93 void returnBackingTexture(CCPrioritizedTexture*); |
| 89 | 94 |
| 95 // Update all backings' priorities from their owning texture. |
| 96 void pushTexturePrioritiesToBackings(); |
| 97 |
| 98 // Mark all textures' backings as being in the drawing impl tree. |
| 99 void updateBackingsInDrawingImplTree(); |
| 100 |
| 90 private: | 101 private: |
| 91 friend class CCPrioritizedTextureTest; | 102 friend class CCPrioritizedTextureTest; |
| 92 | 103 |
| 93 enum EvictionPriorityPolicy { | 104 enum EvictionPriorityPolicy { |
| 94 RespectManagerPriorityCutoff, | 105 RespectManagerPriorityCutoff, |
| 95 DoNotRespectManagerPriorityCutoff, | 106 DoNotRespectManagerPriorityCutoff, |
| 96 }; | 107 }; |
| 97 | 108 |
| 98 // Compare textures. Highest priority first. | 109 // Compare textures. Highest priority first. |
| 99 static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTex
ture* b) | 110 static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTex
ture* b) |
| 100 { | 111 { |
| 101 if (a->requestPriority() == b->requestPriority()) | 112 if (a->requestPriority() == b->requestPriority()) |
| 102 return a < b; | 113 return a < b; |
| 103 return CCPriorityCalculator::priorityIsHigher(a->requestPriority(), b->r
equestPriority()); | 114 return CCPriorityCalculator::priorityIsHigher(a->requestPriority(), b->r
equestPriority()); |
| 104 } | 115 } |
| 105 // Compare backings. Lowest priority first. | 116 // Compare backings. Lowest priority first. |
| 106 static inline bool compareBackings(CCPrioritizedTexture::Backing* a, CCPrior
itizedTexture::Backing* b) | 117 static inline bool compareBackings(CCPrioritizedTexture::Backing* a, CCPrior
itizedTexture::Backing* b) |
| 107 { | 118 { |
| 108 int priorityA = a->requestPriorityAtLastPriorityUpdate(); | 119 // Make textures that can be recycled appear first |
| 109 int priorityB = b->requestPriorityAtLastPriorityUpdate(); | 120 if (a->canBeRecycled() != b->canBeRecycled()) |
| 110 if (priorityA != priorityB) | 121 return (a->canBeRecycled() > b->canBeRecycled()); |
| 111 return CCPriorityCalculator::priorityIsLower(priorityA, priorityB); | 122 // Then sort by being above or below the priority cutoff. |
| 112 bool aboveCutoffA = a->wasAbovePriorityCutoffAtLastPriorityUpdate(); | 123 if (a->wasAbovePriorityCutoffAtLastPriorityUpdate() != b->wasAbovePriori
tyCutoffAtLastPriorityUpdate()) |
| 113 bool aboveCutoffB = b->wasAbovePriorityCutoffAtLastPriorityUpdate(); | 124 return (a->wasAbovePriorityCutoffAtLastPriorityUpdate() < b->wasAbov
ePriorityCutoffAtLastPriorityUpdate()); |
| 114 if (!aboveCutoffA && aboveCutoffB) | 125 // Then sort by priority (note that backings that no longer have owners
will |
| 115 return true; | 126 // always have the lowest priority) |
| 116 if (aboveCutoffA && !aboveCutoffB) | 127 if (a->requestPriorityAtLastPriorityUpdate() != b->requestPriorityAtLast
PriorityUpdate()) |
| 117 return false; | 128 return CCPriorityCalculator::priorityIsLower(a->requestPriorityAtLas
tPriorityUpdate(), b->requestPriorityAtLastPriorityUpdate()); |
| 129 // Finally sort by being in the impl tree versus being completely unrefe
renced |
| 130 if (a->inDrawingImplTree() != b->inDrawingImplTree()) |
| 131 return (a->inDrawingImplTree() < b->inDrawingImplTree()); |
| 118 return a < b; | 132 return a < b; |
| 119 } | 133 } |
| 120 | 134 |
| 121 CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize,
int pool); | 135 CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize,
int pool); |
| 122 | 136 |
| 123 void updateBackingsPriorities(); | |
| 124 void evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy,
CCResourceProvider*); | 137 void evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy,
CCResourceProvider*); |
| 125 CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCRes
ourceProvider*); | 138 CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCRes
ourceProvider*); |
| 126 void evictBackingResource(CCPrioritizedTexture::Backing*, CCResourceProvider
*); | 139 void evictBackingResource(CCPrioritizedTexture::Backing*, CCResourceProvider
*); |
| 140 void deleteUnlinkedEvictedBackings(); |
| 141 void sortBackings(); |
| 127 | 142 |
| 128 #if !ASSERT_DISABLED | 143 #if !ASSERT_DISABLED |
| 129 void assertInvariants(); | 144 void assertInvariants(); |
| 130 #endif | 145 #endif |
| 131 | 146 |
| 132 size_t m_maxMemoryLimitBytes; | 147 size_t m_maxMemoryLimitBytes; |
| 133 unsigned m_priorityCutoff; | 148 unsigned m_priorityCutoff; |
| 134 size_t m_memoryUseBytes; | 149 size_t m_memoryUseBytes; |
| 135 size_t m_memoryAboveCutoffBytes; | 150 size_t m_memoryAboveCutoffBytes; |
| 136 size_t m_memoryAvailableBytes; | 151 size_t m_memoryAvailableBytes; |
| 137 int m_pool; | 152 int m_pool; |
| 138 | 153 |
| 139 typedef base::hash_set<CCPrioritizedTexture*> TextureSet; | 154 typedef base::hash_set<CCPrioritizedTexture*> TextureSet; |
| 140 typedef ListHashSet<CCPrioritizedTexture::Backing*> BackingSet; | 155 typedef ListHashSet<CCPrioritizedTexture::Backing*> BackingSet; |
| 141 typedef Vector<CCPrioritizedTexture*> TextureVector; | 156 typedef Vector<CCPrioritizedTexture*> TextureVector; |
| 142 | 157 |
| 143 TextureSet m_textures; | 158 TextureSet m_textures; |
| 144 BackingSet m_backings; | 159 BackingSet m_backings; |
| 145 BackingVector m_evictedBackings; | 160 BackingVector m_evictedBackings; |
| 146 | 161 |
| 147 TextureVector m_tempTextureVector; | 162 TextureVector m_tempTextureVector; |
| 148 BackingVector m_tempBackingVector; | 163 BackingVector m_tempBackingVector; |
| 149 | 164 |
| 150 // Set by the main thread when it adjust priorities in such a way that | |
| 151 // the m_backings array's view of priorities is now out of date. | |
| 152 bool m_needsUpdateBackingsPrioritites; | |
| 153 | |
| 154 DISALLOW_COPY_AND_ASSIGN(CCPrioritizedTextureManager); | 165 DISALLOW_COPY_AND_ASSIGN(CCPrioritizedTextureManager); |
| 155 }; | 166 }; |
| 156 | 167 |
| 157 } // namespace cc | 168 } // namespace cc |
| 158 | 169 |
| 159 #endif | 170 #endif |
| OLD | NEW |