Merge change 3850

* changes:
  Fix bug with bad conversion of java strings to C strings for object names.  Update test app to test object defines.
This commit is contained in:
Android (Google) Code Review
2009-06-10 19:09:37 -07:00
9 changed files with 47 additions and 15 deletions

View File

@@ -37,7 +37,7 @@ int main(void* con, int ft, int launchID) {
//contextBindProgramFragment(con, loadI32(con, 0, 7));
drawRect(con, 0, 256, 0, 512);
contextBindProgramFragment(con, loadI32(con, 0, 6));
contextBindProgramFragment(con, NAMED_PgmFragParts);
if (touch) {
newPart = loadI32(con, 2, 0);
@@ -106,6 +106,6 @@ int main(void* con, int ft, int launchID) {
}
}
drawTriangleArray(con, loadI32(con, 0, 5), drawCount);
drawTriangleArray(con, NAMED_PartBuffer, drawCount);
return 1;
}

View File

@@ -68,6 +68,7 @@ public class FountainView extends RSSurfaceView {
mIntAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, 10);
mPartAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 3 * 3);
mPartAlloc.setName("PartBuffer");
mVertAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 5 + 1);
{
@@ -97,7 +98,6 @@ public class FountainView extends RSSurfaceView {
mRS.programFragmentBegin(null, null);
mPF = mRS.programFragmentCreate();
mPF.setName("PgmFragParts");
//mRS.contextBindProgramFragment(mPF);
mRS.programFragmentBegin(null, null);
mRS.programFragmentSetTexEnable(0, true);
@@ -113,8 +113,6 @@ public class FountainView extends RSSurfaceView {
mParams[3] = 0;
mParams[4] = 0;
mParams[5] = mPartAlloc.getID();
mParams[6] = mPF.getID();
mParams[7] = mPF2.getID();
mIntAlloc.data(mParams);
int t2[] = new int[partCount * 4*3];

View File

@@ -70,7 +70,7 @@ nAssignName(JNIEnv *_env, jobject _this, jint obj, jbyteArray str)
jint len = _env->GetArrayLength(str);
jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
rsAssignName((void *)obj, (const char *)cptr);
rsAssignName((void *)obj, (const char *)cptr, len);
_env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
}

View File

@@ -19,6 +19,7 @@ ContextBindProgramVertex {
AssignName {
param void *obj
param const char *name
param size_t len
}
ElementBegin {

View File

@@ -17,7 +17,7 @@
#include "rsDevice.h"
#include "rsContext.h"
#include "rsThreadIO.h"
#include "utils/String8.h"
using namespace android;
using namespace android::renderscript;
@@ -246,10 +246,10 @@ void Context::setVertex(ProgramVertex *pv)
pv->setupGL();
}
void Context::assignName(ObjectBase *obj, const char *name)
void Context::assignName(ObjectBase *obj, const char *name, uint32_t len)
{
rsAssert(!obj->getName());
obj->setName(name);
obj->setName(name, len);
mNames.add(obj);
}
@@ -273,6 +273,19 @@ ObjectBase * Context::lookupName(const char *name) const
return NULL;
}
void Context::appendNameDefines(String8 *str) const
{
char buf[256];
for (size_t ct=0; ct < mNames.size(); ct++) {
str->append("#define NAMED_");
str->append(mNames[ct]->getName());
str->append(" ");
sprintf(buf, "%i\n", (int)mNames[ct]);
str->append(buf);
}
}
///////////////////////////////////////////////////////////////////////////////////////////
//
@@ -316,10 +329,10 @@ void rsi_ContextBindProgramVertex(Context *rsc, RsProgramVertex vpv)
rsc->setVertex(pv);
}
void rsi_AssignName(Context *rsc, void * obj, const char *name)
void rsi_AssignName(Context *rsc, void * obj, const char *name, uint32_t len)
{
ObjectBase *ob = static_cast<ObjectBase *>(obj);
rsc->assignName(ob, name);
rsc->assignName(ob, name, len);
}

View File

@@ -76,9 +76,10 @@ public:
void setupCheck();
void assignName(ObjectBase *obj, const char *name);
void assignName(ObjectBase *obj, const char *name, uint32_t len);
void removeName(ObjectBase *obj);
ObjectBase * lookupName(const char *name) const;
void appendNameDefines(String8 *str) const;
protected:
Device *mDev;

View File

@@ -56,3 +56,15 @@ void ObjectBase::setName(const char *name)
strcpy(mName, name);
}
}
void ObjectBase::setName(const char *name, uint32_t len)
{
delete mName;
mName = NULL;
if (name) {
mName = new char[len + 1];
memcpy(mName, name, len);
mName[len] = 0;
}
}

View File

@@ -37,6 +37,7 @@ public:
return mName;
}
void setName(const char *);
void setName(const char *, uint32_t len);
private:
char * mName;

View File

@@ -19,6 +19,7 @@
#include "rsMatrix.h"
#include "acc/acc.h"
#include "utils/String8.h"
using namespace android;
using namespace android::renderscript;
@@ -433,17 +434,22 @@ void ScriptCState::clear()
}
void ScriptCState::runCompiler(Context *rsc)
{
mAccScript = accCreateScript();
String8 tmp;
const char* scriptSource[] = {mProgram.mScriptText};
int scriptLength[] = {mProgram.mScriptTextLength} ;
accScriptSource(mAccScript, 1, scriptSource, scriptLength);
rsc->appendNameDefines(&tmp);
const char* scriptSource[] = {tmp.string(), mProgram.mScriptText};
int scriptLength[] = {tmp.length(), mProgram.mScriptTextLength} ;
accScriptSource(mAccScript, sizeof(scriptLength) / sizeof(int), scriptSource, scriptLength);
accCompileScript(mAccScript);
accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript);
rsAssert(mProgram.mScript);
if (mProgram.mScript) {
const static int pragmaMax = 16;
ACCsizei pragmaCount;