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

Side by Side Diff: cc/CCPrioritizedTextureManager.h

Issue 10919320: Integrate r128344 and r128253 from WebKit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 "CCPrioritizedTexture.h" 8 #include "CCPrioritizedTexture.h"
9 #include "CCPriorityCalculator.h" 9 #include "CCPriorityCalculator.h"
10 #include "CCTexture.h" 10 #include "CCTexture.h"
(...skipping 15 matching lines...) Expand all
26 static PassOwnPtr<CCPrioritizedTextureManager> create(size_t maxMemoryLimitB ytes, int maxTextureSize, int pool) 26 static PassOwnPtr<CCPrioritizedTextureManager> create(size_t maxMemoryLimitB ytes, int maxTextureSize, int pool)
27 { 27 {
28 return adoptPtr(new CCPrioritizedTextureManager(maxMemoryLimitBytes, max TextureSize, pool)); 28 return adoptPtr(new CCPrioritizedTextureManager(maxMemoryLimitBytes, max TextureSize, pool));
29 } 29 }
30 PassOwnPtr<CCPrioritizedTexture> createTexture(IntSize size, GC3Denum format ) 30 PassOwnPtr<CCPrioritizedTexture> createTexture(IntSize size, GC3Denum format )
31 { 31 {
32 return adoptPtr(new CCPrioritizedTexture(this, size, format)); 32 return adoptPtr(new CCPrioritizedTexture(this, size, format));
33 } 33 }
34 ~CCPrioritizedTextureManager(); 34 ~CCPrioritizedTextureManager();
35 35
36 typedef Vector<CCPrioritizedTexture::Backing*> BackingVector;
37
36 // FIXME (http://crbug.com/137094): This 64MB default is a straggler from th e 38 // FIXME (http://crbug.com/137094): This 64MB default is a straggler from th e
37 // old texture manager and is just to give us a default memory allocation be fore 39 // old texture manager and is just to give us a default memory allocation be fore
38 // we get a callback from the GPU memory manager. We should probaby either: 40 // we get a callback from the GPU memory manager. We should probaby either:
39 // - wait for the callback before rendering anything instead 41 // - wait for the callback before rendering anything instead
40 // - push this into the GPU memory manager somehow. 42 // - push this into the GPU memory manager somehow.
41 static size_t defaultMemoryAllocationLimit() { return 64 * 1024 * 1024; } 43 static size_t defaultMemoryAllocationLimit() { return 64 * 1024 * 1024; }
42 44
43 // memoryUseBytes() describes the number of bytes used by existing allocated textures. 45 // memoryUseBytes() describes the number of bytes used by existing allocated textures.
44 // memoryAboveCutoffBytes() describes the number of bytes that would be used if all 46 // memoryAboveCutoffBytes() describes the number of bytes that would be used if all
45 // textures that are above the cutoff were allocated. 47 // textures that are above the cutoff were allocated.
46 // memoryUseBytes() <= memoryAboveCutoffBytes() should always be true. 48 // memoryUseBytes() <= memoryAboveCutoffBytes() should always be true.
47 size_t memoryUseBytes() const { return m_memoryUseBytes; } 49 size_t memoryUseBytes() const { return m_memoryUseBytes; }
48 size_t memoryAboveCutoffBytes() const { return m_memoryAboveCutoffBytes; } 50 size_t memoryAboveCutoffBytes() const { return m_memoryAboveCutoffBytes; }
49 size_t memoryForSelfManagedTextures() const { return m_maxMemoryLimitBytes - m_memoryAvailableBytes; } 51 size_t memoryForSelfManagedTextures() const { return m_maxMemoryLimitBytes - m_memoryAvailableBytes; }
50 52
51 void setMaxMemoryLimitBytes(size_t bytes) { m_maxMemoryLimitBytes = bytes; } 53 void setMaxMemoryLimitBytes(size_t bytes) { m_maxMemoryLimitBytes = bytes; }
52 size_t maxMemoryLimitBytes() const { return m_maxMemoryLimitBytes; } 54 size_t maxMemoryLimitBytes() const { return m_maxMemoryLimitBytes; }
53 55
54 void prioritizeTextures(); 56 void prioritizeTextures();
55 void clearPriorities(); 57 void clearPriorities();
56 58
59 void reduceMemoryOnImplThread(size_t limitBytes, CCResourceProvider*);
60 void getEvictedBackings(BackingVector& evictedBackings);
61 void unlinkEvictedBackings(const BackingVector& evictedBackings);
62 // Deletes all evicted backings, unlinking them from their owning textures i f needed.
63 // Returns true if this function to unlinked any backings from their owning texture while
64 // destroying them.
65 bool deleteEvictedBackings();
66
57 bool requestLate(CCPrioritizedTexture*); 67 bool requestLate(CCPrioritizedTexture*);
58 68
59 void reduceMemory(CCResourceProvider*); 69 void reduceMemory(CCResourceProvider*);
60 void clearAllMemory(CCResourceProvider*); 70 void clearAllMemory(CCResourceProvider*);
61 void unlinkAllBackings();
62 void deleteAllUnlinkedBackings();
63 71
64 void acquireBackingTextureIfNeeded(CCPrioritizedTexture*, CCResourceProvider *); 72 void acquireBackingTextureIfNeeded(CCPrioritizedTexture*, CCResourceProvider *);
65 73
66 void registerTexture(CCPrioritizedTexture*); 74 void registerTexture(CCPrioritizedTexture*);
67 void unregisterTexture(CCPrioritizedTexture*); 75 void unregisterTexture(CCPrioritizedTexture*);
68 void returnBackingTexture(CCPrioritizedTexture*); 76 void returnBackingTexture(CCPrioritizedTexture*);
69 77
70 #if !ASSERT_DISABLED 78 private:
71 void assertInvariants(); 79 friend class CCPrioritizedTextureTest;
72 #endif
73 80
74 private: 81 enum EvictionPriorityPolicy {
82 RespectManagerPriorityCutoff,
83 DoNotRespectManagerPriorityCutoff,
84 };
85
75 // Compare textures. Highest priority first. 86 // Compare textures. Highest priority first.
76 static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTex ture* b) 87 static inline bool compareTextures(CCPrioritizedTexture* a, CCPrioritizedTex ture* b)
77 { 88 {
78 if (a->requestPriority() == b->requestPriority()) 89 if (a->requestPriority() == b->requestPriority())
79 return a < b; 90 return a < b;
80 return CCPriorityCalculator::priorityIsHigher(a->requestPriority(), b->r equestPriority()); 91 return CCPriorityCalculator::priorityIsHigher(a->requestPriority(), b->r equestPriority());
81 } 92 }
82 // Compare backings. Lowest priority first. 93 // Compare backings. Lowest priority first.
83 static inline bool compareBackings(CCPrioritizedTexture::Backing* a, CCPrior itizedTexture::Backing* b) 94 static inline bool compareBackings(CCPrioritizedTexture::Backing* a, CCPrior itizedTexture::Backing* b)
84 { 95 {
85 int priorityA = a->owner() ? a->owner()->requestPriority() : CCPriorityC alculator::lowestPriority(); 96 int priorityA = a->requestPriorityAtLastPriorityUpdate();
86 int priorityB = b->owner() ? b->owner()->requestPriority() : CCPriorityC alculator::lowestPriority(); 97 int priorityB = b->requestPriorityAtLastPriorityUpdate();
87 if (priorityA == priorityB) 98 if (priorityA != priorityB)
88 return a < b; 99 return CCPriorityCalculator::priorityIsLower(priorityA, priorityB);
89 return CCPriorityCalculator::priorityIsLower(priorityA, priorityB); 100 bool aboveCutoffA = a->wasAbovePriorityCutoffAtLastPriorityUpdate();
101 bool aboveCutoffB = b->wasAbovePriorityCutoffAtLastPriorityUpdate();
102 if (!aboveCutoffA && aboveCutoffB)
103 return true;
104 if (aboveCutoffA && !aboveCutoffB)
105 return false;
106 return a < b;
90 } 107 }
91 108
92 CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, int pool); 109 CCPrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, int pool);
93 110
94 void reduceMemory(size_t limit, CCResourceProvider*); 111 void updateBackingsPriorities();
112 void evictBackingsToReduceMemory(size_t limitBytes, EvictionPriorityPolicy, CCResourceProvider*);
113 CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCRes ourceProvider*);
114 void evictBackingResource(CCPrioritizedTexture::Backing*, CCResourceProvider *);
95 115
96 CCPrioritizedTexture::Backing* createBacking(IntSize, GC3Denum format, CCRes ourceProvider*); 116 #if !ASSERT_DISABLED
97 void destroyBacking(CCPrioritizedTexture::Backing*, CCResourceProvider*); 117 void assertInvariants();
118 #endif
98 119
99 size_t m_maxMemoryLimitBytes; 120 size_t m_maxMemoryLimitBytes;
100 unsigned m_priorityCutoff; 121 unsigned m_priorityCutoff;
101 size_t m_memoryUseBytes; 122 size_t m_memoryUseBytes;
102 size_t m_memoryAboveCutoffBytes; 123 size_t m_memoryAboveCutoffBytes;
103 size_t m_memoryAvailableBytes; 124 size_t m_memoryAvailableBytes;
104 int m_pool; 125 int m_pool;
105 126
106 typedef HashSet<CCPrioritizedTexture*> TextureSet; 127 typedef HashSet<CCPrioritizedTexture*> TextureSet;
107 typedef ListHashSet<CCPrioritizedTexture::Backing*> BackingSet; 128 typedef ListHashSet<CCPrioritizedTexture::Backing*> BackingSet;
108 typedef Vector<CCPrioritizedTexture*> TextureVector; 129 typedef Vector<CCPrioritizedTexture*> TextureVector;
109 typedef Vector<CCPrioritizedTexture::Backing*> BackingVector;
110 130
111 TextureSet m_textures; 131 TextureSet m_textures;
112 BackingSet m_backings; 132 BackingSet m_backings;
133 BackingVector m_evictedBackings;
113 134
114 TextureVector m_tempTextureVector; 135 TextureVector m_tempTextureVector;
115 BackingVector m_tempBackingVector; 136 BackingVector m_tempBackingVector;
137
138 // Set by the main thread when it adjust priorities in such a way that
139 // the m_backings array's view of priorities is now out of date.
140 bool m_needsUpdateBackingsPrioritites;
116 }; 141 };
117 142
118 } // cc 143 } // cc
119 144
120 #endif 145 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698