From b091d47a2e31a30581aa210419ff09bcc8715cdf Mon Sep 17 00:00:00 2001 From: Ashok Bhat Date: Wed, 8 Jan 2014 14:32:49 +0000 Subject: [PATCH] AArch64: Use long for pointers in BitmapRegionDecoder For storing pointers, long is used in BitmapRegionDecoder class, as native pointers can be 64-bit. In addition, some minor changes have been done to conform with standard JNI practice (e.g. use of jint instead of int in JNI function prototypes) In addition, Graphics.cpp has been changed to work with modified BitmapRegionDecoder. Change-Id: Id54087dd3bfb29577e8b762e70946793369dc701 Signed-off-by: Ashok Bhat Signed-off-by: Marcus Oakland --- .../android/graphics/BitmapRegionDecoder.cpp | 32 +++++++++++-------- core/jni/android/graphics/Graphics.cpp | 4 +-- .../android/graphics/BitmapRegionDecoder.java | 16 +++++----- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/core/jni/android/graphics/BitmapRegionDecoder.cpp b/core/jni/android/graphics/BitmapRegionDecoder.cpp index ee47ac46ecd19..e7d2422eeb9b6 100644 --- a/core/jni/android/graphics/BitmapRegionDecoder.cpp +++ b/core/jni/android/graphics/BitmapRegionDecoder.cpp @@ -102,7 +102,7 @@ static jobject createBitmapRegionDecoder(JNIEnv* env, SkStream* stream) { } static jobject nativeNewInstanceFromByteArray(JNIEnv* env, jobject, jbyteArray byteArray, - int offset, int length, jboolean isShareable) { + jint offset, jint length, jboolean isShareable) { /* If isShareable we could decide to just wrap the java array and share it, but that means adding a globalref to the java array object For now we just always copy the array's data if isShareable. @@ -151,7 +151,7 @@ static jobject nativeNewInstanceFromStream(JNIEnv* env, jobject clazz, } static jobject nativeNewInstanceFromAsset(JNIEnv* env, jobject clazz, - jint native_asset, // Asset + jlong native_asset, // Asset jboolean isShareable) { Asset* asset = reinterpret_cast(native_asset); SkAutoTUnref stream(CopyAssetToStream(asset)); @@ -170,8 +170,9 @@ static jobject nativeNewInstanceFromAsset(JNIEnv* env, jobject clazz, * purgeable not supported * reportSizeToVM not supported */ -static jobject nativeDecodeRegion(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd, - int start_x, int start_y, int width, int height, jobject options) { +static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, + jint start_x, jint start_y, jint width, jint height, jobject options) { + SkBitmapRegionDecoder *brd = reinterpret_cast(brdHandle); jobject tileBitmap = NULL; SkImageDecoder *decoder = brd->getDecoder(); int sampleSize = 1; @@ -256,15 +257,18 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, SkBitmapRegionDecoder *b return GraphicsJNI::createBitmap(env, bitmap, buff, bitmapCreateFlags, NULL, NULL, -1); } -static int nativeGetHeight(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd) { - return brd->getHeight(); +static jint nativeGetHeight(JNIEnv* env, jobject, jlong brdHandle) { + SkBitmapRegionDecoder *brd = reinterpret_cast(brdHandle); + return static_cast(brd->getHeight()); } -static int nativeGetWidth(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd) { - return brd->getWidth(); +static jint nativeGetWidth(JNIEnv* env, jobject, jlong brdHandle) { + SkBitmapRegionDecoder *brd = reinterpret_cast(brdHandle); + return static_cast(brd->getWidth()); } -static void nativeClean(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd) { +static void nativeClean(JNIEnv* env, jobject, jlong brdHandle) { + SkBitmapRegionDecoder *brd = reinterpret_cast(brdHandle); delete brd; } @@ -274,14 +278,14 @@ static void nativeClean(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd) { static JNINativeMethod gBitmapRegionDecoderMethods[] = { { "nativeDecodeRegion", - "(IIIIILandroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;", + "(JIIIILandroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;", (void*)nativeDecodeRegion}, - { "nativeGetHeight", "(I)I", (void*)nativeGetHeight}, + { "nativeGetHeight", "(J)I", (void*)nativeGetHeight}, - { "nativeGetWidth", "(I)I", (void*)nativeGetWidth}, + { "nativeGetWidth", "(J)I", (void*)nativeGetWidth}, - { "nativeClean", "(I)V", (void*)nativeClean}, + { "nativeClean", "(J)V", (void*)nativeClean}, { "nativeNewInstance", "([BIIZ)Landroid/graphics/BitmapRegionDecoder;", @@ -299,7 +303,7 @@ static JNINativeMethod gBitmapRegionDecoderMethods[] = { }, { "nativeNewInstance", - "(IZ)Landroid/graphics/BitmapRegionDecoder;", + "(JZ)Landroid/graphics/BitmapRegionDecoder;", (void*)nativeNewInstanceFromAsset }, }; diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp index 38a9ba32781aa..a10e1586894cb 100644 --- a/core/jni/android/graphics/Graphics.cpp +++ b/core/jni/android/graphics/Graphics.cpp @@ -392,7 +392,7 @@ jobject GraphicsJNI::createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecode jobject obj = env->NewObject(gBitmapRegionDecoder_class, gBitmapRegionDecoder_constructorMethodID, - static_cast(reinterpret_cast(bitmap))); + reinterpret_cast(bitmap)); hasException(env); // For the side effect of logging. return obj; } @@ -651,7 +651,7 @@ int register_android_graphics_Graphics(JNIEnv* env) gBitmap_reinitMethodID = env->GetMethodID(gBitmap_class, "reinit", "(IIZ)V"); gBitmap_getAllocationByteCountMethodID = env->GetMethodID(gBitmap_class, "getAllocationByteCount", "()I"); gBitmapRegionDecoder_class = make_globalref(env, "android/graphics/BitmapRegionDecoder"); - gBitmapRegionDecoder_constructorMethodID = env->GetMethodID(gBitmapRegionDecoder_class, "", "(I)V"); + gBitmapRegionDecoder_constructorMethodID = env->GetMethodID(gBitmapRegionDecoder_class, "", "(J)V"); gBitmapConfig_class = make_globalref(env, "android/graphics/Bitmap$Config"); gBitmapConfig_nativeInstanceID = getFieldIDCheck(env, gBitmapConfig_class, diff --git a/graphics/java/android/graphics/BitmapRegionDecoder.java b/graphics/java/android/graphics/BitmapRegionDecoder.java index 3a99977df758d..e689b083ad975 100644 --- a/graphics/java/android/graphics/BitmapRegionDecoder.java +++ b/graphics/java/android/graphics/BitmapRegionDecoder.java @@ -33,7 +33,7 @@ import java.io.InputStream; * */ public final class BitmapRegionDecoder { - private int mNativeBitmapRegionDecoder; + private long mNativeBitmapRegionDecoder; private boolean mRecycled; // ensures that the native decoder object exists and that only one decode can // occur at a time. @@ -114,7 +114,7 @@ public final class BitmapRegionDecoder { boolean isShareable) throws IOException { if (is instanceof AssetManager.AssetInputStream) { return nativeNewInstance( - ((AssetManager.AssetInputStream) is).getAssetInt(), + ((AssetManager.AssetInputStream) is).getNativeAsset(), isShareable); } else { // pass some temp storage down to the native code. 1024 is made up, @@ -165,7 +165,7 @@ public final class BitmapRegionDecoder { This can be called from JNI code. */ - private BitmapRegionDecoder(int decoder) { + private BitmapRegionDecoder(long decoder) { mNativeBitmapRegionDecoder = decoder; mRecycled = false; } @@ -254,12 +254,12 @@ public final class BitmapRegionDecoder { } } - private static native Bitmap nativeDecodeRegion(int lbm, + private static native Bitmap nativeDecodeRegion(long lbm, int start_x, int start_y, int width, int height, BitmapFactory.Options options); - private static native int nativeGetWidth(int lbm); - private static native int nativeGetHeight(int lbm); - private static native void nativeClean(int lbm); + private static native int nativeGetWidth(long lbm); + private static native int nativeGetHeight(long lbm); + private static native void nativeClean(long lbm); private static native BitmapRegionDecoder nativeNewInstance( byte[] data, int offset, int length, boolean isShareable); @@ -268,5 +268,5 @@ public final class BitmapRegionDecoder { private static native BitmapRegionDecoder nativeNewInstance( InputStream is, byte[] storage, boolean isShareable); private static native BitmapRegionDecoder nativeNewInstance( - int asset, boolean isShareable); + long asset, boolean isShareable); }