summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2009-06-17 16:52:59 -0700
committerJason Sams <rjsams@android.com>2009-06-17 16:52:59 -0700
commit9c54bdbf458e3c9433d237ae71cf47c4ec47d852 (patch)
tree5c740a213b3ac7518184f53692191d0f3cd8cc48 /libs
parentb37c0a5db65cd8b72cac6a3250faddd1aecb722e (diff)
downloadframeworks_base-9c54bdbf458e3c9433d237ae71cf47c4ec47d852.zip
frameworks_base-9c54bdbf458e3c9433d237ae71cf47c4ec47d852.tar.gz
frameworks_base-9c54bdbf458e3c9433d237ae71cf47c4ec47d852.tar.bz2
Implement default programs and implement defaults and parents for imports.
Diffstat (limited to 'libs')
-rw-r--r--libs/rs/java/Fountain/res/raw/fountain.c5
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java11
-rw-r--r--libs/rs/rsContext.cpp32
-rw-r--r--libs/rs/rsContext.h15
-rw-r--r--libs/rs/rsMatrix.cpp22
-rw-r--r--libs/rs/rsMatrix.h3
-rw-r--r--libs/rs/rsProgramFragment.cpp5
-rw-r--r--libs/rs/rsProgramFragment.h3
-rw-r--r--libs/rs/rsProgramFragmentStore.cpp6
-rw-r--r--libs/rs/rsProgramFragmentStore.h2
-rw-r--r--libs/rs/rsProgramVertex.cpp17
-rw-r--r--libs/rs/rsProgramVertex.h5
-rw-r--r--libs/rs/rsScriptC.cpp41
13 files changed, 134 insertions, 33 deletions
diff --git a/libs/rs/java/Fountain/res/raw/fountain.c b/libs/rs/java/Fountain/res/raw/fountain.c
index 3bd9496..54130f9 100644
--- a/libs/rs/java/Fountain/res/raw/fountain.c
+++ b/libs/rs/java/Fountain/res/raw/fountain.c
@@ -1,10 +1,9 @@
// Fountain test script
#pragma version(1)
-#pragma stateVertex(orthoWindow)
-#pragma stateRaster(flat)
+#pragma stateVertex(default)
#pragma stateFragment(PgmFragBackground)
-#pragma stateFragmentStore(MyBlend)
+#pragma stateFragmentStore(parent)
int main(void* con, int ft, int launchID) {
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 d167b5f..467115a 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -58,10 +58,8 @@ public class FountainRS {
private RenderScript.ProgramFragmentStore mPFS;
private RenderScript.ProgramFragment mPF;
private RenderScript.ProgramFragment mPF2;
- private RenderScript.ProgramVertex mPV;
private RenderScript.Allocation mTexture;
private RenderScript.Sampler mSampler;
- private ProgramVertexAlloc mPVA;
private Bitmap mBackground;
@@ -110,15 +108,6 @@ public class FountainRS {
mPF2.bindSampler(mSampler, 0);
mPF2.setName("PgmFragBackground");
- mRS.programVertexBegin(null, null);
- mPV = mRS.programVertexCreate();
- mPVA = new ProgramVertexAlloc(mRS);
- mPV.bindAllocation(0, mPVA.mAlloc);
- mPVA.setupOrthoWindow(320, 480);
- mRS.contextBindProgramVertex(mPV);
-
-
-
mParams[0] = 0;
mParams[1] = partCount;
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index c466f46..7248ecc 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -119,6 +119,14 @@ void * Context::threadProc(void *vrsc)
rsc->mServerReturns.init(128);
rsc->initEGL();
+
+ rsc->mStateVertex.init(rsc, rsc->mWidth, rsc->mHeight);
+ rsc->setVertex(NULL);
+ rsc->mStateFragment.init(rsc, rsc->mWidth, rsc->mHeight);
+ rsc->setFragment(NULL);
+ rsc->mStateFragmentStore.init(rsc, rsc->mWidth, rsc->mHeight);
+ rsc->setFragmentStore(NULL);
+
rsc->mRunning = true;
bool mDraw = true;
while (!rsc->mExit) {
@@ -212,20 +220,32 @@ void Context::setRootScript(Script *s)
void Context::setFragmentStore(ProgramFragmentStore *pfs)
{
- mFragmentStore.set(pfs);
- pfs->setupGL();
+ if (pfs == NULL) {
+ mFragmentStore.set(mStateFragmentStore.mDefault);
+ } else {
+ mFragmentStore.set(pfs);
+ }
+ mFragmentStore->setupGL();
}
void Context::setFragment(ProgramFragment *pf)
{
- mFragment.set(pf);
- pf->setupGL();
+ if (pf == NULL) {
+ mFragment.set(mStateFragment.mDefault);
+ } else {
+ mFragment.set(pf);
+ }
+ mFragment->setupGL();
}
void Context::setVertex(ProgramVertex *pv)
{
- mVertex.set(pv);
- pv->setupGL();
+ if (pv == NULL) {
+ mVertex.set(mStateVertex.mDefault);
+ } else {
+ mVertex.set(pv);
+ }
+ mVertex->setupGL();
}
void Context::assignName(ObjectBase *obj, const char *name, uint32_t len)
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 21ae8c5..10b9a13 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -81,6 +81,17 @@ public:
ObjectBase * lookupName(const char *name) const;
void appendNameDefines(String8 *str) const;
+
+ ProgramFragment * getDefaultProgramFragment() const {
+ return mStateFragment.mDefault.get();
+ }
+ ProgramVertex * getDefaultProgramVertex() const {
+ return mStateVertex.mDefault.get();
+ }
+ ProgramFragmentStore * getDefaultProgramFragmentStore() const {
+ return mStateFragmentStore.mDefault.get();
+ }
+
protected:
Device *mDev;
@@ -107,10 +118,6 @@ protected:
ObjectBaseRef<ProgramVertex> mVertex;
ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
- ProgramFragment * mDefaultFragment;
- ProgramVertex * mDefaultVertex;
- ProgramFragmentStore * mDefaultFragmentStore;
-
private:
Context();
diff --git a/libs/rs/rsMatrix.cpp b/libs/rs/rsMatrix.cpp
index e68d5ac..258b836 100644
--- a/libs/rs/rsMatrix.cpp
+++ b/libs/rs/rsMatrix.cpp
@@ -136,4 +136,26 @@ void Matrix::loadMultiply(const Matrix *lhs, const Matrix *rhs)
}
}
+void Matrix::loadOrtho(float l, float r, float b, float t, float n, float f) {
+ loadIdentity();
+ m[0] = 2 / (r - l);
+ m[5] = 2 / (t - b);
+ m[10]= -2 / (f - n);
+ m[12]= -(r + l) / (r - l);
+ m[13]= -(t + b) / (t - b);
+ m[14]= -(f + n) / (f - n);
+}
+
+void Matrix::loadFrustum(float l, float r, float b, float t, float n, float f) {
+ loadIdentity();
+ m[0] = 2 * n / (r - l);
+ m[5] = 2 * n / (t - b);
+ m[8] = (r + l) / (r - l);
+ m[9] = (t + b) / (t - b);
+ m[10]= -(f + n) / (f - n);
+ m[11]= -1;
+ m[14]= -2*f*n / (f - n);
+ m[15]= 0;
+}
+
diff --git a/libs/rs/rsMatrix.h b/libs/rs/rsMatrix.h
index 619b494..7dc4165 100644
--- a/libs/rs/rsMatrix.h
+++ b/libs/rs/rsMatrix.h
@@ -44,6 +44,9 @@ struct Matrix
void loadTranslate(float x, float y, float z);
void loadMultiply(const Matrix *lhs, const Matrix *rhs);
+ void loadOrtho(float l, float r, float b, float t, float n, float f);
+ void loadFrustum(float l, float r, float b, float t, float n, float f);
+
void multiply(const Matrix *rhs) {
Matrix tmp;
tmp.loadMultiply(this, rhs);
diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp
index 316e791..8777335 100644
--- a/libs/rs/rsProgramFragment.cpp
+++ b/libs/rs/rsProgramFragment.cpp
@@ -148,6 +148,11 @@ ProgramFragmentState::~ProgramFragmentState()
}
+void ProgramFragmentState::init(Context *rsc, int32_t w, int32_t h)
+{
+ ProgramFragment *pf = new ProgramFragment(NULL, NULL);
+ mDefault.set(pf);
+}
namespace android {
diff --git a/libs/rs/rsProgramFragment.h b/libs/rs/rsProgramFragment.h
index ed9c49b..896d8dd 100644
--- a/libs/rs/rsProgramFragment.h
+++ b/libs/rs/rsProgramFragment.h
@@ -82,9 +82,10 @@ public:
~ProgramFragmentState();
ProgramFragment *mPF;
+ void init(Context *rsc, int32_t w, int32_t h);
ObjectBaseRef<Type> mTextureTypes[ProgramFragment::MAX_TEXTURE];
-
+ ObjectBaseRef<ProgramFragment> mDefault;
Vector<ProgramFragment *> mPrograms;
};
diff --git a/libs/rs/rsProgramFragmentStore.cpp b/libs/rs/rsProgramFragmentStore.cpp
index a1855a6..96d37ae 100644
--- a/libs/rs/rsProgramFragmentStore.cpp
+++ b/libs/rs/rsProgramFragmentStore.cpp
@@ -201,6 +201,12 @@ ProgramFragmentStoreState::~ProgramFragmentStoreState()
}
+void ProgramFragmentStoreState::init(Context *rsc, int32_t w, int32_t h)
+{
+ ProgramFragmentStore *pfs = new ProgramFragmentStore(NULL, NULL);
+ mDefault.set(pfs);
+}
+
namespace android {
namespace renderscript {
diff --git a/libs/rs/rsProgramFragmentStore.h b/libs/rs/rsProgramFragmentStore.h
index d862775..bd3a9f4 100644
--- a/libs/rs/rsProgramFragmentStore.h
+++ b/libs/rs/rsProgramFragmentStore.h
@@ -74,7 +74,9 @@ class ProgramFragmentStoreState
public:
ProgramFragmentStoreState();
~ProgramFragmentStoreState();
+ void init(Context *rsc, int32_t w, int32_t h);
+ ObjectBaseRef<ProgramFragmentStore> mDefault;
ProgramFragmentStore *mPFS;
};
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index c24f228..19afad5 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -81,6 +81,23 @@ ProgramVertexState::~ProgramVertexState()
delete mPV;
}
+void ProgramVertexState::init(Context *rsc, int32_t w, int32_t h)
+{
+ ProgramVertex *pv = new ProgramVertex(NULL, NULL);
+ Allocation *alloc = (Allocation *)
+ rsi_AllocationCreatePredefSized(rsc, RS_ELEMENT_USER_FLOAT, 48);
+ mDefaultAlloc.set(alloc);
+ mDefault.set(pv);
+
+ pv->bindAllocation(0, alloc);
+
+ Matrix m;
+ m.loadOrtho(0,w, h,0, -1,1);
+ alloc->subData(RS_PROGRAM_VERTEX_PROJECTION_OFFSET, 16, &m.m[0]);
+
+ m.loadIdentity();
+ alloc->subData(RS_PROGRAM_VERTEX_MODELVIEW_OFFSET, 16, &m.m[0]);
+}
namespace android {
diff --git a/libs/rs/rsProgramVertex.h b/libs/rs/rsProgramVertex.h
index 0b3a3eb..1a92f01 100644
--- a/libs/rs/rsProgramVertex.h
+++ b/libs/rs/rsProgramVertex.h
@@ -57,6 +57,11 @@ public:
ProgramVertexState();
~ProgramVertexState();
+ void init(Context *rsc, int32_t w, int32_t h);
+
+ ObjectBaseRef<ProgramVertex> mDefault;
+ ObjectBaseRef<Allocation> mDefaultAlloc;
+
ProgramVertex *mPV;
//ObjectBaseRef<Type> mTextureTypes[ProgramFragment::MAX_TEXTURE];
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index 2963831..c650656 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -398,6 +398,9 @@ bool ScriptC::run(Context *rsc, uint32_t launchID)
if (mEnviroment.mFragment.get()) {
rsc->setFragment(mEnviroment.mFragment.get());
}
+ if (mEnviroment.mVertex.get()) {
+ rsc->setVertex(mEnviroment.mVertex.get());
+ }
return mProgram.mScript(&e, &scriptCPtrTable, launchID) != 0;
}
@@ -448,6 +451,9 @@ void ScriptCState::runCompiler(Context *rsc)
accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript);
rsAssert(mProgram.mScript);
+ mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
+ mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
+ mEnviroment.mFragmentStore.set(rsc->getDefaultProgramFragmentStore());
if (mProgram.mScript) {
const static int pragmaMax = 16;
@@ -465,6 +471,18 @@ void ScriptCState::runCompiler(Context *rsc)
if (!strcmp(str[ct], "stateVertex")) {
+ if (!strcmp(str[ct+1], "default")) {
+ continue;
+ }
+ if (!strcmp(str[ct+1], "parent")) {
+ mEnviroment.mVertex.clear();
+ continue;
+ }
+ ProgramVertex * pv = (ProgramVertex *)rsc->lookupName(str[ct+1]);
+ if (pv != NULL) {
+ mEnviroment.mVertex.set(pv);
+ continue;
+ }
LOGE("Unreconized value %s passed to stateVertex", str[ct+1]);
}
@@ -473,8 +491,14 @@ void ScriptCState::runCompiler(Context *rsc)
}
if (!strcmp(str[ct], "stateFragment")) {
- ProgramFragment * pf =
- (ProgramFragment *)rsc->lookupName(str[ct+1]);
+ if (!strcmp(str[ct+1], "default")) {
+ continue;
+ }
+ if (!strcmp(str[ct+1], "parent")) {
+ mEnviroment.mFragment.clear();
+ continue;
+ }
+ ProgramFragment * pf = (ProgramFragment *)rsc->lookupName(str[ct+1]);
if (pf != NULL) {
mEnviroment.mFragment.set(pf);
continue;
@@ -483,18 +507,19 @@ void ScriptCState::runCompiler(Context *rsc)
}
if (!strcmp(str[ct], "stateFragmentStore")) {
+ if (!strcmp(str[ct+1], "default")) {
+ continue;
+ }
+ if (!strcmp(str[ct+1], "parent")) {
+ mEnviroment.mFragmentStore.clear();
+ continue;
+ }
ProgramFragmentStore * pfs =
(ProgramFragmentStore *)rsc->lookupName(str[ct+1]);
if (pfs != NULL) {
mEnviroment.mFragmentStore.set(pfs);
continue;
}
-
- if (!strcmp(str[ct+1], "parent")) {
- //mEnviroment.mStateFragmentStore =
- //Script::Enviroment_t::FRAGMENT_STORE_PARENT;
- continue;
- }
LOGE("Unreconized value %s passed to stateFragmentStore", str[ct+1]);
}