Loading graphics/java/android/renderscript/FileA3D.java +36 −26 Original line number Diff line number Diff line Loading @@ -167,47 +167,57 @@ public class FileA3D extends BaseObj { return mFileEntries[index]; } // API cleanup stand-ins // TODO: implement ermaining loading mechanisms static public FileA3D createFromAsset(RenderScript rs, AssetManager mgr, String path) throws IllegalArgumentException { return null; static public FileA3D createFromAsset(RenderScript rs, AssetManager mgr, String path) { rs.validate(); int fileId = rs.nFileA3DCreateFromAsset(mgr, path); if(fileId == 0) { throw new RSRuntimeException("Unable to create a3d file from asset " + path); } FileA3D fa3d = new FileA3D(fileId, rs, null); fa3d.initEntries(); return fa3d; } static public FileA3D createFromFile(RenderScript rs, String path) throws IllegalArgumentException { return null; static public FileA3D createFromFile(RenderScript rs, String path) { int fileId = rs.nFileA3DCreateFromFile(path); if(fileId == 0) { throw new RSRuntimeException("Unable to create a3d file from " + path); } FileA3D fa3d = new FileA3D(fileId, rs, null); fa3d.initEntries(); return fa3d; } static public FileA3D createFromFile(RenderScript rs, File path) throws IllegalArgumentException { static public FileA3D createFromFile(RenderScript rs, File path) { return createFromFile(rs, path.getAbsolutePath()); } static public FileA3D createFromResource(RenderScript rs, Resources res, int id) throws IllegalArgumentException { static public FileA3D createFromResource(RenderScript rs, Resources res, int id) { rs.validate(); InputStream is = null; try { final TypedValue value = new TypedValue(); is = res.openRawResource(id, value); is = res.openRawResource(id); } catch (Exception e) { throw new RSRuntimeException("Unable to open resource " + id); } int fileId = 0; if (is instanceof AssetManager.AssetInputStream) { int asset = ((AssetManager.AssetInputStream) is).getAssetInt(); int fileId = rs.nFileA3DCreateFromAssetStream(asset); fileId = rs.nFileA3DCreateFromAssetStream(asset); } else { throw new RSRuntimeException("Unsupported asset stream"); } if(fileId == 0) { throw new IllegalStateException("Load failed."); throw new RSRuntimeException("Unable to create a3d file from resource " + id); } FileA3D fa3d = new FileA3D(fileId, rs, is); fa3d.initEntries(); return fa3d; } catch (Exception e) { // Ignore } return null; } } graphics/java/android/renderscript/Font.java +46 −26 Original line number Diff line number Diff line Loading @@ -129,41 +129,62 @@ public class Font extends BaseObj { /** * Takes a specific file name as an argument */ static public Font createFromFile(RenderScript rs, Resources res, String path, float pointSize) throws IllegalArgumentException { static public Font createFromFile(RenderScript rs, Resources res, String path, float pointSize) { rs.validate(); try { int dpi = res.getDisplayMetrics().densityDpi; int fontId = rs.nFontCreateFromFile(path, pointSize, dpi); if(fontId == 0) { throw new IllegalStateException("Failed loading a font"); throw new RSRuntimeException("Unable to create font from file " + path); } Font rsFont = new Font(fontId, rs); return rsFont; } } catch (Exception e) { // Ignore static public Font createFromFile(RenderScript rs, Resources res, File path, float pointSize) { return createFromFile(rs, res, path.getAbsolutePath(), pointSize); } return null; static public Font createFromAsset(RenderScript rs, Resources res, String path, float pointSize) { rs.validate(); AssetManager mgr = res.getAssets(); int dpi = res.getDisplayMetrics().densityDpi; int fontId = rs.nFontCreateFromAsset(mgr, path, pointSize, dpi); if(fontId == 0) { throw new RSRuntimeException("Unable to create font from asset " + path); } Font rsFont = new Font(fontId, rs); return rsFont; } static public Font createFromFile(RenderScript rs, Resources res, File path, float pointSize) throws IllegalArgumentException { return createFromFile(rs, res, path.getAbsolutePath(), pointSize); static public Font createFromResource(RenderScript rs, Resources res, int id, float pointSize) { String name = "R." + Integer.toString(id); rs.validate(); InputStream is = null; try { is = res.openRawResource(id); } catch (Exception e) { throw new RSRuntimeException("Unable to open resource " + id); } static public Font createFromAsset(RenderScript rs, Resources res, AssetManager mgr, String path, float pointSize) throws IllegalArgumentException { return null; int dpi = res.getDisplayMetrics().densityDpi; int fontId = 0; if (is instanceof AssetManager.AssetInputStream) { int asset = ((AssetManager.AssetInputStream) is).getAssetInt(); fontId = rs.nFontCreateFromAssetStream(name, pointSize, dpi, asset); } else { throw new RSRuntimeException("Unsupported asset stream created"); } static public Font createFromResource(RenderScript rs, Resources res, int id, float pointSize) throws IllegalArgumentException { return null; if(fontId == 0) { throw new RSRuntimeException("Unable to create font from resource " + id); } Font rsFont = new Font(fontId, rs); return rsFont; } /** Loading @@ -175,8 +196,7 @@ public class Font extends BaseObj { * "monospace" "courier" "courier new" "monaco" * Returns default font if no match could be found */ static public Font create(RenderScript rs, Resources res, String familyName, Style fontStyle, float pointSize) throws IllegalArgumentException { static public Font create(RenderScript rs, Resources res, String familyName, Style fontStyle, float pointSize) { String fileName = getFontFileName(familyName, fontStyle); String fontPath = Environment.getRootDirectory().getAbsolutePath(); fontPath += "/fonts/" + fileName; Loading graphics/java/android/renderscript/RenderScript.java +17 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.renderscript; import java.lang.reflect.Field; import android.content.Context; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Config; Loading Loading @@ -284,6 +285,14 @@ public class RenderScript { synchronized int nFileA3DCreateFromAssetStream(int assetStream) { return rsnFileA3DCreateFromAssetStream(mContext, assetStream); } native int rsnFileA3DCreateFromFile(int con, String path); synchronized int nFileA3DCreateFromFile(String path) { return rsnFileA3DCreateFromFile(mContext, path); } native int rsnFileA3DCreateFromAsset(int con, AssetManager mgr, String path); synchronized int nFileA3DCreateFromAsset(AssetManager mgr, String path) { return rsnFileA3DCreateFromAsset(mContext, mgr, path); } native int rsnFileA3DGetNumIndexEntries(int con, int fileA3D); synchronized int nFileA3DGetNumIndexEntries(int fileA3D) { return rsnFileA3DGetNumIndexEntries(mContext, fileA3D); Loading @@ -301,6 +310,14 @@ public class RenderScript { synchronized int nFontCreateFromFile(String fileName, float size, int dpi) { return rsnFontCreateFromFile(mContext, fileName, size, dpi); } native int rsnFontCreateFromAssetStream(int con, String name, float size, int dpi, int assetStream); synchronized int nFontCreateFromAssetStream(String name, float size, int dpi, int assetStream) { return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream); } native int rsnFontCreateFromAsset(int con, AssetManager mgr, String path, float size, int dpi); synchronized int nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) { return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi); } native void rsnScriptBindAllocation(int con, int script, int alloc, int slot); Loading graphics/jni/android_renderscript_RenderScript.cpp +100 −19 Original line number Diff line number Diff line Loading @@ -32,12 +32,14 @@ #include <images/SkImageDecoder.h> #include <utils/Asset.h> #include <utils/AssetManager.h> #include <utils/ResourceTypes.h> #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" #include "android_runtime/android_view_Surface.h" #include "android_runtime/android_util_AssetManager.h" #include <RenderScript.h> #include <RenderScriptEnv.h> Loading @@ -47,6 +49,27 @@ using namespace android; class AutoJavaStringToUTF8 { public: AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) { fCStr = env->GetStringUTFChars(str, NULL); fLength = env->GetStringUTFLength(str); } ~AutoJavaStringToUTF8() { fEnv->ReleaseStringUTFChars(fJStr, fCStr); } const char* c_str() const { return fCStr; } jsize length() const { return fLength; } private: JNIEnv* fEnv; jstring fJStr; const char* fCStr; jsize fLength; }; // --------------------------------------------------------------------------- static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL) Loading Loading @@ -572,7 +595,34 @@ nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint n Asset* asset = reinterpret_cast<Asset*>(native_asset); jint id = (jint)rsaFileA3DCreateFromAssetStream(con, asset->getBuffer(false), asset->getLength()); jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength()); return id; } static int nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path) { AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); if (mgr == NULL) { return 0; } AutoJavaStringToUTF8 str(_env, _path); Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); if (asset == NULL) { return 0; } jint id = (jint)rsaFileA3DCreateFromAsset(con, asset); return id; } static int nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName) { AutoJavaStringToUTF8 fileNameUTF(_env, fileName); jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str()); return id; } Loading Loading @@ -611,11 +661,45 @@ nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D // ----------------------------------- static int nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName, jfloat fontSize, jint dpi) nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName, jfloat fontSize, jint dpi) { AutoJavaStringToUTF8 fileNameUTF(_env, fileName); jint id = (jint)rsFontCreateFromFile(con, fileNameUTF.c_str(), fontSize, dpi); return id; } static int nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jstring name, jfloat fontSize, jint dpi, jint native_asset) { const char* fileNameUTF = _env->GetStringUTFChars(fileName, NULL); Asset* asset = reinterpret_cast<Asset*>(native_asset); AutoJavaStringToUTF8 nameUTF(_env, name); jint id = (jint)rsFontCreateFromMemory(con, nameUTF.c_str(), fontSize, dpi, asset->getBuffer(false), asset->getLength()); return id; } static int nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path, jfloat fontSize, jint dpi) { AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); if (mgr == NULL) { return 0; } AutoJavaStringToUTF8 str(_env, _path); Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); if (asset == NULL) { return 0; } jint id = (jint)rsFontCreateFromFile(con, fileNameUTF, fontSize, dpi); jint id = (jint)rsFontCreateFromMemory(con, str.c_str(), fontSize, dpi, asset->getBuffer(false), asset->getLength()); delete asset; return id; } Loading Loading @@ -764,13 +848,10 @@ static jint nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, jstring packageName, jstring resName, jstring cacheDir) { LOG_API("nScriptCCreate, con(%p)", con); const char* packageNameUTF = _env->GetStringUTFChars(packageName, NULL); const char* resNameUTF = _env->GetStringUTFChars(resName, NULL); const char* cacheDirUTF = _env->GetStringUTFChars(cacheDir, NULL); jint i = (jint)rsScriptCCreate(con, packageNameUTF, resNameUTF, cacheDirUTF); _env->ReleaseStringUTFChars(packageName, packageNameUTF); _env->ReleaseStringUTFChars(resName, resNameUTF); _env->ReleaseStringUTFChars(cacheDir, cacheDirUTF); AutoJavaStringToUTF8 packageNameUTF(_env, packageName); AutoJavaStringToUTF8 resNameUTF(_env, resName); AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); jint i = (jint)rsScriptCCreate(con, packageNameUTF.c_str(), resNameUTF.c_str(), cacheDirUTF.c_str()); return i; } Loading Loading @@ -853,15 +934,13 @@ nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint s static jint nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params) { const char* shaderUTF = _env->GetStringUTFChars(shader, NULL); jint shaderLen = _env->GetStringUTFLength(shader); AutoJavaStringToUTF8 shaderUTF(_env, shader); jint *paramPtr = _env->GetIntArrayElements(params, NULL); jint paramLen = _env->GetArrayLength(params); LOG_API("nProgramFragmentCreate, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen); jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen); _env->ReleaseStringUTFChars(shader, shaderUTF); jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen); _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); return ret; } Loading @@ -872,15 +951,13 @@ nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shade static jint nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params) { const char* shaderUTF = _env->GetStringUTFChars(shader, NULL); jint shaderLen = _env->GetStringUTFLength(shader); AutoJavaStringToUTF8 shaderUTF(_env, shader); jint *paramPtr = _env->GetIntArrayElements(params, NULL); jint paramLen = _env->GetArrayLength(params); LOG_API("nProgramVertexCreate, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen); jint ret = (jint)rsProgramVertexCreate(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen); _env->ReleaseStringUTFChars(shader, shaderUTF); jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen); _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); return ret; } Loading Loading @@ -1095,12 +1172,16 @@ static JNINativeMethod methods[] = { {"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName }, {"rsnObjDestroy", "(II)V", (void*)nObjDestroy }, {"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile }, {"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream }, {"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset }, {"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries }, {"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries }, {"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex }, {"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile }, {"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream }, {"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset }, {"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate }, {"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 }, Loading libs/rs/RenderScript.h +3 −1 Original line number Diff line number Diff line Loading @@ -334,7 +334,9 @@ typedef struct { // A3D loading and object update code. // Should only be called at object creation, not thread safe RsObjectBase rsaFileA3DGetEntryByIndex(RsContext, uint32_t idx, RsFile); RsFile rsaFileA3DCreateFromAssetStream(RsContext, const void *data, uint32_t len); RsFile rsaFileA3DCreateFromMemory(RsContext, const void *data, uint32_t len); RsFile rsaFileA3DCreateFromAsset(RsContext, void *asset); RsFile rsaFileA3DCreateFromFile(RsContext, const char *path); void rsaFileA3DGetNumIndexEntries(RsContext, int32_t *numEntries, RsFile); void rsaFileA3DGetIndexEntries(RsContext, RsFileIndexEntry *fileEntries,uint32_t numEntries, RsFile); void rsaGetName(RsContext, void * obj, const char **name); Loading Loading
graphics/java/android/renderscript/FileA3D.java +36 −26 Original line number Diff line number Diff line Loading @@ -167,47 +167,57 @@ public class FileA3D extends BaseObj { return mFileEntries[index]; } // API cleanup stand-ins // TODO: implement ermaining loading mechanisms static public FileA3D createFromAsset(RenderScript rs, AssetManager mgr, String path) throws IllegalArgumentException { return null; static public FileA3D createFromAsset(RenderScript rs, AssetManager mgr, String path) { rs.validate(); int fileId = rs.nFileA3DCreateFromAsset(mgr, path); if(fileId == 0) { throw new RSRuntimeException("Unable to create a3d file from asset " + path); } FileA3D fa3d = new FileA3D(fileId, rs, null); fa3d.initEntries(); return fa3d; } static public FileA3D createFromFile(RenderScript rs, String path) throws IllegalArgumentException { return null; static public FileA3D createFromFile(RenderScript rs, String path) { int fileId = rs.nFileA3DCreateFromFile(path); if(fileId == 0) { throw new RSRuntimeException("Unable to create a3d file from " + path); } FileA3D fa3d = new FileA3D(fileId, rs, null); fa3d.initEntries(); return fa3d; } static public FileA3D createFromFile(RenderScript rs, File path) throws IllegalArgumentException { static public FileA3D createFromFile(RenderScript rs, File path) { return createFromFile(rs, path.getAbsolutePath()); } static public FileA3D createFromResource(RenderScript rs, Resources res, int id) throws IllegalArgumentException { static public FileA3D createFromResource(RenderScript rs, Resources res, int id) { rs.validate(); InputStream is = null; try { final TypedValue value = new TypedValue(); is = res.openRawResource(id, value); is = res.openRawResource(id); } catch (Exception e) { throw new RSRuntimeException("Unable to open resource " + id); } int fileId = 0; if (is instanceof AssetManager.AssetInputStream) { int asset = ((AssetManager.AssetInputStream) is).getAssetInt(); int fileId = rs.nFileA3DCreateFromAssetStream(asset); fileId = rs.nFileA3DCreateFromAssetStream(asset); } else { throw new RSRuntimeException("Unsupported asset stream"); } if(fileId == 0) { throw new IllegalStateException("Load failed."); throw new RSRuntimeException("Unable to create a3d file from resource " + id); } FileA3D fa3d = new FileA3D(fileId, rs, is); fa3d.initEntries(); return fa3d; } catch (Exception e) { // Ignore } return null; } }
graphics/java/android/renderscript/Font.java +46 −26 Original line number Diff line number Diff line Loading @@ -129,41 +129,62 @@ public class Font extends BaseObj { /** * Takes a specific file name as an argument */ static public Font createFromFile(RenderScript rs, Resources res, String path, float pointSize) throws IllegalArgumentException { static public Font createFromFile(RenderScript rs, Resources res, String path, float pointSize) { rs.validate(); try { int dpi = res.getDisplayMetrics().densityDpi; int fontId = rs.nFontCreateFromFile(path, pointSize, dpi); if(fontId == 0) { throw new IllegalStateException("Failed loading a font"); throw new RSRuntimeException("Unable to create font from file " + path); } Font rsFont = new Font(fontId, rs); return rsFont; } } catch (Exception e) { // Ignore static public Font createFromFile(RenderScript rs, Resources res, File path, float pointSize) { return createFromFile(rs, res, path.getAbsolutePath(), pointSize); } return null; static public Font createFromAsset(RenderScript rs, Resources res, String path, float pointSize) { rs.validate(); AssetManager mgr = res.getAssets(); int dpi = res.getDisplayMetrics().densityDpi; int fontId = rs.nFontCreateFromAsset(mgr, path, pointSize, dpi); if(fontId == 0) { throw new RSRuntimeException("Unable to create font from asset " + path); } Font rsFont = new Font(fontId, rs); return rsFont; } static public Font createFromFile(RenderScript rs, Resources res, File path, float pointSize) throws IllegalArgumentException { return createFromFile(rs, res, path.getAbsolutePath(), pointSize); static public Font createFromResource(RenderScript rs, Resources res, int id, float pointSize) { String name = "R." + Integer.toString(id); rs.validate(); InputStream is = null; try { is = res.openRawResource(id); } catch (Exception e) { throw new RSRuntimeException("Unable to open resource " + id); } static public Font createFromAsset(RenderScript rs, Resources res, AssetManager mgr, String path, float pointSize) throws IllegalArgumentException { return null; int dpi = res.getDisplayMetrics().densityDpi; int fontId = 0; if (is instanceof AssetManager.AssetInputStream) { int asset = ((AssetManager.AssetInputStream) is).getAssetInt(); fontId = rs.nFontCreateFromAssetStream(name, pointSize, dpi, asset); } else { throw new RSRuntimeException("Unsupported asset stream created"); } static public Font createFromResource(RenderScript rs, Resources res, int id, float pointSize) throws IllegalArgumentException { return null; if(fontId == 0) { throw new RSRuntimeException("Unable to create font from resource " + id); } Font rsFont = new Font(fontId, rs); return rsFont; } /** Loading @@ -175,8 +196,7 @@ public class Font extends BaseObj { * "monospace" "courier" "courier new" "monaco" * Returns default font if no match could be found */ static public Font create(RenderScript rs, Resources res, String familyName, Style fontStyle, float pointSize) throws IllegalArgumentException { static public Font create(RenderScript rs, Resources res, String familyName, Style fontStyle, float pointSize) { String fileName = getFontFileName(familyName, fontStyle); String fontPath = Environment.getRootDirectory().getAbsolutePath(); fontPath += "/fonts/" + fileName; Loading
graphics/java/android/renderscript/RenderScript.java +17 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.renderscript; import java.lang.reflect.Field; import android.content.Context; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Config; Loading Loading @@ -284,6 +285,14 @@ public class RenderScript { synchronized int nFileA3DCreateFromAssetStream(int assetStream) { return rsnFileA3DCreateFromAssetStream(mContext, assetStream); } native int rsnFileA3DCreateFromFile(int con, String path); synchronized int nFileA3DCreateFromFile(String path) { return rsnFileA3DCreateFromFile(mContext, path); } native int rsnFileA3DCreateFromAsset(int con, AssetManager mgr, String path); synchronized int nFileA3DCreateFromAsset(AssetManager mgr, String path) { return rsnFileA3DCreateFromAsset(mContext, mgr, path); } native int rsnFileA3DGetNumIndexEntries(int con, int fileA3D); synchronized int nFileA3DGetNumIndexEntries(int fileA3D) { return rsnFileA3DGetNumIndexEntries(mContext, fileA3D); Loading @@ -301,6 +310,14 @@ public class RenderScript { synchronized int nFontCreateFromFile(String fileName, float size, int dpi) { return rsnFontCreateFromFile(mContext, fileName, size, dpi); } native int rsnFontCreateFromAssetStream(int con, String name, float size, int dpi, int assetStream); synchronized int nFontCreateFromAssetStream(String name, float size, int dpi, int assetStream) { return rsnFontCreateFromAssetStream(mContext, name, size, dpi, assetStream); } native int rsnFontCreateFromAsset(int con, AssetManager mgr, String path, float size, int dpi); synchronized int nFontCreateFromAsset(AssetManager mgr, String path, float size, int dpi) { return rsnFontCreateFromAsset(mContext, mgr, path, size, dpi); } native void rsnScriptBindAllocation(int con, int script, int alloc, int slot); Loading
graphics/jni/android_renderscript_RenderScript.cpp +100 −19 Original line number Diff line number Diff line Loading @@ -32,12 +32,14 @@ #include <images/SkImageDecoder.h> #include <utils/Asset.h> #include <utils/AssetManager.h> #include <utils/ResourceTypes.h> #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" #include "android_runtime/android_view_Surface.h" #include "android_runtime/android_util_AssetManager.h" #include <RenderScript.h> #include <RenderScriptEnv.h> Loading @@ -47,6 +49,27 @@ using namespace android; class AutoJavaStringToUTF8 { public: AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) { fCStr = env->GetStringUTFChars(str, NULL); fLength = env->GetStringUTFLength(str); } ~AutoJavaStringToUTF8() { fEnv->ReleaseStringUTFChars(fJStr, fCStr); } const char* c_str() const { return fCStr; } jsize length() const { return fLength; } private: JNIEnv* fEnv; jstring fJStr; const char* fCStr; jsize fLength; }; // --------------------------------------------------------------------------- static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL) Loading Loading @@ -572,7 +595,34 @@ nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint n Asset* asset = reinterpret_cast<Asset*>(native_asset); jint id = (jint)rsaFileA3DCreateFromAssetStream(con, asset->getBuffer(false), asset->getLength()); jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength()); return id; } static int nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path) { AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); if (mgr == NULL) { return 0; } AutoJavaStringToUTF8 str(_env, _path); Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); if (asset == NULL) { return 0; } jint id = (jint)rsaFileA3DCreateFromAsset(con, asset); return id; } static int nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName) { AutoJavaStringToUTF8 fileNameUTF(_env, fileName); jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str()); return id; } Loading Loading @@ -611,11 +661,45 @@ nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D // ----------------------------------- static int nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName, jfloat fontSize, jint dpi) nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName, jfloat fontSize, jint dpi) { AutoJavaStringToUTF8 fileNameUTF(_env, fileName); jint id = (jint)rsFontCreateFromFile(con, fileNameUTF.c_str(), fontSize, dpi); return id; } static int nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jstring name, jfloat fontSize, jint dpi, jint native_asset) { const char* fileNameUTF = _env->GetStringUTFChars(fileName, NULL); Asset* asset = reinterpret_cast<Asset*>(native_asset); AutoJavaStringToUTF8 nameUTF(_env, name); jint id = (jint)rsFontCreateFromMemory(con, nameUTF.c_str(), fontSize, dpi, asset->getBuffer(false), asset->getLength()); return id; } static int nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path, jfloat fontSize, jint dpi) { AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); if (mgr == NULL) { return 0; } AutoJavaStringToUTF8 str(_env, _path); Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); if (asset == NULL) { return 0; } jint id = (jint)rsFontCreateFromFile(con, fileNameUTF, fontSize, dpi); jint id = (jint)rsFontCreateFromMemory(con, str.c_str(), fontSize, dpi, asset->getBuffer(false), asset->getLength()); delete asset; return id; } Loading Loading @@ -764,13 +848,10 @@ static jint nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, jstring packageName, jstring resName, jstring cacheDir) { LOG_API("nScriptCCreate, con(%p)", con); const char* packageNameUTF = _env->GetStringUTFChars(packageName, NULL); const char* resNameUTF = _env->GetStringUTFChars(resName, NULL); const char* cacheDirUTF = _env->GetStringUTFChars(cacheDir, NULL); jint i = (jint)rsScriptCCreate(con, packageNameUTF, resNameUTF, cacheDirUTF); _env->ReleaseStringUTFChars(packageName, packageNameUTF); _env->ReleaseStringUTFChars(resName, resNameUTF); _env->ReleaseStringUTFChars(cacheDir, cacheDirUTF); AutoJavaStringToUTF8 packageNameUTF(_env, packageName); AutoJavaStringToUTF8 resNameUTF(_env, resName); AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); jint i = (jint)rsScriptCCreate(con, packageNameUTF.c_str(), resNameUTF.c_str(), cacheDirUTF.c_str()); return i; } Loading Loading @@ -853,15 +934,13 @@ nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint s static jint nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params) { const char* shaderUTF = _env->GetStringUTFChars(shader, NULL); jint shaderLen = _env->GetStringUTFLength(shader); AutoJavaStringToUTF8 shaderUTF(_env, shader); jint *paramPtr = _env->GetIntArrayElements(params, NULL); jint paramLen = _env->GetArrayLength(params); LOG_API("nProgramFragmentCreate, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen); jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen); _env->ReleaseStringUTFChars(shader, shaderUTF); jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen); _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); return ret; } Loading @@ -872,15 +951,13 @@ nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shade static jint nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params) { const char* shaderUTF = _env->GetStringUTFChars(shader, NULL); jint shaderLen = _env->GetStringUTFLength(shader); AutoJavaStringToUTF8 shaderUTF(_env, shader); jint *paramPtr = _env->GetIntArrayElements(params, NULL); jint paramLen = _env->GetArrayLength(params); LOG_API("nProgramVertexCreate, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen); jint ret = (jint)rsProgramVertexCreate(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen); _env->ReleaseStringUTFChars(shader, shaderUTF); jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen); _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); return ret; } Loading Loading @@ -1095,12 +1172,16 @@ static JNINativeMethod methods[] = { {"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName }, {"rsnObjDestroy", "(II)V", (void*)nObjDestroy }, {"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile }, {"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream }, {"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset }, {"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries }, {"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries }, {"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex }, {"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile }, {"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream }, {"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset }, {"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate }, {"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 }, Loading
libs/rs/RenderScript.h +3 −1 Original line number Diff line number Diff line Loading @@ -334,7 +334,9 @@ typedef struct { // A3D loading and object update code. // Should only be called at object creation, not thread safe RsObjectBase rsaFileA3DGetEntryByIndex(RsContext, uint32_t idx, RsFile); RsFile rsaFileA3DCreateFromAssetStream(RsContext, const void *data, uint32_t len); RsFile rsaFileA3DCreateFromMemory(RsContext, const void *data, uint32_t len); RsFile rsaFileA3DCreateFromAsset(RsContext, void *asset); RsFile rsaFileA3DCreateFromFile(RsContext, const char *path); void rsaFileA3DGetNumIndexEntries(RsContext, int32_t *numEntries, RsFile); void rsaFileA3DGetIndexEntries(RsContext, RsFileIndexEntry *fileEntries,uint32_t numEntries, RsFile); void rsaGetName(RsContext, void * obj, const char **name); Loading