Loading graphics/java/android/renderscript/Allocation.java +20 −0 Original line number Diff line number Diff line Loading @@ -233,6 +233,10 @@ public class Allocation extends BaseObj { } } private void setBitmap(Bitmap b) { mBitmap = b; } Allocation(int id, RenderScript rs, Type t, int usage) { super(id, rs); if ((usage & ~(USAGE_SCRIPT | Loading Loading @@ -1151,6 +1155,22 @@ public class Allocation extends BaseObj { rs.validate(); Type t = typeFromBitmap(rs, b, mips); // enable optimized bitmap path only with no mipmap and script-only usage if (mips == MipmapControl.MIPMAP_NONE && t.getElement().isCompatible(Element.RGBA_8888(rs)) && usage == USAGE_SCRIPT) { int id = rs.nAllocationCreateBitmapBackedAllocation(t.getID(rs), mips.mID, b, usage); if (id == 0) { throw new RSRuntimeException("Load failed."); } // keep a reference to the Bitmap around to prevent GC Allocation alloc = new Allocation(id, rs, t, usage); alloc.setBitmap(b); return alloc; } int id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage); if (id == 0) { throw new RSRuntimeException("Load failed."); Loading graphics/java/android/renderscript/RenderScript.java +8 −0 Original line number Diff line number Diff line Loading @@ -261,6 +261,14 @@ public class RenderScript { validate(); return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage); } native int rsnAllocationCreateBitmapBackedAllocation(int con, int type, int mip, Bitmap bmp, int usage); synchronized int nAllocationCreateBitmapBackedAllocation(int type, int mip, Bitmap bmp, int usage) { validate(); return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage); } native int rsnAllocationCubeCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage); synchronized int nAllocationCubeCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) { validate(); Loading graphics/jni/android_renderscript_RenderScript.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -538,6 +538,22 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint typ return id; } static int nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) { SkBitmap const * nativeBitmap = (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); const SkBitmap& bitmap(*nativeBitmap); bitmap.lockPixels(); const void* ptr = bitmap.getPixels(); jint id = (jint)rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mip, (uint32_t)usage, (size_t)ptr); bitmap.unlockPixels(); return id; } static int nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) { Loading Loading @@ -1443,6 +1459,7 @@ static JNINativeMethod methods[] = { {"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped }, {"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap }, {"rsnAllocationCreateBitmapBackedAllocation", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateBitmapBackedAllocation }, {"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap }, {"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, Loading Loading
graphics/java/android/renderscript/Allocation.java +20 −0 Original line number Diff line number Diff line Loading @@ -233,6 +233,10 @@ public class Allocation extends BaseObj { } } private void setBitmap(Bitmap b) { mBitmap = b; } Allocation(int id, RenderScript rs, Type t, int usage) { super(id, rs); if ((usage & ~(USAGE_SCRIPT | Loading Loading @@ -1151,6 +1155,22 @@ public class Allocation extends BaseObj { rs.validate(); Type t = typeFromBitmap(rs, b, mips); // enable optimized bitmap path only with no mipmap and script-only usage if (mips == MipmapControl.MIPMAP_NONE && t.getElement().isCompatible(Element.RGBA_8888(rs)) && usage == USAGE_SCRIPT) { int id = rs.nAllocationCreateBitmapBackedAllocation(t.getID(rs), mips.mID, b, usage); if (id == 0) { throw new RSRuntimeException("Load failed."); } // keep a reference to the Bitmap around to prevent GC Allocation alloc = new Allocation(id, rs, t, usage); alloc.setBitmap(b); return alloc; } int id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage); if (id == 0) { throw new RSRuntimeException("Load failed."); Loading
graphics/java/android/renderscript/RenderScript.java +8 −0 Original line number Diff line number Diff line Loading @@ -261,6 +261,14 @@ public class RenderScript { validate(); return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage); } native int rsnAllocationCreateBitmapBackedAllocation(int con, int type, int mip, Bitmap bmp, int usage); synchronized int nAllocationCreateBitmapBackedAllocation(int type, int mip, Bitmap bmp, int usage) { validate(); return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage); } native int rsnAllocationCubeCreateFromBitmap(int con, int type, int mip, Bitmap bmp, int usage); synchronized int nAllocationCubeCreateFromBitmap(int type, int mip, Bitmap bmp, int usage) { validate(); Loading
graphics/jni/android_renderscript_RenderScript.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -538,6 +538,22 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint typ return id; } static int nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) { SkBitmap const * nativeBitmap = (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); const SkBitmap& bitmap(*nativeBitmap); bitmap.lockPixels(); const void* ptr = bitmap.getPixels(); jint id = (jint)rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mip, (uint32_t)usage, (size_t)ptr); bitmap.unlockPixels(); return id; } static int nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) { Loading Loading @@ -1443,6 +1459,7 @@ static JNINativeMethod methods[] = { {"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped }, {"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap }, {"rsnAllocationCreateBitmapBackedAllocation", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateBitmapBackedAllocation }, {"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap }, {"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, Loading