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" |
11 #include "CCPrioritizedTexture.h" | 11 #include "CCPrioritizedTexture.h" |
12 #include "CCPriorityCalculator.h" | 12 #include "CCPriorityCalculator.h" |
13 #include "CCTexture.h" | 13 #include "CCTexture.h" |
14 #include "GraphicsContext3D.h" | 14 #include "GraphicsContext3D.h" |
15 #include "IntRect.h" | 15 #include "IntRect.h" |
16 #include "IntSize.h" | 16 #include "IntSize.h" |
17 #include <wtf/ListHashSet.h> | |
18 #include <wtf/Vector.h> | 17 #include <wtf/Vector.h> |
| 18 #include <list> |
19 | 19 |
20 #if defined(COMPILER_GCC) | 20 #if defined(COMPILER_GCC) |
21 namespace BASE_HASH_NAMESPACE { | 21 namespace BASE_HASH_NAMESPACE { |
22 template<> | 22 template<> |
23 struct hash<cc::CCPrioritizedTexture*> { | 23 struct hash<cc::CCPrioritizedTexture*> { |
24 size_t operator()(cc::CCPrioritizedTexture* ptr) const { | 24 size_t operator()(cc::CCPrioritizedTexture* ptr) const { |
25 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); | 25 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); |
26 } | 26 } |
27 }; | 27 }; |
28 } // namespace BASE_HASH_NAMESPACE | 28 } // namespace BASE_HASH_NAMESPACE |
29 #endif // COMPILER | 29 #endif // COMPILER |
30 | 30 |
31 namespace cc { | 31 namespace cc { |
32 | 32 |
33 class CCPriorityCalculator; | 33 class CCPriorityCalculator; |
34 | 34 |
35 class CCPrioritizedTextureManager { | 35 class CCPrioritizedTextureManager { |
36 public: | 36 public: |
37 static scoped_ptr<CCPrioritizedTextureManager> create(size_t maxMemoryLimitB
ytes, int maxTextureSize, int pool) | 37 static scoped_ptr<CCPrioritizedTextureManager> create(size_t maxMemoryLimitB
ytes, int maxTextureSize, int pool) |
38 { | 38 { |
39 return make_scoped_ptr(new CCPrioritizedTextureManager(maxMemoryLimitByt
es, maxTextureSize, pool)); | 39 return make_scoped_ptr(new CCPrioritizedTextureManager(maxMemoryLimitByt
es, maxTextureSize, pool)); |
40 } | 40 } |
41 scoped_ptr<CCPrioritizedTexture> createTexture(IntSize size, GC3Denum format
) | 41 scoped_ptr<CCPrioritizedTexture> createTexture(IntSize size, GC3Denum format
) |
42 { | 42 { |
43 return make_scoped_ptr(new CCPrioritizedTexture(this, size, format)); | 43 return make_scoped_ptr(new CCPrioritizedTexture(this, size, format)); |
44 } | 44 } |
45 ~CCPrioritizedTextureManager(); | 45 ~CCPrioritizedTextureManager(); |
46 | 46 |
47 typedef Vector<CCPrioritizedTexture::Backing*> BackingVector; | 47 typedef std::list<CCPrioritizedTexture::Backing*> BackingList; |
48 | 48 |
49 // FIXME (http://crbug.com/137094): This 64MB default is a straggler from th
e | 49 // FIXME (http://crbug.com/137094): This 64MB default is a straggler from th
e |
50 // old texture manager and is just to give us a default memory allocation be
fore | 50 // old texture manager and is just to give us a default memory allocation be
fore |
51 // we get a callback from the GPU memory manager. We should probaby either: | 51 // we get a callback from the GPU memory manager. We should probaby either: |
52 // - wait for the callback before rendering anything instead | 52 // - wait for the callback before rendering anything instead |
53 // - push this into the GPU memory manager somehow. | 53 // - push this into the GPU memory manager somehow. |
54 static size_t defaultMemoryAllocationLimit() { return 64 * 1024 * 1024; } | 54 static size_t defaultMemoryAllocationLimit() { return 64 * 1024 * 1024; } |
55 | 55 |
56 // memoryUseBytes() describes the number of bytes used by existing allocated
textures. | 56 // memoryUseBytes() describes the number of bytes used by existing allocated
textures. |
57 // memoryAboveCutoffBytes() describes the number of bytes that would be used
if all | 57 // memoryAboveCutoffBytes() describes the number of bytes that would be used
if all |
(...skipping 11 matching lines...) Expand all Loading... |
69 | 69 |
70 // Delete contents textures' backing resources until they use only bytesLimi
t bytes. This may | 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. | 71 // be called on the impl thread while the main thread is running. |
72 void reduceMemoryOnImplThread(size_t limitBytes, CCResourceProvider*); | 72 void reduceMemoryOnImplThread(size_t limitBytes, CCResourceProvider*); |
73 // Returns true if there exist any textures that are linked to backings that
have had their | 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 | 74 // resources evicted. Only when we commit a tree that has no textures linked
to evicted backings |
75 // may we allow drawing. | 75 // may we allow drawing. |
76 bool linkedEvictedBackingsExist() const; | 76 bool linkedEvictedBackingsExist() const; |
77 // Retrieve the list of all contents textures' backings that have been evict
ed, to pass to the | 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. | 78 // main thread to unlink them from their owning textures. |
79 void getEvictedBackings(BackingVector& evictedBackings); | 79 void getEvictedBackings(BackingList& evictedBackings); |
80 // Unlink the list of contents textures' backings from their owning textures
on the main thread | 80 // Unlink the list of contents textures' backings from their owning textures
on the main thread |
81 // before updating layers. | 81 // before updating layers. |
82 void unlinkEvictedBackings(const BackingVector& evictedBackings); | 82 void unlinkEvictedBackings(const BackingList& evictedBackings); |
83 | 83 |
84 bool requestLate(CCPrioritizedTexture*); | 84 bool requestLate(CCPrioritizedTexture*); |
85 | 85 |
86 void reduceMemory(CCResourceProvider*); | 86 void reduceMemory(CCResourceProvider*); |
87 void clearAllMemory(CCResourceProvider*); | 87 void clearAllMemory(CCResourceProvider*); |
88 | 88 |
89 void acquireBackingTextureIfNeeded(CCPrioritizedTexture*, CCResourceProvider
*); | 89 void acquireBackingTextureIfNeeded(CCPrioritizedTexture*, CCResourceProvider
*); |
90 | 90 |
91 void registerTexture(CCPrioritizedTexture*); | 91 void registerTexture(CCPrioritizedTexture*); |
92 void unregisterTexture(CCPrioritizedTexture*); | 92 void unregisterTexture(CCPrioritizedTexture*); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 // Finally sort by being in the impl tree versus being completely unrefe
renced | 129 // Finally sort by being in the impl tree versus being completely unrefe
renced |
130 if (a->inDrawingImplTree() != b->inDrawingImplTree()) | 130 if (a->inDrawingImplTree() != b->inDrawingImplTree()) |
131 return (a->inDrawingImplTree() < b->inDrawingImplTree()); | 131 return (a->inDrawingImplTree() < b->inDrawingImplTree()); |
132 return a < b; | 132 return a < b; |
133 } | 133 } |
134 | 134 |
135 CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize,
int pool); | 135 CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize,
int pool); |
136 | 136 |
137 void evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy,
CCResourceProvider*); | 137 void evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy,
CCResourceProvider*); |
138 CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCRes
ourceProvider*); | 138 CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCRes
ourceProvider*); |
139 void evictBackingResource(CCPrioritizedTexture::Backing*, CCResourceProvider
*); | 139 void evictFirstBackingResource(CCResourceProvider*); |
140 void deleteUnlinkedEvictedBackings(); | 140 void deleteUnlinkedEvictedBackings(); |
141 void sortBackings(); | 141 void sortBackings(); |
142 | 142 |
143 #if !ASSERT_DISABLED | |
144 void assertInvariants(); | 143 void assertInvariants(); |
145 #endif | |
146 | 144 |
147 size_t m_maxMemoryLimitBytes; | 145 size_t m_maxMemoryLimitBytes; |
148 unsigned m_priorityCutoff; | 146 unsigned m_priorityCutoff; |
149 size_t m_memoryUseBytes; | 147 size_t m_memoryUseBytes; |
150 size_t m_memoryAboveCutoffBytes; | 148 size_t m_memoryAboveCutoffBytes; |
151 size_t m_memoryAvailableBytes; | 149 size_t m_memoryAvailableBytes; |
152 int m_pool; | 150 int m_pool; |
153 | 151 |
154 typedef base::hash_set<CCPrioritizedTexture*> TextureSet; | 152 typedef base::hash_set<CCPrioritizedTexture*> TextureSet; |
155 typedef ListHashSet<CCPrioritizedTexture::Backing*> BackingSet; | |
156 typedef Vector<CCPrioritizedTexture*> TextureVector; | 153 typedef Vector<CCPrioritizedTexture*> TextureVector; |
157 | 154 |
158 TextureSet m_textures; | 155 TextureSet m_textures; |
159 BackingSet m_backings; | 156 // This list is always sorted in eviction order, with the exception the |
160 BackingVector m_evictedBackings; | 157 // newly-allocated or recycled textures at the very end of the tail that |
| 158 // are not sorted by priority. |
| 159 BackingList m_backings; |
| 160 bool m_backingsTailNotSorted; |
| 161 BackingList m_evictedBackings; |
161 | 162 |
162 TextureVector m_tempTextureVector; | 163 TextureVector m_tempTextureVector; |
163 BackingVector m_tempBackingVector; | |
164 | 164 |
165 DISALLOW_COPY_AND_ASSIGN(CCPrioritizedTextureManager); | 165 DISALLOW_COPY_AND_ASSIGN(CCPrioritizedTextureManager); |
166 }; | 166 }; |
167 | 167 |
168 } // namespace cc | 168 } // namespace cc |
169 | 169 |
170 #endif | 170 #endif |
OLD | NEW |