| 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 <list> | 8 #include <list> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "IntRect.h" | 11 #include "IntRect.h" |
| 12 #include "IntSize.h" | 12 #include "IntSize.h" |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "cc/proxy.h" |
| 16 #include "cc/prioritized_texture.h" | 17 #include "cc/prioritized_texture.h" |
| 17 #include "cc/priority_calculator.h" | 18 #include "cc/priority_calculator.h" |
| 18 #include "cc/texture.h" | 19 #include "cc/texture.h" |
| 19 #include "third_party/khronos/GLES2/gl2.h" | 20 #include "third_party/khronos/GLES2/gl2.h" |
| 20 | 21 |
| 21 #if defined(COMPILER_GCC) | 22 #if defined(COMPILER_GCC) |
| 22 namespace BASE_HASH_NAMESPACE { | 23 namespace BASE_HASH_NAMESPACE { |
| 23 template<> | 24 template<> |
| 24 struct hash<cc::CCPrioritizedTexture*> { | 25 struct hash<cc::CCPrioritizedTexture*> { |
| 25 size_t operator()(cc::CCPrioritizedTexture* ptr) const { | 26 size_t operator()(cc::CCPrioritizedTexture* ptr) const { |
| 26 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); | 27 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); |
| 27 } | 28 } |
| 28 }; | 29 }; |
| 29 } // namespace BASE_HASH_NAMESPACE | 30 } // namespace BASE_HASH_NAMESPACE |
| 30 #endif // COMPILER | 31 #endif // COMPILER |
| 31 | 32 |
| 32 namespace cc { | 33 namespace cc { |
| 33 | 34 |
| 34 class CCPriorityCalculator; | 35 class CCPriorityCalculator; |
| 35 | 36 |
| 36 class CCPrioritizedTextureManager { | 37 class CCPrioritizedTextureManager { |
| 37 public: | 38 public: |
| 38 static scoped_ptr<CCPrioritizedTextureManager> create(size_t maxMemoryLimitB
ytes, int maxTextureSize, int pool) | 39 static scoped_ptr<CCPrioritizedTextureManager> create(size_t maxMemoryLimitB
ytes, int maxTextureSize, int pool, CCProxy* proxy) |
| 39 { | 40 { |
| 40 return make_scoped_ptr(new CCPrioritizedTextureManager(maxMemoryLimitByt
es, maxTextureSize, pool)); | 41 return make_scoped_ptr(new CCPrioritizedTextureManager(maxMemoryLimitByt
es, maxTextureSize, pool, proxy)); |
| 41 } | 42 } |
| 42 scoped_ptr<CCPrioritizedTexture> createTexture(IntSize size, GLenum format) | 43 scoped_ptr<CCPrioritizedTexture> createTexture(IntSize size, GLenum format) |
| 43 { | 44 { |
| 44 return make_scoped_ptr(new CCPrioritizedTexture(this, size, format)); | 45 return make_scoped_ptr(new CCPrioritizedTexture(this, size, format)); |
| 45 } | 46 } |
| 46 ~CCPrioritizedTextureManager(); | 47 ~CCPrioritizedTextureManager(); |
| 47 | 48 |
| 48 typedef std::list<CCPrioritizedTexture::Backing*> BackingList; | 49 typedef std::list<CCPrioritizedTexture::Backing*> BackingList; |
| 49 | 50 |
| 50 // FIXME (http://crbug.com/137094): This 64MB default is a straggler from th
e | 51 // FIXME (http://crbug.com/137094): This 64MB default is a straggler from th
e |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 void registerTexture(CCPrioritizedTexture*); | 94 void registerTexture(CCPrioritizedTexture*); |
| 94 void unregisterTexture(CCPrioritizedTexture*); | 95 void unregisterTexture(CCPrioritizedTexture*); |
| 95 void returnBackingTexture(CCPrioritizedTexture*); | 96 void returnBackingTexture(CCPrioritizedTexture*); |
| 96 | 97 |
| 97 // Update all backings' priorities from their owning texture. | 98 // Update all backings' priorities from their owning texture. |
| 98 void pushTexturePrioritiesToBackings(); | 99 void pushTexturePrioritiesToBackings(); |
| 99 | 100 |
| 100 // Mark all textures' backings as being in the drawing impl tree. | 101 // Mark all textures' backings as being in the drawing impl tree. |
| 101 void updateBackingsInDrawingImplTree(); | 102 void updateBackingsInDrawingImplTree(); |
| 102 | 103 |
| 104 CCProxy* proxy() const { return m_proxy; } |
| 105 |
| 103 private: | 106 private: |
| 104 friend class CCPrioritizedTextureTest; | 107 friend class CCPrioritizedTextureTest; |
| 105 | 108 |
| 106 enum EvictionPriorityPolicy { | 109 enum EvictionPriorityPolicy { |
| 107 RespectManagerPriorityCutoff, | 110 RespectManagerPriorityCutoff, |
| 108 DoNotRespectManagerPriorityCutoff, | 111 DoNotRespectManagerPriorityCutoff, |
| 109 }; | 112 }; |
| 110 | 113 |
| 111 // Compare textures. Highest priority first. | 114 // Compare textures. Highest priority first. |
| 112 static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTex
ture* b) | 115 static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTex
ture* b) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 127 // Then sort by priority (note that backings that no longer have owners
will | 130 // Then sort by priority (note that backings that no longer have owners
will |
| 128 // always have the lowest priority) | 131 // always have the lowest priority) |
| 129 if (a->requestPriorityAtLastPriorityUpdate() != b->requestPriorityAtLast
PriorityUpdate()) | 132 if (a->requestPriorityAtLastPriorityUpdate() != b->requestPriorityAtLast
PriorityUpdate()) |
| 130 return CCPriorityCalculator::priorityIsLower(a->requestPriorityAtLas
tPriorityUpdate(), b->requestPriorityAtLastPriorityUpdate()); | 133 return CCPriorityCalculator::priorityIsLower(a->requestPriorityAtLas
tPriorityUpdate(), b->requestPriorityAtLastPriorityUpdate()); |
| 131 // Finally sort by being in the impl tree versus being completely unrefe
renced | 134 // Finally sort by being in the impl tree versus being completely unrefe
renced |
| 132 if (a->inDrawingImplTree() != b->inDrawingImplTree()) | 135 if (a->inDrawingImplTree() != b->inDrawingImplTree()) |
| 133 return (a->inDrawingImplTree() < b->inDrawingImplTree()); | 136 return (a->inDrawingImplTree() < b->inDrawingImplTree()); |
| 134 return a < b; | 137 return a < b; |
| 135 } | 138 } |
| 136 | 139 |
| 137 CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize,
int pool); | 140 CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize,
int pool, CCProxy* proxy); |
| 138 | 141 |
| 139 bool evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy,
CCResourceProvider*); | 142 bool evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy,
CCResourceProvider*); |
| 140 CCPrioritizedTexture::Backing* createBacking(IntSize, GLenum format, CCResou
rceProvider*); | 143 CCPrioritizedTexture::Backing* createBacking(IntSize, GLenum format, CCResou
rceProvider*); |
| 141 void evictFirstBackingResource(CCResourceProvider*); | 144 void evictFirstBackingResource(CCResourceProvider*); |
| 142 void deleteUnlinkedEvictedBackings(); | 145 void deleteUnlinkedEvictedBackings(); |
| 143 void sortBackings(); | 146 void sortBackings(); |
| 144 | 147 |
| 145 void assertInvariants(); | 148 void assertInvariants(); |
| 146 | 149 |
| 147 size_t m_maxMemoryLimitBytes; | 150 size_t m_maxMemoryLimitBytes; |
| 148 unsigned m_priorityCutoff; | 151 unsigned m_priorityCutoff; |
| 149 size_t m_memoryUseBytes; | 152 size_t m_memoryUseBytes; |
| 150 size_t m_memoryAboveCutoffBytes; | 153 size_t m_memoryAboveCutoffBytes; |
| 151 size_t m_memoryAvailableBytes; | 154 size_t m_memoryAvailableBytes; |
| 152 int m_pool; | 155 int m_pool; |
| 153 | 156 |
| 154 typedef base::hash_set<CCPrioritizedTexture*> TextureSet; | 157 typedef base::hash_set<CCPrioritizedTexture*> TextureSet; |
| 155 typedef std::vector<CCPrioritizedTexture*> TextureVector; | 158 typedef std::vector<CCPrioritizedTexture*> TextureVector; |
| 156 | 159 |
| 160 CCProxy* m_proxy; |
| 157 TextureSet m_textures; | 161 TextureSet m_textures; |
| 158 // This list is always sorted in eviction order, with the exception the | 162 // This list is always sorted in eviction order, with the exception the |
| 159 // newly-allocated or recycled textures at the very end of the tail that | 163 // newly-allocated or recycled textures at the very end of the tail that |
| 160 // are not sorted by priority. | 164 // are not sorted by priority. |
| 161 BackingList m_backings; | 165 BackingList m_backings; |
| 162 bool m_backingsTailNotSorted; | 166 bool m_backingsTailNotSorted; |
| 163 BackingList m_evictedBackings; | 167 BackingList m_evictedBackings; |
| 164 | 168 |
| 165 TextureVector m_tempTextureVector; | 169 TextureVector m_tempTextureVector; |
| 166 | 170 |
| 167 DISALLOW_COPY_AND_ASSIGN(CCPrioritizedTextureManager); | 171 DISALLOW_COPY_AND_ASSIGN(CCPrioritizedTextureManager); |
| 168 }; | 172 }; |
| 169 | 173 |
| 170 } // namespace cc | 174 } // namespace cc |
| 171 | 175 |
| 172 #endif | 176 #endif |
| OLD | NEW |