aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu/GrGpuResource.h
diff options
context:
space:
mode:
authorGravatar kkinnunen <kkinnunen@nvidia.com>2016-04-22 01:48:29 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-22 01:48:29 -0700
commit2e6055b3ea14a04fcde1ac1974a70bf00b1e295b (patch)
tree38513879d9f2840cb7d08f85365722016448f787 /include/gpu/GrGpuResource.h
parentcb61a6452fbf9b147dc9d3f31bf520efb0e2c7fd (diff)
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state: a) instance is budgeted or not budgeted b) instance references wrapped backend objects or not The "object lifecycle" was also attached to backend object handles (ids), which made the code a bit unclear. Backend objects would be associated with GrGpuResource::LifeCycle, even though GrGpuResource::LifeCycle refers to the GpuResource, and individual backend objects in one GpuResource might be governed with different "lifecycle". Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo. This was previously GrGpuResource::kCached_LifeCycle, GrGpuResource::kUncached_LifeCycle. Mark the "references wrapped object" with boolean. This was previously GrGpuResource::kBorrowed_LifeCycle, GrGpuResource::kAdopted_LifeCycle for GrGpuResource. Associate the backend object ownership status with GrBackendObjectOwnership for the backend object handles. The resource type leaf constuctors, such has GrGLTexture or GrGLTextureRenderTarget take "budgeted" parameter. This parameter is passed to GrGpuResource::registerWithCache(). The resource type intermediary constructors, such as GrGLTexture constructors for class GrGLTextureRenderTarget do not take "budgeted" parameters, intermediary construtors do not call registerWithCache. Removes the need for tagging GrGpuResource -derived subclass constructors with "Derived" parameter. Makes instances that wrap backend objects be registered with a new function GrGpuResource::registerWithCacheWrapped(). Removes "budgeted" parameter from classes such as StencilAttahment, as they are always cached and never wrap any external backend objects. Removes the use of concept "external" from the member function names. The API refers to the objects as "wrapped", so make all related functions use the term consistently. No change in functionality. Resources referencing wrapped objects are always inserted to the cache with budget decision kNo. BUG=594928 GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002 Review URL: https://codereview.chromium.org/1862043002
Diffstat (limited to 'include/gpu/GrGpuResource.h')
-rw-r--r--include/gpu/GrGpuResource.h65
1 files changed, 19 insertions, 46 deletions
diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h
index 8103959984..37a87d364d 100644
--- a/include/gpu/GrGpuResource.h
+++ b/include/gpu/GrGpuResource.h
@@ -140,34 +140,6 @@ private:
class SK_API GrGpuResource : public GrIORef<GrGpuResource> {
public:
-
- enum LifeCycle {
- /**
- * The resource is cached and owned by Skia. Resources with this status may be kept alive
- * by the cache as either scratch or unique resources even when there are no refs to them.
- * The cache may release them whenever there are no refs.
- */
- kCached_LifeCycle,
-
- /**
- * The resource is uncached. As soon as there are no more refs to it, it is released. Under
- * the hood the cache may opaquely recycle it as a cached resource.
- */
- kUncached_LifeCycle,
-
- /**
- * Similar to uncached, but Skia does not manage the lifetime of the underlying backend
- * 3D API object(s). The client is responsible for freeing those. Used to inject client-
- * created GPU resources into Skia (e.g. to render to a client-created texture).
- */
- kBorrowed_LifeCycle,
-
- /**
- * An external resource with ownership transfered into Skia. Skia will free the resource.
- */
- kAdopted_LifeCycle,
- };
-
/**
* Tests whether a object has been abandoned or released. All objects will
* be in this state after their creating GrContext is destroyed or has
@@ -261,11 +233,16 @@ public:
virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
protected:
- // This must be called by every GrGpuObject. It should be called once the object is fully
- // initialized (i.e. not in a base class constructor).
- void registerWithCache();
+ // This must be called by every non-wrapped GrGpuObject. It should be called once the object is
+ // fully initialized (i.e. only from the constructors of the final class).
+ void registerWithCache(SkBudgeted);
+
+ // This must be called by every GrGpuObject that references any wrapped backend objects. It
+ // should be called once the object is fully initialized (i.e. only from the constructors of the
+ // final class).
+ void registerWithCacheWrapped();
- GrGpuResource(GrGpu*, LifeCycle);
+ GrGpuResource(GrGpu*);
virtual ~GrGpuResource();
GrGpu* getGpu() const { return fGpu; }
@@ -277,13 +254,6 @@ protected:
backend API calls should be made. */
virtual void onAbandon() { }
- bool shouldFreeResources() const { return fLifeCycle != kBorrowed_LifeCycle; }
-
- bool isExternal() const {
- return GrGpuResource::kAdopted_LifeCycle == fLifeCycle ||
- GrGpuResource::kBorrowed_LifeCycle == fLifeCycle;
- }
-
/**
* This entry point should be called whenever gpuMemorySize() should report a different size.
* The cache will call gpuMemorySize() to update the current size of the resource.
@@ -291,12 +261,6 @@ protected:
void didChangeGpuMemorySize() const;
/**
- * Optionally called by the GrGpuResource subclass if the resource can be used as scratch.
- * By default resources are not usable as scratch. This should only be called once.
- **/
- void setScratchKey(const GrScratchKey& scratchKey);
-
- /**
* Allows subclasses to add additional backing information to the SkTraceMemoryDump. Called by
* onMemoryDump. The default implementation adds no backing information.
**/
@@ -304,6 +268,14 @@ protected:
private:
/**
+ * Called by the registerWithCache if the resource is available to be used as scratch.
+ * Resource subclasses should override this if the instances should be recycled as scratch
+ * resources and populate the scratchKey with the key.
+ * By default resources are not recycled as scratch.
+ **/
+ virtual void computeScratchKey(GrScratchKey*) const { };
+
+ /**
* Frees the object in the underlying 3D API. Called by CacheAccess.
*/
void release();
@@ -341,7 +313,8 @@ private:
GrGpu* fGpu;
mutable size_t fGpuMemorySize;
- LifeCycle fLifeCycle;
+ SkBudgeted fBudgeted;
+ bool fRefsWrappedObjects;
const uint32_t fUniqueID;
SkAutoTUnref<const SkData> fData;