diff options
| author | Joe Onorato <joeo@android.com> | 2009-08-09 22:57:44 -0700 |
|---|---|---|
| committer | Joe Onorato <joeo@android.com> | 2009-08-09 22:58:20 -0700 |
| commit | d7b3774da62d3c70cc7e8cf549967a1c823501e6 (patch) | |
| tree | 42fa1d36c3a0d2d07850352758bfc22650d60308 /libs/rs | |
| parent | 3370ec9e54c373ccca3c4f545b4c96f9419a081d (diff) | |
| download | frameworks_base-d7b3774da62d3c70cc7e8cf549967a1c823501e6.zip frameworks_base-d7b3774da62d3c70cc7e8cf549967a1c823501e6.tar.gz frameworks_base-d7b3774da62d3c70cc7e8cf549967a1c823501e6.tar.bz2 | |
Let java put #defines into renderscript
Diffstat (limited to 'libs/rs')
| -rw-r--r-- | libs/rs/rs.spec | 19 | ||||
| -rw-r--r-- | libs/rs/rsContext.cpp | 29 | ||||
| -rw-r--r-- | libs/rs/rsContext.h | 14 | ||||
| -rw-r--r-- | libs/rs/rsScriptC.cpp | 39 | ||||
| -rw-r--r-- | libs/rs/rsScriptC.h | 6 |
5 files changed, 105 insertions, 2 deletions
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index e5d30e4..b644833 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -16,6 +16,16 @@ ContextBindProgramVertex { param RsProgramVertex pgm } +ContextSetDefineF { + param const char* name + param float value + } + +ContextSetDefineI32 { + param const char* name + param int32_t value + } + AssignName { param void *obj param const char *name @@ -318,6 +328,15 @@ ScriptCCreate { ret RsScript } +ScriptCSetDefineF { + param const char* name + param float value + } + +ScriptCSetDefineI32 { + param const char* name + param int32_t value + } ProgramFragmentStoreBegin { param RsElement in diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index 46bd892..9de23b3 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -331,6 +331,26 @@ void Context::appendNameDefines(String8 *str) const } } +void Context::appendVarDefines(String8 *str) const +{ + char buf[256]; + for (size_t ct=0; ct < mInt32Defines.size(); ct++) { + str->append("#define "); + str->append(mInt32Defines.keyAt(ct)); + str->append(" "); + sprintf(buf, "%i\n", (int)mInt32Defines.valueAt(ct)); + str->append(buf); + + } + for (size_t ct=0; ct < mFloatDefines.size(); ct++) { + str->append("#define "); + str->append(mFloatDefines.keyAt(ct)); + str->append(" "); + sprintf(buf, "%ff\n", mFloatDefines.valueAt(ct)); + str->append(buf); + } +} + /////////////////////////////////////////////////////////////////////////////////////////// // @@ -381,6 +401,15 @@ void rsi_AssignName(Context *rsc, void * obj, const char *name, uint32_t len) rsc->assignName(ob, name, len); } +void rsi_ContextSetDefineF(Context *rsc, const char* name, float value) +{ + rsc->addInt32Define(name, value); +} + +void rsi_ContextSetDefineI32(Context *rsc, const char* name, int32_t value) +{ + rsc->addFloatDefine(name, value); +} } } diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h index 5d41460..799c443 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/rsContext.h @@ -19,6 +19,8 @@ #include "rsUtils.h" +#include <utils/KeyedVector.h> +#include <utils/String8.h> #include <utils/Vector.h> #include <ui/Surface.h> @@ -93,7 +95,7 @@ public: void removeName(ObjectBase *obj); ObjectBase * lookupName(const char *name) const; void appendNameDefines(String8 *str) const; - + void appendVarDefines(String8 *str) const; ProgramFragment * getDefaultProgramFragment() const { return mStateFragment.mDefault.get(); @@ -105,6 +107,14 @@ public: return mStateFragmentStore.mDefault.get(); } + void addInt32Define(const char* name, int32_t value) { + mInt32Defines.add(String8(name), value); + } + + void addFloatDefine(const char* name, float value) { + mFloatDefines.add(String8(name), value); + } + protected: Device *mDev; @@ -143,6 +153,8 @@ private: Surface *mWndSurface; Vector<ObjectBase *> mNames; + KeyedVector<String8,int> mInt32Defines; + KeyedVector<String8,float> mFloatDefines; }; diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index efe6ff7..3343db5 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -104,6 +104,8 @@ void ScriptCState::clear() mAccScript = NULL; + mInt32Defines.clear(); + mFloatDefines.clear(); } static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name) @@ -123,6 +125,8 @@ void ScriptCState::runCompiler(Context *rsc) rsc->appendNameDefines(&tmp); appendDecls(&tmp); + rsc->appendVarDefines(&tmp); + appendVarDefines(&tmp); tmp.append("#line 1\n"); const char* scriptSource[] = {tmp.string(), mProgram.mScriptText}; @@ -138,7 +142,6 @@ void ScriptCState::runCompiler(Context *rsc) ACCsizei len; accGetScriptInfoLog(mAccScript, sizeof(buf), &len, buf); LOGE(buf); - } mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); @@ -215,9 +218,31 @@ void ScriptCState::runCompiler(Context *rsc) } else { // Deal with an error. } +} + +void ScriptCState::appendVarDefines(String8 *str) +{ + char buf[256]; + LOGD("appendVarDefines mInt32Defines.size()=%d mFloatDefines.size()=%d\n", + mInt32Defines.size(), mFloatDefines.size()); + for (size_t ct=0; ct < mInt32Defines.size(); ct++) { + str->append("#define "); + str->append(mInt32Defines.keyAt(ct)); + str->append(" "); + sprintf(buf, "%i\n", (int)mInt32Defines.valueAt(ct)); + str->append(buf); + } + for (size_t ct=0; ct < mFloatDefines.size(); ct++) { + str->append("#define "); + str->append(mFloatDefines.keyAt(ct)); + str->append(" "); + sprintf(buf, "%ff\n", mFloatDefines.valueAt(ct)); + str->append(buf); + } } + namespace android { namespace renderscript { @@ -270,6 +295,18 @@ RsScript rsi_ScriptCCreate(Context * rsc) return s; } +void rsi_ScriptCSetDefineF(Context *rsc, const char* name, float value) +{ + ScriptCState *ss = &rsc->mScriptC; + ss->mFloatDefines.add(String8(name), value); +} + +void rsi_ScriptCSetDefineI32(Context *rsc, const char* name, int32_t value) +{ + ScriptCState *ss = &rsc->mScriptC; + ss->mInt32Defines.add(String8(name), value); +} + } } diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h index 860b4d1..ad0e3ee 100644 --- a/libs/rs/rsScriptC.h +++ b/libs/rs/rsScriptC.h @@ -21,6 +21,8 @@ #include "RenderScriptEnv.h" +#include <utils/KeyedVector.h> + struct ACCscript; // --------------------------------------------------------------------------- @@ -70,6 +72,7 @@ public: void clear(); void runCompiler(Context *rsc); + void appendVarDefines(String8 *str); struct SymbolTable_t { const char * mName; @@ -80,6 +83,9 @@ public: static SymbolTable_t gSyms[]; static const SymbolTable_t * lookupSymbol(const char *); static void appendDecls(String8 *str); + + KeyedVector<String8,int> mInt32Defines; + KeyedVector<String8,float> mFloatDefines; }; |
