Loading graphics/java/android/renderscript/Allocation.java +45 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.util.TypedValue; **/ public class Allocation extends BaseObj { Type mType; Bitmap mBitmap; Allocation(int id, RenderScript rs, Type t) { super(rs); Loading Loading @@ -262,15 +263,58 @@ public class Allocation extends BaseObj { return new Allocation(id, rs, t); } static private Element elementFromBitmap(RenderScript rs, Bitmap b) { final Bitmap.Config bc = b.getConfig(); if (bc == Bitmap.Config.ALPHA_8) { return Element.A_8(rs); } if (bc == Bitmap.Config.ARGB_4444) { return Element.RGBA_4444(rs); } if (bc == Bitmap.Config.ARGB_8888) { return Element.RGBA_8888(rs); } if (bc == Bitmap.Config.RGB_565) { return Element.RGB_565(rs); } throw new IllegalStateException("Bad bitmap type."); } static private Type typeFromBitmap(RenderScript rs, Bitmap b) { Element e = elementFromBitmap(rs, b); Type.Builder tb = new Type.Builder(rs, e); tb.add(Dimension.X, b.getWidth()); tb.add(Dimension.Y, b.getHeight()); return tb.create(); } static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) throws IllegalArgumentException { rs.validate(); Type t = typeFromBitmap(rs, b); int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b); if(id == 0) { throw new IllegalStateException("Load failed."); } return new Allocation(id, rs, null); return new Allocation(id, rs, t); } static public Allocation createBitmapRef(RenderScript rs, Bitmap b) throws IllegalArgumentException { rs.validate(); Type t = typeFromBitmap(rs, b); int id = rs.nAllocationCreateBitmapRef(t.getID(), b); if(id == 0) { throw new IllegalStateException("Load failed."); } Allocation a = new Allocation(id, rs, t); a.mBitmap = b; return a; } static Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) Loading graphics/java/android/renderscript/RenderScript.java +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ public class RenderScript { native int nAllocationCreateTyped(int type); native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp); native int nAllocationCreateBitmapRef(int type, Bitmap bmp); native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp); native int nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream); Loading graphics/jni/android_renderscript_RenderScript.cpp +21 −0 Original line number Diff line number Diff line Loading @@ -501,6 +501,26 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean g return 0; } static void ReleaseBitmapCallback(void *bmp) { SkBitmap const * nativeBitmap = (SkBitmap const *)bmp; nativeBitmap->unlockPixels(); } static int nAllocationCreateBitmapRef(JNIEnv *_env, jobject _this, jint type, jobject jbitmap) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); SkBitmap * nativeBitmap = (SkBitmap *)_env->GetIntField(jbitmap, gNativeBitmapID); nativeBitmap->lockPixels(); void* ptr = nativeBitmap->getPixels(); jint id = (jint)rsAllocationCreateBitmapRef(con, (RsType)type, ptr, nativeBitmap, ReleaseBitmapCallback); return id; } static int nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jint native_asset) { Loading Loading @@ -1367,6 +1387,7 @@ static JNINativeMethod methods[] = { {"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped }, {"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap }, {"nAllocationCreateBitmapRef", "(ILandroid/graphics/Bitmap;)I", (void*)nAllocationCreateBitmapRef }, {"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed }, {"nAllocationCreateFromAssetStream","(IZI)I", (void*)nAllocationCreateFromAssetStream }, {"nAllocationUploadToTexture", "(IZI)V", (void*)nAllocationUploadToTexture }, Loading libs/rs/RenderScript.h +2 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,8 @@ typedef void * RsProgramFragment; typedef void * RsProgramFragmentStore; typedef void * RsProgramRaster; typedef void (* RsBitmapCallback_t)(void *); enum RsDeviceParam { RS_DEVICE_PARAM_FORCE_SOFTWARE_GL, RS_DEVICE_PARAM_COUNT Loading libs/rs/rs.spec +8 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,14 @@ AllocationCreateSized { ret RsAllocation } AllocationCreateBitmapRef { param RsType type param void * bmpPtr param void * callbackData param RsBitmapCallback_t callback ret RsAllocation } AllocationCreateFromBitmap { param uint32_t width param uint32_t height Loading Loading
graphics/java/android/renderscript/Allocation.java +45 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.util.TypedValue; **/ public class Allocation extends BaseObj { Type mType; Bitmap mBitmap; Allocation(int id, RenderScript rs, Type t) { super(rs); Loading Loading @@ -262,15 +263,58 @@ public class Allocation extends BaseObj { return new Allocation(id, rs, t); } static private Element elementFromBitmap(RenderScript rs, Bitmap b) { final Bitmap.Config bc = b.getConfig(); if (bc == Bitmap.Config.ALPHA_8) { return Element.A_8(rs); } if (bc == Bitmap.Config.ARGB_4444) { return Element.RGBA_4444(rs); } if (bc == Bitmap.Config.ARGB_8888) { return Element.RGBA_8888(rs); } if (bc == Bitmap.Config.RGB_565) { return Element.RGB_565(rs); } throw new IllegalStateException("Bad bitmap type."); } static private Type typeFromBitmap(RenderScript rs, Bitmap b) { Element e = elementFromBitmap(rs, b); Type.Builder tb = new Type.Builder(rs, e); tb.add(Dimension.X, b.getWidth()); tb.add(Dimension.Y, b.getHeight()); return tb.create(); } static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) throws IllegalArgumentException { rs.validate(); Type t = typeFromBitmap(rs, b); int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b); if(id == 0) { throw new IllegalStateException("Load failed."); } return new Allocation(id, rs, null); return new Allocation(id, rs, t); } static public Allocation createBitmapRef(RenderScript rs, Bitmap b) throws IllegalArgumentException { rs.validate(); Type t = typeFromBitmap(rs, b); int id = rs.nAllocationCreateBitmapRef(t.getID(), b); if(id == 0) { throw new IllegalStateException("Load failed."); } Allocation a = new Allocation(id, rs, t); a.mBitmap = b; return a; } static Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) Loading
graphics/java/android/renderscript/RenderScript.java +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ public class RenderScript { native int nAllocationCreateTyped(int type); native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp); native int nAllocationCreateBitmapRef(int type, Bitmap bmp); native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp); native int nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream); Loading
graphics/jni/android_renderscript_RenderScript.cpp +21 −0 Original line number Diff line number Diff line Loading @@ -501,6 +501,26 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean g return 0; } static void ReleaseBitmapCallback(void *bmp) { SkBitmap const * nativeBitmap = (SkBitmap const *)bmp; nativeBitmap->unlockPixels(); } static int nAllocationCreateBitmapRef(JNIEnv *_env, jobject _this, jint type, jobject jbitmap) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); SkBitmap * nativeBitmap = (SkBitmap *)_env->GetIntField(jbitmap, gNativeBitmapID); nativeBitmap->lockPixels(); void* ptr = nativeBitmap->getPixels(); jint id = (jint)rsAllocationCreateBitmapRef(con, (RsType)type, ptr, nativeBitmap, ReleaseBitmapCallback); return id; } static int nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jint native_asset) { Loading Loading @@ -1367,6 +1387,7 @@ static JNINativeMethod methods[] = { {"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped }, {"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap }, {"nAllocationCreateBitmapRef", "(ILandroid/graphics/Bitmap;)I", (void*)nAllocationCreateBitmapRef }, {"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed }, {"nAllocationCreateFromAssetStream","(IZI)I", (void*)nAllocationCreateFromAssetStream }, {"nAllocationUploadToTexture", "(IZI)V", (void*)nAllocationUploadToTexture }, Loading
libs/rs/RenderScript.h +2 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,8 @@ typedef void * RsProgramFragment; typedef void * RsProgramFragmentStore; typedef void * RsProgramRaster; typedef void (* RsBitmapCallback_t)(void *); enum RsDeviceParam { RS_DEVICE_PARAM_FORCE_SOFTWARE_GL, RS_DEVICE_PARAM_COUNT Loading
libs/rs/rs.spec +8 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,14 @@ AllocationCreateSized { ret RsAllocation } AllocationCreateBitmapRef { param RsType type param void * bmpPtr param void * callbackData param RsBitmapCallback_t callback ret RsAllocation } AllocationCreateFromBitmap { param uint32_t width param uint32_t height Loading