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

Side by Side Diff: cc/prioritized_texture_manager.h

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

Powered by Google App Engine
This is Rietveld 408576698