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

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

Issue 846303002: Make uncached textures uncached from the get go. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 template <typename, GrIOType> friend class GrPendingIOResource; 118 template <typename, GrIOType> friend class GrPendingIOResource;
119 }; 119 };
120 120
121 /** 121 /**
122 * Base class for objects that can be kept in the GrResourceCache2. 122 * Base class for objects that can be kept in the GrResourceCache2.
123 */ 123 */
124 class SK_API GrGpuResource : public GrIORef<GrGpuResource> { 124 class SK_API GrGpuResource : public GrIORef<GrGpuResource> {
125 public: 125 public:
126 SK_DECLARE_INST_COUNT(GrGpuResource) 126 SK_DECLARE_INST_COUNT(GrGpuResource)
127 127
128 enum LifeCycle {
129 /**
130 * The resource is cached and owned by Skia. Resources with this status may be kept alive
131 * by the cache as either scratch or content resources even when there a re no refs to them.
132 * The cache may release them whenever there are no refs.
133 */
134 kCached_LifeCycle,
robertphillips 2015/01/14 16:42:59 Don't we reserve the right to recycle uncached if
bsalomon 2015/01/14 18:32:03 Yeah, I'll add a comment to that effect.
135 /**
136 * The resource is uncached. As soon as there are no more refs to it, it is released.
137 */
138 kUncached_LifeCycle,
139 /**
140 * Similar to uncached, but Skia does not manage the lifetime of the und erlying backend
141 * 3D API object(s). The client is responsible for freeing those. Used t o inject client-
142 * created GPU resources into Skia (e.g. to render to a client-created t exture).
143 */
144 kWrapped_LifeCycle,
145 };
146
128 /** 147 /**
129 * Tests whether a object has been abandoned or released. All objects will 148 * Tests whether a object has been abandoned or released. All objects will
130 * be in this state after their creating GrContext is destroyed or has 149 * be in this state after their creating GrContext is destroyed or has
131 * contextLost called. It's up to the client to test wasDestroyed() before 150 * contextLost called. It's up to the client to test wasDestroyed() before
132 * attempting to use an object if it holds refs on objects across 151 * attempting to use an object if it holds refs on objects across
133 * ~GrContext, freeResources with the force flag, or contextLost. 152 * ~GrContext, freeResources with the force flag, or contextLost.
134 * 153 *
135 * @return true if the object has been released or abandoned, 154 * @return true if the object has been released or abandoned,
136 * false otherwise. 155 * false otherwise.
137 */ 156 */
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 * when a texture becomes unsafe to use after having been shared through 216 * when a texture becomes unsafe to use after having been shared through
198 * a texture mailbox. 217 * a texture mailbox.
199 */ 218 */
200 void abandon(); 219 void abandon();
201 220
202 protected: 221 protected:
203 // This must be called by every GrGpuObject. It should be called once the ob ject is fully 222 // 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). 223 // initialized (i.e. not in a base class constructor).
205 void registerWithCache(); 224 void registerWithCache();
206 225
207 GrGpuResource(GrGpu*, bool isWrapped); 226 GrGpuResource(GrGpu*, LifeCycle);
208 virtual ~GrGpuResource(); 227 virtual ~GrGpuResource();
209 228
210 GrGpu* getGpu() const { return fGpu; } 229 GrGpu* getGpu() const { return fGpu; }
211 230
212 /** Overridden to free GPU resources in the backend API. */ 231 /** Overridden to free GPU resources in the backend API. */
213 virtual void onRelease() { } 232 virtual void onRelease() { }
214 /** Overridden to abandon any internal handles, ptrs, etc to backend API res ources. 233 /** Overridden to abandon any internal handles, ptrs, etc to backend API res ources.
215 This may be called when the underlying 3D context is no longer valid and so no 234 This may be called when the underlying 3D context is no longer valid and so no
216 backend API calls should be made. */ 235 backend API calls should be made. */
217 virtual void onAbandon() { } 236 virtual void onAbandon() { }
218 237
219 bool isWrapped() const { return SkToBool(kWrapped_Flag & fFlags); } 238 bool isWrapped() const { return kWrapped_LifeCycle == fLifeCycle; }
220 239
221 /** 240 /**
222 * This entry point should be called whenever gpuMemorySize() should report a different size. 241 * This entry point should be called whenever gpuMemorySize() should report a different size.
223 * The cache will call gpuMemorySize() to update the current size of the res ource. 242 * The cache will call gpuMemorySize() to update the current size of the res ource.
224 */ 243 */
225 void didChangeGpuMemorySize() const; 244 void didChangeGpuMemorySize() const;
226 245
227 /** 246 /**
228 * Optionally called by the GrGpuResource subclass if the resource can be us ed as scratch. 247 * Optionally called by the GrGpuResource subclass if the resource can be us ed as scratch.
229 * By default resources are not usable as scratch. This should only be calle d once. 248 * By default resources are not usable as scratch. This should only be calle d once.
230 **/ 249 **/
231 void setScratchKey(const GrScratchKey& scratchKey); 250 void setScratchKey(const GrScratchKey& scratchKey);
232 251
233 private: 252 private:
234 /** 253 /**
235 * Frees the object in the underlying 3D API. Called by CacheAccess. 254 * Frees the object in the underlying 3D API. Called by CacheAccess.
236 */ 255 */
237 void release(); 256 void release();
238 257
239 virtual size_t onGpuMemorySize() const = 0; 258 virtual size_t onGpuMemorySize() const = 0;
240 259
241 // See comments in CacheAccess. 260 // See comments in CacheAccess.
242 bool setContentKey(const GrResourceKey& contentKey); 261 bool setContentKey(const GrResourceKey& contentKey);
243 void setBudgeted(bool countsAgainstBudget);
244 void notifyIsPurgable() const; 262 void notifyIsPurgable() const;
245 void removeScratchKey(); 263 void removeScratchKey();
246 264
247 #ifdef SK_DEBUG 265 #ifdef SK_DEBUG
248 friend class GrGpu; // for assert in GrGpu to access getGpu 266 friend class GrGpu; // for assert in GrGpu to access getGpu
249 #endif 267 #endif
250 268
251 static uint32_t CreateUniqueID(); 269 static uint32_t CreateUniqueID();
252 270
253 // We're in an internal doubly linked list owned by GrResourceCache2 271 // We're in an internal doubly linked list owned by GrResourceCache2
254 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); 272 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource);
255 273
256 274
257 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); 275 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
258 enum Flags { 276 enum Flags {
259 /** 277 /**
260 * The resource counts against the resource cache's budget.
261 */
262 kBudgeted_Flag = 0x1,
263
264 /**
265 * This object wraps a GPU object given to us by Skia's client. Skia wil l not free the
266 * underlying backend API GPU resources when the GrGpuResource is destro yed. This also
267 * implies that kBudgeted_Flag is not set.
268 */
269 kWrapped_Flag = 0x2,
270
271 /**
272 * If set then fContentKey is valid and the resource is cached based on its content. 278 * If set then fContentKey is valid and the resource is cached based on its content.
273 */ 279 */
274 kContentKeySet_Flag = 0x4, 280 kContentKeySet_Flag = 0x1,
275 }; 281 };
276 282
277 GrScratchKey fScratchKey; 283 GrScratchKey fScratchKey;
278 // TODO(bsalomon): Remove GrResourceKey and use different simpler type for c ontent keys. 284 // TODO(bsalomon): Remove GrResourceKey and use different simpler type for c ontent keys.
279 GrResourceKey fContentKey; 285 GrResourceKey fContentKey;
280 286
281 // This is not ref'ed but abandon() or release() will be called before the G rGpu object 287 // This is not ref'ed but abandon() or release() will be called before the G rGpu object
282 // is destroyed. Those calls set will this to NULL. 288 // is destroyed. Those calls set will this to NULL.
283 GrGpu* fGpu; 289 GrGpu* fGpu;
284 mutable size_t fGpuMemorySize; 290 mutable size_t fGpuMemorySize;
285 291
286 uint32_t fFlags; 292 uint32_t fFlags;
293 LifeCycle fLifeCycle;
287 const uint32_t fUniqueID; 294 const uint32_t fUniqueID;
288 295
289 SkAutoTUnref<const SkData> fData; 296 SkAutoTUnref<const SkData> fData;
290 297
291 typedef GrIORef<GrGpuResource> INHERITED; 298 typedef GrIORef<GrGpuResource> INHERITED;
292 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable. 299 friend class GrIORef<GrGpuResource>; // to access notifyIsPurgable.
293 }; 300 };
294 301
295 #endif 302 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698