Ref GrDirectContext in MakeBackendRenderTargetSurface
Fixes crashes when running vkbert config where we tear down a Vulkan
GrDirectContext before deleting the backing store of a SkSurface
created via MakeBackendRenderTargetSurface.
Bug: skia:10843
Change-Id: I99ea2266ba14325d3aaac5ee59aa712688fb9329
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/327196
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/tools/gpu/BackendSurfaceFactory.cpp b/tools/gpu/BackendSurfaceFactory.cpp
index bbb13ea..5fcbc82 100644
--- a/tools/gpu/BackendSurfaceFactory.cpp
+++ b/tools/gpu/BackendSurfaceFactory.cpp
@@ -71,13 +71,13 @@
auto ct = SkColorTypeToGrColorType(ii.colorType());
struct ReleaseContext {
- GrDirectContext* fContext;
+ sk_sp<GrDirectContext> fContext;
GrBackendRenderTarget fRenderTarget;
};
auto bert = dContext->priv().getGpu()->createTestingOnlyBackendRenderTarget(
ii.dimensions(), ct, sampleCnt, isProtected);
- auto rc = new ReleaseContext{dContext, bert};
+ auto rc = new ReleaseContext{sk_ref_sp(dContext), bert};
SkASSERT(!bert.isValid() || bert.sampleCnt() >= sampleCnt);
auto proc = [](void* c) {