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

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

Issue 721353002: Allow GPU resources to not be counted against the cache budget. (Closed) Base URL: https://skia.googlesource.com/skia.git@wrap
Patch Set: fix constructor order 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 | « no previous file | 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 184
185 GrGpu* getGpu() const { return fGpu; } 185 GrGpu* getGpu() const { return fGpu; }
186 186
187 /** Overridden to free GPU resources in the backend API. */ 187 /** Overridden to free GPU resources in the backend API. */
188 virtual void onRelease() { } 188 virtual void onRelease() { }
189 /** Overridden to abandon any internal handles, ptrs, etc to backend API res ources. 189 /** Overridden to abandon any internal handles, ptrs, etc to backend API res ources.
190 This may be called when the underlying 3D context is no longer valid and so no 190 This may be called when the underlying 3D context is no longer valid and so no
191 backend API calls should be made. */ 191 backend API calls should be made. */
192 virtual void onAbandon() { } 192 virtual void onAbandon() { }
193 193
194 bool isWrapped() const { return kWrapped_FlagBit & fFlags; } 194 bool isWrapped() const { return SkToBool(kWrapped_Flag & fFlags); }
195 195
196 /** 196 /**
197 * This entry point should be called whenever gpuMemorySize() should report a different size. 197 * This entry point should be called whenever gpuMemorySize() should report a different size.
198 * The cache will call gpuMemorySize() to update the current size of the res ource. 198 * The cache will call gpuMemorySize() to update the current size of the res ource.
199 */ 199 */
200 void didChangeGpuMemorySize() const; 200 void didChangeGpuMemorySize() const;
201 201
202 /** 202 /**
203 * Optionally called by the GrGpuResource subclass if the resource can be us ed as scratch. 203 * Optionally called by the GrGpuResource subclass if the resource can be us ed as scratch.
204 * By default resources are not usable as scratch. This should only be calle d once. 204 * By default resources are not usable as scratch. This should only be calle d once.
205 **/ 205 **/
206 void setScratchKey(const GrResourceKey& scratchKey); 206 void setScratchKey(const GrResourceKey& scratchKey);
207 207
208 private: 208 private:
209 /** 209 /**
210 * Frees the object in the underlying 3D API. Called by CacheAccess. 210 * Frees the object in the underlying 3D API. Called by CacheAccess.
211 */ 211 */
212 void release(); 212 void release();
213 213
214 /** 214 /**
215 * Removes references to objects in the underlying 3D API without freeing th em. 215 * Removes references to objects in the underlying 3D API without freeing th em.
216 * Called by CacheAccess. 216 * Called by CacheAccess.
217 */ 217 */
218 void abandon(); 218 void abandon();
219 219
220 virtual size_t onGpuMemorySize() const = 0; 220 virtual size_t onGpuMemorySize() const = 0;
221 221
222 // See comments in CacheAccess. 222 // See comments in CacheAccess.
223 bool setContentKey(const GrResourceKey& contentKey); 223 bool setContentKey(const GrResourceKey& contentKey);
224 224 void setBudgeted(bool countsAgainstBudget);
225 void notifyIsPurgable() const; 225 void notifyIsPurgable() const;
226 226
227 #ifdef SK_DEBUG 227 #ifdef SK_DEBUG
228 friend class GrGpu; // for assert in GrGpu to access getGpu 228 friend class GrGpu; // for assert in GrGpu to access getGpu
229 #endif 229 #endif
230 230
231 static uint32_t CreateUniqueID(); 231 static uint32_t CreateUniqueID();
232 232
233 // We're in an internal doubly linked list owned by GrResourceCache2 233 // We're in an internal doubly linked list owned by GrResourceCache2
234 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); 234 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource);
235 235
236 // This is not ref'ed but abandon() or release() will be called before the G rGpu object
237 // is destroyed. Those calls set will this to NULL.
238 GrGpu* fGpu;
239 236
237 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
240 enum Flags { 238 enum Flags {
241 /** 239 /**
242 * This object wraps a GPU object given to us by the user. 240 * The resource counts against the resource cache's budget.
243 * Lifetime management is left up to the user (i.e., we will not
244 * free it).
245 */ 241 */
246 kWrapped_FlagBit = 0x1, 242 kBudgeted_Flag = 0x1,
243
244 /**
245 * This object wraps a GPU object given to us by Skia's client. Skia wil l not free the
246 * underlying backend API GPU resources when the GrGpuResource is destro yed. This also
247 * implies that kBudgeted_Flag is not set.
248 */
249 kWrapped_Flag = 0x2,
250
251 /**
252 * If set then fContentKey is valid and the resource is cached based on its content.
253 */
254 kContentKeySet_Flag = 0x4,
247 }; 255 };
248 256
249 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
250
251 uint32_t fFlags;
252
253 mutable size_t fGpuMemorySize;
254 const uint32_t fUniqueID;
255
256 // TODO(bsalomon): Remove GrResourceKey and use different simpler types for content and scratch 257 // TODO(bsalomon): Remove GrResourceKey and use different simpler types for content and scratch
257 // keys. 258 // keys.
258 GrResourceKey fScratchKey; 259 GrResourceKey fScratchKey;
259 GrResourceKey fContentKey; 260 GrResourceKey fContentKey;
260 bool fContentKeySet; 261
262 // This is not ref'ed but abandon() or release() will be called before the G rGpu object
263 // is destroyed. Those calls set will this to NULL.
264 GrGpu* fGpu;
265 mutable size_t fGpuMemorySize;
266
267 uint32_t fFlags;
268 const uint32_t fUniqueID;
261 269
262 typedef GrIORef<GrGpuResource> INHERITED; 270 typedef GrIORef<GrGpuResource> INHERITED;
263 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. 271 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable.
264 }; 272 };
265 273
266 #endif 274 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698