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

Side by Side Diff: cc/prioritized_resource_manager.h

Issue 11369109: cc: Rename PrioritizedTexture to PrioritizedResource. (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_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_TEXTURE_MANAGER_H_ 5 #ifndef CC_PRIORITIZED_RESOURCE_MANAGER_H_
6 #define CC_PRIORITIZED_TEXTURE_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/prioritized_texture.h" 15 #include "cc/prioritized_resource.h"
16 #include "cc/priority_calculator.h" 16 #include "cc/priority_calculator.h"
17 #include "cc/texture.h" 17 #include "cc/texture.h"
18 #include "third_party/khronos/GLES2/gl2.h" 18 #include "third_party/khronos/GLES2/gl2.h"
19 #include "ui/gfx/size.h" 19 #include "ui/gfx/size.h"
20 20
21 #if defined(COMPILER_GCC) 21 #if defined(COMPILER_GCC)
22 namespace BASE_HASH_NAMESPACE { 22 namespace BASE_HASH_NAMESPACE {
23 template<> 23 template<>
24 struct hash<cc::PrioritizedTexture*> { 24 struct hash<cc::PrioritizedResource*> {
25 size_t operator()(cc::PrioritizedTexture* ptr) const { 25 size_t operator()(cc::PrioritizedResource* ptr) const {
26 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); 26 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
27 } 27 }
28 }; 28 };
29 } // namespace BASE_HASH_NAMESPACE 29 } // namespace BASE_HASH_NAMESPACE
30 #endif // COMPILER 30 #endif // COMPILER
31 31
32 namespace cc { 32 namespace cc {
33 33
34 class PriorityCalculator; 34 class PriorityCalculator;
35 35
36 class CC_EXPORT PrioritizedTextureManager { 36 class CC_EXPORT PrioritizedResourceManager {
37 public: 37 public:
38 static scoped_ptr<PrioritizedTextureManager> create(size_t maxMemoryLimitByt es, int maxTextureSize, int pool) 38 static scoped_ptr<PrioritizedResourceManager> create(size_t maxMemoryLimitBy tes, int maxTextureSize, int pool)
39 { 39 {
40 return make_scoped_ptr(new PrioritizedTextureManager(maxMemoryLimitBytes , maxTextureSize, pool)); 40 return make_scoped_ptr(new PrioritizedResourceManager(maxMemoryLimitByte s, maxTextureSize, pool));
41 } 41 }
42 scoped_ptr<PrioritizedTexture> createTexture(gfx::Size size, GLenum format) 42 scoped_ptr<PrioritizedResource> createTexture(gfx::Size size, GLenum format)
43 { 43 {
44 return make_scoped_ptr(new PrioritizedTexture(this, size, format)); 44 return make_scoped_ptr(new PrioritizedResource(this, size, format));
45 } 45 }
46 ~PrioritizedTextureManager(); 46 ~PrioritizedResourceManager();
47 47
48 typedef std::list<PrioritizedTexture::Backing*> BackingList; 48 typedef std::list<PrioritizedResource::Backing*> BackingList;
49 49
50 // 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
51 // old texture manager and is just to give us a default memory allocation be fore 51 // old texture manager and is just to give us a default memory allocation be fore
52 // we get a callback from the GPU memory manager. We should probaby either: 52 // we get a callback from the GPU memory manager. We should probaby either:
53 // - wait for the callback before rendering anything instead 53 // - wait for the callback before rendering anything instead
54 // - push this into the GPU memory manager somehow. 54 // - push this into the GPU memory manager somehow.
55 static size_t defaultMemoryAllocationLimit() { return 64 * 1024 * 1024; } 55 static size_t defaultMemoryAllocationLimit() { return 64 * 1024 * 1024; }
56 56
57 // memoryUseBytes() describes the number of bytes used by existing allocated textures. 57 // memoryUseBytes() describes the number of bytes used by existing allocated textures.
58 // memoryAboveCutoffBytes() describes the number of bytes that would be used if all 58 // memoryAboveCutoffBytes() describes the number of bytes that would be used if all
(...skipping 25 matching lines...) Expand all
84 // resources evicted. Only when we commit a tree that has no textures linked to evicted backings 84 // resources evicted. Only when we commit a tree that has no textures linked to evicted backings
85 // may we allow drawing. 85 // may we allow drawing.
86 bool linkedEvictedBackingsExist() const; 86 bool linkedEvictedBackingsExist() const;
87 // Retrieve the list of all contents textures' backings that have been evict ed, to pass to the 87 // Retrieve the list of all contents textures' backings that have been evict ed, to pass to the
88 // main thread to unlink them from their owning textures. 88 // main thread to unlink them from their owning textures.
89 void getEvictedBackings(BackingList& evictedBackings); 89 void getEvictedBackings(BackingList& evictedBackings);
90 // Unlink the list of contents textures' backings from their owning textures on the main thread 90 // Unlink the list of contents textures' backings from their owning textures on the main thread
91 // before updating layers. 91 // before updating layers.
92 void unlinkEvictedBackings(const BackingList& evictedBackings); 92 void unlinkEvictedBackings(const BackingList& evictedBackings);
93 93
94 bool requestLate(PrioritizedTexture*); 94 bool requestLate(PrioritizedResource*);
95 95
96 void reduceMemory(ResourceProvider*); 96 void reduceMemory(ResourceProvider*);
97 void clearAllMemory(ResourceProvider*); 97 void clearAllMemory(ResourceProvider*);
98 98
99 void acquireBackingTextureIfNeeded(PrioritizedTexture*, ResourceProvider*); 99 void acquireBackingTextureIfNeeded(PrioritizedResource*, ResourceProvider*);
100 100
101 void registerTexture(PrioritizedTexture*); 101 void registerTexture(PrioritizedResource*);
102 void unregisterTexture(PrioritizedTexture*); 102 void unregisterTexture(PrioritizedResource*);
103 void returnBackingTexture(PrioritizedTexture*); 103 void returnBackingTexture(PrioritizedResource*);
104 104
105 // Update all backings' priorities from their owning texture. 105 // Update all backings' priorities from their owning texture.
106 void pushTexturePrioritiesToBackings(); 106 void pushTexturePrioritiesToBackings();
107 107
108 // Mark all textures' backings as being in the drawing impl tree. 108 // Mark all textures' backings as being in the drawing impl tree.
109 void updateBackingsInDrawingImplTree(); 109 void updateBackingsInDrawingImplTree();
110 110
111 private: 111 private:
112 friend class PrioritizedTextureTest; 112 friend class PrioritizedResourceTest;
113 113
114 enum EvictionPolicy { 114 enum EvictionPolicy {
115 EvictOnlyRecyclable, 115 EvictOnlyRecyclable,
116 EvictAnything, 116 EvictAnything,
117 }; 117 };
118 118
119 // Compare textures. Highest priority first. 119 // Compare textures. Highest priority first.
120 static inline bool compareTextures(PrioritizedTexture* a, PrioritizedTexture * b) 120 static inline bool compareTextures(PrioritizedResource* a, PrioritizedResour ce* b)
121 { 121 {
122 if (a->requestPriority() == b->requestPriority()) 122 if (a->requestPriority() == b->requestPriority())
123 return a < b; 123 return a < b;
124 return PriorityCalculator::priorityIsHigher(a->requestPriority(), b->req uestPriority()); 124 return PriorityCalculator::priorityIsHigher(a->requestPriority(), b->req uestPriority());
125 } 125 }
126 // Compare backings. Lowest priority first. 126 // Compare backings. Lowest priority first.
127 static inline bool compareBackings(PrioritizedTexture::Backing* a, Prioritiz edTexture::Backing* b) 127 static inline bool compareBackings(PrioritizedResource::Backing* a, Prioriti zedResource::Backing* b)
128 { 128 {
129 // Make textures that can be recycled appear first 129 // Make textures that can be recycled appear first
130 if (a->canBeRecycled() != b->canBeRecycled()) 130 if (a->canBeRecycled() != b->canBeRecycled())
131 return (a->canBeRecycled() > b->canBeRecycled()); 131 return (a->canBeRecycled() > b->canBeRecycled());
132 // Then sort by being above or below the priority cutoff. 132 // Then sort by being above or below the priority cutoff.
133 if (a->wasAbovePriorityCutoffAtLastPriorityUpdate() != b->wasAbovePriori tyCutoffAtLastPriorityUpdate()) 133 if (a->wasAbovePriorityCutoffAtLastPriorityUpdate() != b->wasAbovePriori tyCutoffAtLastPriorityUpdate())
134 return (a->wasAbovePriorityCutoffAtLastPriorityUpdate() < b->wasAbov ePriorityCutoffAtLastPriorityUpdate()); 134 return (a->wasAbovePriorityCutoffAtLastPriorityUpdate() < b->wasAbov ePriorityCutoffAtLastPriorityUpdate());
135 // 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
136 // always have the lowest priority) 136 // always have the lowest priority)
137 if (a->requestPriorityAtLastPriorityUpdate() != b->requestPriorityAtLast PriorityUpdate()) 137 if (a->requestPriorityAtLastPriorityUpdate() != b->requestPriorityAtLast PriorityUpdate())
138 return PriorityCalculator::priorityIsLower(a->requestPriorityAtLastP riorityUpdate(), b->requestPriorityAtLastPriorityUpdate()); 138 return PriorityCalculator::priorityIsLower(a->requestPriorityAtLastP riorityUpdate(), b->requestPriorityAtLastPriorityUpdate());
139 // 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
140 if (a->inDrawingImplTree() != b->inDrawingImplTree()) 140 if (a->inDrawingImplTree() != b->inDrawingImplTree())
141 return (a->inDrawingImplTree() < b->inDrawingImplTree()); 141 return (a->inDrawingImplTree() < b->inDrawingImplTree());
142 return a < b; 142 return a < b;
143 } 143 }
144 144
145 PrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, in t pool); 145 PrioritizedResourceManager(size_t maxMemoryLimitBytes, int maxTextureSize, i nt pool);
146 146
147 bool evictBackingsToReduceMemory(size_t limitBytes, int priorityCutoff, Evic tionPolicy, ResourceProvider*); 147 bool evictBackingsToReduceMemory(size_t limitBytes, int priorityCutoff, Evic tionPolicy, ResourceProvider*);
148 PrioritizedTexture::Backing* createBacking(gfx::Size, GLenum format, Resourc eProvider*); 148 PrioritizedResource::Backing* createBacking(gfx::Size, GLenum format, Resour ceProvider*);
149 void evictFirstBackingResource(ResourceProvider*); 149 void evictFirstBackingResource(ResourceProvider*);
150 void deleteUnlinkedEvictedBackings(); 150 void deleteUnlinkedEvictedBackings();
151 void sortBackings(); 151 void sortBackings();
152 152
153 void assertInvariants(); 153 void assertInvariants();
154 154
155 size_t m_maxMemoryLimitBytes; 155 size_t m_maxMemoryLimitBytes;
156 // 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
157 // cutoff -- requestLate allows textures with priority equal to this 157 // cutoff -- requestLate allows textures with priority equal to this
158 // cutoff to be allowed. 158 // cutoff to be allowed.
159 int m_priorityCutoff; 159 int m_priorityCutoff;
160 // 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
161 // 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.
162 int m_externalPriorityCutoff; 162 int m_externalPriorityCutoff;
163 size_t m_memoryUseBytes; 163 size_t m_memoryUseBytes;
164 size_t m_memoryAboveCutoffBytes; 164 size_t m_memoryAboveCutoffBytes;
165 size_t m_memoryAvailableBytes; 165 size_t m_memoryAvailableBytes;
166 int m_pool; 166 int m_pool;
167 167
168 typedef base::hash_set<PrioritizedTexture*> TextureSet; 168 typedef base::hash_set<PrioritizedResource*> TextureSet;
169 typedef std::vector<PrioritizedTexture*> TextureVector; 169 typedef std::vector<PrioritizedResource*> TextureVector;
170 170
171 TextureSet m_textures; 171 TextureSet m_textures;
172 // 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
173 // 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
174 // are not sorted by priority. 174 // are not sorted by priority.
175 BackingList m_backings; 175 BackingList m_backings;
176 bool m_backingsTailNotSorted; 176 bool m_backingsTailNotSorted;
177 BackingList m_evictedBackings; 177 BackingList m_evictedBackings;
178 178
179 TextureVector m_tempTextureVector; 179 TextureVector m_tempTextureVector;
180 180
181 // Statistics about memory usage at priority cutoffs, computed at prioritize Textures. 181 // Statistics about memory usage at priority cutoffs, computed at prioritize Textures.
182 size_t m_memoryVisibleBytes; 182 size_t m_memoryVisibleBytes;
183 size_t m_memoryVisibleAndNearbyBytes; 183 size_t m_memoryVisibleAndNearbyBytes;
184 184
185 // Statistics copied at the time of pushTexturePrioritiesToBackings. 185 // Statistics copied at the time of pushTexturePrioritiesToBackings.
186 size_t m_memoryVisibleLastPushedBytes; 186 size_t m_memoryVisibleLastPushedBytes;
187 size_t m_memoryVisibleAndNearbyLastPushedBytes; 187 size_t m_memoryVisibleAndNearbyLastPushedBytes;
188 188
189 DISALLOW_COPY_AND_ASSIGN(PrioritizedTextureManager); 189 DISALLOW_COPY_AND_ASSIGN(PrioritizedResourceManager);
190 }; 190 };
191 191
192 } // namespace cc 192 } // namespace cc
193 193
194 #endif // CC_PRIORITIZED_TEXTURE_MANAGER_H_ 194 #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