Add release proc apis to SkSurface::MakeFromBackend* calls.
Bug: skia:
Change-Id: I0e6cd8895c328a89cd0fa50260fe4e8adbff5990
Reviewed-on: https://skia-review.googlesource.com/c/188634
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index e1588ae..7701011 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -886,12 +886,15 @@
GrSurfaceOrigin origin,
int sampleCnt,
sk_sp<SkColorSpace> colorSpace,
- const SkSurfaceProps* props) {
+ const SkSurfaceProps* props,
+ ReleaseProc releaseProc,
+ ReleaseContext releaseCtx) {
ASSERT_SINGLE_OWNER_PRIV
SkASSERT(sampleCnt > 0);
sk_sp<GrTextureProxy> proxy(this->proxyProvider()->wrapRenderableBackendTexture(
- tex, origin, sampleCnt, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo));
+ tex, origin, sampleCnt, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, releaseProc,
+ releaseCtx));
if (!proxy) {
return nullptr;
}
@@ -904,10 +907,13 @@
const GrBackendRenderTarget& backendRT,
GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace,
- const SkSurfaceProps* surfaceProps) {
+ const SkSurfaceProps* surfaceProps,
+ ReleaseProc releaseProc,
+ ReleaseContext releaseCtx) {
ASSERT_SINGLE_OWNER_PRIV
- sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendRenderTarget(backendRT, origin);
+ sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendRenderTarget(
+ backendRT, origin, releaseProc, releaseCtx);
if (!proxy) {
return nullptr;
}
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 02dc7a3..5b36351 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -70,18 +70,26 @@
GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace);
+ // These match the definitions in SkSurface & GrSurface.h, for whence they came
+ typedef void* ReleaseContext;
+ typedef void (*ReleaseProc)(ReleaseContext);
+
sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
const GrBackendTexture& tex,
GrSurfaceOrigin origin,
int sampleCnt,
sk_sp<SkColorSpace> colorSpace,
- const SkSurfaceProps* = nullptr);
+ const SkSurfaceProps* = nullptr,
+ ReleaseProc = nullptr,
+ ReleaseContext = nullptr);
sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext(
const GrBackendRenderTarget&,
GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace,
- const SkSurfaceProps* = nullptr);
+ const SkSurfaceProps* = nullptr,
+ ReleaseProc = nullptr,
+ ReleaseContext = nullptr);
sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext(
const GrBackendTexture& tex,
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index f13cf7c..46f2709 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -475,7 +475,7 @@
if (releaseProc) {
releaseHelper.reset(new GrReleaseProcHelper(releaseProc, releaseCtx));
// This gives the texture a ref on the releaseHelper
- tex->setRelease(releaseHelper);
+ tex->setRelease(std::move(releaseHelper));
}
SkASSERT(!tex->asRenderTarget()); // Strictly a GrTexture
@@ -487,7 +487,8 @@
sk_sp<GrTextureProxy> GrProxyProvider::wrapRenderableBackendTexture(
const GrBackendTexture& backendTex, GrSurfaceOrigin origin, int sampleCnt,
- GrWrapOwnership ownership, GrWrapCacheable cacheable) {
+ GrWrapOwnership ownership, GrWrapCacheable cacheable, ReleaseProc releaseProc,
+ ReleaseContext releaseCtx) {
if (this->isAbandoned()) {
return nullptr;
}
@@ -508,6 +509,13 @@
return nullptr;
}
+ sk_sp<GrReleaseProcHelper> releaseHelper;
+ if (releaseProc) {
+ releaseHelper.reset(new GrReleaseProcHelper(releaseProc, releaseCtx));
+ // This gives the texture a ref on the releaseHelper
+ tex->setRelease(std::move(releaseHelper));
+ }
+
SkASSERT(tex->asRenderTarget()); // A GrTextureRenderTarget
// Make sure we match how we created the proxy with SkBudgeted::kNo
SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType());
@@ -516,7 +524,8 @@
}
sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendRenderTarget(
- const GrBackendRenderTarget& backendRT, GrSurfaceOrigin origin) {
+ const GrBackendRenderTarget& backendRT, GrSurfaceOrigin origin, ReleaseProc releaseProc,
+ ReleaseContext releaseCtx) {
if (this->isAbandoned()) {
return nullptr;
}
@@ -530,6 +539,14 @@
if (!rt) {
return nullptr;
}
+
+ sk_sp<GrReleaseProcHelper> releaseHelper;
+ if (releaseProc) {
+ releaseHelper.reset(new GrReleaseProcHelper(releaseProc, releaseCtx));
+ // This gives the render target a ref on the releaseHelper
+ rt->setRelease(std::move(releaseHelper));
+ }
+
SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable
SkASSERT(!rt->getUniqueKey().isValid());
// Make sure we match how we created the proxy with SkBudgeted::kNo
diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h
index f093416..f7481e5 100644
--- a/src/gpu/GrProxyProvider.h
+++ b/src/gpu/GrProxyProvider.h
@@ -121,12 +121,14 @@
*/
sk_sp<GrTextureProxy> wrapRenderableBackendTexture(const GrBackendTexture&, GrSurfaceOrigin,
int sampleCnt, GrWrapOwnership,
- GrWrapCacheable);
+ GrWrapCacheable, ReleaseProc,
+ ReleaseContext);
/*
* Create a render target proxy that wraps a backend render target
*/
- sk_sp<GrSurfaceProxy> wrapBackendRenderTarget(const GrBackendRenderTarget&, GrSurfaceOrigin);
+ sk_sp<GrSurfaceProxy> wrapBackendRenderTarget(const GrBackendRenderTarget&, GrSurfaceOrigin,
+ ReleaseProc, ReleaseContext);
/*
* Create a render target proxy that wraps a backend texture
diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp
index c51ce9b..272e18b 100644
--- a/src/image/SkSurface.cpp
+++ b/src/image/SkSurface.cpp
@@ -308,7 +308,8 @@
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTexture&,
GrSurfaceOrigin origin, int sampleCnt,
SkColorType, sk_sp<SkColorSpace>,
- const SkSurfaceProps*) {
+ const SkSurfaceProps*,
+ TextureReleaseProc, ReleaseContext) {
return nullptr;
}
@@ -317,7 +318,8 @@
GrSurfaceOrigin origin,
SkColorType,
sk_sp<SkColorSpace>,
- const SkSurfaceProps*) {
+ const SkSurfaceProps*,
+ RenderTargetReleaseProc, ReleaseContext) {
return nullptr;
}
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 89959f1..7163f21 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -421,7 +421,9 @@
GrSurfaceOrigin origin, int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
- const SkSurfaceProps* props) {
+ const SkSurfaceProps* props,
+ SkSurface::TextureReleaseProc textureReleaseProc,
+ SkSurface::ReleaseContext releaseContext) {
if (!context) {
return nullptr;
}
@@ -445,7 +447,9 @@
origin,
sampleCnt,
std::move(colorSpace),
- props));
+ props,
+ textureReleaseProc,
+ releaseContext));
if (!rtc) {
return nullptr;
}
@@ -490,7 +494,9 @@
GrSurfaceOrigin origin,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
- const SkSurfaceProps* props) {
+ const SkSurfaceProps* props,
+ SkSurface::RenderTargetReleaseProc relProc,
+ SkSurface::ReleaseContext releaseContext) {
if (!context) {
return nullptr;
}
@@ -509,7 +515,7 @@
sk_sp<GrRenderTargetContext> rtc(
context->priv().makeBackendRenderTargetRenderTargetContext(
- rtCopy, origin, std::move(colorSpace), props));
+ rtCopy, origin, std::move(colorSpace), props, relProc, releaseContext));
if (!rtc) {
return nullptr;
}