Merge change 21152
* changes: 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;
|
||||
|
@ -824,6 +824,29 @@ nScriptSetTimeZone(JNIEnv *_env, jobject _this, jint script, jbyteArray timeZone
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nScriptSetType(JNIEnv *_env, jobject _this, jint type, jstring _str, jint slot)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nScriptCAddType, con(%p), type(%p), slot(%i)", con, (RsType)type, slot);
|
||||
const char* n = NULL;
|
||||
if (_str) {
|
||||
n = _env->GetStringUTFChars(_str, NULL);
|
||||
}
|
||||
rsScriptSetType((RsType)type, slot, n);
|
||||
if (n) {
|
||||
_env->ReleaseStringUTFChars(_str, n);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nScriptSetRoot(JNIEnv *_env, jobject _this, jboolean isRoot)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nScriptCSetRoot, con(%p), isRoot(%i)", con, isRoot);
|
||||
rsScriptSetRoot(isRoot);
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
|
||||
static void
|
||||
@ -834,22 +857,6 @@ nScriptCBegin(JNIEnv *_env, jobject _this)
|
||||
rsScriptCBegin();
|
||||
}
|
||||
|
||||
static void
|
||||
nScriptCAddType(JNIEnv *_env, jobject _this, jint type)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nScriptCAddType, con(%p), type(%p)", con, (RsType)type);
|
||||
rsScriptCAddType((RsType)type);
|
||||
}
|
||||
|
||||
static void
|
||||
nScriptCSetRoot(JNIEnv *_env, jobject _this, jboolean isRoot)
|
||||
{
|
||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
||||
LOG_API("nScriptCSetRoot, con(%p), isRoot(%i)", con, isRoot);
|
||||
rsScriptCSetRoot(isRoot);
|
||||
}
|
||||
|
||||
static void
|
||||
nScriptCSetScript(JNIEnv *_env, jobject _this, jbyteArray scriptRef,
|
||||
jint offset, jint length)
|
||||
@ -1374,10 +1381,10 @@ static JNINativeMethod methods[] = {
|
||||
{"nScriptSetClearDepth", "(IF)V", (void*)nScriptSetClearDepth },
|
||||
{"nScriptSetClearStencil", "(II)V", (void*)nScriptSetClearStencil },
|
||||
{"nScriptSetTimeZone", "(I[B)V", (void*)nScriptSetTimeZone },
|
||||
{"nScriptSetType", "(ILjava/lang/String;I)V", (void*)nScriptSetType },
|
||||
{"nScriptSetRoot", "(Z)V", (void*)nScriptSetRoot },
|
||||
|
||||
{"nScriptCBegin", "()V", (void*)nScriptCBegin },
|
||||
{"nScriptCAddType", "(I)V", (void*)nScriptCAddType },
|
||||
{"nScriptCSetRoot", "(Z)V", (void*)nScriptCSetRoot },
|
||||
{"nScriptCSetScript", "([BII)V", (void*)nScriptCSetScript },
|
||||
{"nScriptCCreate", "()I", (void*)nScriptCCreate },
|
||||
{"nScriptCAddDefineI32", "(Ljava/lang/String;I)V", (void*)nScriptCAddDefineI32 },
|
||||
|
@ -22,8 +22,8 @@ int main(int index)
|
||||
{
|
||||
float mat1[16];
|
||||
|
||||
float trans = loadF(1, POS_TRANSLATE);
|
||||
float rot = loadF(1, POS_ROTATE);
|
||||
float trans = Pos_translate;
|
||||
float rot = Pos_rotate;
|
||||
matrixLoadScale(mat1, 2.f, 2.f, 2.f);
|
||||
matrixTranslate(mat1, 0.f, 0.f, trans);
|
||||
matrixRotate(mat1, 90.f, 0.f, 0.f, 1.f);
|
||||
@ -39,7 +39,7 @@ int main(int index)
|
||||
bindProgramFragment(NAMED_PFImages);
|
||||
bindProgramVertex(NAMED_PVImages);
|
||||
|
||||
float focusPos = loadF(1, POS_FOCUS);
|
||||
float focusPos = Pos_focus;
|
||||
int focusID = 0;
|
||||
int lastFocusID = loadI32(2, STATE_LAST_FOCUS);
|
||||
int imgCount = 13;
|
||||
@ -65,7 +65,7 @@ int main(int index)
|
||||
*/
|
||||
storeI32(2, STATE_LAST_FOCUS, focusID);
|
||||
|
||||
int triangleOffsetsCount = loadI32(2, STATE_TRIANGLE_OFFSET_COUNT);
|
||||
int triangleOffsetsCount = Pos_triangleOffsetCount;
|
||||
|
||||
int imgId = 0;
|
||||
for (imgId=1; imgId <= imgCount; imgId++) {
|
||||
|
@ -23,25 +23,18 @@ import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
|
||||
import android.renderscript.Matrix;
|
||||
import android.renderscript.ProgramVertex;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Dimension;
|
||||
import android.renderscript.ScriptC;
|
||||
import android.renderscript.Script;
|
||||
import android.renderscript.ProgramFragment;
|
||||
import android.renderscript.ProgramStore;
|
||||
import android.renderscript.Sampler;
|
||||
import android.renderscript.Light;
|
||||
import android.renderscript.*;
|
||||
|
||||
public class FilmRS {
|
||||
private final int POS_TRANSLATE = 0;
|
||||
private final int POS_ROTATE = 1;
|
||||
private final int POS_FOCUS = 2;
|
||||
class StripPosition {
|
||||
public float translate;
|
||||
public float rotate;
|
||||
public float focus;
|
||||
public int triangleOffsetCount;
|
||||
}
|
||||
StripPosition mPos = new StripPosition();
|
||||
|
||||
|
||||
private final int STATE_TRIANGLE_OFFSET_COUNT = 0;
|
||||
private final int STATE_LAST_FOCUS = 1;
|
||||
|
||||
public FilmRS() {
|
||||
@ -63,10 +56,11 @@ public class FilmRS {
|
||||
}
|
||||
|
||||
float anim = ((float)x-50) / 270.f;
|
||||
mBufferPos[POS_TRANSLATE] = 2f * anim + 0.5f; // translation
|
||||
mBufferPos[POS_ROTATE] = (anim * 40); // rotation
|
||||
mBufferPos[POS_FOCUS] = ((float)y) / 16.f - 10.f; // focusPos
|
||||
mAllocPos.data(mBufferPos);
|
||||
mPos.translate = 2f * anim + 0.5f; // translation
|
||||
mPos.rotate = (anim * 40); // rotation
|
||||
mPos.focus = ((float)y) / 16.f - 10.f; // focusPos
|
||||
mPos.triangleOffsetCount = mFSM.mTriangleOffsetsCount;
|
||||
mAllocPos.data(mPos);
|
||||
}
|
||||
|
||||
|
||||
@ -84,6 +78,7 @@ public class FilmRS {
|
||||
private ProgramVertex mPVBackground;
|
||||
private ProgramVertex mPVImages;
|
||||
private ProgramVertex.MatrixAllocation mPVA;
|
||||
private Type mStripPositionType;
|
||||
|
||||
private Allocation mImages[];
|
||||
private Allocation mAllocIDs;
|
||||
@ -204,10 +199,7 @@ public class FilmRS {
|
||||
mBufferState = new int[10];
|
||||
mAllocState = Allocation.createSized(mRS,
|
||||
Element.USER_FLOAT, mBufferState.length);
|
||||
|
||||
mBufferState[STATE_TRIANGLE_OFFSET_COUNT] = mFSM.mTriangleOffsetsCount;
|
||||
mBufferState[STATE_LAST_FOCUS] = -1;
|
||||
|
||||
mAllocState.data(mBufferState);
|
||||
}
|
||||
|
||||
@ -227,14 +219,16 @@ public class FilmRS {
|
||||
|
||||
Log.e("rs", "Done loading named");
|
||||
|
||||
mStripPositionType = Type.createFromClass(mRS, StripPosition.class, 1);
|
||||
|
||||
ScriptC.Builder sb = new ScriptC.Builder(mRS);
|
||||
sb.setScript(mRes, R.raw.filmstrip);
|
||||
sb.setRoot(true);
|
||||
sb.setType(mStripPositionType, "Pos", 1);
|
||||
mScriptStrip = sb.create();
|
||||
mScriptStrip.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
mAllocPos = Allocation.createSized(mRS,
|
||||
Element.USER_FLOAT, mBufferPos.length);
|
||||
mAllocPos = Allocation.createTyped(mRS, mStripPositionType);
|
||||
|
||||
loadImages();
|
||||
initState();
|
||||
|
@ -118,7 +118,7 @@ public class FountainRS {
|
||||
ScriptC.Builder sb = new ScriptC.Builder(mRS);
|
||||
sb.setScript(mRes, R.raw.fountain);
|
||||
sb.setRoot(true);
|
||||
sb.addType(mSDType);
|
||||
sb.setType(mSDType, 0);
|
||||
mScript = sb.create();
|
||||
mScript.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
|
@ -312,14 +312,18 @@ ScriptSetClearStencil {
|
||||
param uint32_t stencil
|
||||
}
|
||||
|
||||
ScriptCAddType {
|
||||
ScriptSetType {
|
||||
param RsType type
|
||||
param uint32_t slot
|
||||
param const char * name
|
||||
}
|
||||
|
||||
ScriptCSetRoot {
|
||||
ScriptSetRoot {
|
||||
param bool isRoot
|
||||
}
|
||||
|
||||
|
||||
|
||||
ScriptCSetScript {
|
||||
param void * codePtr
|
||||
}
|
||||
|
@ -42,6 +42,26 @@ Component::Component(
|
||||
}
|
||||
}
|
||||
|
||||
const char * Component::getCType() const
|
||||
{
|
||||
switch(mType) {
|
||||
case FLOAT:
|
||||
return "float";
|
||||
case SIGNED:
|
||||
case UNSIGNED:
|
||||
switch(mBits) {
|
||||
case 32:
|
||||
return "int";
|
||||
case 16:
|
||||
return "short";
|
||||
case 8:
|
||||
return "char";
|
||||
}
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Component::~Component()
|
||||
{
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ public:
|
||||
uint32_t getBits() const {return mBits;}
|
||||
|
||||
uint32_t getGLType() const;
|
||||
const char * getCType() const;
|
||||
|
||||
const char * getComponentName() const {return mName.string();}
|
||||
|
||||
|
@ -76,6 +76,25 @@ void rsi_ScriptSetClearStencil(Context * rsc, RsScript vs, uint32_t v)
|
||||
s->mEnviroment.mClearStencil = v;
|
||||
}
|
||||
|
||||
void rsi_ScriptSetType(Context * rsc, RsType vt, uint32_t slot, const char *name)
|
||||
{
|
||||
ScriptCState *ss = &rsc->mScriptC;
|
||||
const Type *t = static_cast<const Type *>(vt);
|
||||
ss->mConstantBufferTypes[slot].set(t);
|
||||
if (name) {
|
||||
ss->mSlotNames[slot].setTo(name);
|
||||
} else {
|
||||
ss->mSlotNames[slot].setTo("");
|
||||
}
|
||||
}
|
||||
|
||||
void rsi_ScriptSetRoot(Context * rsc, bool isRoot)
|
||||
{
|
||||
ScriptCState *ss = &rsc->mScriptC;
|
||||
ss->mEnviroment.mIsRoot = isRoot;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,11 +56,11 @@ public:
|
||||
};
|
||||
Enviroment_t mEnviroment;
|
||||
|
||||
const Type * mConstantBufferTypes;
|
||||
uint32_t mCounstantBufferCount;
|
||||
|
||||
ObjectBaseRef<Allocation> mSlots[MAX_SCRIPT_BANKS];
|
||||
ObjectBaseRef<Type> mTypes[MAX_SCRIPT_BANKS];
|
||||
ObjectBaseRef<const Type> mTypes[MAX_SCRIPT_BANKS];
|
||||
String8 mSlotNames[MAX_SCRIPT_BANKS];
|
||||
|
||||
virtual bool run(Context *, uint32_t launchID) = 0;
|
||||
};
|
||||
|
@ -90,9 +90,9 @@ void ScriptCState::clear()
|
||||
{
|
||||
memset(&mProgram, 0, sizeof(mProgram));
|
||||
|
||||
mConstantTypeCount = 0;
|
||||
for (uint32_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
|
||||
mConstantBufferTypes[ct].clear();
|
||||
mSlotNames[ct].setTo("");
|
||||
}
|
||||
|
||||
memset(&mEnviroment, 0, sizeof(mEnviroment));
|
||||
@ -248,24 +248,56 @@ void ScriptCState::appendVarDefines(String8 *str)
|
||||
void ScriptCState::appendTypes(String8 *str)
|
||||
{
|
||||
char buf[256];
|
||||
String8 tmp;
|
||||
|
||||
for (size_t ct=0; ct < mConstantTypeCount; ct++) {
|
||||
for (size_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
|
||||
const Type *t = mConstantBufferTypes[ct].get();
|
||||
const Element *e = t->getElement();
|
||||
|
||||
if (!t->getName()) {
|
||||
if (!t) {
|
||||
continue;
|
||||
}
|
||||
for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) {
|
||||
const Component *c = e->getComponent(ct2);
|
||||
str->append("#define OFFSETOF_");
|
||||
str->append(t->getName());
|
||||
str->append("_");
|
||||
str->append(c->getComponentName());
|
||||
sprintf(buf, " %i\n", ct2);
|
||||
str->append(buf);
|
||||
const Element *e = t->getElement();
|
||||
|
||||
if (t->getName()) {
|
||||
for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) {
|
||||
const Component *c = e->getComponent(ct2);
|
||||
tmp.setTo("#define OFFSETOF_");
|
||||
tmp.append(t->getName());
|
||||
tmp.append("_");
|
||||
tmp.append(c->getComponentName());
|
||||
sprintf(buf, " %i\n", ct2);
|
||||
tmp.append(buf);
|
||||
LOGD(tmp);
|
||||
str->append(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
if (mSlotNames[ct].length() > 0) {
|
||||
for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) {
|
||||
const Component *c = e->getComponent(ct2);
|
||||
tmp.setTo("#define ");
|
||||
tmp.append(mSlotNames[ct]);
|
||||
tmp.append("_");
|
||||
tmp.append(c->getComponentName());
|
||||
switch (c->getType()) {
|
||||
case Component::FLOAT:
|
||||
tmp.append(" loadF(");
|
||||
break;
|
||||
case Component::SIGNED:
|
||||
sprintf(buf, " loadI%i(", c->getBits());
|
||||
tmp.append(buf);
|
||||
break;
|
||||
case Component::UNSIGNED:
|
||||
sprintf(buf, " loadU%i(", c->getBits());
|
||||
tmp.append(buf);
|
||||
break;
|
||||
}
|
||||
sprintf(buf, "%i, %i)\n", ct, ct2);
|
||||
tmp.append(buf);
|
||||
|
||||
LOGD(tmp);
|
||||
str->append(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -280,27 +312,12 @@ void rsi_ScriptCBegin(Context * rsc)
|
||||
ss->clear();
|
||||
}
|
||||
|
||||
void rsi_ScriptCAddType(Context * rsc, RsType vt)
|
||||
{
|
||||
ScriptCState *ss = &rsc->mScriptC;
|
||||
const Type *t = static_cast<const Type *>(vt);
|
||||
|
||||
ss->mConstantBufferTypes[ss->mConstantTypeCount].set(t);
|
||||
ss->mConstantTypeCount ++;
|
||||
}
|
||||
|
||||
void rsi_ScriptCSetScript(Context * rsc, void *vp)
|
||||
{
|
||||
ScriptCState *ss = &rsc->mScriptC;
|
||||
ss->mProgram.mScript = reinterpret_cast<ScriptC::RunScript_t>(vp);
|
||||
}
|
||||
|
||||
void rsi_ScriptCSetRoot(Context * rsc, bool isRoot)
|
||||
{
|
||||
ScriptCState *ss = &rsc->mScriptC;
|
||||
ss->mEnviroment.mIsRoot = isRoot;
|
||||
}
|
||||
|
||||
void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len)
|
||||
{
|
||||
ScriptCState *ss = &rsc->mScriptC;
|
||||
@ -321,8 +338,12 @@ RsScript rsi_ScriptCCreate(Context * rsc)
|
||||
ss->mAccScript = NULL;
|
||||
s->mEnviroment = ss->mEnviroment;
|
||||
s->mProgram = ss->mProgram;
|
||||
ss->clear();
|
||||
for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
|
||||
s->mTypes[ct].set(ss->mConstantBufferTypes[ct].get());
|
||||
s->mSlotNames[ct] = ss->mSlotNames[ct];
|
||||
}
|
||||
|
||||
ss->clear();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ public:
|
||||
Script::Enviroment_t mEnviroment;
|
||||
|
||||
ObjectBaseRef<const Type> mConstantBufferTypes[MAX_SCRIPT_BANKS];
|
||||
uint32_t mConstantTypeCount;
|
||||
String8 mSlotNames[MAX_SCRIPT_BANKS];
|
||||
|
||||
void clear();
|
||||
void runCompiler(Context *rsc);
|
||||
|
Reference in New Issue
Block a user