diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-02-06 13:43:07 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-02-06 13:43:07 +0000 |
commit | 999da9c5e45fb533efe8782c9096794b9ad1c1b3 (patch) | |
tree | 6c5f31692f11428fb2e8fd4496a51c5bc9501b9e | |
parent | 9d6e7e5b1368ba45b0b71b7b1d5d193a4b24e8d1 (diff) |
fix refcounting in SkImage::NewRasterData
git-svn-id: http://skia.googlecode.com/svn/trunk@13338 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | src/image/SkImage_Raster.cpp | 7 | ||||
-rw-r--r-- | tests/SurfaceTest.cpp | 19 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index 32d53fc52e..ab8a635c1c 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -133,7 +133,7 @@ SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz } -SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* pixelData, size_t rowBytes) { +SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t rowBytes) { if (!SkImage_Raster::ValidArgs(info, rowBytes)) { return NULL; } @@ -141,17 +141,16 @@ SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* pixelData, size return SkImage_Raster::NewEmpty(); } // check this after empty-check - if (NULL == pixelData) { + if (NULL == data) { return NULL; } // did they give us enough data? size_t size = info.fHeight * rowBytes; - if (pixelData->size() < size) { + if (data->size() < size) { return NULL; } - SkAutoDataUnref data(pixelData); return SkNEW_ARGS(SkImage_Raster, (info, data, rowBytes)); } diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 820d24dfac..20e7505966 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -48,6 +48,23 @@ static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context) { return NULL; } +#include "SkData.h" + +static void test_image(skiatest::Reporter* reporter) { + SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); + size_t rowBytes = info.minRowBytes(); + size_t size = info.getSafeSize(rowBytes); + void* addr = sk_malloc_throw(size); + SkData* data = SkData::NewFromMalloc(addr, size); + + REPORTER_ASSERT(reporter, 1 == data->getRefCnt()); + SkImage* image = SkImage::NewRasterData(info, data, rowBytes); + REPORTER_ASSERT(reporter, 2 == data->getRefCnt()); + image->unref(); + REPORTER_ASSERT(reporter, 1 == data->getRefCnt()); + data->unref(); +} + static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType surfaceType, GrContext* context) { // Verify that the right canvas commands trigger a copy on write @@ -232,6 +249,8 @@ static void TestSurfaceNoCanvas(skiatest::Reporter* reporter, } DEF_GPUTEST(Surface, reporter, factory) { + test_image(reporter); + TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL); |