diff options
author | John Reck <jreck@google.com> | 2015-03-04 08:36:12 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2015-03-05 09:55:02 -0800 |
commit | b2915245b74b3b5541b123e38403f8e26426b4b7 (patch) | |
tree | 295bee60e89bba1ae2221bf40833a80e6d2c41ef /core/jni/android | |
parent | f855b0d2d0c0c157d657668fcb98097e2aca097e (diff) | |
download | frameworks_base-b2915245b74b3b5541b123e38403f8e26426b4b7.zip frameworks_base-b2915245b74b3b5541b123e38403f8e26426b4b7.tar.gz frameworks_base-b2915245b74b3b5541b123e38403f8e26426b4b7.tar.bz2 |
Cleanup Bitmap JNI
Fix a bunch of places where mNativeBitmap was being
poked at directly, switch them either to the NDK API
or to GraphicsJNI where it made sense
Change-Id: I6b3df3712d6497cba828c2d3012e725cb4ebb64d
Diffstat (limited to 'core/jni/android')
-rw-r--r-- | core/jni/android/graphics/BitmapFactory.cpp | 4 | ||||
-rw-r--r-- | core/jni/android/graphics/BitmapRegionDecoder.cpp | 2 | ||||
-rw-r--r-- | core/jni/android/graphics/Graphics.cpp | 8 | ||||
-rw-r--r-- | core/jni/android/graphics/GraphicsJNI.h | 2 | ||||
-rw-r--r-- | core/jni/android/opengl/util.cpp | 26 |
5 files changed, 12 insertions, 30 deletions
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index 672008d..6a50b52 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -41,7 +41,6 @@ jfieldID gOptions_mimeFieldID; jfieldID gOptions_mCancelID; jfieldID gOptions_bitmapFieldID; -jfieldID gBitmap_nativeBitmapFieldID; jfieldID gBitmap_ninePatchInsetsFieldID; jclass gInsetStruct_class; @@ -262,7 +261,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding SkBitmap* outputBitmap = NULL; unsigned int existingBufferSize = 0; if (javaBitmap != NULL) { - outputBitmap = (SkBitmap*) env->GetLongField(javaBitmap, gBitmap_nativeBitmapFieldID); + outputBitmap = GraphicsJNI::getSkBitmap(env, javaBitmap); if (outputBitmap->isImmutable()) { ALOGW("Unable to reuse an immutable bitmap as an image decoder target."); javaBitmap = NULL; @@ -601,7 +600,6 @@ int register_android_graphics_BitmapFactory(JNIEnv* env) { gOptions_mCancelID = GetFieldIDOrDie(env, options_class, "mCancel", "Z"); jclass bitmap_class = FindClassOrDie(env, "android/graphics/Bitmap"); - gBitmap_nativeBitmapFieldID = GetFieldIDOrDie(env, bitmap_class, "mNativeBitmap", "J"); gBitmap_ninePatchInsetsFieldID = GetFieldIDOrDie(env, bitmap_class, "mNinePatchInsets", "Landroid/graphics/NinePatch$InsetStruct;"); diff --git a/core/jni/android/graphics/BitmapRegionDecoder.cpp b/core/jni/android/graphics/BitmapRegionDecoder.cpp index 90a7f69..04afe3e 100644 --- a/core/jni/android/graphics/BitmapRegionDecoder.cpp +++ b/core/jni/android/graphics/BitmapRegionDecoder.cpp @@ -213,7 +213,7 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, if (tileBitmap != NULL) { // Re-use bitmap. - bitmap = GraphicsJNI::getNativeBitmap(env, tileBitmap); + bitmap = GraphicsJNI::getSkBitmap(env, tileBitmap); } if (bitmap == NULL) { bitmap = new SkBitmap; diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp index dde1393..0747969 100644 --- a/core/jni/android/graphics/Graphics.cpp +++ b/core/jni/android/graphics/Graphics.cpp @@ -154,7 +154,7 @@ static jfieldID gPointF_xFieldID; static jfieldID gPointF_yFieldID; static jclass gBitmap_class; -static jfieldID gBitmap_nativeInstanceID; +static jfieldID gBitmap_skBitmapPtr; static jmethodID gBitmap_constructorMethodID; static jmethodID gBitmap_reinitMethodID; static jmethodID gBitmap_getAllocationByteCountMethodID; @@ -338,11 +338,11 @@ SkColorType GraphicsJNI::legacyBitmapConfigToColorType(jint legacyConfig) { return static_cast<SkColorType>(gConfig2ColorType[legacyConfig]); } -SkBitmap* GraphicsJNI::getNativeBitmap(JNIEnv* env, jobject bitmap) { +SkBitmap* GraphicsJNI::getSkBitmap(JNIEnv* env, jobject bitmap) { SkASSERT(env); SkASSERT(bitmap); SkASSERT(env->IsInstanceOf(bitmap, gBitmap_class)); - jlong bitmapHandle = env->GetLongField(bitmap, gBitmap_nativeInstanceID); + jlong bitmapHandle = env->GetLongField(bitmap, gBitmap_skBitmapPtr); SkBitmap* b = reinterpret_cast<SkBitmap*>(bitmapHandle); SkASSERT(b); return b; @@ -676,7 +676,7 @@ int register_android_graphics_Graphics(JNIEnv* env) gPointF_yFieldID = getFieldIDCheck(env, gPointF_class, "y", "F"); gBitmap_class = make_globalref(env, "android/graphics/Bitmap"); - gBitmap_nativeInstanceID = getFieldIDCheck(env, gBitmap_class, "mNativeBitmap", "J"); + gBitmap_skBitmapPtr = getFieldIDCheck(env, gBitmap_class, "mSkBitmapPtr", "J"); gBitmap_constructorMethodID = env->GetMethodID(gBitmap_class, "<init>", "(J[BIIIZZ[BLandroid/graphics/NinePatch$InsetStruct;)V"); gBitmap_reinitMethodID = env->GetMethodID(gBitmap_class, "reinit", "(IIZ)V"); gBitmap_getAllocationByteCountMethodID = env->GetMethodID(gBitmap_class, "getAllocationByteCount", "()I"); diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h index a202c38..422d3f1 100644 --- a/core/jni/android/graphics/GraphicsJNI.h +++ b/core/jni/android/graphics/GraphicsJNI.h @@ -48,7 +48,7 @@ public: static void point_to_jpointf(const SkPoint& point, JNIEnv*, jobject jpointf); static SkCanvas* getNativeCanvas(JNIEnv*, jobject canvas); - static SkBitmap* getNativeBitmap(JNIEnv*, jobject bitmap); + static SkBitmap* getSkBitmap(JNIEnv*, jobject bitmap); static SkRegion* getNativeRegion(JNIEnv*, jobject region); // Given the 'native' long held by the Rasterizer.java object, return a diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp index 461507f..5c2d0d0 100644 --- a/core/jni/android/opengl/util.cpp +++ b/core/jni/android/opengl/util.cpp @@ -16,6 +16,7 @@ #include "jni.h" #include "JNIHelp.h" +#include "GraphicsJNI.h" #include <math.h> #include <stdio.h> @@ -149,10 +150,6 @@ int visibilityTest(float* pWS, float* pPositions, int positionsLength, return result; } -static void doThrowIAE(JNIEnv* env, const char* msg) { - jniThrowException(env, "java/lang/IllegalArgumentException", msg); -} - template<class JArray, class T> class ArrayHelper { public: @@ -548,14 +545,6 @@ void util_multiplyMV(JNIEnv *env, jclass clazz, // --------------------------------------------------------------------------- -static jfieldID nativeBitmapID = 0; - -void nativeUtilsClassInit(JNIEnv *env, jclass clazz) -{ - jclass bitmapClass = env->FindClass("android/graphics/Bitmap"); - nativeBitmapID = env->GetFieldID(bitmapClass, "mNativeBitmap", "J"); -} - extern void setGLDebugLevel(int level); void setTracingLevel(JNIEnv *env, jclass clazz, jint level) { @@ -629,16 +618,14 @@ static int getType(SkColorType colorType) static jint util_getInternalFormat(JNIEnv *env, jclass clazz, jobject jbitmap) { - SkBitmap const * nativeBitmap = - (SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID); + SkBitmap const * nativeBitmap = GraphicsJNI::getSkBitmap(env, jbitmap); return getInternalFormat(nativeBitmap->colorType()); } static jint util_getType(JNIEnv *env, jclass clazz, jobject jbitmap) { - SkBitmap const * nativeBitmap = - (SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID); + SkBitmap const * nativeBitmap = GraphicsJNI::getSkBitmap(env, jbitmap); return getType(nativeBitmap->colorType()); } @@ -646,8 +633,7 @@ static jint util_texImage2D(JNIEnv *env, jclass clazz, jint target, jint level, jint internalformat, jobject jbitmap, jint type, jint border) { - SkBitmap const * nativeBitmap = - (SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID); + SkBitmap const * nativeBitmap = GraphicsJNI::getSkBitmap(env, jbitmap); const SkBitmap& bitmap(*nativeBitmap); SkColorType colorType = bitmap.colorType(); if (internalformat < 0) { @@ -694,8 +680,7 @@ static jint util_texSubImage2D(JNIEnv *env, jclass clazz, jint target, jint level, jint xoffset, jint yoffset, jobject jbitmap, jint format, jint type) { - SkBitmap const * nativeBitmap = - (SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID); + SkBitmap const * nativeBitmap = GraphicsJNI::getSkBitmap(env, jbitmap); const SkBitmap& bitmap(*nativeBitmap); SkColorType colorType = bitmap.colorType(); if (format < 0) { @@ -1014,7 +999,6 @@ static JNINativeMethod gVisibilityMethods[] = { }; static JNINativeMethod gUtilsMethods[] = { - {"nativeClassInit", "()V", (void*)nativeUtilsClassInit }, { "native_getInternalFormat", "(Landroid/graphics/Bitmap;)I", (void*) util_getInternalFormat }, { "native_getType", "(Landroid/graphics/Bitmap;)I", (void*) util_getType }, { "native_texImage2D", "(IIILandroid/graphics/Bitmap;II)I", (void*)util_texImage2D }, |