From: junov@chromium.org Date: Wed, 3 Apr 2013 15:03:26 +0000 (+0000) Subject: Fixed bug with SkImage leaving canvas backing store in an immutable state after destroy. X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~12863 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af0583528c7dd5344abfe14347377011abe374e2;p=platform%2Fupstream%2FlibSkiaSharp.git Fixed bug with SkImage leaving canvas backing store in an immutable state after destroy. Added unit test that verifies that surface backing is writable after creating and destroying an image. Review URL: https://codereview.chromium.org/13226002 git-svn-id: http://skia.googlecode.com/svn/trunk@8512 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index d4ed171..4a18f4a 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -100,7 +100,6 @@ SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes); fBitmap.setPixelRef(pr); fBitmap.setIsOpaque(isOpaque); - fBitmap.setImmutable(); } SkImage_Raster::~SkImage_Raster() {} diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 69a73f8..59e565b 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -35,12 +35,8 @@ static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context) { case kRaster_SurfaceType: return SkSurface::NewRaster(imageSpec); case kGpu_SurfaceType: -#if SK_SUPPORT_GPU SkASSERT(NULL != context); return SkSurface::NewRenderTarget(context, imageSpec); -#else - SkASSERT(0); -#endif case kPicture_SurfaceType: return SkSurface::NewPicture(10, 10); } @@ -133,18 +129,33 @@ static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur testPaint)) } -static void TestSurface(skiatest::Reporter* reporter) { - TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); - TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); +static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter, + SurfaceType surfaceType, + GrContext* context) { + // This test succeeds by not triggering an assertion. + // The test verifies that the surface remains writable (usable) after + // acquiring and releasing a snapshot without triggering a copy on write. + SkSurface* surface = createSurface(surfaceType, context); + SkAutoTUnref aur_surface(surface); + SkCanvas* canvas = surface->getCanvas(); + canvas->clear(1); + surface->newImageShapshot()->unref(); // Create and destroy SkImage + canvas->clear(2); } -static void TestSurfaceGpu(skiatest::Reporter* reporter, GrContextFactory* factory) { +static void TestSurface(skiatest::Reporter* reporter, GrContextFactory* factory) { + TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); + TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); + TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL); + TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL); #if SK_SUPPORT_GPU - GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); - TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); + if (NULL != factory) { + GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); + TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); + TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, context); + } #endif } #include "TestClassDef.h" -DEFINE_TESTCLASS("Surface", SurfaceTestClass, TestSurface) -DEFINE_GPUTESTCLASS("SurfaceGpu", SurfaceGpuTestClass, TestSurfaceGpu) +DEFINE_GPUTESTCLASS("Surface", SurfaceTestClass, TestSurface)