summaryrefslogtreecommitdiffstats
path: root/libs/rs
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2009-08-13 12:59:04 -0700
committerJason Sams <rjsams@android.com>2009-08-13 12:59:04 -0700
commitfbf0b9ecda03fbdbd4ebabfd18da09a789686249 (patch)
tree6c321ebb1d011aae9961ed7c046645028b05da86 /libs/rs
parent1b52aae4d908fcf749e9a8d86bb0a33c70728c56 (diff)
downloadframeworks_base-fbf0b9ecda03fbdbd4ebabfd18da09a789686249.zip
frameworks_base-fbf0b9ecda03fbdbd4ebabfd18da09a789686249.tar.gz
frameworks_base-fbf0b9ecda03fbdbd4ebabfd18da09a789686249.tar.bz2
Implement named slots and convert script.addType to script.setType to remove ordering restrictions.
Diffstat (limited to 'libs/rs')
-rw-r--r--libs/rs/java/Film/res/raw/filmstrip.c8
-rw-r--r--libs/rs/java/Film/src/com/android/film/FilmRS.java44
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java2
-rw-r--r--libs/rs/rs.spec8
-rw-r--r--libs/rs/rsComponent.cpp20
-rw-r--r--libs/rs/rsComponent.h1
-rw-r--r--libs/rs/rsScript.cpp19
-rw-r--r--libs/rs/rsScript.h4
-rw-r--r--libs/rs/rsScriptC.cpp79
-rw-r--r--libs/rs/rsScriptC.h2
10 files changed, 123 insertions, 64 deletions
diff --git a/libs/rs/java/Film/res/raw/filmstrip.c b/libs/rs/java/Film/res/raw/filmstrip.c
index 4e7c37a..255d908 100644
--- a/libs/rs/java/Film/res/raw/filmstrip.c
+++ b/libs/rs/java/Film/res/raw/filmstrip.c
@@ -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++) {
diff --git a/libs/rs/java/Film/src/com/android/film/FilmRS.java b/libs/rs/java/Film/src/com/android/film/FilmRS.java
index 74f88c4..e6cd52d 100644
--- a/libs/rs/java/Film/src/com/android/film/FilmRS.java
+++ b/libs/rs/java/Film/src/com/android/film/FilmRS.java
@@ -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();
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
index 3e680e3..da4eeb4 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -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);
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index d4fbf6b..105142b 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -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
}
diff --git a/libs/rs/rsComponent.cpp b/libs/rs/rsComponent.cpp
index 831580b..b88710c 100644
--- a/libs/rs/rsComponent.cpp
+++ b/libs/rs/rsComponent.cpp
@@ -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()
{
}
diff --git a/libs/rs/rsComponent.h b/libs/rs/rsComponent.h
index 5ee95c7..6342f1b 100644
--- a/libs/rs/rsComponent.h
+++ b/libs/rs/rsComponent.h
@@ -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();}
diff --git a/libs/rs/rsScript.cpp b/libs/rs/rsScript.cpp
index 6ce9f61..75c994b 100644
--- a/libs/rs/rsScript.cpp
+++ b/libs/rs/rsScript.cpp
@@ -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;
+}
+
+
}
}
diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h
index 6983ef4..dc66763 100644
--- a/libs/rs/rsScript.h
+++ b/libs/rs/rsScript.h
@@ -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;
};
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index 652283d..ced2516 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -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;
}
diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h
index 60a6fba..32a9079 100644
--- a/libs/rs/rsScriptC.h
+++ b/libs/rs/rsScriptC.h
@@ -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);