Make GrResource know whether 3D objects' lifetimes are managed by Skia or not.
Review URL: https://codereview.appspot.com/7201046
git-svn-id: http://skia.googlecode.com/svn/trunk@7348 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrRenderTarget.h b/include/gpu/GrRenderTarget.h
index 9964c9b..4e77466 100644
--- a/include/gpu/GrRenderTarget.h
+++ b/include/gpu/GrRenderTarget.h
@@ -139,10 +139,11 @@
protected:
GrRenderTarget(GrGpu* gpu,
+ bool isWrapped,
GrTexture* texture,
const GrTextureDesc& desc,
Origin origin)
- : INHERITED(gpu, desc, origin)
+ : INHERITED(gpu, isWrapped, desc, origin)
, fStencilBuffer(NULL)
, fTexture(texture) {
fResolveRect.setLargestInverted();
diff --git a/include/gpu/GrResource.h b/include/gpu/GrResource.h
index 3c306f8..9330abb 100644
--- a/include/gpu/GrResource.h
+++ b/include/gpu/GrResource.h
@@ -70,7 +70,12 @@
GrResourceEntry* getCacheEntry() { return fCacheEntry; }
protected:
- explicit GrResource(GrGpu* gpu);
+ /**
+ * isWrapped indicates we have wrapped a client-created backend resource in a GrResource. If it
+ * is true then the client is responsible for the lifetime of the underlying backend resource.
+ * Otherwise, our onRelease() should free the resource.
+ */
+ GrResource(GrGpu* gpu, bool isWrapped);
virtual ~GrResource();
GrGpu* getGpu() const { return fGpu; }
@@ -81,9 +86,9 @@
virtual void onAbandon() {};
bool isInCache() const { return NULL != fCacheEntry; }
+ bool isWrapped() const { return kWrapped_Flag & fFlags; }
private:
-
#if GR_DEBUG
friend class GrGpu; // for assert in GrGpu to access getGpu
#endif
@@ -98,6 +103,11 @@
GrResourceEntry* fCacheEntry; // NULL if not in cache
+ enum Flags {
+ kWrapped_Flag,
+ };
+ uint32_t fFlags;
+
typedef GrRefCnt INHERITED;
};
diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h
index d7aa267..4ef0acb 100644
--- a/include/gpu/GrSurface.h
+++ b/include/gpu/GrSurface.h
@@ -115,8 +115,8 @@
uint32_t pixelOpsFlags = 0) = 0;
protected:
- GrSurface(GrGpu* gpu, const GrTextureDesc& desc, Origin origin)
- : INHERITED(gpu)
+ GrSurface(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc, Origin origin)
+ : INHERITED(gpu, isWrapped)
, fDesc(desc)
, fOrigin(origin) {
}
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index 36515b4..657e6e5 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -140,8 +140,8 @@
// base class cons sets to NULL
// subclass cons can create and set
- GrTexture(GrGpu* gpu, const GrTextureDesc& desc, Origin origin)
- : INHERITED(gpu, desc, origin)
+ GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc, Origin origin)
+ : INHERITED(gpu, isWrapped, desc, origin)
, fRenderTarget(NULL) {
// only make sense if alloc size is pow2
@@ -167,4 +167,3 @@
};
#endif
-