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

Side by Side Diff: cc/prioritized_texture_manager.h

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.cc ('k') | cc/prioritized_texture_manager.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 #ifndef CC_PRIORITIZED_TEXTURE_MANAGER_H_ 5 #ifndef CC_PRIORITIZED_TEXTURE_MANAGER_H_
6 #define CC_PRIORITIZED_TEXTURE_MANAGER_H_ 6 #define CC_PRIORITIZED_TEXTURE_MANAGER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/hash_tables.h" 12 #include "base/hash_tables.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "cc/cc_export.h" 14 #include "cc/cc_export.h"
15 #include "cc/proxy.h"
16 #include "cc/prioritized_texture.h" 15 #include "cc/prioritized_texture.h"
17 #include "cc/priority_calculator.h" 16 #include "cc/priority_calculator.h"
18 #include "cc/texture.h" 17 #include "cc/texture.h"
19 #include "third_party/khronos/GLES2/gl2.h" 18 #include "third_party/khronos/GLES2/gl2.h"
20 #include "ui/gfx/size.h" 19 #include "ui/gfx/size.h"
21 20
22 #if defined(COMPILER_GCC) 21 #if defined(COMPILER_GCC)
23 namespace BASE_HASH_NAMESPACE { 22 namespace BASE_HASH_NAMESPACE {
24 template<> 23 template<>
25 struct hash<cc::PrioritizedTexture*> { 24 struct hash<cc::PrioritizedTexture*> {
26 size_t operator()(cc::PrioritizedTexture* ptr) const { 25 size_t operator()(cc::PrioritizedTexture* ptr) const {
27 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); 26 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
28 } 27 }
29 }; 28 };
30 } // namespace BASE_HASH_NAMESPACE 29 } // namespace BASE_HASH_NAMESPACE
31 #endif // COMPILER 30 #endif // COMPILER
32 31
33 namespace cc { 32 namespace cc {
34 33
35 class PriorityCalculator; 34 class PriorityCalculator;
36 class Proxy;
37 35
38 class CC_EXPORT PrioritizedTextureManager { 36 class CC_EXPORT PrioritizedTextureManager {
39 public: 37 public:
40 static scoped_ptr<PrioritizedTextureManager> create(size_t maxMemoryLimitByt es, int maxTextureSize, int pool, const Proxy* proxy) 38 static scoped_ptr<PrioritizedTextureManager> create(size_t maxMemoryLimitByt es, int maxTextureSize, int pool)
41 { 39 {
42 return make_scoped_ptr(new PrioritizedTextureManager(maxMemoryLimitBytes , maxTextureSize, pool, proxy)); 40 return make_scoped_ptr(new PrioritizedTextureManager(maxMemoryLimitBytes , maxTextureSize, pool));
43 } 41 }
44 scoped_ptr<PrioritizedTexture> createTexture(gfx::Size size, GLenum format) 42 scoped_ptr<PrioritizedTexture> createTexture(gfx::Size size, GLenum format)
45 { 43 {
46 return make_scoped_ptr(new PrioritizedTexture(this, size, format)); 44 return make_scoped_ptr(new PrioritizedTexture(this, size, format));
47 } 45 }
48 ~PrioritizedTextureManager(); 46 ~PrioritizedTextureManager();
49 47
50 typedef std::list<PrioritizedTexture::Backing*> BackingList; 48 typedef std::list<PrioritizedTexture::Backing*> BackingList;
51 49
52 // FIXME (http://crbug.com/137094): This 64MB default is a straggler from th e 50 // FIXME (http://crbug.com/137094): This 64MB default is a straggler from th e
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 void registerTexture(PrioritizedTexture*); 101 void registerTexture(PrioritizedTexture*);
104 void unregisterTexture(PrioritizedTexture*); 102 void unregisterTexture(PrioritizedTexture*);
105 void returnBackingTexture(PrioritizedTexture*); 103 void returnBackingTexture(PrioritizedTexture*);
106 104
107 // Update all backings' priorities from their owning texture. 105 // Update all backings' priorities from their owning texture.
108 void pushTexturePrioritiesToBackings(); 106 void pushTexturePrioritiesToBackings();
109 107
110 // Mark all textures' backings as being in the drawing impl tree. 108 // Mark all textures' backings as being in the drawing impl tree.
111 void updateBackingsInDrawingImplTree(); 109 void updateBackingsInDrawingImplTree();
112 110
113 const Proxy* proxyForDebug() const;
114
115 private: 111 private:
116 friend class PrioritizedTextureTest; 112 friend class PrioritizedTextureTest;
117 113
118 enum EvictionPolicy { 114 enum EvictionPolicy {
119 EvictOnlyRecyclable, 115 EvictOnlyRecyclable,
120 EvictAnything, 116 EvictAnything,
121 }; 117 };
122 118
123 // Compare textures. Highest priority first. 119 // Compare textures. Highest priority first.
124 static inline bool compareTextures(PrioritizedTexture* a, PrioritizedTexture * b) 120 static inline bool compareTextures(PrioritizedTexture* a, PrioritizedTexture * b)
(...skipping 14 matching lines...) Expand all
139 // Then sort by priority (note that backings that no longer have owners will 135 // Then sort by priority (note that backings that no longer have owners will
140 // always have the lowest priority) 136 // always have the lowest priority)
141 if (a->requestPriorityAtLastPriorityUpdate() != b->requestPriorityAtLast PriorityUpdate()) 137 if (a->requestPriorityAtLastPriorityUpdate() != b->requestPriorityAtLast PriorityUpdate())
142 return PriorityCalculator::priorityIsLower(a->requestPriorityAtLastP riorityUpdate(), b->requestPriorityAtLastPriorityUpdate()); 138 return PriorityCalculator::priorityIsLower(a->requestPriorityAtLastP riorityUpdate(), b->requestPriorityAtLastPriorityUpdate());
143 // Finally sort by being in the impl tree versus being completely unrefe renced 139 // Finally sort by being in the impl tree versus being completely unrefe renced
144 if (a->inDrawingImplTree() != b->inDrawingImplTree()) 140 if (a->inDrawingImplTree() != b->inDrawingImplTree())
145 return (a->inDrawingImplTree() < b->inDrawingImplTree()); 141 return (a->inDrawingImplTree() < b->inDrawingImplTree());
146 return a < b; 142 return a < b;
147 } 143 }
148 144
149 PrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, in t pool, const Proxy* proxy); 145 PrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, in t pool);
150 146
151 bool evictBackingsToReduceMemory(size_t limitBytes, int priorityCutoff, Evic tionPolicy, ResourceProvider*); 147 bool evictBackingsToReduceMemory(size_t limitBytes, int priorityCutoff, Evic tionPolicy, ResourceProvider*);
152 PrioritizedTexture::Backing* createBacking(gfx::Size, GLenum format, Resourc eProvider*); 148 PrioritizedTexture::Backing* createBacking(gfx::Size, GLenum format, Resourc eProvider*);
153 void evictFirstBackingResource(ResourceProvider*); 149 void evictFirstBackingResource(ResourceProvider*);
154 void deleteUnlinkedEvictedBackings(); 150 void deleteUnlinkedEvictedBackings();
155 void sortBackings(); 151 void sortBackings();
156 152
157 void assertInvariants(); 153 void assertInvariants();
158 154
159 size_t m_maxMemoryLimitBytes; 155 size_t m_maxMemoryLimitBytes;
160 // The priority cutoff based on memory pressure. This is not a strict 156 // The priority cutoff based on memory pressure. This is not a strict
161 // cutoff -- requestLate allows textures with priority equal to this 157 // cutoff -- requestLate allows textures with priority equal to this
162 // cutoff to be allowed. 158 // cutoff to be allowed.
163 int m_priorityCutoff; 159 int m_priorityCutoff;
164 // The priority cutoff based on external memory policy. This is a strict 160 // The priority cutoff based on external memory policy. This is a strict
165 // cutoff -- no textures with priority equal to this cutoff will be allowed. 161 // cutoff -- no textures with priority equal to this cutoff will be allowed.
166 int m_externalPriorityCutoff; 162 int m_externalPriorityCutoff;
167 size_t m_memoryUseBytes; 163 size_t m_memoryUseBytes;
168 size_t m_memoryAboveCutoffBytes; 164 size_t m_memoryAboveCutoffBytes;
169 size_t m_memoryAvailableBytes; 165 size_t m_memoryAvailableBytes;
170 int m_pool; 166 int m_pool;
171 167
172 typedef base::hash_set<PrioritizedTexture*> TextureSet; 168 typedef base::hash_set<PrioritizedTexture*> TextureSet;
173 typedef std::vector<PrioritizedTexture*> TextureVector; 169 typedef std::vector<PrioritizedTexture*> TextureVector;
174 170
175 const Proxy* m_proxy;
176
177 TextureSet m_textures; 171 TextureSet m_textures;
178 // This list is always sorted in eviction order, with the exception the 172 // This list is always sorted in eviction order, with the exception the
179 // newly-allocated or recycled textures at the very end of the tail that 173 // newly-allocated or recycled textures at the very end of the tail that
180 // are not sorted by priority. 174 // are not sorted by priority.
181 BackingList m_backings; 175 BackingList m_backings;
182 bool m_backingsTailNotSorted; 176 bool m_backingsTailNotSorted;
183 BackingList m_evictedBackings; 177 BackingList m_evictedBackings;
184 178
185 TextureVector m_tempTextureVector; 179 TextureVector m_tempTextureVector;
186 180
187 // Statistics about memory usage at priority cutoffs, computed at prioritize Textures. 181 // Statistics about memory usage at priority cutoffs, computed at prioritize Textures.
188 size_t m_memoryVisibleBytes; 182 size_t m_memoryVisibleBytes;
189 size_t m_memoryVisibleAndNearbyBytes; 183 size_t m_memoryVisibleAndNearbyBytes;
190 184
191 // Statistics copied at the time of pushTexturePrioritiesToBackings. 185 // Statistics copied at the time of pushTexturePrioritiesToBackings.
192 size_t m_memoryVisibleLastPushedBytes; 186 size_t m_memoryVisibleLastPushedBytes;
193 size_t m_memoryVisibleAndNearbyLastPushedBytes; 187 size_t m_memoryVisibleAndNearbyLastPushedBytes;
194 188
195 DISALLOW_COPY_AND_ASSIGN(PrioritizedTextureManager); 189 DISALLOW_COPY_AND_ASSIGN(PrioritizedTextureManager);
196 }; 190 };
197 191
198 } // namespace cc 192 } // namespace cc
199 193
200 #endif // CC_PRIORITIZED_TEXTURE_MANAGER_H_ 194 #endif // CC_PRIORITIZED_TEXTURE_MANAGER_H_
OLDNEW
« no previous file with comments | « cc/prioritized_texture.cc ('k') | cc/prioritized_texture_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698