Revert "Cleanup Bitmap JNI"
This reverts commit b2915245b74b3b5541b123e38403f8e26426b4b7.
Change-Id: Idd7d7f33eec4ea5024c83de6b10d3d1a6ab2b17a
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java
index 06e196d..0d36949 100644
--- a/core/java/android/view/GLES20Canvas.java
+++ b/core/java/android/view/GLES20Canvas.java
@@ -204,7 +204,7 @@
Bitmap bitmap = patch.getBitmap();
throwIfCannotDraw(bitmap);
final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
- nDrawPatch(mNativeCanvasWrapper, bitmap.getSkBitmap(), patch.mNativeChunk,
+ nDrawPatch(mNativeCanvasWrapper, bitmap.mNativeBitmap, patch.mNativeChunk,
dst.left, dst.top, dst.right, dst.bottom, nativePaint);
}
@@ -214,7 +214,7 @@
Bitmap bitmap = patch.getBitmap();
throwIfCannotDraw(bitmap);
final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
- nDrawPatch(mNativeCanvasWrapper, bitmap.getSkBitmap(), patch.mNativeChunk,
+ nDrawPatch(mNativeCanvasWrapper, bitmap.mNativeBitmap, patch.mNativeChunk,
dst.left, dst.top, dst.right, dst.bottom, nativePaint);
}
diff --git a/core/java/android/view/ThreadedRenderer.java b/core/java/android/view/ThreadedRenderer.java
index 69b4c47..df0838f 100644
--- a/core/java/android/view/ThreadedRenderer.java
+++ b/core/java/android/view/ThreadedRenderer.java
@@ -364,7 +364,7 @@
@Override
boolean copyLayerInto(final HardwareLayer layer, final Bitmap bitmap) {
return nCopyLayerInto(mNativeProxy,
- layer.getDeferredLayerUpdater(), bitmap.getSkBitmap());
+ layer.getDeferredLayerUpdater(), bitmap.mNativeBitmap);
}
@Override
@@ -465,7 +465,7 @@
for (int i = 0; i < count; i++) {
drawables.valueAt(i).addAtlasableBitmaps(tmpList);
for (int j = 0; j < tmpList.size(); j++) {
- preloadedPointers.add(tmpList.get(j).getSkBitmap());
+ preloadedPointers.add(tmpList.get(j).mNativeBitmap);
}
tmpList.clear();
}
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 97744ea..28f1a3a 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -147,7 +147,7 @@
android_hardware_location_ActivityRecognitionHardware.cpp \
android_util_FileObserver.cpp \
android/opengl/poly_clip.cpp.arm \
- android/opengl/util.cpp \
+ android/opengl/util.cpp.arm \
android_server_FingerprintManager.cpp \
android_server_NetworkManagementSocketTagger.cpp \
android_server_Watchdog.cpp \
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp
index 6a50b52..672008d 100644
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -41,6 +41,7 @@
jfieldID gOptions_mCancelID;
jfieldID gOptions_bitmapFieldID;
+jfieldID gBitmap_nativeBitmapFieldID;
jfieldID gBitmap_ninePatchInsetsFieldID;
jclass gInsetStruct_class;
@@ -261,7 +262,7 @@
SkBitmap* outputBitmap = NULL;
unsigned int existingBufferSize = 0;
if (javaBitmap != NULL) {
- outputBitmap = GraphicsJNI::getSkBitmap(env, javaBitmap);
+ outputBitmap = (SkBitmap*) env->GetLongField(javaBitmap, gBitmap_nativeBitmapFieldID);
if (outputBitmap->isImmutable()) {
ALOGW("Unable to reuse an immutable bitmap as an image decoder target.");
javaBitmap = NULL;
@@ -600,6 +601,7 @@
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 04afe3e..90a7f69 100644
--- a/core/jni/android/graphics/BitmapRegionDecoder.cpp
+++ b/core/jni/android/graphics/BitmapRegionDecoder.cpp
@@ -213,7 +213,7 @@
if (tileBitmap != NULL) {
// Re-use bitmap.
- bitmap = GraphicsJNI::getSkBitmap(env, tileBitmap);
+ bitmap = GraphicsJNI::getNativeBitmap(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 0747969..dde1393 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -154,7 +154,7 @@
static jfieldID gPointF_yFieldID;
static jclass gBitmap_class;
-static jfieldID gBitmap_skBitmapPtr;
+static jfieldID gBitmap_nativeInstanceID;
static jmethodID gBitmap_constructorMethodID;
static jmethodID gBitmap_reinitMethodID;
static jmethodID gBitmap_getAllocationByteCountMethodID;
@@ -338,11 +338,11 @@
return static_cast<SkColorType>(gConfig2ColorType[legacyConfig]);
}
-SkBitmap* GraphicsJNI::getSkBitmap(JNIEnv* env, jobject bitmap) {
+SkBitmap* GraphicsJNI::getNativeBitmap(JNIEnv* env, jobject bitmap) {
SkASSERT(env);
SkASSERT(bitmap);
SkASSERT(env->IsInstanceOf(bitmap, gBitmap_class));
- jlong bitmapHandle = env->GetLongField(bitmap, gBitmap_skBitmapPtr);
+ jlong bitmapHandle = env->GetLongField(bitmap, gBitmap_nativeInstanceID);
SkBitmap* b = reinterpret_cast<SkBitmap*>(bitmapHandle);
SkASSERT(b);
return b;
@@ -676,7 +676,7 @@
gPointF_yFieldID = getFieldIDCheck(env, gPointF_class, "y", "F");
gBitmap_class = make_globalref(env, "android/graphics/Bitmap");
- gBitmap_skBitmapPtr = getFieldIDCheck(env, gBitmap_class, "mSkBitmapPtr", "J");
+ gBitmap_nativeInstanceID = getFieldIDCheck(env, gBitmap_class, "mNativeBitmap", "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 422d3f1..a202c38 100644
--- a/core/jni/android/graphics/GraphicsJNI.h
+++ b/core/jni/android/graphics/GraphicsJNI.h
@@ -48,7 +48,7 @@
static void point_to_jpointf(const SkPoint& point, JNIEnv*, jobject jpointf);
static SkCanvas* getNativeCanvas(JNIEnv*, jobject canvas);
- static SkBitmap* getSkBitmap(JNIEnv*, jobject bitmap);
+ static SkBitmap* getNativeBitmap(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 5c2d0d0..461507f 100644
--- a/core/jni/android/opengl/util.cpp
+++ b/core/jni/android/opengl/util.cpp
@@ -16,7 +16,6 @@
#include "jni.h"
#include "JNIHelp.h"
-#include "GraphicsJNI.h"
#include <math.h>
#include <stdio.h>
@@ -150,6 +149,10 @@
return result;
}
+static void doThrowIAE(JNIEnv* env, const char* msg) {
+ jniThrowException(env, "java/lang/IllegalArgumentException", msg);
+}
+
template<class JArray, class T>
class ArrayHelper {
public:
@@ -545,6 +548,14 @@
// ---------------------------------------------------------------------------
+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)
{
@@ -618,14 +629,16 @@
static jint util_getInternalFormat(JNIEnv *env, jclass clazz,
jobject jbitmap)
{
- SkBitmap const * nativeBitmap = GraphicsJNI::getSkBitmap(env, jbitmap);
+ SkBitmap const * nativeBitmap =
+ (SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID);
return getInternalFormat(nativeBitmap->colorType());
}
static jint util_getType(JNIEnv *env, jclass clazz,
jobject jbitmap)
{
- SkBitmap const * nativeBitmap = GraphicsJNI::getSkBitmap(env, jbitmap);
+ SkBitmap const * nativeBitmap =
+ (SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID);
return getType(nativeBitmap->colorType());
}
@@ -633,7 +646,8 @@
jint target, jint level, jint internalformat,
jobject jbitmap, jint type, jint border)
{
- SkBitmap const * nativeBitmap = GraphicsJNI::getSkBitmap(env, jbitmap);
+ SkBitmap const * nativeBitmap =
+ (SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID);
const SkBitmap& bitmap(*nativeBitmap);
SkColorType colorType = bitmap.colorType();
if (internalformat < 0) {
@@ -680,7 +694,8 @@
jint target, jint level, jint xoffset, jint yoffset,
jobject jbitmap, jint format, jint type)
{
- SkBitmap const * nativeBitmap = GraphicsJNI::getSkBitmap(env, jbitmap);
+ SkBitmap const * nativeBitmap =
+ (SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID);
const SkBitmap& bitmap(*nativeBitmap);
SkColorType colorType = bitmap.colorType();
if (format < 0) {
@@ -999,6 +1014,7 @@
};
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 },
diff --git a/core/jni/android_view_PointerIcon.cpp b/core/jni/android_view_PointerIcon.cpp
index f6d9a1a..bbd031e 100644
--- a/core/jni/android_view_PointerIcon.cpp
+++ b/core/jni/android_view_PointerIcon.cpp
@@ -80,7 +80,7 @@
jobject bitmapObj = env->GetObjectField(loadedPointerIconObj, gPointerIconClassInfo.mBitmap);
if (bitmapObj) {
- SkBitmap* bitmap = GraphicsJNI::getSkBitmap(env, bitmapObj);
+ SkBitmap* bitmap = GraphicsJNI::getNativeBitmap(env, bitmapObj);
if (bitmap) {
outPointerIcon->bitmap = *bitmap; // use a shared pixel ref
}
diff --git a/core/jni/com_google_android_gles_jni_EGLImpl.cpp b/core/jni/com_google_android_gles_jni_EGLImpl.cpp
index 7080e2a..6c21bab 100644
--- a/core/jni/com_google_android_gles_jni_EGLImpl.cpp
+++ b/core/jni/com_google_android_gles_jni_EGLImpl.cpp
@@ -30,7 +30,6 @@
#include <gui/GLConsumer.h>
#include <gui/Surface.h>
-#include <GraphicsJNI.h>
#include <SkBitmap.h>
#include <SkPixelRef.h>
@@ -47,6 +46,7 @@
static jfieldID gSurface_EGLSurfaceFieldID;
static jfieldID gSurface_NativePixelRefFieldID;
static jfieldID gConfig_EGLConfigFieldID;
+static jfieldID gBitmap_NativeBitmapFieldID;
static inline EGLDisplay getDisplay(JNIEnv* env, jobject o) {
if (!o) return EGL_NO_DISPLAY;
@@ -85,6 +85,9 @@
jclass surface_class = _env->FindClass("com/google/android/gles_jni/EGLSurfaceImpl");
gSurface_EGLSurfaceFieldID = _env->GetFieldID(surface_class, "mEGLSurface", "J");
gSurface_NativePixelRefFieldID = _env->GetFieldID(surface_class, "mNativePixelRef", "J");
+
+ jclass bitmap_class = _env->FindClass("android/graphics/Bitmap");
+ gBitmap_NativeBitmapFieldID = _env->GetFieldID(bitmap_class, "mNativeBitmap", "J");
}
static const jint gNull_attrib_base[] = {EGL_NONE};
@@ -277,7 +280,9 @@
EGLConfig cnf = getConfig(_env, config);
jint* base = 0;
- SkBitmap const * nativeBitmap = GraphicsJNI::getSkBitmap(_env, native_pixmap);
+ SkBitmap const * nativeBitmap =
+ (SkBitmap const *)_env->GetLongField(native_pixmap,
+ gBitmap_NativeBitmapFieldID);
SkPixelRef* ref = nativeBitmap ? nativeBitmap->pixelRef() : 0;
if (ref == NULL) {
jniThrowException(_env, "java/lang/IllegalArgumentException", "Bitmap has no PixelRef");
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index 5b20d48..132c6ef 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -21,7 +21,6 @@
import android.os.Parcelable;
import android.os.Trace;
import android.util.DisplayMetrics;
-
import dalvik.system.VMRuntime;
import java.io.OutputStream;
@@ -38,14 +37,21 @@
* @see Bitmap#setDensity(int)
*/
public static final int DENSITY_NONE = 0;
-
- private final long mSkBitmapPtr;
+
+ /**
+ * Note: mNativeBitmap is used by FaceDetector_jni.cpp
+ * Don't change/rename without updating FaceDetector_jni.cpp
+ *
+ * @hide
+ */
+ public final long mNativeBitmap;
/**
* Backing buffer for the Bitmap.
*/
private byte[] mBuffer;
+ @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // Keep to finalize native resources
private final BitmapFinalizer mFinalizer;
private final boolean mIsMutable;
@@ -86,11 +92,11 @@
sDefaultDensity = density;
}
- @SuppressWarnings("deprecation")
static int getDefaultDensity() {
if (sDefaultDensity >= 0) {
return sDefaultDensity;
}
+ //noinspection deprecation
sDefaultDensity = DisplayMetrics.DENSITY_DEVICE;
return sDefaultDensity;
}
@@ -99,7 +105,7 @@
* Private constructor that must received an already allocated native bitmap
* int (pointer).
*/
- // called from JNI
+ @SuppressWarnings({"UnusedDeclaration"}) // called from JNI
Bitmap(long nativeBitmap, byte[] buffer, int width, int height, int density,
boolean isMutable, boolean requestPremultiplied,
byte[] ninePatchChunk, NinePatch.InsetStruct ninePatchInsets) {
@@ -114,7 +120,7 @@
mBuffer = buffer;
// we delete this in our finalizer
- mSkBitmapPtr = nativeBitmap;
+ mNativeBitmap = nativeBitmap;
mNinePatchChunk = ninePatchChunk;
mNinePatchInsets = ninePatchInsets;
@@ -130,7 +136,7 @@
* Native bitmap has been reconfigured, so set premult and cached
* width/height values
*/
- // called from JNI
+ @SuppressWarnings({"UnusedDeclaration"}) // called from JNI
void reinit(int width, int height, boolean requestPremultiplied) {
mWidth = width;
mHeight = height;
@@ -221,7 +227,7 @@
throw new IllegalStateException("native-backed bitmaps may not be reconfigured");
}
- nativeReconfigure(mSkBitmapPtr, width, height, config.nativeInt, mBuffer.length,
+ nativeReconfigure(mNativeBitmap, width, height, config.nativeInt, mBuffer.length,
mRequestPremultiplied);
mWidth = width;
mHeight = height;
@@ -299,7 +305,7 @@
*/
public void recycle() {
if (!mRecycled && mFinalizer.mNativeBitmap != 0) {
- if (nativeRecycle(mSkBitmapPtr)) {
+ if (nativeRecycle(mNativeBitmap)) {
// return value indicates whether native pixel object was actually recycled.
// false indicates that it is still in use at the native level and these
// objects should not be collected now. They will be collected later when the
@@ -325,13 +331,13 @@
* Returns the generation ID of this bitmap. The generation ID changes
* whenever the bitmap is modified. This can be used as an efficient way to
* check if a bitmap has changed.
- *
+ *
* @return The current generation ID for this bitmap.
*/
public int getGenerationId() {
- return nativeGenerationId(mSkBitmapPtr);
+ return nativeGenerationId(mNativeBitmap);
}
-
+
/**
* This is called by methods that want to throw an exception if the bitmap
* has already been recycled.
@@ -393,12 +399,12 @@
* encoded: red is stored with 5 bits of precision (32 possible
* values), green is stored with 6 bits of precision (64 possible
* values) and blue is stored with 5 bits of precision.
- *
+ *
* This configuration can produce slight visual artifacts depending
* on the configuration of the source. For instance, without
* dithering, the result might show a greenish tint. To get better
* results dithering should be applied.
- *
+ *
* This configuration may be useful when using opaque bitmaps
* that do not require high color fidelity.
*/
@@ -408,18 +414,18 @@
* Each pixel is stored on 2 bytes. The three RGB color channels
* and the alpha channel (translucency) are stored with a 4 bits
* precision (16 possible values.)
- *
+ *
* This configuration is mostly useful if the application needs
* to store translucency information but also needs to save
* memory.
- *
+ *
* It is recommended to use {@link #ARGB_8888} instead of this
* configuration.
*
* Note: as of {@link android.os.Build.VERSION_CODES#KITKAT},
* any bitmap created with this configuration will be created
* using {@link #ARGB_8888} instead.
- *
+ *
* @deprecated Because of the poor quality of this configuration,
* it is advised to use {@link #ARGB_8888} instead.
*/
@@ -430,7 +436,7 @@
* Each pixel is stored on 4 bytes. Each channel (RGB and alpha
* for translucency) is stored with 8 bits of precision (256
* possible values.)
- *
+ *
* This configuration is very flexible and offers the best
* quality. It should be used whenever possible.
*/
@@ -438,10 +444,11 @@
final int nativeInt;
+ @SuppressWarnings({"deprecation"})
private static Config sConfigs[] = {
null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888
};
-
+
Config(int ni) {
this.nativeInt = ni;
}
@@ -485,7 +492,7 @@
throw new RuntimeException("Buffer not large enough for pixels");
}
- nativeCopyPixelsToBuffer(mSkBitmapPtr, dst);
+ nativeCopyPixelsToBuffer(mNativeBitmap, dst);
// now update the buffer's position
int position = dst.position();
@@ -525,7 +532,7 @@
throw new RuntimeException("Buffer not large enough for pixels");
}
- nativeCopyPixelsFromBuffer(mSkBitmapPtr, src);
+ nativeCopyPixelsFromBuffer(mNativeBitmap, src);
// now update the buffer's position
int position = src.position();
@@ -547,7 +554,7 @@
*/
public Bitmap copy(Config config, boolean isMutable) {
checkRecycled("Can't copy a recycled bitmap");
- Bitmap b = nativeCopy(mSkBitmapPtr, config.nativeInt, isMutable);
+ Bitmap b = nativeCopy(mNativeBitmap, config.nativeInt, isMutable);
if (b != null) {
b.setPremultiplied(mRequestPremultiplied);
b.mDensity = mDensity;
@@ -557,7 +564,7 @@
/**
* Creates a new bitmap, scaled from an existing bitmap, when possible. If the
- * specified width and height are the same as the current width and height of
+ * specified width and height are the same as the current width and height of
* the source bitmap, the source bitmap is returned and no new bitmap is
* created.
*
@@ -632,7 +639,7 @@
* transformed by the optional matrix. The new bitmap may be the
* same object as source, or a copy may have been made. It is
* initialized with the same density as the original bitmap.
- *
+ *
* If the source bitmap is immutable and the requested subset is the
* same as the source bitmap itself, then the source bitmap is
* returned and no new bitmap is created.
@@ -774,8 +781,8 @@
* @param config The bitmap config to create.
* @param hasAlpha If the bitmap is ARGB_8888 this flag can be used to mark the
* bitmap as opaque. Doing so will clear the bitmap in black
- * instead of transparent.
- *
+ * instead of transparent.
+ *
* @throws IllegalArgumentException if the width or height are <= 0
*/
private static Bitmap createBitmap(int width, int height, Config config, boolean hasAlpha) {
@@ -793,8 +800,8 @@
* @param config The bitmap config to create.
* @param hasAlpha If the bitmap is ARGB_8888 this flag can be used to mark the
* bitmap as opaque. Doing so will clear the bitmap in black
- * instead of transparent.
- *
+ * instead of transparent.
+ *
* @throws IllegalArgumentException if the width or height are <= 0
*/
private static Bitmap createBitmap(DisplayMetrics display, int width, int height,
@@ -808,7 +815,7 @@
}
bm.setHasAlpha(hasAlpha);
if (config == Config.ARGB_8888 && !hasAlpha) {
- nativeErase(bm.mSkBitmapPtr, 0xff000000);
+ nativeErase(bm.mNativeBitmap, 0xff000000);
}
// No need to initialize the bitmap to zeroes with other configs;
// it is backed by a VM byte array which is by definition preinitialized
@@ -998,7 +1005,7 @@
throw new IllegalArgumentException("quality must be 0..100");
}
Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "Bitmap.compress");
- boolean result = nativeCompress(mSkBitmapPtr, format.nativeInt, quality,
+ boolean result = nativeCompress(mNativeBitmap, format.nativeInt, quality,
stream, new byte[WORKING_COMPRESS_STORAGE]);
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
return result;
@@ -1015,12 +1022,12 @@
* <p>Indicates whether pixels stored in this bitmaps are stored pre-multiplied.
* When a pixel is pre-multiplied, the RGB components have been multiplied by
* the alpha component. For instance, if the original color is a 50%
- * translucent red <code>(128, 255, 0, 0)</code>, the pre-multiplied form is
+ * translucent red <code>(128, 255, 0, 0)</code>, the pre-multiplied form is
* <code>(128, 128, 0, 0)</code>.</p>
- *
+ *
* <p>This method always returns false if {@link #getConfig()} is
* {@link Bitmap.Config#RGB_565}.</p>
- *
+ *
* <p>The return value is undefined if {@link #getConfig()} is
* {@link Bitmap.Config#ALPHA_8}.</p>
*
@@ -1039,7 +1046,7 @@
* @see BitmapFactory.Options#inPremultiplied
*/
public final boolean isPremultiplied() {
- return nativeIsPremultiplied(mSkBitmapPtr);
+ return nativeIsPremultiplied(mNativeBitmap);
}
/**
@@ -1064,7 +1071,7 @@
*/
public final void setPremultiplied(boolean premultiplied) {
mRequestPremultiplied = premultiplied;
- nativeSetPremultiplied(mSkBitmapPtr, premultiplied);
+ nativeSetPremultiplied(mNativeBitmap, premultiplied);
}
/** Returns the bitmap's width */
@@ -1130,7 +1137,7 @@
public int getScaledHeight(int targetDensity) {
return scaleFromDensity(getHeight(), mDensity, targetDensity);
}
-
+
/**
* @hide
*/
@@ -1138,11 +1145,11 @@
if (sdensity == DENSITY_NONE || tdensity == DENSITY_NONE || sdensity == tdensity) {
return size;
}
-
+
// Scale by tdensity / sdensity, rounding up.
return ((size * tdensity) + (sdensity >> 1)) / sdensity;
}
-
+
/**
* Return the number of bytes between rows in the bitmap's pixels. Note that
* this refers to the pixels as stored natively by the bitmap. If you call
@@ -1156,7 +1163,7 @@
* @return number of bytes between rows of the native bitmap pixels.
*/
public final int getRowBytes() {
- return nativeRowBytes(mSkBitmapPtr);
+ return nativeRowBytes(mNativeBitmap);
}
/**
@@ -1199,7 +1206,7 @@
* that config, otherwise return null.
*/
public final Config getConfig() {
- return Config.nativeToConfig(nativeConfig(mSkBitmapPtr));
+ return Config.nativeToConfig(nativeConfig(mNativeBitmap));
}
/** Returns true if the bitmap's config supports per-pixel alpha, and
@@ -1211,7 +1218,7 @@
* it will return true by default.
*/
public final boolean hasAlpha() {
- return nativeHasAlpha(mSkBitmapPtr);
+ return nativeHasAlpha(mNativeBitmap);
}
/**
@@ -1225,28 +1232,28 @@
* non-opaque per-pixel alpha values.
*/
public void setHasAlpha(boolean hasAlpha) {
- nativeSetHasAlpha(mSkBitmapPtr, hasAlpha, mRequestPremultiplied);
+ nativeSetHasAlpha(mNativeBitmap, hasAlpha, mRequestPremultiplied);
}
/**
* Indicates whether the renderer responsible for drawing this
* bitmap should attempt to use mipmaps when this bitmap is drawn
* scaled down.
- *
+ *
* If you know that you are going to draw this bitmap at less than
* 50% of its original size, you may be able to obtain a higher
* quality
- *
+ *
* This property is only a suggestion that can be ignored by the
* renderer. It is not guaranteed to have any effect.
- *
+ *
* @return true if the renderer should attempt to use mipmaps,
* false otherwise
- *
+ *
* @see #setHasMipMap(boolean)
*/
public final boolean hasMipMap() {
- return nativeHasMipMap(mSkBitmapPtr);
+ return nativeHasMipMap(mNativeBitmap);
}
/**
@@ -1257,7 +1264,7 @@
* If you know that you are going to draw this bitmap at less than
* 50% of its original size, you may be able to obtain a higher
* quality by turning this property on.
- *
+ *
* Note that if the renderer respects this hint it might have to
* allocate extra memory to hold the mipmap levels for this bitmap.
*
@@ -1270,7 +1277,7 @@
* @see #hasMipMap()
*/
public final void setHasMipMap(boolean hasMipMap) {
- nativeSetHasMipMap(mSkBitmapPtr, hasMipMap);
+ nativeSetHasMipMap(mNativeBitmap, hasMipMap);
}
/**
@@ -1283,7 +1290,7 @@
if (!isMutable()) {
throw new IllegalStateException("cannot erase immutable bitmaps");
}
- nativeErase(mSkBitmapPtr, c);
+ nativeErase(mNativeBitmap, c);
}
/**
@@ -1299,7 +1306,7 @@
public int getPixel(int x, int y) {
checkRecycled("Can't call getPixel() on a recycled bitmap");
checkPixelAccess(x, y);
- return nativeGetPixel(mSkBitmapPtr, x, y);
+ return nativeGetPixel(mNativeBitmap, x, y);
}
/**
@@ -1332,14 +1339,14 @@
return; // nothing to do
}
checkPixelsAccess(x, y, width, height, offset, stride, pixels);
- nativeGetPixels(mSkBitmapPtr, pixels, offset, stride,
+ nativeGetPixels(mNativeBitmap, pixels, offset, stride,
x, y, width, height);
}
/**
* Shared code to check for illegal arguments passed to getPixel()
* or setPixel()
- *
+ *
* @param x x coordinate of the pixel
* @param y y coordinate of the pixel
*/
@@ -1413,7 +1420,7 @@
throw new IllegalStateException();
}
checkPixelAccess(x, y);
- nativeSetPixel(mSkBitmapPtr, x, y, color);
+ nativeSetPixel(mNativeBitmap, x, y, color);
}
/**
@@ -1449,7 +1456,7 @@
return; // nothing to do
}
checkPixelsAccess(x, y, width, height, offset, stride, pixels);
- nativeSetPixels(mSkBitmapPtr, pixels, offset, stride,
+ nativeSetPixels(mNativeBitmap, pixels, offset, stride,
x, y, width, height);
}
@@ -1487,7 +1494,7 @@
*/
public void writeToParcel(Parcel p, int flags) {
checkRecycled("Can't parcel a recycled bitmap");
- if (!nativeWriteToParcel(mSkBitmapPtr, mIsMutable, mDensity, p)) {
+ if (!nativeWriteToParcel(mNativeBitmap, mIsMutable, mDensity, p)) {
throw new RuntimeException("native writeToParcel failed");
}
}
@@ -1515,9 +1522,9 @@
* -2, -2, so that drawing the alpha bitmap offset by (-2, -2) and then
* drawing the original would result in the blur visually aligning with
* the original.
- *
+ *
* <p>The initial density of the returned bitmap is the same as the original's.
- *
+ *
* @param paint Optional paint used to modify the alpha values in the
* resulting bitmap. Pass null for default behavior.
* @param offsetXY Optional array that returns the X (index 0) and Y
@@ -1531,7 +1538,7 @@
public Bitmap extractAlpha(Paint paint, int[] offsetXY) {
checkRecycled("Can't extractAlpha on a recycled bitmap");
long nativePaint = paint != null ? paint.getNativeInstance() : 0;
- Bitmap bm = nativeExtractAlpha(mSkBitmapPtr, nativePaint, offsetXY);
+ Bitmap bm = nativeExtractAlpha(mNativeBitmap, nativePaint, offsetXY);
if (bm == null) {
throw new RuntimeException("Failed to extractAlpha on Bitmap");
}
@@ -1545,7 +1552,7 @@
* If other is null, return false.
*/
public boolean sameAs(Bitmap other) {
- return this == other || (other != null && nativeSameAs(mSkBitmapPtr, other.mSkBitmapPtr));
+ return this == other || (other != null && nativeSameAs(mNativeBitmap, other.mNativeBitmap));
}
/**
@@ -1560,12 +1567,7 @@
* and therefore is harmless.
*/
public void prepareToDraw() {
- nativePrepareToDraw(mSkBitmapPtr);
- }
-
- /** @hide */
- public final long getSkBitmap() {
- return mSkBitmapPtr;
+ nativePrepareToDraw(mNativeBitmap);
}
private static class BitmapFinalizer {
@@ -1656,4 +1658,8 @@
private static native boolean nativeHasMipMap(long nativeBitmap);
private static native void nativeSetHasMipMap(long nativeBitmap, boolean hasMipMap);
private static native boolean nativeSameAs(long nativeBitmap0, long nativeBitmap1);
+
+ /* package */ final long ni() {
+ return mNativeBitmap;
+ }
}
diff --git a/graphics/java/android/graphics/BitmapShader.java b/graphics/java/android/graphics/BitmapShader.java
index f2f890e..5e004a3 100644
--- a/graphics/java/android/graphics/BitmapShader.java
+++ b/graphics/java/android/graphics/BitmapShader.java
@@ -42,7 +42,7 @@
mBitmap = bitmap;
mTileX = tileX;
mTileY = tileY;
- final long b = bitmap.getSkBitmap();
+ final long b = bitmap.ni();
init(nativeCreate(b, tileX.nativeInt, tileY.nativeInt));
}
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java
index 85fa3cb..e4c2f0e 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -154,7 +154,7 @@
throw new IllegalStateException("Immutable bitmap passed to Canvas constructor");
}
throwIfCannotDraw(bitmap);
- mNativeCanvasWrapper = initRaster(bitmap.getSkBitmap());
+ mNativeCanvasWrapper = initRaster(bitmap.ni());
mFinalizer = new CanvasFinalizer(mNativeCanvasWrapper);
mBitmap = bitmap;
mDensity = bitmap.mDensity;
@@ -219,7 +219,7 @@
}
throwIfCannotDraw(bitmap);
- native_setBitmap(mNativeCanvasWrapper, bitmap.getSkBitmap(), true);
+ native_setBitmap(mNativeCanvasWrapper, bitmap.ni(), true);
mDensity = bitmap.mDensity;
}
@@ -1339,7 +1339,7 @@
*/
public void drawBitmap(@NonNull Bitmap bitmap, float left, float top, @Nullable Paint paint) {
throwIfCannotDraw(bitmap);
- native_drawBitmap(mNativeCanvasWrapper, bitmap.getSkBitmap(), left, top,
+ native_drawBitmap(mNativeCanvasWrapper, bitmap.ni(), left, top,
paint != null ? paint.getNativeInstance() : 0, mDensity, mScreenDensity, bitmap.mDensity);
}
@@ -1385,7 +1385,7 @@
bottom = src.bottom;
}
- native_drawBitmap(mNativeCanvasWrapper, bitmap.getSkBitmap(), left, top, right, bottom,
+ native_drawBitmap(mNativeCanvasWrapper, bitmap.ni(), left, top, right, bottom,
dst.left, dst.top, dst.right, dst.bottom, nativePaint, mScreenDensity,
bitmap.mDensity);
}
@@ -1432,7 +1432,7 @@
bottom = src.bottom;
}
- native_drawBitmap(mNativeCanvasWrapper, bitmap.getSkBitmap(), left, top, right, bottom,
+ native_drawBitmap(mNativeCanvasWrapper, bitmap.ni(), left, top, right, bottom,
dst.left, dst.top, dst.right, dst.bottom, nativePaint, mScreenDensity,
bitmap.mDensity);
}
@@ -1513,7 +1513,7 @@
* @param paint May be null. The paint used to draw the bitmap
*/
public void drawBitmap(@NonNull Bitmap bitmap, @NonNull Matrix matrix, @Nullable Paint paint) {
- nativeDrawBitmapMatrix(mNativeCanvasWrapper, bitmap.getSkBitmap(), matrix.ni(),
+ nativeDrawBitmapMatrix(mNativeCanvasWrapper, bitmap.ni(), matrix.ni(),
paint != null ? paint.getNativeInstance() : 0);
}
@@ -1568,7 +1568,7 @@
// no mul by 2, since we need only 1 color per vertex
checkRange(colors.length, colorOffset, count);
}
- nativeDrawBitmapMesh(mNativeCanvasWrapper, bitmap.getSkBitmap(), meshWidth, meshHeight,
+ nativeDrawBitmapMesh(mNativeCanvasWrapper, bitmap.ni(), meshWidth, meshHeight,
verts, vertOffset, colors, colorOffset,
paint != null ? paint.getNativeInstance() : 0);
}
diff --git a/graphics/java/android/graphics/NinePatch.java b/graphics/java/android/graphics/NinePatch.java
index 9c4299a..ebc86aa 100644
--- a/graphics/java/android/graphics/NinePatch.java
+++ b/graphics/java/android/graphics/NinePatch.java
@@ -98,7 +98,7 @@
public NinePatch(Bitmap bitmap, byte[] chunk, String srcName) {
mBitmap = bitmap;
mSrcName = srcName;
- mNativeChunk = validateNinePatchChunk(mBitmap.getSkBitmap(), chunk);
+ mNativeChunk = validateNinePatchChunk(mBitmap.ni(), chunk);
}
/**
@@ -199,12 +199,12 @@
}
void drawSoftware(Canvas canvas, RectF location, Paint paint) {
- nativeDraw(canvas.getNativeCanvasWrapper(), location, mBitmap.getSkBitmap(), mNativeChunk,
+ nativeDraw(canvas.getNativeCanvasWrapper(), location, mBitmap.ni(), mNativeChunk,
paint != null ? paint.getNativeInstance() : 0, canvas.mDensity, mBitmap.mDensity);
}
void drawSoftware(Canvas canvas, Rect location, Paint paint) {
- nativeDraw(canvas.getNativeCanvasWrapper(), location, mBitmap.getSkBitmap(), mNativeChunk,
+ nativeDraw(canvas.getNativeCanvasWrapper(), location, mBitmap.ni(), mNativeChunk,
paint != null ? paint.getNativeInstance() : 0, canvas.mDensity, mBitmap.mDensity);
}
@@ -252,7 +252,7 @@
* that are transparent.
*/
public final Region getTransparentRegion(Rect bounds) {
- long r = nativeGetTransparentRegion(mBitmap.getSkBitmap(), mNativeChunk, bounds);
+ long r = nativeGetTransparentRegion(mBitmap.ni(), mNativeChunk, bounds);
return r != 0 ? new Region(r) : null;
}
diff --git a/graphics/java/android/graphics/pdf/PdfRenderer.java b/graphics/java/android/graphics/pdf/PdfRenderer.java
index b32dcc6..79934da 100644
--- a/graphics/java/android/graphics/pdf/PdfRenderer.java
+++ b/graphics/java/android/graphics/pdf/PdfRenderer.java
@@ -380,7 +380,7 @@
final long transformPtr = (transform != null) ? transform.native_instance : 0;
- nativeRenderPage(mNativeDocument, mNativePage, destination.getSkBitmap(), contentLeft,
+ nativeRenderPage(mNativeDocument, mNativePage, destination.mNativeBitmap, contentLeft,
contentTop, contentRight, contentBottom, transformPtr, renderMode);
}
diff --git a/media/jni/android_media_MediaMetadataRetriever.cpp b/media/jni/android_media_MediaMetadataRetriever.cpp
index 2f6bbf4..93138fa 100644
--- a/media/jni/android_media_MediaMetadataRetriever.cpp
+++ b/media/jni/android_media_MediaMetadataRetriever.cpp
@@ -40,6 +40,7 @@
struct fields_t {
jfieldID context;
jclass bitmapClazz; // Must be a global ref
+ jfieldID nativeBitmap;
jmethodID createBitmapMethod;
jmethodID createScaledBitmapMethod;
jclass configClazz; // Must be a global ref
@@ -281,7 +282,8 @@
return NULL;
}
- SkBitmap *bitmap = GraphicsJNI::getSkBitmap(env, jBitmap);
+ SkBitmap *bitmap =
+ (SkBitmap *) env->GetLongField(jBitmap, fields.nativeBitmap);
bitmap->lockPixels();
rotate((uint16_t*)bitmap->getPixels(),
@@ -419,6 +421,10 @@
if (fields.createScaledBitmapMethod == NULL) {
return;
}
+ fields.nativeBitmap = env->GetFieldID(fields.bitmapClazz, "mNativeBitmap", "J");
+ if (fields.nativeBitmap == NULL) {
+ return;
+ }
jclass configClazz = env->FindClass("android/graphics/Bitmap$Config");
if (configClazz == NULL) {
diff --git a/native/graphics/jni/bitmap.cpp b/native/graphics/jni/bitmap.cpp
index ddb01a0..ea32edc 100644
--- a/native/graphics/jni/bitmap.cpp
+++ b/native/graphics/jni/bitmap.cpp
@@ -27,7 +27,7 @@
return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
}
- SkBitmap* bm = GraphicsJNI::getSkBitmap(env, jbitmap);
+ SkBitmap* bm = GraphicsJNI::getNativeBitmap(env, jbitmap);
if (NULL == bm) {
return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
}
@@ -64,7 +64,7 @@
return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
}
- SkBitmap* bm = GraphicsJNI::getSkBitmap(env, jbitmap);
+ SkBitmap* bm = GraphicsJNI::getNativeBitmap(env, jbitmap);
if (NULL == bm) {
return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
}
@@ -87,7 +87,7 @@
return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
}
- SkBitmap* bm = GraphicsJNI::getSkBitmap(env, jbitmap);
+ SkBitmap* bm = GraphicsJNI::getNativeBitmap(env, jbitmap);
if (NULL == bm) {
return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
}
diff --git a/opengl/java/android/opengl/GLUtils.java b/opengl/java/android/opengl/GLUtils.java
index 4d890c9..a9d33dd 100644
--- a/opengl/java/android/opengl/GLUtils.java
+++ b/opengl/java/android/opengl/GLUtils.java
@@ -29,6 +29,14 @@
public final class GLUtils {
+ /*
+ * We use a class initializer to allow the native code to cache some
+ * field offsets.
+ */
+ static {
+ nativeClassInit();
+ }
+
private GLUtils() {
}
@@ -267,6 +275,8 @@
*/
native public static void setTracingLevel(int level);
+ native private static void nativeClassInit();
+
native private static int native_getInternalFormat(Bitmap bitmap);
native private static int native_getType(Bitmap bitmap);
native private static int native_texImage2D(int target, int level, int internalformat,
diff --git a/rs/jni/Android.mk b/rs/jni/Android.mk
index 94f0859..f1f0bfc 100644
--- a/rs/jni/Android.mk
+++ b/rs/jni/Android.mk
@@ -14,8 +14,7 @@
libskia \
libutils \
libui \
- libgui \
- libjnigraphics
+ libgui
LOCAL_STATIC_LIBRARIES :=
@@ -24,7 +23,6 @@
LOCAL_C_INCLUDES += \
$(JNI_H_INCLUDE) \
frameworks/rs \
- frameworks/base/core/jni \
$(rs_generated_include_dir)
LOCAL_CFLAGS += -Wno-unused-parameter -std=c++11
diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp
index d8e1464..a145166 100644
--- a/rs/jni/android_renderscript_RenderScript.cpp
+++ b/rs/jni/android_renderscript_RenderScript.cpp
@@ -24,6 +24,8 @@
#include <utils/misc.h>
#include <inttypes.h>
+#include <SkBitmap.h>
+
#include <androidfw/Asset.h>
#include <androidfw/AssetManager.h>
#include <androidfw/ResourceTypes.h>
@@ -33,7 +35,6 @@
#include "android_runtime/AndroidRuntime.h"
#include "android_runtime/android_view_Surface.h"
#include "android_runtime/android_util_AssetManager.h"
-#include "android/graphics/GraphicsJNI.h"
#include <rs.h>
#include <rsEnv.h>
@@ -171,10 +172,14 @@
// ---------------------------------------------------------------------------
static jfieldID gContextId = 0;
+static jfieldID gNativeBitmapID = 0;
static void _nInit(JNIEnv *_env, jclass _this)
{
gContextId = _env->GetFieldID(_this, "mContext", "J");
+
+ jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
+ gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
}
// ---------------------------------------------------------------------------
@@ -929,7 +934,7 @@
jobject jbitmap, jint usage)
{
SkBitmap const * nativeBitmap =
- GraphicsJNI::getSkBitmap(_env, jbitmap);
+ (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
const SkBitmap& bitmap(*nativeBitmap);
bitmap.lockPixels();
@@ -946,7 +951,7 @@
jint mip, jobject jbitmap, jint usage)
{
SkBitmap const * nativeBitmap =
- GraphicsJNI::getSkBitmap(_env, jbitmap);
+ (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
const SkBitmap& bitmap(*nativeBitmap);
bitmap.lockPixels();
@@ -963,7 +968,7 @@
jobject jbitmap, jint usage)
{
SkBitmap const * nativeBitmap =
- GraphicsJNI::getSkBitmap(_env, jbitmap);
+ (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
const SkBitmap& bitmap(*nativeBitmap);
bitmap.lockPixels();
@@ -979,7 +984,7 @@
nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
{
SkBitmap const * nativeBitmap =
- GraphicsJNI::getSkBitmap(_env, jbitmap);
+ (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
const SkBitmap& bitmap(*nativeBitmap);
int w = bitmap.width();
int h = bitmap.height();
@@ -996,7 +1001,7 @@
nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
{
SkBitmap const * nativeBitmap =
- GraphicsJNI::getSkBitmap(_env, jbitmap);
+ (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
const SkBitmap& bitmap(*nativeBitmap);
bitmap.lockPixels();
diff --git a/services/core/java/com/android/server/AssetAtlasService.java b/services/core/java/com/android/server/AssetAtlasService.java
index e6dc1c7..a2c87b9 100644
--- a/services/core/java/com/android/server/AssetAtlasService.java
+++ b/services/core/java/com/android/server/AssetAtlasService.java
@@ -291,7 +291,7 @@
}
canvas.drawBitmap(bitmap, 0.0f, 0.0f, null);
canvas.restore();
- atlasMap[mapIndex++] = bitmap.getSkBitmap();
+ atlasMap[mapIndex++] = bitmap.mNativeBitmap;
atlasMap[mapIndex++] = entry.x;
atlasMap[mapIndex++] = entry.y;
atlasMap[mapIndex++] = entry.rotated ? 1 : 0;