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

Side by Side Diff: cc/prioritized_texture_manager.h

Issue 11189043: cc: Rename cc classes and members to match filenames (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | Annotate | Revision Log
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 "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/hash_tables.h" 9 #include "base/hash_tables.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "CCPrioritizedTexture.h" 11 #include "CCPrioritizedTexture.h"
12 #include "CCPriorityCalculator.h" 12 #include "CCPriorityCalculator.h"
13 #include "CCTexture.h" 13 #include "CCTexture.h"
14 #include "GraphicsContext3D.h" 14 #include "GraphicsContext3D.h"
15 #include "IntRect.h" 15 #include "IntRect.h"
16 #include "IntSize.h" 16 #include "IntSize.h"
17 #include <wtf/Vector.h> 17 #include <wtf/Vector.h>
18 #include <list> 18 #include <list>
19 19
20 #if defined(COMPILER_GCC) 20 #if defined(COMPILER_GCC)
21 namespace BASE_HASH_NAMESPACE { 21 namespace BASE_HASH_NAMESPACE {
22 template<> 22 template<>
23 struct hash<cc::CCPrioritizedTexture*> { 23 struct hash<cc::PrioritizedTexture*> {
24 size_t operator()(cc::CCPrioritizedTexture* ptr) const { 24 size_t operator()(cc::PrioritizedTexture* ptr) const {
25 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); 25 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
26 } 26 }
27 }; 27 };
28 } // namespace BASE_HASH_NAMESPACE 28 } // namespace BASE_HASH_NAMESPACE
29 #endif // COMPILER 29 #endif // COMPILER
30 30
31 namespace cc { 31 namespace cc {
32 32
33 class CCPriorityCalculator; 33 class PriorityCalculator;
34 34
35 class CCPrioritizedTextureManager { 35 class PrioritizedTextureManager {
36 public: 36 public:
37 static scoped_ptr<CCPrioritizedTextureManager> create(size_t maxMemoryLimitB ytes, int maxTextureSize, int pool) 37 static scoped_ptr<PrioritizedTextureManager> create(size_t maxMemoryLimitByt es, int maxTextureSize, int pool)
38 { 38 {
39 return make_scoped_ptr(new CCPrioritizedTextureManager(maxMemoryLimitByt es, maxTextureSize, pool)); 39 return make_scoped_ptr(new PrioritizedTextureManager(maxMemoryLimitBytes , maxTextureSize, pool));
40 } 40 }
41 scoped_ptr<CCPrioritizedTexture> createTexture(IntSize size, GC3Denum format ) 41 scoped_ptr<PrioritizedTexture> createTexture(IntSize size, GC3Denum format)
42 { 42 {
43 return make_scoped_ptr(new CCPrioritizedTexture(this, size, format)); 43 return make_scoped_ptr(new PrioritizedTexture(this, size, format));
44 } 44 }
45 ~CCPrioritizedTextureManager(); 45 ~PrioritizedTextureManager();
46 46
47 typedef std::list<CCPrioritizedTexture::Backing*> BackingList; 47 typedef std::list<PrioritizedTexture::Backing*> BackingList;
48 48
49 // FIXME (http://crbug.com/137094): This 64MB default is a straggler from th e 49 // FIXME (http://crbug.com/137094): This 64MB default is a straggler from th e
50 // old texture manager and is just to give us a default memory allocation be fore 50 // old texture manager and is just to give us a default memory allocation be fore
51 // we get a callback from the GPU memory manager. We should probaby either: 51 // we get a callback from the GPU memory manager. We should probaby either:
52 // - wait for the callback before rendering anything instead 52 // - wait for the callback before rendering anything instead
53 // - push this into the GPU memory manager somehow. 53 // - push this into the GPU memory manager somehow.
54 static size_t defaultMemoryAllocationLimit() { return 64 * 1024 * 1024; } 54 static size_t defaultMemoryAllocationLimit() { return 64 * 1024 * 1024; }
55 55
56 // memoryUseBytes() describes the number of bytes used by existing allocated textures. 56 // memoryUseBytes() describes the number of bytes used by existing allocated textures.
57 // memoryAboveCutoffBytes() describes the number of bytes that would be used if all 57 // memoryAboveCutoffBytes() describes the number of bytes that would be used if all
58 // textures that are above the cutoff were allocated. 58 // textures that are above the cutoff were allocated.
59 // memoryUseBytes() <= memoryAboveCutoffBytes() should always be true. 59 // memoryUseBytes() <= memoryAboveCutoffBytes() should always be true.
60 size_t memoryUseBytes() const { return m_memoryUseBytes; } 60 size_t memoryUseBytes() const { return m_memoryUseBytes; }
61 size_t memoryAboveCutoffBytes() const { return m_memoryAboveCutoffBytes; } 61 size_t memoryAboveCutoffBytes() const { return m_memoryAboveCutoffBytes; }
62 size_t memoryForSelfManagedTextures() const { return m_maxMemoryLimitBytes - m_memoryAvailableBytes; } 62 size_t memoryForSelfManagedTextures() const { return m_maxMemoryLimitBytes - m_memoryAvailableBytes; }
63 63
64 void setMaxMemoryLimitBytes(size_t bytes) { m_maxMemoryLimitBytes = bytes; } 64 void setMaxMemoryLimitBytes(size_t bytes) { m_maxMemoryLimitBytes = bytes; }
65 size_t maxMemoryLimitBytes() const { return m_maxMemoryLimitBytes; } 65 size_t maxMemoryLimitBytes() const { return m_maxMemoryLimitBytes; }
66 66
67 void prioritizeTextures(); 67 void prioritizeTextures();
68 void clearPriorities(); 68 void clearPriorities();
69 69
70 // Delete contents textures' backing resources until they use only bytesLimi t bytes. This may 70 // Delete contents textures' backing resources until they use only bytesLimi t bytes. This may
71 // be called on the impl thread while the main thread is running. Returns tr ue if resources are 71 // be called on the impl thread while the main thread is running. Returns tr ue if resources are
72 // indeed evicted as a result of this call. 72 // indeed evicted as a result of this call.
73 bool reduceMemoryOnImplThread(size_t limitBytes, CCResourceProvider*); 73 bool reduceMemoryOnImplThread(size_t limitBytes, ResourceProvider*);
74 // Returns true if there exist any textures that are linked to backings that have had their 74 // Returns true if there exist any textures that are linked to backings that have had their
75 // resources evicted. Only when we commit a tree that has no textures linked to evicted backings 75 // resources evicted. Only when we commit a tree that has no textures linked to evicted backings
76 // may we allow drawing. 76 // may we allow drawing.
77 bool linkedEvictedBackingsExist() const; 77 bool linkedEvictedBackingsExist() const;
78 // Retrieve the list of all contents textures' backings that have been evict ed, to pass to the 78 // Retrieve the list of all contents textures' backings that have been evict ed, to pass to the
79 // main thread to unlink them from their owning textures. 79 // main thread to unlink them from their owning textures.
80 void getEvictedBackings(BackingList& evictedBackings); 80 void getEvictedBackings(BackingList& evictedBackings);
81 // Unlink the list of contents textures' backings from their owning textures on the main thread 81 // Unlink the list of contents textures' backings from their owning textures on the main thread
82 // before updating layers. 82 // before updating layers.
83 void unlinkEvictedBackings(const BackingList& evictedBackings); 83 void unlinkEvictedBackings(const BackingList& evictedBackings);
84 84
85 bool requestLate(CCPrioritizedTexture*); 85 bool requestLate(PrioritizedTexture*);
86 86
87 void reduceMemory(CCResourceProvider*); 87 void reduceMemory(ResourceProvider*);
88 void clearAllMemory(CCResourceProvider*); 88 void clearAllMemory(ResourceProvider*);
89 89
90 void acquireBackingTextureIfNeeded(CCPrioritizedTexture*, CCResourceProvider *); 90 void acquireBackingTextureIfNeeded(PrioritizedTexture*, ResourceProvider*);
91 91
92 void registerTexture(CCPrioritizedTexture*); 92 void registerTexture(PrioritizedTexture*);
93 void unregisterTexture(CCPrioritizedTexture*); 93 void unregisterTexture(PrioritizedTexture*);
94 void returnBackingTexture(CCPrioritizedTexture*); 94 void returnBackingTexture(PrioritizedTexture*);
95 95
96 // Update all backings' priorities from their owning texture. 96 // Update all backings' priorities from their owning texture.
97 void pushTexturePrioritiesToBackings(); 97 void pushTexturePrioritiesToBackings();
98 98
99 // Mark all textures' backings as being in the drawing impl tree. 99 // Mark all textures' backings as being in the drawing impl tree.
100 void updateBackingsInDrawingImplTree(); 100 void updateBackingsInDrawingImplTree();
101 101
102 private: 102 private:
103 friend class CCPrioritizedTextureTest; 103 friend class PrioritizedTextureTest;
104 104
105 enum EvictionPriorityPolicy { 105 enum EvictionPriorityPolicy {
106 RespectManagerPriorityCutoff, 106 RespectManagerPriorityCutoff,
107 DoNotRespectManagerPriorityCutoff, 107 DoNotRespectManagerPriorityCutoff,
108 }; 108 };
109 109
110 // Compare textures. Highest priority first. 110 // Compare textures. Highest priority first.
111 static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTex ture* b) 111 static inline bool compareTextures(PrioritizedTexture* a, PrioritizedTexture * b)
112 { 112 {
113 if (a->requestPriority() == b->requestPriority()) 113 if (a->requestPriority() == b->requestPriority())
114 return a < b; 114 return a < b;
115 return CCPriorityCalculator::priorityIsHigher(a->requestPriority(), b->r equestPriority()); 115 return PriorityCalculator::priorityIsHigher(a->requestPriority(), b->req uestPriority());
116 } 116 }
117 // Compare backings. Lowest priority first. 117 // Compare backings. Lowest priority first.
118 static inline bool compareBackings(CCPrioritizedTexture::Backing* a, CCPrior itizedTexture::Backing* b) 118 static inline bool compareBackings(PrioritizedTexture::Backing* a, Prioritiz edTexture::Backing* b)
119 { 119 {
120 // Make textures that can be recycled appear first 120 // Make textures that can be recycled appear first
121 if (a->canBeRecycled() != b->canBeRecycled()) 121 if (a->canBeRecycled() != b->canBeRecycled())
122 return (a->canBeRecycled() > b->canBeRecycled()); 122 return (a->canBeRecycled() > b->canBeRecycled());
123 // Then sort by being above or below the priority cutoff. 123 // Then sort by being above or below the priority cutoff.
124 if (a->wasAbovePriorityCutoffAtLastPriorityUpdate() != b->wasAbovePriori tyCutoffAtLastPriorityUpdate()) 124 if (a->wasAbovePriorityCutoffAtLastPriorityUpdate() != b->wasAbovePriori tyCutoffAtLastPriorityUpdate())
125 return (a->wasAbovePriorityCutoffAtLastPriorityUpdate() < b->wasAbov ePriorityCutoffAtLastPriorityUpdate()); 125 return (a->wasAbovePriorityCutoffAtLastPriorityUpdate() < b->wasAbov ePriorityCutoffAtLastPriorityUpdate());
126 // Then sort by priority (note that backings that no longer have owners will 126 // Then sort by priority (note that backings that no longer have owners will
127 // always have the lowest priority) 127 // always have the lowest priority)
128 if (a->requestPriorityAtLastPriorityUpdate() != b->requestPriorityAtLast PriorityUpdate()) 128 if (a->requestPriorityAtLastPriorityUpdate() != b->requestPriorityAtLast PriorityUpdate())
129 return CCPriorityCalculator::priorityIsLower(a->requestPriorityAtLas tPriorityUpdate(), b->requestPriorityAtLastPriorityUpdate()); 129 return PriorityCalculator::priorityIsLower(a->requestPriorityAtLastP riorityUpdate(), b->requestPriorityAtLastPriorityUpdate());
130 // Finally sort by being in the impl tree versus being completely unrefe renced 130 // Finally sort by being in the impl tree versus being completely unrefe renced
131 if (a->inDrawingImplTree() != b->inDrawingImplTree()) 131 if (a->inDrawingImplTree() != b->inDrawingImplTree())
132 return (a->inDrawingImplTree() < b->inDrawingImplTree()); 132 return (a->inDrawingImplTree() < b->inDrawingImplTree());
133 return a < b; 133 return a < b;
134 } 134 }
135 135
136 CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, int pool); 136 PrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, in t pool);
137 137
138 bool evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy, CCResourceProvider*); 138 bool evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy, ResourceProvider*);
139 CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCRes ourceProvider*); 139 PrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, Resourc eProvider*);
140 void evictFirstBackingResource(CCResourceProvider*); 140 void evictFirstBackingResource(ResourceProvider*);
141 void deleteUnlinkedEvictedBackings(); 141 void deleteUnlinkedEvictedBackings();
142 void sortBackings(); 142 void sortBackings();
143 143
144 void assertInvariants(); 144 void assertInvariants();
145 145
146 size_t m_maxMemoryLimitBytes; 146 size_t m_maxMemoryLimitBytes;
147 unsigned m_priorityCutoff; 147 unsigned m_priorityCutoff;
148 size_t m_memoryUseBytes; 148 size_t m_memoryUseBytes;
149 size_t m_memoryAboveCutoffBytes; 149 size_t m_memoryAboveCutoffBytes;
150 size_t m_memoryAvailableBytes; 150 size_t m_memoryAvailableBytes;
151 int m_pool; 151 int m_pool;
152 152
153 typedef base::hash_set<CCPrioritizedTexture*> TextureSet; 153 typedef base::hash_set<PrioritizedTexture*> TextureSet;
154 typedef Vector<CCPrioritizedTexture*> TextureVector; 154 typedef Vector<PrioritizedTexture*> TextureVector;
155 155
156 TextureSet m_textures; 156 TextureSet m_textures;
157 // This list is always sorted in eviction order, with the exception the 157 // This list is always sorted in eviction order, with the exception the
158 // newly-allocated or recycled textures at the very end of the tail that 158 // newly-allocated or recycled textures at the very end of the tail that
159 // are not sorted by priority. 159 // are not sorted by priority.
160 BackingList m_backings; 160 BackingList m_backings;
161 bool m_backingsTailNotSorted; 161 bool m_backingsTailNotSorted;
162 BackingList m_evictedBackings; 162 BackingList m_evictedBackings;
163 163
164 TextureVector m_tempTextureVector; 164 TextureVector m_tempTextureVector;
165 165
166 DISALLOW_COPY_AND_ASSIGN(CCPrioritizedTextureManager); 166 DISALLOW_COPY_AND_ASSIGN(PrioritizedTextureManager);
167 }; 167 };
168 168
169 } // namespace cc 169 } // namespace cc
170 170
171 #endif 171 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698