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

Side by Side Diff: cc/prioritized_resource_manager.h

Issue 11411251: Use a lock to deal with concurrent access to the m_evictedBackings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 CC_PRIORITIZED_RESOURCE_MANAGER_H_ 5 #ifndef CC_PRIORITIZED_RESOURCE_MANAGER_H_
6 #define CC_PRIORITIZED_RESOURCE_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 "base/synchronization/lock.h"
14 #include "cc/cc_export.h" 15 #include "cc/cc_export.h"
15 #include "cc/proxy.h" 16 #include "cc/proxy.h"
16 #include "cc/prioritized_resource.h" 17 #include "cc/prioritized_resource.h"
17 #include "cc/priority_calculator.h" 18 #include "cc/priority_calculator.h"
18 #include "cc/resource.h" 19 #include "cc/resource.h"
19 #include "third_party/khronos/GLES2/gl2.h" 20 #include "third_party/khronos/GLES2/gl2.h"
20 #include "ui/gfx/size.h" 21 #include "ui/gfx/size.h"
21 22
22 #if defined(COMPILER_GCC) 23 #if defined(COMPILER_GCC)
23 namespace BASE_HASH_NAMESPACE { 24 namespace BASE_HASH_NAMESPACE {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 size_t memoryVisibleBytes() const; 76 size_t memoryVisibleBytes() const;
76 size_t memoryVisibleAndNearbyBytes() const; 77 size_t memoryVisibleAndNearbyBytes() const;
77 78
78 void prioritizeTextures(); 79 void prioritizeTextures();
79 void clearPriorities(); 80 void clearPriorities();
80 81
81 // Delete contents textures' backing resources until they use only bytesLimi t bytes. This may 82 // Delete contents textures' backing resources until they use only bytesLimi t bytes. This may
82 // be called on the impl thread while the main thread is running. Returns tr ue if resources are 83 // be called on the impl thread while the main thread is running. Returns tr ue if resources are
83 // indeed evicted as a result of this call. 84 // indeed evicted as a result of this call.
84 bool reduceMemoryOnImplThread(size_t limitBytes, int priorityCutoff, Resourc eProvider*); 85 bool reduceMemoryOnImplThread(size_t limitBytes, int priorityCutoff, Resourc eProvider*);
86
85 // Returns true if there exist any textures that are linked to backings that have had their 87 // Returns true if there exist any textures that are linked to backings that have had their
86 // resources evicted. Only when we commit a tree that has no textures linked to evicted backings 88 // resources evicted. Only when we commit a tree that has no textures linked to evicted backings
87 // may we allow drawing. 89 // may we allow drawing. After an eviction, this will not become true until
88 bool linkedEvictedBackingsExist() const; 90 // unlinkAndClearEvictedBackings is called.
89 // Retrieve the list of all contents textures' backings that have been evict ed, to pass to the 91 bool linkedEvictedBackingsExist();
90 // main thread to unlink them from their owning textures. 92
91 void getEvictedBackings(BackingList& evictedBackings); 93 // Unlink the list of contents textures' backings from their owning textures and delete the evicted
92 // Unlink the list of contents textures' backings from their owning textures on the main thread 94 // backings' structures. This is called just before updating layers.
93 // before updating layers. 95 void unlinkAndClearEvictedBackings();
jamesr 2012/11/29 22:06:16 You should document that this can be called from m
piman 2012/11/29 22:24:09 Wait, this should only be called from the main thr
ccameron 2012/11/29 22:25:35 This one can only be called on the main thread --
94 void unlinkEvictedBackings(const BackingList& evictedBackings);
95 96
96 bool requestLate(PrioritizedResource*); 97 bool requestLate(PrioritizedResource*);
97 98
98 void reduceMemory(ResourceProvider*); 99 void reduceMemory(ResourceProvider*);
99 void clearAllMemory(ResourceProvider*); 100 void clearAllMemory(ResourceProvider*);
100 101
101 void acquireBackingTextureIfNeeded(PrioritizedResource*, ResourceProvider*); 102 void acquireBackingTextureIfNeeded(PrioritizedResource*, ResourceProvider*);
102 103
103 void registerTexture(PrioritizedResource*); 104 void registerTexture(PrioritizedResource*);
104 void unregisterTexture(PrioritizedResource*); 105 void unregisterTexture(PrioritizedResource*);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 153
153 PrioritizedResourceManager(int pool, const Proxy* proxy); 154 PrioritizedResourceManager(int pool, const Proxy* proxy);
154 155
155 bool evictBackingsToReduceMemory(size_t limitBytes, 156 bool evictBackingsToReduceMemory(size_t limitBytes,
156 int priorityCutoff, 157 int priorityCutoff,
157 EvictionPolicy, 158 EvictionPolicy,
158 UnlinkPolicy, 159 UnlinkPolicy,
159 ResourceProvider*); 160 ResourceProvider*);
160 PrioritizedResource::Backing* createBacking(gfx::Size, GLenum format, Resour ceProvider*); 161 PrioritizedResource::Backing* createBacking(gfx::Size, GLenum format, Resour ceProvider*);
161 void evictFirstBackingResource(ResourceProvider*); 162 void evictFirstBackingResource(ResourceProvider*);
162 void deleteAllEvictedBackings();
163 void sortBackings(); 163 void sortBackings();
164 164
165 void assertInvariants(); 165 void assertInvariants();
166 166
167 size_t m_maxMemoryLimitBytes; 167 size_t m_maxMemoryLimitBytes;
168 // The priority cutoff based on memory pressure. This is not a strict 168 // The priority cutoff based on memory pressure. This is not a strict
169 // cutoff -- requestLate allows textures with priority equal to this 169 // cutoff -- requestLate allows textures with priority equal to this
170 // cutoff to be allowed. 170 // cutoff to be allowed.
171 int m_priorityCutoff; 171 int m_priorityCutoff;
172 // The priority cutoff based on external memory policy. This is a strict 172 // The priority cutoff based on external memory policy. This is a strict
173 // cutoff -- no textures with priority equal to this cutoff will be allowed. 173 // cutoff -- no textures with priority equal to this cutoff will be allowed.
174 int m_externalPriorityCutoff; 174 int m_externalPriorityCutoff;
175 size_t m_memoryUseBytes; 175 size_t m_memoryUseBytes;
176 size_t m_memoryAboveCutoffBytes; 176 size_t m_memoryAboveCutoffBytes;
177 size_t m_memoryAvailableBytes; 177 size_t m_memoryAvailableBytes;
178 int m_pool; 178 int m_pool;
179 179
180 typedef base::hash_set<PrioritizedResource*> TextureSet; 180 typedef base::hash_set<PrioritizedResource*> TextureSet;
181 typedef std::vector<PrioritizedResource*> TextureVector; 181 typedef std::vector<PrioritizedResource*> TextureVector;
182 182
183 const Proxy* m_proxy; 183 const Proxy* m_proxy;
184 184
185 TextureSet m_textures; 185 TextureSet m_textures;
186 // This list is always sorted in eviction order, with the exception the 186 // This list is always sorted in eviction order, with the exception the
187 // newly-allocated or recycled textures at the very end of the tail that 187 // newly-allocated or recycled textures at the very end of the tail that
188 // are not sorted by priority. 188 // are not sorted by priority.
189 BackingList m_backings; 189 BackingList m_backings;
190 bool m_backingsTailNotSorted; 190 bool m_backingsTailNotSorted;
191
192 // The list of backings that have been evicted, but may still be linked
193 // to textures. This can be accessed concurrently by the main and impl
194 // threads, and may only be accessed while holding m_evictedBackingsLock.
191 BackingList m_evictedBackings; 195 BackingList m_evictedBackings;
196 base::Lock m_evictedBackingsLock;
192 197
193 TextureVector m_tempTextureVector; 198 TextureVector m_tempTextureVector;
194 199
195 // Statistics about memory usage at priority cutoffs, computed at prioritize Textures. 200 // Statistics about memory usage at priority cutoffs, computed at prioritize Textures.
196 size_t m_memoryVisibleBytes; 201 size_t m_memoryVisibleBytes;
197 size_t m_memoryVisibleAndNearbyBytes; 202 size_t m_memoryVisibleAndNearbyBytes;
198 203
199 // Statistics copied at the time of pushTexturePrioritiesToBackings. 204 // Statistics copied at the time of pushTexturePrioritiesToBackings.
200 size_t m_memoryVisibleLastPushedBytes; 205 size_t m_memoryVisibleLastPushedBytes;
201 size_t m_memoryVisibleAndNearbyLastPushedBytes; 206 size_t m_memoryVisibleAndNearbyLastPushedBytes;
202 207
203 DISALLOW_COPY_AND_ASSIGN(PrioritizedResourceManager); 208 DISALLOW_COPY_AND_ASSIGN(PrioritizedResourceManager);
204 }; 209 };
205 210
206 } // namespace cc 211 } // namespace cc
207 212
208 #endif // CC_PRIORITIZED_RESOURCE_MANAGER_H_ 213 #endif // CC_PRIORITIZED_RESOURCE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698