Loading core/jni/android/graphics/Bitmap.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -719,6 +719,21 @@ static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle, getPremulBitmapCreateFlags(isMutable)); } static jobject Bitmap_copyAshmem(JNIEnv* env, jobject, jlong srcHandle) { SkBitmap src; reinterpret_cast<Bitmap*>(srcHandle)->getSkBitmap(&src); SkBitmap result; AshmemPixelAllocator allocator(env); if (!src.copyTo(&result, &allocator)) { return NULL; } Bitmap* bitmap = allocator.getStorageObjAndReset(); bitmap->peekAtPixelRef()->setImmutable(); jobject ret = GraphicsJNI::createBitmap(env, bitmap, getPremulBitmapCreateFlags(false)); return ret; } static void Bitmap_destructor(JNIEnv* env, jobject, jlong bitmapHandle) { LocalScopedBitmap bitmap(bitmapHandle); bitmap->detachFromJava(); Loading Loading @@ -1267,6 +1282,8 @@ static JNINativeMethod gBitmapMethods[] = { (void*)Bitmap_creator }, { "nativeCopy", "(JIZ)Landroid/graphics/Bitmap;", (void*)Bitmap_copy }, { "nativeCopyAshmem", "(J)Landroid/graphics/Bitmap;", (void*)Bitmap_copyAshmem }, { "nativeDestructor", "(J)V", (void*)Bitmap_destructor }, { "nativeRecycle", "(J)Z", (void*)Bitmap_recycle }, { "nativeReconfigure", "(JIIIIZ)V", (void*)Bitmap_reconfigure }, Loading core/jni/android/graphics/Graphics.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -674,6 +674,25 @@ bool JavaPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { //////////////////////////////////////////////////////////////////////////////// AshmemPixelAllocator::AshmemPixelAllocator(JNIEnv *env) { LOG_ALWAYS_FATAL_IF(env->GetJavaVM(&mJavaVM) != JNI_OK, "env->GetJavaVM failed"); } AshmemPixelAllocator::~AshmemPixelAllocator() { if (mStorage) { mStorage->detachFromJava(); } } bool AshmemPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { JNIEnv* env = vm2env(mJavaVM); mStorage = GraphicsJNI::allocateAshmemPixelRef(env, bitmap, ctable); return mStorage != nullptr; } //////////////////////////////////////////////////////////////////////////////// static jclass make_globalref(JNIEnv* env, const char classname[]) { jclass c = env->FindClass(classname); Loading core/jni/android/graphics/GraphicsJNI.h +17 −0 Original line number Diff line number Diff line Loading @@ -144,6 +144,23 @@ private: android::Bitmap* mStorage = nullptr; }; class AshmemPixelAllocator : public SkBitmap::Allocator { public: AshmemPixelAllocator(JNIEnv* env); ~AshmemPixelAllocator(); virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable); android::Bitmap* getStorageObjAndReset() { android::Bitmap* result = mStorage; mStorage = NULL; return result; }; private: JavaVM* mJavaVM; android::Bitmap* mStorage = nullptr; }; enum JNIAccess { kRO_JNIAccess, kRW_JNIAccess Loading graphics/java/android/graphics/Bitmap.java +17 −0 Original line number Diff line number Diff line Loading @@ -557,6 +557,22 @@ public final class Bitmap implements Parcelable { return b; } /** * Creates a new immutable bitmap backed by ashmem which can efficiently * be passed between processes. * * @hide */ public Bitmap createAshmemBitmap() { checkRecycled("Can't copy a recycled bitmap"); Bitmap b = nativeCopyAshmem(mFinalizer.mNativeBitmap); if (b != null) { b.setPremultiplied(mRequestPremultiplied); b.mDensity = mDensity; } return b; } /** * 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 Loading Loading @@ -1636,6 +1652,7 @@ public final class Bitmap implements Parcelable { int nativeConfig, boolean mutable); private static native Bitmap nativeCopy(long nativeSrcBitmap, int nativeConfig, boolean isMutable); private static native Bitmap nativeCopyAshmem(long nativeSrcBitmap); private static native void nativeDestructor(long nativeBitmap); private static native boolean nativeRecycle(long nativeBitmap); private static native void nativeReconfigure(long nativeBitmap, int width, int height, Loading Loading
core/jni/android/graphics/Bitmap.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -719,6 +719,21 @@ static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle, getPremulBitmapCreateFlags(isMutable)); } static jobject Bitmap_copyAshmem(JNIEnv* env, jobject, jlong srcHandle) { SkBitmap src; reinterpret_cast<Bitmap*>(srcHandle)->getSkBitmap(&src); SkBitmap result; AshmemPixelAllocator allocator(env); if (!src.copyTo(&result, &allocator)) { return NULL; } Bitmap* bitmap = allocator.getStorageObjAndReset(); bitmap->peekAtPixelRef()->setImmutable(); jobject ret = GraphicsJNI::createBitmap(env, bitmap, getPremulBitmapCreateFlags(false)); return ret; } static void Bitmap_destructor(JNIEnv* env, jobject, jlong bitmapHandle) { LocalScopedBitmap bitmap(bitmapHandle); bitmap->detachFromJava(); Loading Loading @@ -1267,6 +1282,8 @@ static JNINativeMethod gBitmapMethods[] = { (void*)Bitmap_creator }, { "nativeCopy", "(JIZ)Landroid/graphics/Bitmap;", (void*)Bitmap_copy }, { "nativeCopyAshmem", "(J)Landroid/graphics/Bitmap;", (void*)Bitmap_copyAshmem }, { "nativeDestructor", "(J)V", (void*)Bitmap_destructor }, { "nativeRecycle", "(J)Z", (void*)Bitmap_recycle }, { "nativeReconfigure", "(JIIIIZ)V", (void*)Bitmap_reconfigure }, Loading
core/jni/android/graphics/Graphics.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -674,6 +674,25 @@ bool JavaPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { //////////////////////////////////////////////////////////////////////////////// AshmemPixelAllocator::AshmemPixelAllocator(JNIEnv *env) { LOG_ALWAYS_FATAL_IF(env->GetJavaVM(&mJavaVM) != JNI_OK, "env->GetJavaVM failed"); } AshmemPixelAllocator::~AshmemPixelAllocator() { if (mStorage) { mStorage->detachFromJava(); } } bool AshmemPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { JNIEnv* env = vm2env(mJavaVM); mStorage = GraphicsJNI::allocateAshmemPixelRef(env, bitmap, ctable); return mStorage != nullptr; } //////////////////////////////////////////////////////////////////////////////// static jclass make_globalref(JNIEnv* env, const char classname[]) { jclass c = env->FindClass(classname); Loading
core/jni/android/graphics/GraphicsJNI.h +17 −0 Original line number Diff line number Diff line Loading @@ -144,6 +144,23 @@ private: android::Bitmap* mStorage = nullptr; }; class AshmemPixelAllocator : public SkBitmap::Allocator { public: AshmemPixelAllocator(JNIEnv* env); ~AshmemPixelAllocator(); virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable); android::Bitmap* getStorageObjAndReset() { android::Bitmap* result = mStorage; mStorage = NULL; return result; }; private: JavaVM* mJavaVM; android::Bitmap* mStorage = nullptr; }; enum JNIAccess { kRO_JNIAccess, kRW_JNIAccess Loading
graphics/java/android/graphics/Bitmap.java +17 −0 Original line number Diff line number Diff line Loading @@ -557,6 +557,22 @@ public final class Bitmap implements Parcelable { return b; } /** * Creates a new immutable bitmap backed by ashmem which can efficiently * be passed between processes. * * @hide */ public Bitmap createAshmemBitmap() { checkRecycled("Can't copy a recycled bitmap"); Bitmap b = nativeCopyAshmem(mFinalizer.mNativeBitmap); if (b != null) { b.setPremultiplied(mRequestPremultiplied); b.mDensity = mDensity; } return b; } /** * 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 Loading Loading @@ -1636,6 +1652,7 @@ public final class Bitmap implements Parcelable { int nativeConfig, boolean mutable); private static native Bitmap nativeCopy(long nativeSrcBitmap, int nativeConfig, boolean isMutable); private static native Bitmap nativeCopyAshmem(long nativeSrcBitmap); private static native void nativeDestructor(long nativeBitmap); private static native boolean nativeRecycle(long nativeBitmap); private static native void nativeReconfigure(long nativeBitmap, int width, int height, Loading