fix refcounting in SkImage::NewRasterData

git-svn-id: http://skia.googlecode.com/svn/trunk@13338 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index 820d24d..20e7505 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -48,6 +48,23 @@
     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 @@
 }
 
 DEF_GPUTEST(Surface, reporter, factory) {
+    test_image(reporter);
+
     TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL);
     TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL);
     TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL);