Implement named slots and convert script.addType to script.setType to remove ordering restrictions.
This commit is contained in:
@ -142,10 +142,10 @@ public class RenderScript {
|
||||
native void nScriptSetClearDepth(int script, float depth);
|
||||
native void nScriptSetClearStencil(int script, int stencil);
|
||||
native void nScriptSetTimeZone(int script, byte[] timeZone);
|
||||
native void nScriptSetType(int type, String name, int slot);
|
||||
native void nScriptSetRoot(boolean isRoot);
|
||||
|
||||
native void nScriptCBegin();
|
||||
native void nScriptCAddType(int type);
|
||||
native void nScriptCSetRoot(boolean isRoot);
|
||||
native void nScriptCSetScript(byte[] script, int offset, int length);
|
||||
native int nScriptCCreate();
|
||||
native void nScriptCAddDefineI32(String name, int value);
|
||||
|
@ -20,6 +20,8 @@ package android.renderscript;
|
||||
* @hide
|
||||
**/
|
||||
public class Script extends BaseObj {
|
||||
public static final int MAX_SLOT = 16;
|
||||
|
||||
boolean mIsRoot;
|
||||
Type[] mTypes;
|
||||
|
||||
@ -64,39 +66,36 @@ public class Script extends BaseObj {
|
||||
RenderScript mRS;
|
||||
boolean mIsRoot = false;
|
||||
Type[] mTypes;
|
||||
int mTypeCount;
|
||||
String[] mNames;
|
||||
|
||||
Builder(RenderScript rs) {
|
||||
mRS = rs;
|
||||
mTypes = new Type[4];
|
||||
mTypeCount = 0;
|
||||
mTypes = new Type[MAX_SLOT];
|
||||
mNames = new String[MAX_SLOT];
|
||||
}
|
||||
|
||||
public void addType(Type t) {
|
||||
if(mTypeCount >= mTypes.length) {
|
||||
Type[] nt = new Type[mTypeCount * 2];
|
||||
for(int ct=0; ct < mTypeCount; ct++) {
|
||||
nt[ct] = mTypes[ct];
|
||||
}
|
||||
mTypes = nt;
|
||||
}
|
||||
mTypes[mTypeCount] = t;
|
||||
mTypeCount++;
|
||||
public void setType(Type t, int slot) {
|
||||
mTypes[slot] = t;
|
||||
mNames[slot] = null;
|
||||
}
|
||||
|
||||
public void setType(Type t, String name, int slot) {
|
||||
mTypes[slot] = t;
|
||||
mNames[slot] = name;
|
||||
}
|
||||
|
||||
void transferCreate() {
|
||||
mRS.nScriptCSetRoot(mIsRoot);
|
||||
for(int ct=0; ct < mTypeCount; ct++) {
|
||||
mRS.nScriptCAddType(mTypes[ct].mID);
|
||||
mRS.nScriptSetRoot(mIsRoot);
|
||||
for(int ct=0; ct < mTypes.length; ct++) {
|
||||
if(mTypes[ct] != null) {
|
||||
mRS.nScriptSetType(mTypes[ct].mID, mNames[ct], ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void transferObject(Script s) {
|
||||
s.mIsRoot = mIsRoot;
|
||||
s.mTypes = new Type[mTypeCount];
|
||||
for(int ct=0; ct < mTypeCount; ct++) {
|
||||
s.mTypes[ct] = mTypes[ct];
|
||||
}
|
||||
s.mTypes = mTypes;
|
||||
}
|
||||
|
||||
public void setRoot(boolean r) {
|
||||
|
@ -56,7 +56,7 @@ public class Type extends BaseObj {
|
||||
mRS.nTypeDestroy(mID);
|
||||
}
|
||||
|
||||
public static Type createFromClass(RenderScript rs, Class c, int size, String scriptName) {
|
||||
public static Type createFromClass(RenderScript rs, Class c, int size) {
|
||||
Element e = Element.createFromClass(rs, c);
|
||||
Builder b = new Builder(rs, e);
|
||||
b.add(Dimension.X, size);
|
||||
@ -91,10 +91,16 @@ public class Type extends BaseObj {
|
||||
rs.nTypeSetupFields(t, arTypes, arBits, fields);
|
||||
}
|
||||
t.mJavaClass = c;
|
||||
return t;
|
||||
}
|
||||
|
||||
public static Type createFromClass(RenderScript rs, Class c, int size, String scriptName) {
|
||||
Type t = createFromClass(rs, c, size);
|
||||
t.setName(scriptName);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
RenderScript mRS;
|
||||
Entry[] mEntries;
|
||||
|
Reference in New Issue
Block a user