Index: include/gpu/GrSurface.h |
diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h |
index 2b40f9c1d7ddd2f3c854aa2ade912f014bf3f9ed..4d40e2e8142cfdbe9fe1a8a9e360370553610cb3 100644 |
--- a/include/gpu/GrSurface.h |
+++ b/include/gpu/GrSurface.h |
@@ -127,6 +127,14 @@ public: |
inline GrSurfacePriv surfacePriv(); |
inline const GrSurfacePriv surfacePriv() const; |
+ typedef void* ReleaseCtx; |
+ typedef void (*ReleaseProc)(ReleaseCtx); |
+ |
+ void setRelease(ReleaseProc proc, ReleaseCtx ctx) { |
+ fReleaseProc = proc; |
+ fReleaseCtx = ctx; |
+ } |
+ |
protected: |
// Methods made available via GrSurfacePriv |
SkImageInfo info() const; |
@@ -140,12 +148,32 @@ protected: |
GrSurface(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc) |
: INHERITED(gpu, lifeCycle) |
- , fDesc(desc) { |
+ , fDesc(desc) |
+ , fReleaseProc(NULL) |
+ , fReleaseCtx(NULL) |
+ {} |
+ |
+ ~GrSurface() override { |
+ // check that invokeReleaseProc has been called (if needed) |
+ SkASSERT(NULL == fReleaseProc); |
} |
GrSurfaceDesc fDesc; |
+ void onRelease() override; |
+ void onAbandon() override; |
+ |
private: |
+ void invokeReleaseProc() { |
+ if (fReleaseProc) { |
+ fReleaseProc(fReleaseCtx); |
+ fReleaseProc = NULL; |
+ } |
+ } |
+ |
+ ReleaseProc fReleaseProc; |
+ ReleaseCtx fReleaseCtx; |
+ |
typedef GrGpuResource INHERITED; |
}; |