OLD | NEW |
---|---|
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 "CCPrioritizedTexture.h" | 9 #include "CCPrioritizedTexture.h" |
10 #include "CCPriorityCalculator.h" | 10 #include "CCPriorityCalculator.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 size_t memoryAboveCutoffBytes() const { return m_memoryAboveCutoffBytes; } | 50 size_t memoryAboveCutoffBytes() const { return m_memoryAboveCutoffBytes; } |
51 size_t memoryForSelfManagedTextures() const { return m_maxMemoryLimitBytes - m_memoryAvailableBytes; } | 51 size_t memoryForSelfManagedTextures() const { return m_maxMemoryLimitBytes - m_memoryAvailableBytes; } |
52 | 52 |
53 void setMaxMemoryLimitBytes(size_t bytes) { m_maxMemoryLimitBytes = bytes; } | 53 void setMaxMemoryLimitBytes(size_t bytes) { m_maxMemoryLimitBytes = bytes; } |
54 size_t maxMemoryLimitBytes() const { return m_maxMemoryLimitBytes; } | 54 size_t maxMemoryLimitBytes() const { return m_maxMemoryLimitBytes; } |
55 | 55 |
56 void prioritizeTextures(); | 56 void prioritizeTextures(); |
57 void clearPriorities(); | 57 void clearPriorities(); |
58 | 58 |
59 void reduceMemoryOnImplThread(size_t limitBytes, CCResourceProvider*); | 59 void reduceMemoryOnImplThread(size_t limitBytes, CCResourceProvider*); |
60 bool evictedBackingsExist() const { return !m_evictedBackings.isEmpty(); } | 60 bool linkedEvictedBackingsExist() const; |
epenner
2012/10/09 17:25:04
Nit: I was having trouble understanding what this
ccameron
2012/10/09 21:03:56
I added a comment saying that this returns true if
| |
61 void getEvictedBackings(BackingVector& evictedBackings); | 61 void getEvictedBackings(BackingVector& evictedBackings); |
62 void unlinkEvictedBackings(const BackingVector& evictedBackings); | 62 void unlinkEvictedBackings(const BackingVector& evictedBackings); |
63 // Deletes all evicted backings, unlinking them from their owning textures i f needed. | |
64 // Returns true if this function unlinked any backings from their owning tex ture while | |
65 // destroying them. | |
66 bool deleteEvictedBackings(); | |
67 | 63 |
68 bool requestLate(CCPrioritizedTexture*); | 64 bool requestLate(CCPrioritizedTexture*); |
69 | 65 |
70 void reduceMemory(CCResourceProvider*); | 66 void reduceMemory(CCResourceProvider*); |
71 void clearAllMemory(CCResourceProvider*); | 67 void clearAllMemory(CCResourceProvider*); |
72 | 68 |
73 void acquireBackingTextureIfNeeded(CCPrioritizedTexture*, CCResourceProvider *); | 69 void acquireBackingTextureIfNeeded(CCPrioritizedTexture*, CCResourceProvider *); |
74 | 70 |
75 void registerTexture(CCPrioritizedTexture*); | 71 void registerTexture(CCPrioritizedTexture*); |
76 void unregisterTexture(CCPrioritizedTexture*); | 72 void unregisterTexture(CCPrioritizedTexture*); |
77 void returnBackingTexture(CCPrioritizedTexture*); | 73 void returnBackingTexture(CCPrioritizedTexture*); |
78 | 74 |
75 // Update all backings' priorities from their owning texture. | |
76 void pushTexturePrioritiesToBackings(); | |
77 | |
78 // Mark all textures' backings as being in the drawing impl tree. | |
79 void updateBackingsInDrawingImplTree(); | |
80 | |
79 private: | 81 private: |
80 friend class CCPrioritizedTextureTest; | 82 friend class CCPrioritizedTextureTest; |
81 | 83 |
82 enum EvictionPriorityPolicy { | 84 enum EvictionPriorityPolicy { |
83 RespectManagerPriorityCutoff, | 85 RespectManagerPriorityCutoff, |
84 DoNotRespectManagerPriorityCutoff, | 86 DoNotRespectManagerPriorityCutoff, |
85 }; | 87 }; |
86 | 88 |
87 // Compare textures. Highest priority first. | 89 // Compare textures. Highest priority first. |
88 static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTex ture* b) | 90 static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTex ture* b) |
89 { | 91 { |
90 if (a->requestPriority() == b->requestPriority()) | 92 if (a->requestPriority() == b->requestPriority()) |
91 return a < b; | 93 return a < b; |
92 return CCPriorityCalculator::priorityIsHigher(a->requestPriority(), b->r equestPriority()); | 94 return CCPriorityCalculator::priorityIsHigher(a->requestPriority(), b->r equestPriority()); |
93 } | 95 } |
94 // Compare backings. Lowest priority first. | 96 // Compare backings. Lowest priority first. |
95 static inline bool compareBackings(CCPrioritizedTexture::Backing* a, CCPrior itizedTexture::Backing* b) | 97 static inline bool compareBackings(CCPrioritizedTexture::Backing* a, CCPrior itizedTexture::Backing* b) |
96 { | 98 { |
97 int priorityA = a->requestPriorityAtLastPriorityUpdate(); | 99 // Sort first by priority (note that backings that no longer have owners will |
epenner
2012/10/09 17:25:04
If we make some backings recyclable by intentional
ccameron
2012/10/09 21:03:56
I went ahead and put a "canBeRecycled" test first.
| |
98 int priorityB = b->requestPriorityAtLastPriorityUpdate(); | 100 // always have the lowest priority) |
99 if (priorityA != priorityB) | 101 if (a->requestPriorityAtLastPriorityUpdate() != b->requestPriorityAtLast PriorityUpdate()) |
100 return CCPriorityCalculator::priorityIsLower(priorityA, priorityB); | 102 return CCPriorityCalculator::priorityIsLower(a->requestPriorityAtLas tPriorityUpdate(), b->requestPriorityAtLastPriorityUpdate()); |
101 bool aboveCutoffA = a->wasAbovePriorityCutoffAtLastPriorityUpdate(); | 103 // Then sort by being above or below the priority cutoff. |
102 bool aboveCutoffB = b->wasAbovePriorityCutoffAtLastPriorityUpdate(); | 104 if (a->wasAbovePriorityCutoffAtLastPriorityUpdate() != b->wasAbovePriori tyCutoffAtLastPriorityUpdate()) |
103 if (!aboveCutoffA && aboveCutoffB) | 105 return (a->wasAbovePriorityCutoffAtLastPriorityUpdate() < b->wasAbov ePriorityCutoffAtLastPriorityUpdate()); |
104 return true; | 106 // Finally sort by being in the impl tree versus being completely unrefe renced |
105 if (aboveCutoffA && !aboveCutoffB) | 107 if (a->inDrawingImplTree() != b->inDrawingImplTree()) |
106 return false; | 108 return (a->inDrawingImplTree() < b->inDrawingImplTree()); |
107 return a < b; | 109 return a < b; |
108 } | 110 } |
109 | 111 |
110 CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, int pool); | 112 CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, int pool); |
111 | 113 |
112 void updateBackingsPriorities(); | |
113 void evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy, CCResourceProvider*); | 114 void evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy, CCResourceProvider*); |
114 CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCRes ourceProvider*); | 115 CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCRes ourceProvider*); |
115 void evictBackingResource(CCPrioritizedTexture::Backing*, CCResourceProvider *); | 116 void evictBackingResource(CCPrioritizedTexture::Backing*, CCResourceProvider *); |
117 void deleteUnlinkedEvictedBackings(); | |
118 void sortBackings(); | |
116 | 119 |
117 #if !ASSERT_DISABLED | 120 #if !ASSERT_DISABLED |
118 void assertInvariants(); | 121 void assertInvariants(); |
119 #endif | 122 #endif |
120 | 123 |
121 size_t m_maxMemoryLimitBytes; | 124 size_t m_maxMemoryLimitBytes; |
122 unsigned m_priorityCutoff; | 125 unsigned m_priorityCutoff; |
123 size_t m_memoryUseBytes; | 126 size_t m_memoryUseBytes; |
124 size_t m_memoryAboveCutoffBytes; | 127 size_t m_memoryAboveCutoffBytes; |
125 size_t m_memoryAvailableBytes; | 128 size_t m_memoryAvailableBytes; |
126 int m_pool; | 129 int m_pool; |
127 | 130 |
128 typedef HashSet<CCPrioritizedTexture*> TextureSet; | 131 typedef HashSet<CCPrioritizedTexture*> TextureSet; |
129 typedef ListHashSet<CCPrioritizedTexture::Backing*> BackingSet; | 132 typedef ListHashSet<CCPrioritizedTexture::Backing*> BackingSet; |
130 typedef Vector<CCPrioritizedTexture*> TextureVector; | 133 typedef Vector<CCPrioritizedTexture*> TextureVector; |
131 | 134 |
132 TextureSet m_textures; | 135 TextureSet m_textures; |
133 BackingSet m_backings; | 136 BackingSet m_backings; |
134 BackingVector m_evictedBackings; | 137 BackingVector m_evictedBackings; |
135 | 138 |
136 TextureVector m_tempTextureVector; | 139 TextureVector m_tempTextureVector; |
137 BackingVector m_tempBackingVector; | 140 BackingVector m_tempBackingVector; |
138 | 141 |
139 // Set by the main thread when it adjust priorities in such a way that | |
140 // the m_backings array's view of priorities is now out of date. | |
141 bool m_needsUpdateBackingsPrioritites; | |
142 | |
143 DISALLOW_COPY_AND_ASSIGN(CCPrioritizedTextureManager); | 142 DISALLOW_COPY_AND_ASSIGN(CCPrioritizedTextureManager); |
144 }; | 143 }; |
145 | 144 |
146 } // namespace cc | 145 } // namespace cc |
147 | 146 |
148 #endif | 147 #endif |
OLD | NEW |