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

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

Issue 815833004: Add a simpler key type for scratch resource keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: final fix Created 5 years, 11 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/GrPathRange.h ('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
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 enum { 91 enum {
92 /** Preferentially returns scratch resources with no pending IO. */ 92 /** Preferentially returns scratch resources with no pending IO. */
93 kPreferNoPendingIO_ScratchFlag = 0x1, 93 kPreferNoPendingIO_ScratchFlag = 0x1,
94 /** Will not return any resources that match but have pending IO. */ 94 /** Will not return any resources that match but have pending IO. */
95 kRequireNoPendingIO_ScratchFlag = 0x2, 95 kRequireNoPendingIO_ScratchFlag = 0x2,
96 }; 96 };
97 97
98 /** 98 /**
99 * Find a resource that matches a scratch key. 99 * Find a resource that matches a scratch key.
100 */ 100 */
101 GrGpuResource* findAndRefScratchResource(const GrResourceKey& scratchKey, ui nt32_t flags = 0); 101 GrGpuResource* findAndRefScratchResource(const GrScratchKey& scratchKey, uin t32_t flags = 0);
102 102
103 #ifdef SK_DEBUG 103 #ifdef SK_DEBUG
104 // This is not particularly fast and only used for validation, so debug only . 104 // This is not particularly fast and only used for validation, so debug only .
105 int countScratchEntriesForKey(const GrResourceKey& scratchKey) const { 105 int countScratchEntriesForKey(const GrScratchKey& scratchKey) const {
106 SkASSERT(scratchKey.isScratch());
107 return fScratchMap.countForKey(scratchKey); 106 return fScratchMap.countForKey(scratchKey);
108 } 107 }
109 #endif 108 #endif
110 109
111 /** 110 /**
112 * Find a resource that matches a content key. 111 * Find a resource that matches a content key.
113 */ 112 */
114 GrGpuResource* findAndRefContentResource(const GrResourceKey& contentKey) { 113 GrGpuResource* findAndRefContentResource(const GrResourceKey& contentKey) {
115 SkASSERT(!contentKey.isScratch());
116 GrGpuResource* resource = fContentHash.find(contentKey); 114 GrGpuResource* resource = fContentHash.find(contentKey);
117 if (resource) { 115 if (resource) {
118 resource->ref(); 116 resource->ref();
119 this->makeResourceMRU(resource); 117 this->makeResourceMRU(resource);
120 } 118 }
121 return resource; 119 return resource;
122 } 120 }
123 121
124 /** 122 /**
125 * Query whether a content key exists in the cache. 123 * Query whether a content key exists in the cache.
126 */ 124 */
127 bool hasContentKey(const GrResourceKey& contentKey) const { 125 bool hasContentKey(const GrResourceKey& contentKey) const {
128 SkASSERT(!contentKey.isScratch());
129 return SkToBool(fContentHash.find(contentKey)); 126 return SkToBool(fContentHash.find(contentKey));
130 } 127 }
131 128
132 /** Purges all resources that don't have external owners. */ 129 /** Purges all resources that don't have external owners. */
133 void purgeAllUnlocked(); 130 void purgeAllUnlocked();
134 131
135 /** 132 /**
136 * The callback function used by the cache when it is still over budget afte r a purge. The 133 * The callback function used by the cache when it is still over budget afte r a purge. The
137 * passed in 'data' is the same 'data' handed to setOverbudgetCallback. 134 * passed in 'data' is the same 'data' handed to setOverbudgetCallback.
138 */ 135 */
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 void validate() const; 177 void validate() const;
181 #else 178 #else
182 void validate() const {} 179 void validate() const {}
183 #endif 180 #endif
184 181
185 class AutoValidate; 182 class AutoValidate;
186 183
187 class AvailableForScratchUse; 184 class AvailableForScratchUse;
188 185
189 struct ScratchMapTraits { 186 struct ScratchMapTraits {
190 static const GrResourceKey& GetKey(const GrGpuResource& r) { 187 static const GrScratchKey& GetKey(const GrGpuResource& r) {
191 return r.cacheAccess().getScratchKey(); 188 return r.cacheAccess().getScratchKey();
192 } 189 }
193 190
194 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); } 191 static uint32_t Hash(const GrScratchKey& key) { return key.hash(); }
195 }; 192 };
196 typedef SkTMultiMap<GrGpuResource, GrResourceKey, ScratchMapTraits> ScratchM ap; 193 typedef SkTMultiMap<GrGpuResource, GrScratchKey, ScratchMapTraits> ScratchMa p;
197 194
198 struct ContentHashTraits { 195 struct ContentHashTraits {
199 static const GrResourceKey& GetKey(const GrGpuResource& r) { 196 static const GrResourceKey& GetKey(const GrGpuResource& r) {
200 return *r.cacheAccess().getContentKey(); 197 return *r.cacheAccess().getContentKey();
201 } 198 }
202 199
203 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); } 200 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); }
204 }; 201 };
205 typedef SkTDynamicHash<GrGpuResource, GrResourceKey, ContentHashTraits> Cont entHash; 202 typedef SkTDynamicHash<GrGpuResource, GrResourceKey, ContentHashTraits> Cont entHash;
206 203
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 295
299 friend class GrGpuResource; // To access all the proxy inline methods. 296 friend class GrGpuResource; // To access all the proxy inline methods.
300 friend class GrResourceCache2; // To create this type. 297 friend class GrResourceCache2; // To create this type.
301 }; 298 };
302 299
303 inline GrResourceCache2::ResourceAccess GrResourceCache2::resourceAccess() { 300 inline GrResourceCache2::ResourceAccess GrResourceCache2::resourceAccess() {
304 return ResourceAccess(this); 301 return ResourceAccess(this);
305 } 302 }
306 303
307 #endif 304 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrPathRange.h ('k') | src/gpu/GrResourceCache2.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698