summaryrefslogtreecommitdiffstats
path: root/graphics/java
diff options
context:
space:
mode:
authorJoe Onorato <joeo@android.com>2009-08-10 15:15:52 -0700
committerJoe Onorato <joeo@android.com>2009-08-10 15:15:52 -0700
commitf415cf2d78cb214b0a661e0f03905b4279656ea8 (patch)
tree8cc217b5a86b589b87e34215098c1c9c86a01842 /graphics/java
parent5d3b13150d126e6d7f04978f4b142900311758ed (diff)
downloadframeworks_base-f415cf2d78cb214b0a661e0f03905b4279656ea8.zip
frameworks_base-f415cf2d78cb214b0a661e0f03905b4279656ea8.tar.gz
frameworks_base-f415cf2d78cb214b0a661e0f03905b4279656ea8.tar.bz2
Add two addDefines methods to ScriptC.Builder. They add #defines from the fileds on a class or object that you pass in.
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/renderscript/ScriptC.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/graphics/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java
index 0f231d6..bb99e23 100644
--- a/graphics/java/android/renderscript/ScriptC.java
+++ b/graphics/java/android/renderscript/ScriptC.java
@@ -24,10 +24,15 @@ import java.io.InputStream;
import java.util.Map.Entry;
import java.util.HashMap;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
/**
* @hide
**/
public class ScriptC extends Script {
+ private static final String TAG = "ScriptC";
+
ScriptC(int id, RenderScript rs) {
super(id, rs);
}
@@ -113,6 +118,41 @@ public class ScriptC extends Script {
mFloatDefines.put(name, value);
}
+ /**
+ * Takes the all public static final fields for a class, and adds defines
+ * for them, using the name of the field as the name of the define.
+ */
+ public void addDefines(Class cl) {
+ addDefines(cl.getFields(), (Modifier.STATIC | Modifier.FINAL | Modifier.PUBLIC), null);
+ }
+
+ /**
+ * Takes the all public fields for an object, and adds defines
+ * for them, using the name of the field as the name of the define.
+ */
+ public void addDefines(Object o) {
+ addDefines(o.getClass().getFields(), Modifier.PUBLIC, o);
+ }
+
+ void addDefines(Field[] fields, int mask, Object o) {
+ for (Field f: fields) {
+ try {
+ if ((f.getModifiers() & mask) == mask) {
+ Class t = f.getType();
+ if (t == int.class) {
+ mIntDefines.put(f.getName(), f.getInt(o));
+ }
+ else if (t == float.class) {
+ mFloatDefines.put(f.getName(), f.getFloat(o));
+ }
+ }
+ } catch (IllegalAccessException ex) {
+ // TODO: Do we want this log?
+ Log.d(TAG, "addDefines skipping field " + f.getName());
+ }
+ }
+ }
+
public ScriptC create() {
return internalCreate(this);
}