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
diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h
index 6ee8dcf..05d26c8 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -16,7 +16,6 @@
class GrGLGpu;
class GrGLTexture : public GrTexture {
-
public:
struct TexParams {
GrGLenum fMinFilter;
@@ -31,11 +30,11 @@
struct IDDesc {
GrGLTextureInfo fInfo;
- GrGpuResource::LifeCycle fLifeCycle;
+ GrBackendObjectOwnership fOwnership;
};
-
- GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
- GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, bool wasMipMapDataProvided);
+ GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&);
+ GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&,
+ bool wasMipMapDataProvided);
GrBackendObject getTextureHandle() const override;
@@ -57,12 +56,14 @@
GrGLenum target() const { return fInfo.fTarget; }
+ static GrGLTexture* CreateWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
protected:
- // The public constructor registers this object with the cache. However, only the most derived
- // class should register with the cache. This constructor does not do the registration and
- // rather moves that burden onto the derived class.
- enum Derived { kDerived };
- GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived);
+ // Constructor for subclasses.
+ GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
+
+ enum Wrapped { kWrapped };
+ // Constructor for instances wrapping backend objects.
+ GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, const IDDesc&);
void init(const GrSurfaceDesc&, const IDDesc&);
@@ -77,10 +78,7 @@
// Holds the texture target and ID. A pointer to this may be shared to external clients for
// direct interaction with the GL object.
GrGLTextureInfo fInfo;
-
- // We track this separately from GrGpuResource because this may be both a texture and a render
- // target, and the texture may be wrapped while the render target is not.
- LifeCycle fTextureIDLifecycle;
+ GrBackendObjectOwnership fTextureIDOwnership;
typedef GrTexture INHERITED;
};