From 8a8dd33e18ce6946913247732273b1cd48ba0433 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Thu, 24 May 2018 14:08:31 -0400 Subject: Make SkImage own its GrContext. Change-Id: I86577fab5406ae9ad89d87fa971b0db6e0283cb4 Reviewed-on: https://skia-review.googlesource.com/130020 Commit-Queue: Brian Salomon Reviewed-by: Robert Phillips --- tests/ImageTest.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests/ImageTest.cpp') diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index b69dd2e1b2..44e901e3e0 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -580,6 +580,45 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UnpremulTextureImage, reporter, ctxInfo) { } } +DEF_GPUTEST(AbandonedContextImage, reporter, options) { + using Factory = sk_gpu_test::GrContextFactory; + for (int ct = 0; ct < Factory::kContextTypeCnt; ++ct) { + auto type = static_cast(ct); + std::unique_ptr factory(new Factory); + if (!factory->get(type)) { + continue; + } + + sk_sp img; + auto gsurf = SkSurface::MakeRenderTarget( + factory->get(type), SkBudgeted::kYes, + SkImageInfo::Make(100, 100, kRGBA_8888_SkColorType, kPremul_SkAlphaType), 1, + nullptr); + if (!gsurf) { + continue; + } + img = gsurf->makeImageSnapshot(); + gsurf.reset(); + + auto rsurf = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100)); + + REPORTER_ASSERT(reporter, img->isValid(factory->get(type))); + REPORTER_ASSERT(reporter, img->isValid(rsurf->getCanvas()->getGrContext())); + + factory->get(type)->abandonContext(); + REPORTER_ASSERT(reporter, !img->isValid(factory->get(type))); + REPORTER_ASSERT(reporter, !img->isValid(rsurf->getCanvas()->getGrContext())); + // This shouldn't crash. + rsurf->getCanvas()->drawImage(img, 0, 0); + + // Give up all other refs on GrContext. + factory.reset(nullptr); + REPORTER_ASSERT(reporter, !img->isValid(rsurf->getCanvas()->getGrContext())); + // This shouldn't crash. + rsurf->getCanvas()->drawImage(img, 0, 0); + } +} + #endif class EmptyGenerator : public SkImageGenerator { -- cgit v1.2.3