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

Side by Side Diff: include/gpu/GrGpuResource.h

Issue 703303003: Add GrGpuResource::CacheAccess (Closed) Base URL: https://skia.googlesource.com/skia.git@nohash
Patch Set: fix warning Created 6 years, 1 month 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 | « gyp/gpu.gypi ('k') | src/gpu/GrContext.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 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrGpuResource_DEFINED 8 #ifndef GrGpuResource_DEFINED
9 #define GrGpuResource_DEFINED 9 #define GrGpuResource_DEFINED
10 10
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 /** 168 /**
169 * Retrieves the amount of GPU memory used by this resource in bytes. It is 169 * Retrieves the amount of GPU memory used by this resource in bytes. It is
170 * approximate since we aren't aware of additional padding or copies made 170 * approximate since we aren't aware of additional padding or copies made
171 * by the driver. 171 * by the driver.
172 * 172 *
173 * @return the amount of GPU memory used in bytes 173 * @return the amount of GPU memory used in bytes
174 */ 174 */
175 virtual size_t gpuMemorySize() const = 0; 175 virtual size_t gpuMemorySize() const = 0;
176 176
177 // TODO(bsalomon): Move this stuff to GrGpuResourcePriv.
178 bool setContentKey(const GrResourceKey& contentKey);
179 void setCacheEntry(GrResourceCacheEntry* cacheEntry);
180 GrResourceCacheEntry* getCacheEntry() const { return fCacheEntry; }
181 bool isScratch() const;
182 /**
183 * If this resource can be used as a scratch resource this returns a valid
184 * scratch key. Otherwise it returns a key for which isNullScratch is true.
185 * The resource may currently be used as content resource rather than scratc h.
186 * Check isScratch().
187 */
188 const GrResourceKey& getScratchKey() const { return fScratchKey; }
189 /**
190 * If this resource is currently cached by its contents then this will retur n
191 * the content key. Otherwise, NULL is returned.
192 */
193 const GrResourceKey* getContentKey() const;
194
195 /** 177 /**
196 * Gets an id that is unique for this GrGpuResource object. It is static in that it does 178 * Gets an id that is unique for this GrGpuResource object. It is static in that it does
197 * not change when the content of the GrGpuResource object changes. This wil l never return 179 * not change when the content of the GrGpuResource object changes. This wil l never return
198 * 0. 180 * 0.
199 */ 181 */
200 uint32_t getUniqueID() const { return fUniqueID; } 182 uint32_t getUniqueID() const { return fUniqueID; }
201 183
184 /**
185 * Internal-only helper class used for cache manipulations of the reosurce.
186 */
187 class CacheAccess;
188 inline CacheAccess cacheAccess();
189 inline const CacheAccess cacheAccess() const;
190
202 protected: 191 protected:
203 // This must be called by every GrGpuObject. It should be called once the ob ject is fully 192 // This must be called by every GrGpuObject. It should be called once the ob ject is fully
204 // initialized (i.e. not in a base class constructor). 193 // initialized (i.e. not in a base class constructor).
205 void registerWithCache(); 194 void registerWithCache();
206 195
207 GrGpuResource(GrGpu*, bool isWrapped); 196 GrGpuResource(GrGpu*, bool isWrapped);
208 virtual ~GrGpuResource(); 197 virtual ~GrGpuResource();
209 198
210 bool isInCache() const { return SkToBool(fCacheEntry); }
211
212 GrGpu* getGpu() const { return fGpu; } 199 GrGpu* getGpu() const { return fGpu; }
213 200
214 // Derived classes should always call their parent class' onRelease 201 // Derived classes should always call their parent class' onRelease
215 // and onAbandon methods in their overrides. 202 // and onAbandon methods in their overrides.
216 virtual void onRelease() {}; 203 virtual void onRelease() {};
217 virtual void onAbandon() {}; 204 virtual void onAbandon() {};
218 205
219 bool isWrapped() const { return kWrapped_FlagBit & fFlags; } 206 bool isWrapped() const { return kWrapped_FlagBit & fFlags; }
220 207
221 /** 208 /**
222 * This entry point should be called whenever gpuMemorySize() begins 209 * This entry point should be called whenever gpuMemorySize() begins
223 * reporting a different size. If the object is in the cache, it will call 210 * reporting a different size. If the object is in the cache, it will call
224 * gpuMemorySize() immediately and pass the new size on to the resource 211 * gpuMemorySize() immediately and pass the new size on to the resource
225 * cache. 212 * cache.
226 */ 213 */
227 void didChangeGpuMemorySize() const; 214 void didChangeGpuMemorySize() const;
228 215
229 /** 216 /**
230 * Optionally called by the GrGpuResource subclass if the resource can be us ed as scratch. 217 * Optionally called by the GrGpuResource subclass if the resource can be us ed as scratch.
231 * By default resources are not usable as scratch. This should only be calle d once. 218 * By default resources are not usable as scratch. This should only be calle d once.
232 **/ 219 **/
233 void setScratchKey(const GrResourceKey& scratchKey); 220 void setScratchKey(const GrResourceKey& scratchKey);
234 221
235 private: 222 private:
223 // See comments in CacheAccess.
224 bool setContentKey(const GrResourceKey& contentKey);
225
236 void notifyIsPurgable() const; 226 void notifyIsPurgable() const;
237 227
238 #ifdef SK_DEBUG 228 #ifdef SK_DEBUG
239 friend class GrGpu; // for assert in GrGpu to access getGpu 229 friend class GrGpu; // for assert in GrGpu to access getGpu
240 #endif 230 #endif
241 231
242 static uint32_t CreateUniqueID(); 232 static uint32_t CreateUniqueID();
243 233
244 // We're in an internal doubly linked list owned by GrResourceCache2 234 // We're in an internal doubly linked list owned by GrResourceCache2
245 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); 235 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource);
(...skipping 20 matching lines...) Expand all
266 // keys. 256 // keys.
267 GrResourceKey fScratchKey; 257 GrResourceKey fScratchKey;
268 GrResourceKey fContentKey; 258 GrResourceKey fContentKey;
269 bool fContentKeySet; 259 bool fContentKeySet;
270 260
271 typedef GrIORef<GrGpuResource> INHERITED; 261 typedef GrIORef<GrGpuResource> INHERITED;
272 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. 262 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable.
273 }; 263 };
274 264
275 #endif 265 #endif
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698