Additional loading methods for fonts and a3d files.
Cleaned up error messages.
Change-Id: Id33b7149671df23c37cc11375d844a7837dac750
Change-Id: I6663ce54f7b9bbaf285935ca658d93ba417f8179
diff --git a/graphics/java/android/renderscript/FileA3D.java b/graphics/java/android/renderscript/FileA3D.java
index c3e5faf..01a9a82 100644
--- a/graphics/java/android/renderscript/FileA3D.java
+++ b/graphics/java/android/renderscript/FileA3D.java
@@ -167,47 +167,57 @@
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);
-
- int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
-
- int fileId = rs.nFileA3DCreateFromAssetStream(asset);
-
- if(fileId == 0) {
- throw new IllegalStateException("Load failed.");
- }
- FileA3D fa3d = new FileA3D(fileId, rs, is);
- fa3d.initEntries();
- return fa3d;
-
+ is = res.openRawResource(id);
} catch (Exception e) {
- // Ignore
+ throw new RSRuntimeException("Unable to open resource " + id);
}
- return null;
+ int fileId = 0;
+ if (is instanceof AssetManager.AssetInputStream) {
+ int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
+ fileId = rs.nFileA3DCreateFromAssetStream(asset);
+ } else {
+ throw new RSRuntimeException("Unsupported asset stream");
+ }
+
+ if(fileId == 0) {
+ throw new RSRuntimeException("Unable to create a3d file from resource " + id);
+ }
+ FileA3D fa3d = new FileA3D(fileId, rs, is);
+ fa3d.initEntries();
+ return fa3d;
+
}
}
diff --git a/graphics/java/android/renderscript/Font.java b/graphics/java/android/renderscript/Font.java
index 0f7c24d..ae209fa 100644
--- a/graphics/java/android/renderscript/Font.java
+++ b/graphics/java/android/renderscript/Font.java
@@ -129,41 +129,62 @@
/**
* 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);
+ int dpi = res.getDisplayMetrics().densityDpi;
+ int fontId = rs.nFontCreateFromFile(path, pointSize, dpi);
- if(fontId == 0) {
- throw new IllegalStateException("Failed loading a font");
- }
- Font rsFont = new Font(fontId, rs);
-
- return rsFont;
-
- } catch (Exception e) {
- // Ignore
+ if(fontId == 0) {
+ throw new RSRuntimeException("Unable to create font from file " + path);
}
+ Font rsFont = new Font(fontId, rs);
- return null;
+ return rsFont;
}
- static public Font createFromFile(RenderScript rs, Resources res, File path, float pointSize)
- throws IllegalArgumentException {
+ static public Font createFromFile(RenderScript rs, Resources res, File path, float pointSize) {
return createFromFile(rs, res, path.getAbsolutePath(), pointSize);
}
- static public Font createFromAsset(RenderScript rs, Resources res, AssetManager mgr, String path, float pointSize)
- throws IllegalArgumentException {
- 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 createFromResource(RenderScript rs, Resources res, int id, float pointSize)
- throws IllegalArgumentException {
- return null;
+ 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);
+ }
+
+ 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");
+ }
+
+ if(fontId == 0) {
+ throw new RSRuntimeException("Unable to create font from resource " + id);
+ }
+ Font rsFont = new Font(fontId, rs);
+ return rsFont;
}
/**
@@ -175,8 +196,7 @@
* "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;
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 6a52810..665a893 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -19,6 +19,7 @@
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;
@@ -284,6 +285,14 @@
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);
@@ -301,6 +310,14 @@
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);