diff options
| author | 2010-07-15 11:33:03 -0700 | |
|---|---|---|
| committer | 2010-07-15 14:02:54 -0700 | |
| commit | dfac814c18f73dd7289f9927edca3e3b6ec6bc00 (patch) | |
| tree | 386ca04866a3e7be79ae621582222a8f2b09ceda | |
| parent | 506821b406181ff9b9a10c2fc078d16b79a8cf92 (diff) | |
Populate java objects with native data from a3d file.
Remove legacy constructor from programraster
Make a3d object creation synchronous
Change-Id: Ic7d7547cf6eee6f9a7c6e3ee12cd104e80056a7b
| -rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 10 | ||||
| -rw-r--r-- | graphics/java/android/renderscript/Element.java | 40 | ||||
| -rw-r--r-- | graphics/java/android/renderscript/FileA3D.java | 32 | ||||
| -rw-r--r-- | graphics/java/android/renderscript/ProgramRaster.java | 8 | ||||
| -rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 4 | ||||
| -rw-r--r-- | graphics/java/android/renderscript/Type.java | 23 | ||||
| -rw-r--r-- | graphics/jni/android_renderscript_RenderScript.cpp | 72 | ||||
| -rw-r--r-- | libs/rs/rs.spec | 24 | ||||
| -rw-r--r-- | libs/rs/rsElement.cpp | 26 | ||||
| -rw-r--r-- | libs/rs/rsType.cpp | 18 |
10 files changed, 236 insertions, 21 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index bfa61f35cdbe..87735b5856b6 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 308d66347ac9..5d2a0590d691 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 3b3711bb320f..302a5f48938a 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 55e6586f9664..6fc9fff48979 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 240d54497db6..1135a755a204 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 14422b2f371a..8e45f2b5927c 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 13360c35e24a..888c76a66855 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 }, diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index 1719029ee000..1b8159114261 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -78,6 +78,19 @@ ElementCreate2 { ret RsElement } +ElementGetNativeData { + param RsElement elem + param uint32_t *elemData + param uint32_t elemDataSize + } + +ElementGetSubElements { + param RsElement elem + param uint32_t *ids + param const char **names + param uint32_t dataSize + } + TypeBegin { param RsElement type } @@ -91,6 +104,12 @@ TypeCreate { ret RsType } +TypeGetNativeData { + param RsType type + param uint32_t * typeData + param uint32_t typeDataSize + } + AllocationCreateTyped { param RsType type ret RsAllocation @@ -231,6 +250,11 @@ Adapter2DSubData { param const void *data } +AllocationGetType { + param RsAllocation va + ret const void* + } + SamplerBegin { } diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp index aa20275cd873..37b8bd6bd1a6 100644 --- a/libs/rs/rsElement.cpp +++ b/libs/rs/rsElement.cpp @@ -293,6 +293,32 @@ RsElement rsi_ElementCreate2(Context *rsc, return (RsElement)e; } +void rsi_ElementGetNativeData(Context *rsc, RsElement elem, uint32_t *elemData, uint32_t elemDataSize) +{ + rsAssert(elemDataSize == 5); + // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements + Element *e = static_cast<Element *>(elem); + + (*elemData++) = (uint32_t)e->getType(); + (*elemData++) = (uint32_t)e->getKind(); + (*elemData++) = e->getComponent().getIsNormalized() ? 1 : 0; + (*elemData++) = e->getComponent().getVectorSize(); + (*elemData++) = e->getFieldCount(); + +} + +void rsi_ElementGetSubElements(Context *rsc, RsElement elem, uint32_t *ids, const char **names, uint32_t dataSize) +{ + Element *e = static_cast<Element *>(elem); + rsAssert(e->getFieldCount() == dataSize); + + for(uint32_t i = 0; i < dataSize; i ++) { + ids[i] = (uint32_t)e->getField(i); + names[i] = e->getFieldName(i); + } + +} + } } diff --git a/libs/rs/rsType.cpp b/libs/rs/rsType.cpp index 8dca0fe2a28b..52e0d52efa40 100644 --- a/libs/rs/rsType.cpp +++ b/libs/rs/rsType.cpp @@ -91,7 +91,7 @@ void Type::compute() if (mLODCount != oldLODCount) { if(mLODs){ delete [] mLODs; - } + } mLODs = new LOD[mLODCount]; } @@ -340,6 +340,22 @@ RsType rsi_TypeCreate(Context *rsc) return st; } +void rsi_TypeGetNativeData(Context *rsc, RsType type, uint32_t *typeData, uint32_t typeDataSize) +{ + rsAssert(typeDataSize == 6); + // Pack the data in the follofing way mDimX; mDimY; mDimZ; + // mDimLOD; mDimFaces; mElement; into typeData + Type *t = static_cast<Type *>(type); + + (*typeData++) = t->getDimX(); + (*typeData++) = t->getDimY(); + (*typeData++) = t->getDimZ(); + (*typeData++) = t->getDimLOD(); + (*typeData++) = t->getDimFaces() ? 1 : 0; + (*typeData++) = (uint32_t)t->getElement(); + +} + } } |