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

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

Issue 1187523005: Add support for creating texture backed images where Skia will delete the texture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add default param to support Chrome's current callers Created 5 years, 6 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 | « include/core/SkImage.h ('k') | include/gpu/GrTextureProvider.h » ('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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 public: 143 public:
144 SK_DECLARE_INST_COUNT(GrGpuResource) 144 SK_DECLARE_INST_COUNT(GrGpuResource)
145 145
146 enum LifeCycle { 146 enum LifeCycle {
147 /** 147 /**
148 * The resource is cached and owned by Skia. Resources with this status may be kept alive 148 * The resource is cached and owned by Skia. Resources with this status may be kept alive
149 * by the cache as either scratch or unique resources even when there ar e no refs to them. 149 * by the cache as either scratch or unique resources even when there ar e no refs to them.
150 * The cache may release them whenever there are no refs. 150 * The cache may release them whenever there are no refs.
151 */ 151 */
152 kCached_LifeCycle, 152 kCached_LifeCycle,
153
153 /** 154 /**
154 * The resource is uncached. As soon as there are no more refs to it, it is released. Under 155 * The resource is uncached. As soon as there are no more refs to it, it is released. Under
155 * the hood the cache may opaquely recycle it as a cached resource. 156 * the hood the cache may opaquely recycle it as a cached resource.
156 */ 157 */
157 kUncached_LifeCycle, 158 kUncached_LifeCycle,
159
158 /** 160 /**
159 * Similar to uncached, but Skia does not manage the lifetime of the und erlying backend 161 * Similar to uncached, but Skia does not manage the lifetime of the und erlying backend
160 * 3D API object(s). The client is responsible for freeing those. Used t o inject client- 162 * 3D API object(s). The client is responsible for freeing those. Used t o inject client-
161 * created GPU resources into Skia (e.g. to render to a client-created t exture). 163 * created GPU resources into Skia (e.g. to render to a client-created t exture).
162 */ 164 */
163 kWrapped_LifeCycle, 165 kBorrowed_LifeCycle,
166
167 /**
168 * An external resource with ownership transfered into Skia. Skia will f ree the resource.
169 */
170 kAdopted_LifeCycle,
164 }; 171 };
165 172
166 /** 173 /**
167 * Tests whether a object has been abandoned or released. All objects will 174 * Tests whether a object has been abandoned or released. All objects will
168 * be in this state after their creating GrContext is destroyed or has 175 * be in this state after their creating GrContext is destroyed or has
169 * contextLost called. It's up to the client to test wasDestroyed() before 176 * contextLost called. It's up to the client to test wasDestroyed() before
170 * attempting to use an object if it holds refs on objects across 177 * attempting to use an object if it holds refs on objects across
171 * ~GrContext, freeResources with the force flag, or contextLost. 178 * ~GrContext, freeResources with the force flag, or contextLost.
172 * 179 *
173 * @return true if the object has been released or abandoned, 180 * @return true if the object has been released or abandoned,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 265
259 GrGpu* getGpu() const { return fGpu; } 266 GrGpu* getGpu() const { return fGpu; }
260 267
261 /** Overridden to free GPU resources in the backend API. */ 268 /** Overridden to free GPU resources in the backend API. */
262 virtual void onRelease() { } 269 virtual void onRelease() { }
263 /** Overridden to abandon any internal handles, ptrs, etc to backend API res ources. 270 /** Overridden to abandon any internal handles, ptrs, etc to backend API res ources.
264 This may be called when the underlying 3D context is no longer valid and so no 271 This may be called when the underlying 3D context is no longer valid and so no
265 backend API calls should be made. */ 272 backend API calls should be made. */
266 virtual void onAbandon() { } 273 virtual void onAbandon() { }
267 274
268 bool isWrapped() const { return kWrapped_LifeCycle == fLifeCycle; } 275 bool shouldFreeResources() const { return fLifeCycle != kBorrowed_LifeCycle; }
276
277 bool isExternal() const {
278 return GrGpuResource::kAdopted_LifeCycle == fLifeCycle ||
279 GrGpuResource::kBorrowed_LifeCycle == fLifeCycle;
280 }
269 281
270 /** 282 /**
271 * This entry point should be called whenever gpuMemorySize() should report a different size. 283 * This entry point should be called whenever gpuMemorySize() should report a different size.
272 * The cache will call gpuMemorySize() to update the current size of the res ource. 284 * The cache will call gpuMemorySize() to update the current size of the res ource.
273 */ 285 */
274 void didChangeGpuMemorySize() const; 286 void didChangeGpuMemorySize() const;
275 287
276 /** 288 /**
277 * Optionally called by the GrGpuResource subclass if the resource can be us ed as scratch. 289 * Optionally called by the GrGpuResource subclass if the resource can be us ed as scratch.
278 * By default resources are not usable as scratch. This should only be calle d once. 290 * By default resources are not usable as scratch. This should only be calle d once.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 LifeCycle fLifeCycle; 333 LifeCycle fLifeCycle;
322 const uint32_t fUniqueID; 334 const uint32_t fUniqueID;
323 335
324 SkAutoTUnref<const SkData> fData; 336 SkAutoTUnref<const SkData> fData;
325 337
326 typedef GrIORef<GrGpuResource> INHERITED; 338 typedef GrIORef<GrGpuResource> INHERITED;
327 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n otifyRefCntIsZero. 339 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n otifyRefCntIsZero.
328 }; 340 };
329 341
330 #endif 342 #endif
OLDNEW
« no previous file with comments | « include/core/SkImage.h ('k') | include/gpu/GrTextureProvider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698