Change how Java Bitmaps are accessed in a few places

Stop assuming that a Java Bitmap has a SkBitmap* that
has some externally managed lifecycle, and instead switch
a bunch of users to accessing the bitmap by providing
their own SkBitmap* on which to set the (ref counted!)
SkPixelRef* instead

Attempt #2 to land this, original issue was in getSkBitmap
and should be fixed

Change-Id: I0fd9e193968b41e5597784140d56b4885906864a
diff --git a/native/graphics/jni/bitmap.cpp b/native/graphics/jni/bitmap.cpp
index ddb01a0..0521833 100644
--- a/native/graphics/jni/bitmap.cpp
+++ b/native/graphics/jni/bitmap.cpp
@@ -27,18 +27,16 @@
         return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
     }
 
-    SkBitmap* bm = GraphicsJNI::getSkBitmap(env, jbitmap);
-    if (NULL == bm) {
-        return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
-    }
+    SkBitmap bm;
+    GraphicsJNI::getSkBitmap(env, jbitmap, &bm);
 
     if (info) {
-        info->width     = bm->width();
-        info->height    = bm->height();
-        info->stride    = bm->rowBytes();
+        info->width     = bm.width();
+        info->height    = bm.height();
+        info->stride    = bm.rowBytes();
         info->flags     = 0;
 
-        switch (bm->colorType()) {
+        switch (bm.colorType()) {
             case kN32_SkColorType:
                 info->format = ANDROID_BITMAP_FORMAT_RGBA_8888;
                 break;
@@ -64,17 +62,18 @@
         return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
     }
 
-    SkBitmap* bm = GraphicsJNI::getSkBitmap(env, jbitmap);
-    if (NULL == bm) {
+    SkPixelRef* pixelRef = GraphicsJNI::getSkPixelRef(env, jbitmap);
+    if (!pixelRef) {
         return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
     }
 
-    bm->lockPixels();
-    void* addr = bm->getPixels();
+    pixelRef->lockPixels();
+    void* addr = pixelRef->pixels();
     if (NULL == addr) {
-        bm->unlockPixels();
+        pixelRef->unlockPixels();
         return ANDROID_BITMAP_RESULT_ALLOCATION_FAILED;
     }
+    pixelRef->ref();
 
     if (addrPtr) {
         *addrPtr = addr;
@@ -87,8 +86,8 @@
         return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
     }
 
-    SkBitmap* bm = GraphicsJNI::getSkBitmap(env, jbitmap);
-    if (NULL == bm) {
+    SkPixelRef* pixelRef = GraphicsJNI::getSkPixelRef(env, jbitmap);
+    if (!pixelRef) {
         return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
     }
 
@@ -96,9 +95,11 @@
     // bitmaps.  Note that this will slow down read-only accesses to the
     // bitmaps, but the NDK methods are primarily intended to be used for
     // writes.
-    bm->notifyPixelsChanged();
+    pixelRef->notifyPixelsChanged();
 
-    bm->unlockPixels();
+    pixelRef->unlockPixels();
+    pixelRef->unref();
+
     return ANDROID_BITMAP_RESULT_SUCCESS;
 }