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

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: Apply Dana's code review suggestions Created 8 years, 2 months 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 void registerTexture(PrioritizedTexture*); 99 void registerTexture(PrioritizedTexture*);
98 void unregisterTexture(PrioritizedTexture*); 100 void unregisterTexture(PrioritizedTexture*);
99 void returnBackingTexture(PrioritizedTexture*); 101 void returnBackingTexture(PrioritizedTexture*);
100 102
101 // Update all backings' priorities from their owning texture. 103 // Update all backings' priorities from their owning texture.
102 void pushTexturePrioritiesToBackings(); 104 void pushTexturePrioritiesToBackings();
103 105
104 // Mark all textures' backings as being in the drawing impl tree. 106 // Mark all textures' backings as being in the drawing impl tree.
105 void updateBackingsInDrawingImplTree(); 107 void updateBackingsInDrawingImplTree();
106 108
109 const Proxy* proxyForDebug() const;
110
107 private: 111 private:
108 friend class PrioritizedTextureTest; 112 friend class PrioritizedTextureTest;
109 113
110 enum EvictionPolicy { 114 enum EvictionPolicy {
111 EvictOnlyRecyclable, 115 EvictOnlyRecyclable,
112 EvictAnything, 116 EvictAnything,
113 }; 117 };
114 118
115 // Compare textures. Highest priority first. 119 // Compare textures. Highest priority first.
116 static inline bool compareTextures(PrioritizedTexture* a, PrioritizedTexture * b) 120 static inline bool compareTextures(PrioritizedTexture* a, PrioritizedTexture * b)
(...skipping 14 matching lines...) Expand all
131 // 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
132 // always have the lowest priority) 136 // always have the lowest priority)
133 if (a->requestPriorityAtLastPriorityUpdate() != b->requestPriorityAtLast PriorityUpdate()) 137 if (a->requestPriorityAtLastPriorityUpdate() != b->requestPriorityAtLast PriorityUpdate())
134 return PriorityCalculator::priorityIsLower(a->requestPriorityAtLastP riorityUpdate(), b->requestPriorityAtLastPriorityUpdate()); 138 return PriorityCalculator::priorityIsLower(a->requestPriorityAtLastP riorityUpdate(), b->requestPriorityAtLastPriorityUpdate());
135 // 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
136 if (a->inDrawingImplTree() != b->inDrawingImplTree()) 140 if (a->inDrawingImplTree() != b->inDrawingImplTree())
137 return (a->inDrawingImplTree() < b->inDrawingImplTree()); 141 return (a->inDrawingImplTree() < b->inDrawingImplTree());
138 return a < b; 142 return a < b;
139 } 143 }
140 144
141 PrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, in t pool); 145 PrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, in t pool, const Proxy* proxy);
142 146
143 bool evictBackingsToReduceMemory(size_t limitBytes, int priorityCutoff, Evic tionPolicy, ResourceProvider*); 147 bool evictBackingsToReduceMemory(size_t limitBytes, int priorityCutoff, Evic tionPolicy, ResourceProvider*);
144 PrioritizedTexture::Backing* createBacking(IntSize, GLenum format, ResourceP rovider*); 148 PrioritizedTexture::Backing* createBacking(IntSize, GLenum format, ResourceP rovider*);
145 void evictFirstBackingResource(ResourceProvider*); 149 void evictFirstBackingResource(ResourceProvider*);
146 void deleteUnlinkedEvictedBackings(); 150 void deleteUnlinkedEvictedBackings();
147 void sortBackings(); 151 void sortBackings();
148 152
149 void assertInvariants(); 153 void assertInvariants();
150 154
151 size_t m_maxMemoryLimitBytes; 155 size_t m_maxMemoryLimitBytes;
152 // 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
153 // cutoff -- requestLate allows textures with priority equal to this 157 // cutoff -- requestLate allows textures with priority equal to this
154 // cutoff to be allowed. 158 // cutoff to be allowed.
155 int m_priorityCutoff; 159 int m_priorityCutoff;
156 // 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
157 // 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.
158 int m_externalPriorityCutoff; 162 int m_externalPriorityCutoff;
159 size_t m_memoryUseBytes; 163 size_t m_memoryUseBytes;
160 size_t m_memoryAboveCutoffBytes; 164 size_t m_memoryAboveCutoffBytes;
161 size_t m_memoryAvailableBytes; 165 size_t m_memoryAvailableBytes;
162 int m_pool; 166 int m_pool;
163 167
164 typedef base::hash_set<PrioritizedTexture*> TextureSet; 168 typedef base::hash_set<PrioritizedTexture*> TextureSet;
165 typedef std::vector<PrioritizedTexture*> TextureVector; 169 typedef std::vector<PrioritizedTexture*> TextureVector;
166 170
171 const Proxy* m_proxy;
172
167 TextureSet m_textures; 173 TextureSet m_textures;
168 // This list is always sorted in eviction order, with the exception the 174 // This list is always sorted in eviction order, with the exception the
169 // newly-allocated or recycled textures at the very end of the tail that 175 // newly-allocated or recycled textures at the very end of the tail that
170 // are not sorted by priority. 176 // are not sorted by priority.
171 BackingList m_backings; 177 BackingList m_backings;
172 bool m_backingsTailNotSorted; 178 bool m_backingsTailNotSorted;
173 BackingList m_evictedBackings; 179 BackingList m_evictedBackings;
174 180
175 TextureVector m_tempTextureVector; 181 TextureVector m_tempTextureVector;
176 182
177 DISALLOW_COPY_AND_ASSIGN(PrioritizedTextureManager); 183 DISALLOW_COPY_AND_ASSIGN(PrioritizedTextureManager);
178 }; 184 };
179 185
180 } // namespace cc 186 } // namespace cc
181 187
182 #endif 188 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698