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

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

Powered by Google App Engine
This is Rietveld 408576698