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

Side by Side Diff: src/gpu/GrResourceCache2.h

Issue 902873002: Reimplement gpu message bus for invalidated bitmap gen IDs (Closed) Base URL: https://skia.googlesource.com/skia.git@one_tex
Patch Set: fix speeling error Created 5 years, 10 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
« no previous file with comments | « src/gpu/GrLayerCache.cpp ('k') | src/gpu/GrResourceCache2.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #ifndef GrResourceCache2_DEFINED 9 #ifndef GrResourceCache2_DEFINED
10 #define GrResourceCache2_DEFINED 10 #define GrResourceCache2_DEFINED
11 11
12 #include "GrGpuResource.h" 12 #include "GrGpuResource.h"
13 #include "GrGpuResourceCacheAccess.h" 13 #include "GrGpuResourceCacheAccess.h"
14 #include "GrResourceKey.h" 14 #include "GrResourceKey.h"
15 #include "SkMessageBus.h"
15 #include "SkRefCnt.h" 16 #include "SkRefCnt.h"
17 #include "SkTArray.h"
16 #include "SkTInternalLList.h" 18 #include "SkTInternalLList.h"
17 #include "SkTMultiMap.h" 19 #include "SkTMultiMap.h"
18 20
19 class SkString; 21 class SkString;
20 22
21 /** 23 /**
22 * Manages the lifetime of all GrGpuResource instances. 24 * Manages the lifetime of all GrGpuResource instances.
23 * 25 *
24 * Resources may have optionally have two types of keys: 26 * Resources may have optionally have two types of keys:
25 * 1) A scratch key. This is for resources whose allocations are cached but not their contents. 27 * 1) A scratch key. This is for resources whose allocations are cached but not their contents.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 return resource; 123 return resource;
122 } 124 }
123 125
124 /** 126 /**
125 * Query whether a content key exists in the cache. 127 * Query whether a content key exists in the cache.
126 */ 128 */
127 bool hasContentKey(const GrContentKey& contentKey) const { 129 bool hasContentKey(const GrContentKey& contentKey) const {
128 return SkToBool(fContentHash.find(contentKey)); 130 return SkToBool(fContentHash.find(contentKey));
129 } 131 }
130 132
133 /** Purges resources to become under budget and processes resources with inv alidated content
134 keys. */
135 void purgeAsNeeded() {
136 SkTArray<GrContentKeyInvalidatedMessage> invalidKeyMsgs;
137 fInvalidContentKeyInbox.poll(&invalidKeyMsgs);
138 if (invalidKeyMsgs.count()) {
139 this->processInvalidContentKeys(invalidKeyMsgs);
140 }
141 if (fPurging || (fBudgetedCount <= fMaxCount && fBudgetedBytes <= fMaxBy tes)) {
142 return;
143 }
144 this->internalPurgeAsNeeded();
145 }
146
131 /** Purges all resources that don't have external owners. */ 147 /** Purges all resources that don't have external owners. */
132 void purgeAllUnlocked(); 148 void purgeAllUnlocked();
133 149
134 /** 150 /**
135 * The callback function used by the cache when it is still over budget afte r a purge. The 151 * The callback function used by the cache when it is still over budget afte r a purge. The
136 * passed in 'data' is the same 'data' handed to setOverbudgetCallback. 152 * passed in 'data' is the same 'data' handed to setOverbudgetCallback.
137 */ 153 */
138 typedef void (*PFOverBudgetCB)(void* data); 154 typedef void (*PFOverBudgetCB)(void* data);
139 155
140 /** 156 /**
(...skipping 13 matching lines...) Expand all
154 private: 170 private:
155 /////////////////////////////////////////////////////////////////////////// 171 ///////////////////////////////////////////////////////////////////////////
156 /// @name Methods accessible via ResourceAccess 172 /// @name Methods accessible via ResourceAccess
157 //// 173 ////
158 void insertResource(GrGpuResource*); 174 void insertResource(GrGpuResource*);
159 void removeResource(GrGpuResource*); 175 void removeResource(GrGpuResource*);
160 void notifyPurgeable(GrGpuResource*); 176 void notifyPurgeable(GrGpuResource*);
161 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize); 177 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize);
162 bool didSetContentKey(GrGpuResource*); 178 bool didSetContentKey(GrGpuResource*);
163 void willRemoveScratchKey(const GrGpuResource*); 179 void willRemoveScratchKey(const GrGpuResource*);
180 void willRemoveContentKey(const GrGpuResource*);
164 void didChangeBudgetStatus(GrGpuResource*); 181 void didChangeBudgetStatus(GrGpuResource*);
165 void makeResourceMRU(GrGpuResource*); 182 void makeResourceMRU(GrGpuResource*);
166 /// @} 183 /// @}
167 184
168 void purgeAsNeeded() {
169 if (fPurging || (fBudgetedCount <= fMaxCount && fBudgetedBytes <= fMaxBy tes)) {
170 return;
171 }
172 this->internalPurgeAsNeeded();
173 }
174
175 void internalPurgeAsNeeded(); 185 void internalPurgeAsNeeded();
186 void processInvalidContentKeys(const SkTArray<GrContentKeyInvalidatedMessage >&);
176 187
177 #ifdef SK_DEBUG 188 #ifdef SK_DEBUG
178 bool isInCache(const GrGpuResource* r) const { return fResources.isInList(r) ; } 189 bool isInCache(const GrGpuResource* r) const { return fResources.isInList(r) ; }
179 void validate() const; 190 void validate() const;
180 #else 191 #else
181 void validate() const {} 192 void validate() const {}
182 #endif 193 #endif
183 194
184 class AutoValidate; 195 class AutoValidate;
185 196
(...skipping 12 matching lines...) Expand all
198 static const GrContentKey& GetKey(const GrGpuResource& r) { 209 static const GrContentKey& GetKey(const GrGpuResource& r) {
199 return r.getContentKey(); 210 return r.getContentKey();
200 } 211 }
201 212
202 static uint32_t Hash(const GrContentKey& key) { return key.hash(); } 213 static uint32_t Hash(const GrContentKey& key) { return key.hash(); }
203 }; 214 };
204 typedef SkTDynamicHash<GrGpuResource, GrContentKey, ContentHashTraits> Conte ntHash; 215 typedef SkTDynamicHash<GrGpuResource, GrContentKey, ContentHashTraits> Conte ntHash;
205 216
206 typedef SkTInternalLList<GrGpuResource> ResourceList; 217 typedef SkTInternalLList<GrGpuResource> ResourceList;
207 218
219 typedef SkMessageBus<GrContentKeyInvalidatedMessage>::Inbox InvalidContentKe yInbox;
220
208 ResourceList fResources; 221 ResourceList fResources;
209 // This map holds all resources that can be used as scratch resources. 222 // This map holds all resources that can be used as scratch resources.
210 ScratchMap fScratchMap; 223 ScratchMap fScratchMap;
211 // This holds all resources that have content keys. 224 // This holds all resources that have content keys.
212 ContentHash fContentHash; 225 ContentHash fContentHash;
213 226
214 // our budget, used in purgeAsNeeded() 227 // our budget, used in purgeAsNeeded()
215 int fMaxCount; 228 int fMaxCount;
216 size_t fMaxBytes; 229 size_t fMaxBytes;
217 230
(...skipping 12 matching lines...) Expand all
230 int fBudgetedCount; 243 int fBudgetedCount;
231 size_t fBudgetedBytes; 244 size_t fBudgetedBytes;
232 245
233 // prevents recursive purging 246 // prevents recursive purging
234 bool fPurging; 247 bool fPurging;
235 bool fNewlyPurgeableResourceWhilePurging; 248 bool fNewlyPurgeableResourceWhilePurging;
236 249
237 PFOverBudgetCB fOverBudgetCB; 250 PFOverBudgetCB fOverBudgetCB;
238 void* fOverBudgetData; 251 void* fOverBudgetData;
239 252
253 InvalidContentKeyInbox fInvalidContentKeyInbox;
254
240 }; 255 };
241 256
242 class GrResourceCache2::ResourceAccess { 257 class GrResourceCache2::ResourceAccess {
243 private: 258 private:
244 ResourceAccess(GrResourceCache2* cache) : fCache(cache) { } 259 ResourceAccess(GrResourceCache2* cache) : fCache(cache) { }
245 ResourceAccess(const ResourceAccess& that) : fCache(that.fCache) { } 260 ResourceAccess(const ResourceAccess& that) : fCache(that.fCache) { }
246 ResourceAccess& operator=(const ResourceAccess&); // unimpl 261 ResourceAccess& operator=(const ResourceAccess&); // unimpl
247 262
248 /** 263 /**
249 * Insert a resource into the cache. 264 * Insert a resource into the cache.
(...skipping 21 matching lines...) Expand all
271 * Called by GrGpuResources when their content keys change. 286 * Called by GrGpuResources when their content keys change.
272 * 287 *
273 * This currently returns a bool and fails when an existing resource has a k ey that collides 288 * This currently returns a bool and fails when an existing resource has a k ey that collides
274 * with the new content key. In the future it will null out the content key for the existing 289 * with the new content key. In the future it will null out the content key for the existing
275 * resource. The failure is a temporary measure taken because duties are spl it between two 290 * resource. The failure is a temporary measure taken because duties are spl it between two
276 * cache objects currently. 291 * cache objects currently.
277 */ 292 */
278 bool didSetContentKey(GrGpuResource* resource) { return fCache->didSetConten tKey(resource); } 293 bool didSetContentKey(GrGpuResource* resource) { return fCache->didSetConten tKey(resource); }
279 294
280 /** 295 /**
281 * Called by GrGpuResources when the remove their scratch key. 296 * Called by a GrGpuResource when it removes its content key.
297 */
298 void willRemoveContentKey(GrGpuResource* resource) {
299 return fCache->willRemoveContentKey(resource);
300 }
301
302 /**
303 * Called by a GrGpuResource when it removes its scratch key.
282 */ 304 */
283 void willRemoveScratchKey(const GrGpuResource* resource) { 305 void willRemoveScratchKey(const GrGpuResource* resource) {
284 fCache->willRemoveScratchKey(resource); 306 fCache->willRemoveScratchKey(resource);
285 } 307 }
286 308
287 /** 309 /**
288 * Called by GrGpuResources when they change from budgeted to unbudgeted or vice versa. 310 * Called by GrGpuResources when they change from budgeted to unbudgeted or vice versa.
289 */ 311 */
290 void didChangeBudgetStatus(GrGpuResource* resource) { fCache->didChangeBudge tStatus(resource); } 312 void didChangeBudgetStatus(GrGpuResource* resource) { fCache->didChangeBudge tStatus(resource); }
291 313
292 // No taking addresses of this type. 314 // No taking addresses of this type.
293 const ResourceAccess* operator&() const; 315 const ResourceAccess* operator&() const;
294 ResourceAccess* operator&(); 316 ResourceAccess* operator&();
295 317
296 GrResourceCache2* fCache; 318 GrResourceCache2* fCache;
297 319
298 friend class GrGpuResource; // To access all the proxy inline methods. 320 friend class GrGpuResource; // To access all the proxy inline methods.
299 friend class GrResourceCache2; // To create this type. 321 friend class GrResourceCache2; // To create this type.
300 }; 322 };
301 323
302 inline GrResourceCache2::ResourceAccess GrResourceCache2::resourceAccess() { 324 inline GrResourceCache2::ResourceAccess GrResourceCache2::resourceAccess() {
303 return ResourceAccess(this); 325 return ResourceAccess(this);
304 } 326 }
305 327
306 #endif 328 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrLayerCache.cpp ('k') | src/gpu/GrResourceCache2.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698