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

Side by Side Diff: cc/prioritized_resource_manager.h

Issue 11232051: Remove static thread pointers from CC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Apply code review comments 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
« no previous file with comments | « cc/prioritized_resource.cc ('k') | cc/prioritized_resource_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_RESOURCE_MANAGER_H_ 5 #ifndef CC_PRIORITIZED_RESOURCE_MANAGER_H_
6 #define CC_PRIORITIZED_RESOURCE_MANAGER_H_ 6 #define CC_PRIORITIZED_RESOURCE_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"
15 #include "cc/prioritized_resource.h" 16 #include "cc/prioritized_resource.h"
16 #include "cc/priority_calculator.h" 17 #include "cc/priority_calculator.h"
17 #include "cc/texture.h" 18 #include "cc/texture.h"
18 #include "third_party/khronos/GLES2/gl2.h" 19 #include "third_party/khronos/GLES2/gl2.h"
19 #include "ui/gfx/size.h" 20 #include "ui/gfx/size.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::PrioritizedResource*> { 25 struct hash<cc::PrioritizedResource*> {
25 size_t operator()(cc::PrioritizedResource* ptr) const { 26 size_t operator()(cc::PrioritizedResource* 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 CC_EXPORT PrioritizedResourceManager { 38 class CC_EXPORT PrioritizedResourceManager {
37 public: 39 public:
38 static scoped_ptr<PrioritizedResourceManager> create(size_t maxMemoryLimitBy tes, int maxTextureSize, int pool) 40 static scoped_ptr<PrioritizedResourceManager> create(size_t maxMemoryLimitBy tes, int maxTextureSize, int pool, const Proxy* proxy)
39 { 41 {
40 return make_scoped_ptr(new PrioritizedResourceManager(maxMemoryLimitByte s, maxTextureSize, pool)); 42 return make_scoped_ptr(new PrioritizedResourceManager(maxMemoryLimitByte s, maxTextureSize, pool, proxy));
41 } 43 }
42 scoped_ptr<PrioritizedResource> createTexture(gfx::Size size, GLenum format) 44 scoped_ptr<PrioritizedResource> createTexture(gfx::Size size, GLenum format)
43 { 45 {
44 return make_scoped_ptr(new PrioritizedResource(this, size, format)); 46 return make_scoped_ptr(new PrioritizedResource(this, size, format));
45 } 47 }
46 ~PrioritizedResourceManager(); 48 ~PrioritizedResourceManager();
47 49
48 typedef std::list<PrioritizedResource::Backing*> BackingList; 50 typedef std::list<PrioritizedResource::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(PrioritizedResource*); 103 void registerTexture(PrioritizedResource*);
102 void unregisterTexture(PrioritizedResource*); 104 void unregisterTexture(PrioritizedResource*);
103 void returnBackingTexture(PrioritizedResource*); 105 void returnBackingTexture(PrioritizedResource*);
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 PrioritizedResourceTest; 116 friend class PrioritizedResourceTest;
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(PrioritizedResource* a, PrioritizedResour ce* b) 124 static inline bool compareTextures(PrioritizedResource* a, PrioritizedResour ce* 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 PrioritizedResourceManager(size_t maxMemoryLimitBytes, int maxTextureSize, i nt pool); 149 PrioritizedResourceManager(size_t maxMemoryLimitBytes, int maxTextureSize, i nt 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 PrioritizedResource::Backing* createBacking(gfx::Size, GLenum format, Resour ceProvider*); 152 PrioritizedResource::Backing* createBacking(gfx::Size, GLenum format, Resour ceProvider*);
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<PrioritizedResource*> TextureSet; 172 typedef base::hash_set<PrioritizedResource*> TextureSet;
169 typedef std::vector<PrioritizedResource*> TextureVector; 173 typedef std::vector<PrioritizedResource*> 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(PrioritizedResourceManager); 195 DISALLOW_COPY_AND_ASSIGN(PrioritizedResourceManager);
190 }; 196 };
191 197
192 } // namespace cc 198 } // namespace cc
193 199
194 #endif // CC_PRIORITIZED_RESOURCE_MANAGER_H_ 200 #endif // CC_PRIORITIZED_RESOURCE_MANAGER_H_
OLDNEW
« no previous file with comments | « cc/prioritized_resource.cc ('k') | cc/prioritized_resource_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698