summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2010-07-15 11:33:03 -0700
committerAlex Sakhartchouk <alexst@google.com>2010-07-15 14:02:54 -0700
commitdfac814c18f73dd7289f9927edca3e3b6ec6bc00 (patch)
tree386ca04866a3e7be79ae621582222a8f2b09ceda /graphics
parent506821b406181ff9b9a10c2fc078d16b79a8cf92 (diff)
downloadframeworks_base-dfac814c18f73dd7289f9927edca3e3b6ec6bc00.zip
frameworks_base-dfac814c18f73dd7289f9927edca3e3b6ec6bc00.tar.gz
frameworks_base-dfac814c18f73dd7289f9927edca3e3b6ec6bc00.tar.bz2
Populate java objects with native data from a3d file.
Remove legacy constructor from programraster Make a3d object creation synchronous Change-Id: Ic7d7547cf6eee6f9a7c6e3ee12cd104e80056a7b
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/renderscript/Allocation.java10
-rw-r--r--graphics/java/android/renderscript/Element.java40
-rw-r--r--graphics/java/android/renderscript/FileA3D.java32
-rw-r--r--graphics/java/android/renderscript/ProgramRaster.java8
-rw-r--r--graphics/java/android/renderscript/RenderScript.java4
-rw-r--r--graphics/java/android/renderscript/Type.java23
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp72
7 files changed, 169 insertions, 20 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index bfa61f3..87735b5 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -45,6 +45,16 @@ public class Allocation extends BaseObj {
mID = id;
}
+ @Override
+ void updateFromNative() {
+ mRS.validate();
+ int typeID = mRS.nAllocationGetType(mID);
+ if(typeID != 0) {
+ mType = new Type(typeID, mRS);
+ mType.updateFromNative();
+ }
+ }
+
public Type getType() {
return mType;
}
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index 308d663..5d2a059 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -17,6 +17,7 @@
package android.renderscript;
import java.lang.reflect.Field;
+import android.util.Log;
/**
* @hide
@@ -308,6 +309,45 @@ public class Element extends BaseObj {
mID = rs.nElementCreate(dt.mID, dk.mID, norm, size);
}
+ Element(RenderScript rs, int id) {
+ super(rs);
+ mID = id;
+ }
+
+ @Override
+ void updateFromNative() {
+
+ // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
+ int[] dataBuffer = new int[5];
+ mRS.nElementGetNativeData(mID, dataBuffer);
+ for (DataType dt: DataType.values()) {
+ if(dt.mID == dataBuffer[0]){
+ mType = dt;
+ }
+ }
+ for (DataKind dk: DataKind.values()) {
+ if(dk.mID == dataBuffer[1]){
+ mKind = dk;
+ }
+ }
+
+ mNormalized = dataBuffer[2] == 1 ? true : false;
+ mVectorSize = dataBuffer[3];
+ int numSubElements = dataBuffer[4];
+ if(numSubElements > 0) {
+ mElements = new Element[numSubElements];
+ mElementNames = new String[numSubElements];
+
+ int[] subElementIds = new int[numSubElements];
+ mRS.nElementGetSubElements(mID, subElementIds, mElementNames);
+ for(int i = 0; i < numSubElements; i ++) {
+ mElements[i] = new Element(mRS, subElementIds[i]);
+ mElements[i].updateFromNative();
+ }
+ }
+
+ }
+
public void destroy() throws IllegalStateException {
super.destroy();
}
diff --git a/graphics/java/android/renderscript/FileA3D.java b/graphics/java/android/renderscript/FileA3D.java
index 3b3711b..302a5f4 100644
--- a/graphics/java/android/renderscript/FileA3D.java
+++ b/graphics/java/android/renderscript/FileA3D.java
@@ -56,7 +56,7 @@ public class FileA3D extends BaseObj {
}
// Read only class with index entries
- public class IndexEntry {
+ public static class IndexEntry {
RenderScript mRS;
int mIndex;
int mID;
@@ -73,34 +73,40 @@ public class FileA3D extends BaseObj {
}
public BaseObj getObject() {
- if(mLoadedObj != null) {
- return mLoadedObj;
+ mRS.validate();
+ BaseObj obj = internalCreate(mRS, this);
+ return obj;
+ }
+
+ static synchronized BaseObj internalCreate(RenderScript rs, IndexEntry entry) {
+ if(entry.mLoadedObj != null) {
+ return entry.mLoadedObj;
}
- if(mClassID == ClassID.UNKNOWN) {
+ if(entry.mClassID == ClassID.UNKNOWN) {
return null;
}
- int objectID = mRS.nFileA3DGetEntryByIndex(mID, mIndex);
+ int objectID = rs.nFileA3DGetEntryByIndex(entry.mID, entry.mIndex);
if(objectID == 0) {
return null;
}
- switch (mClassID) {
+ switch (entry.mClassID) {
case MESH:
- mLoadedObj = new Mesh(objectID, mRS);
+ entry.mLoadedObj = new Mesh(objectID, rs);
break;
case TYPE:
- mLoadedObj = new Type(objectID, mRS);
+ entry.mLoadedObj = new Type(objectID, rs);
break;
case ELEMENT:
- mLoadedObj = null;
+ entry.mLoadedObj = null;
break;
case ALLOCATION:
- mLoadedObj = null;
+ entry.mLoadedObj = null;
break;
case PROGRAM_VERTEX:
- mLoadedObj = new ProgramVertex(objectID, mRS);
+ entry.mLoadedObj = new ProgramVertex(objectID, rs);
break;
case PROGRAM_RASTER:
break;
@@ -122,7 +128,9 @@ public class FileA3D extends BaseObj {
break;
}
- return mLoadedObj;
+ entry.mLoadedObj.updateFromNative();
+
+ return entry.mLoadedObj;
}
IndexEntry(RenderScript rs, int index, int id, String name, ClassID classID) {
diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java
index 55e6586..6fc9fff 100644
--- a/graphics/java/android/renderscript/ProgramRaster.java
+++ b/graphics/java/android/renderscript/ProgramRaster.java
@@ -74,14 +74,6 @@ public class ProgramRaster extends BaseObj {
boolean mPointSmooth;
boolean mLineSmooth;
- // Legacy to not break app in other projects, will be removed in cleanup pass
- public Builder(RenderScript rs, Element in, Element out) {
- mRS = rs;
- mPointSmooth = false;
- mLineSmooth = false;
- mPointSprite = false;
- }
-
public Builder(RenderScript rs) {
mRS = rs;
mPointSmooth = false;
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 240d544..1135a75 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -90,12 +90,15 @@ public class RenderScript {
native int nElementCreate(int type, int kind, boolean norm, int vecSize);
native int nElementCreate2(int[] elements, String[] names);
+ native void nElementGetNativeData(int id, int[] elementData);
+ native void nElementGetSubElements(int id, int[] IDs, String[] names);
native void nTypeBegin(int elementID);
native void nTypeAdd(int dim, int val);
native int nTypeCreate();
native void nTypeFinalDestroy(Type t);
native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs);
+ native void nTypeGetNativeData(int id, int[] typeData);
native int nAllocationCreateTyped(int type);
native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
@@ -117,6 +120,7 @@ public class RenderScript {
native void nAllocationRead(int id, float[] d);
native void nAllocationSubDataFromObject(int id, Type t, int offset, Object o);
native void nAllocationSubReadFromObject(int id, Type t, int offset, Object o);
+ native int nAllocationGetType(int id);
native int nFileA3DCreateFromAssetStream(int assetStream);
native int nFileA3DGetNumIndexEntries(int fileA3D);
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index 14422b2..8e45f2b 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -16,7 +16,9 @@
package android.renderscript;
+
import java.lang.reflect.Field;
+import android.util.Log;
/**
* @hide
@@ -108,6 +110,27 @@ public class Type extends BaseObj {
super.finalize();
}
+ @Override
+ void updateFromNative() {
+ // We have 6 integer to obtain mDimX; mDimY; mDimZ;
+ // mDimLOD; mDimFaces; mElement;
+ int[] dataBuffer = new int[6];
+ mRS.nTypeGetNativeData(mID, dataBuffer);
+
+ mDimX = dataBuffer[0];
+ mDimY = dataBuffer[1];
+ mDimZ = dataBuffer[2];
+ mDimLOD = dataBuffer[3] == 1 ? true : false;
+ mDimFaces = dataBuffer[4] == 1 ? true : false;
+
+ int elementID = dataBuffer[5];
+ if(elementID != 0) {
+ mElement = new Element(mRS, elementID);
+ mElement.updateFromNative();
+ }
+ calcElementCount();
+ }
+
public static Type createFromClass(RenderScript rs, Class c, int size, String scriptName) {
android.util.Log.e("RenderScript", "Calling depricated createFromClass");
return null;
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 13360c3..888c76a 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -297,6 +297,46 @@ nElementCreate2(JNIEnv *_env, jobject _this, jintArray _ids, jobjectArray _names
return (jint)id;
}
+static void
+nElementGetNativeData(JNIEnv *_env, jobject _this, jint id, jintArray _elementData)
+{
+ int dataSize = _env->GetArrayLength(_elementData);
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nElementGetNativeData, con(%p)", con);
+
+ // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
+ assert(dataSize == 5);
+
+ uint32_t elementData[5];
+ rsElementGetNativeData(con, (RsElement)id, elementData, dataSize);
+
+ for(jint i = 0; i < dataSize; i ++) {
+ _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
+ }
+}
+
+
+static void
+nElementGetSubElements(JNIEnv *_env, jobject _this, jint id, jintArray _IDs, jobjectArray _names)
+{
+ int dataSize = _env->GetArrayLength(_IDs);
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nElementGetSubElements, con(%p)", con);
+
+ uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
+ const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
+
+ rsElementGetSubElements(con, (RsElement)id, ids, names, (uint32_t)dataSize);
+
+ for(jint i = 0; i < dataSize; i ++) {
+ _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
+ _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
+ }
+
+ free(ids);
+ free(names);
+}
+
// -----------------------------------
static void
@@ -323,6 +363,26 @@ nTypeCreate(JNIEnv *_env, jobject _this)
return (jint)rsTypeCreate(con);
}
+static void
+nTypeGetNativeData(JNIEnv *_env, jobject _this, jint id, jintArray _typeData)
+{
+ // We are packing 6 items: mDimX; mDimY; mDimZ;
+ // mDimLOD; mDimFaces; mElement; into typeData
+ int elementCount = _env->GetArrayLength(_typeData);
+
+ assert(elementCount == 6);
+
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nTypeCreate, con(%p)", con);
+
+ uint32_t typeData[6];
+ rsTypeGetNativeData(con, (RsType)id, typeData, 6);
+
+ for(jint i = 0; i < elementCount; i ++) {
+ _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
+ }
+}
+
static void * SF_LoadInt(JNIEnv *_env, jobject _obj, jfieldID _field, void *buffer)
{
((int32_t *)buffer)[0] = _env->GetIntField(_obj, _field);
@@ -708,6 +768,14 @@ nAllocationSubReadFromObject(JNIEnv *_env, jobject _this, jint alloc, jobject _t
free(bufAlloc);
}
+static jint
+nAllocationGetType(JNIEnv *_env, jobject _this, jint a)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
+ return (jint) rsAllocationGetType(con, (RsAllocation)a);
+}
+
// -----------------------------------
static int
@@ -1466,12 +1534,15 @@ static JNINativeMethod methods[] = {
{"nElementCreate", "(IIZI)I", (void*)nElementCreate },
{"nElementCreate2", "([I[Ljava/lang/String;)I", (void*)nElementCreate2 },
+{"nElementGetNativeData", "(I[I)V", (void*)nElementGetNativeData },
+{"nElementGetSubElements", "(I[I[Ljava/lang/String;)V", (void*)nElementGetSubElements },
{"nTypeBegin", "(I)V", (void*)nTypeBegin },
{"nTypeAdd", "(II)V", (void*)nTypeAdd },
{"nTypeCreate", "()I", (void*)nTypeCreate },
{"nTypeFinalDestroy", "(Landroid/renderscript/Type;)V", (void*)nTypeFinalDestroy },
{"nTypeSetupFields", "(Landroid/renderscript/Type;[I[I[Ljava/lang/reflect/Field;)V", (void*)nTypeSetupFields },
+{"nTypeGetNativeData", "(I[I)V", (void*)nTypeGetNativeData },
{"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped },
{"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap },
@@ -1490,6 +1561,7 @@ static JNINativeMethod methods[] = {
{"nAllocationRead", "(I[F)V", (void*)nAllocationRead_f },
{"nAllocationSubDataFromObject", "(ILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubDataFromObject },
{"nAllocationSubReadFromObject", "(ILandroid/renderscript/Type;ILjava/lang/Object;)V", (void*)nAllocationSubReadFromObject },
+{"nAllocationGetType", "(I)I", (void*)nAllocationGetType},
{"nAdapter1DBindAllocation", "(II)V", (void*)nAdapter1DBindAllocation },
{"nAdapter1DSetConstraint", "(III)V", (void*)nAdapter1DSetConstraint },