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 "base/synchronization/lock.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::PrioritizedTexture*> { | 25 struct hash<cc::PrioritizedTexture*> { |
25 size_t operator()(cc::PrioritizedTexture* ptr) const { | 26 size_t operator()(cc::PrioritizedTexture* ptr) const { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 size_t memoryVisibleBytes() const; | 74 size_t memoryVisibleBytes() const; |
74 size_t memoryVisibleAndNearbyBytes() const; | 75 size_t memoryVisibleAndNearbyBytes() const; |
75 | 76 |
76 void prioritizeTextures(); | 77 void prioritizeTextures(); |
77 void clearPriorities(); | 78 void clearPriorities(); |
78 | 79 |
79 // Delete contents textures' backing resources until they use only bytesLimi
t bytes. This may | 80 // Delete contents textures' backing resources until they use only bytesLimi
t bytes. This may |
80 // be called on the impl thread while the main thread is running. Returns tr
ue if resources are | 81 // be called on the impl thread while the main thread is running. Returns tr
ue if resources are |
81 // indeed evicted as a result of this call. | 82 // indeed evicted as a result of this call. |
82 bool reduceMemoryOnImplThread(size_t limitBytes, int priorityCutoff, Resourc
eProvider*); | 83 bool reduceMemoryOnImplThread(size_t limitBytes, int priorityCutoff, Resourc
eProvider*); |
| 84 |
83 // Returns true if there exist any textures that are linked to backings that
have had their | 85 // Returns true if there exist any textures that are linked to backings that
have had their |
84 // resources evicted. Only when we commit a tree that has no textures linked
to evicted backings | 86 // resources evicted. Only when we commit a tree that has no textures linked
to evicted backings |
85 // may we allow drawing. | 87 // may we allow drawing. |
86 bool linkedEvictedBackingsExist() const; | 88 bool linkedEvictedBackingsExist() const; |
87 // Retrieve the list of all contents textures' backings that have been evict
ed, to pass to the | 89 |
88 // main thread to unlink them from their owning textures. | 90 // Unlink the list of contents textures' backings from their owning textures
and delete the evicted |
89 void getEvictedBackings(BackingList& evictedBackings); | 91 // backings' structures. This is called just before updating layers, and is
only ever called on the |
90 // Unlink the list of contents textures' backings from their owning textures
on the main thread | 92 // main thread. |
91 // before updating layers. | 93 void unlinkAndClearEvictedBackings(); |
92 void unlinkEvictedBackings(const BackingList& evictedBackings); | |
93 | 94 |
94 bool requestLate(PrioritizedTexture*); | 95 bool requestLate(PrioritizedTexture*); |
95 | 96 |
96 void reduceMemory(ResourceProvider*); | 97 void reduceMemory(ResourceProvider*); |
97 void clearAllMemory(ResourceProvider*); | 98 void clearAllMemory(ResourceProvider*); |
98 | 99 |
99 void acquireBackingTextureIfNeeded(PrioritizedTexture*, ResourceProvider*); | 100 void acquireBackingTextureIfNeeded(PrioritizedTexture*, ResourceProvider*); |
100 | 101 |
101 void registerTexture(PrioritizedTexture*); | 102 void registerTexture(PrioritizedTexture*); |
102 void unregisterTexture(PrioritizedTexture*); | 103 void unregisterTexture(PrioritizedTexture*); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 149 |
149 PrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, in
t pool); | 150 PrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, in
t pool); |
150 | 151 |
151 bool evictBackingsToReduceMemory(size_t limitBytes, | 152 bool evictBackingsToReduceMemory(size_t limitBytes, |
152 int priorityCutoff, | 153 int priorityCutoff, |
153 EvictionPolicy, | 154 EvictionPolicy, |
154 UnlinkPolicy, | 155 UnlinkPolicy, |
155 ResourceProvider*); | 156 ResourceProvider*); |
156 PrioritizedTexture::Backing* createBacking(IntSize, GLenum format, ResourceP
rovider*); | 157 PrioritizedTexture::Backing* createBacking(IntSize, GLenum format, ResourceP
rovider*); |
157 void evictFirstBackingResource(ResourceProvider*); | 158 void evictFirstBackingResource(ResourceProvider*); |
158 void deleteUnlinkedEvictedBackings(); | |
159 void sortBackings(); | 159 void sortBackings(); |
160 | 160 |
161 void assertInvariants(); | 161 void assertInvariants(); |
162 | 162 |
163 size_t m_maxMemoryLimitBytes; | 163 size_t m_maxMemoryLimitBytes; |
164 // The priority cutoff based on memory pressure. This is not a strict | 164 // The priority cutoff based on memory pressure. This is not a strict |
165 // cutoff -- requestLate allows textures with priority equal to this | 165 // cutoff -- requestLate allows textures with priority equal to this |
166 // cutoff to be allowed. | 166 // cutoff to be allowed. |
167 int m_priorityCutoff; | 167 int m_priorityCutoff; |
168 // The priority cutoff based on external memory policy. This is a strict | 168 // The priority cutoff based on external memory policy. This is a strict |
169 // cutoff -- no textures with priority equal to this cutoff will be allowed. | 169 // cutoff -- no textures with priority equal to this cutoff will be allowed. |
170 int m_externalPriorityCutoff; | 170 int m_externalPriorityCutoff; |
171 size_t m_memoryUseBytes; | 171 size_t m_memoryUseBytes; |
172 size_t m_memoryAboveCutoffBytes; | 172 size_t m_memoryAboveCutoffBytes; |
173 size_t m_memoryAvailableBytes; | 173 size_t m_memoryAvailableBytes; |
174 int m_pool; | 174 int m_pool; |
175 | 175 |
176 typedef base::hash_set<PrioritizedTexture*> TextureSet; | 176 typedef base::hash_set<PrioritizedTexture*> TextureSet; |
177 typedef std::vector<PrioritizedTexture*> TextureVector; | 177 typedef std::vector<PrioritizedTexture*> TextureVector; |
178 | 178 |
179 TextureSet m_textures; | 179 TextureSet m_textures; |
180 // This list is always sorted in eviction order, with the exception the | 180 // This list is always sorted in eviction order, with the exception the |
181 // newly-allocated or recycled textures at the very end of the tail that | 181 // newly-allocated or recycled textures at the very end of the tail that |
182 // are not sorted by priority. | 182 // are not sorted by priority. |
183 BackingList m_backings; | 183 BackingList m_backings; |
184 bool m_backingsTailNotSorted; | 184 bool m_backingsTailNotSorted; |
| 185 |
| 186 // The list of backings that have been evicted, but may still be linked |
| 187 // to textures. This can be accessed concurrently by the main and impl |
| 188 // threads, and may only be accessed while holding m_evictedBackingsLock. |
| 189 mutable base::Lock m_evictedBackingsLock; |
185 BackingList m_evictedBackings; | 190 BackingList m_evictedBackings; |
186 | 191 |
187 TextureVector m_tempTextureVector; | 192 TextureVector m_tempTextureVector; |
188 | 193 |
189 // Statistics about memory usage at priority cutoffs, computed at prioritize
Textures. | 194 // Statistics about memory usage at priority cutoffs, computed at prioritize
Textures. |
190 size_t m_memoryVisibleBytes; | 195 size_t m_memoryVisibleBytes; |
191 size_t m_memoryVisibleAndNearbyBytes; | 196 size_t m_memoryVisibleAndNearbyBytes; |
192 | 197 |
193 // Statistics copied at the time of pushTexturePrioritiesToBackings. | 198 // Statistics copied at the time of pushTexturePrioritiesToBackings. |
194 size_t m_memoryVisibleLastPushedBytes; | 199 size_t m_memoryVisibleLastPushedBytes; |
195 size_t m_memoryVisibleAndNearbyLastPushedBytes; | 200 size_t m_memoryVisibleAndNearbyLastPushedBytes; |
196 | 201 |
197 DISALLOW_COPY_AND_ASSIGN(PrioritizedTextureManager); | 202 DISALLOW_COPY_AND_ASSIGN(PrioritizedTextureManager); |
198 }; | 203 }; |
199 | 204 |
200 } // namespace cc | 205 } // namespace cc |
201 | 206 |
202 #endif | 207 #endif |
OLD | NEW |