Merge "Pipe rsa function though the RS api table."

This commit is contained in:
Jason Sams
2011-04-29 14:51:37 -07:00
committed by Android (Google) Code Review
7 changed files with 157 additions and 73 deletions

View File

@@ -381,7 +381,7 @@ nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
con, eid, dimx, dimy, dimz, mips, faces);
jint id = (jint)rsaTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
return (jint)id;
}
@@ -409,7 +409,7 @@ static jint
nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage)
{
LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i)", con, (RsElement)type, mips, usage);
return (jint) rsaAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage);
return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage);
}
static void
@@ -435,7 +435,7 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint typ
bitmap.lockPixels();
const void* ptr = bitmap.getPixels();
jint id = (jint)rsaAllocationCreateFromBitmap(con,
jint id = (jint)rsAllocationCreateFromBitmap(con,
(RsType)type, (RsAllocationMipmapControl)mip,
ptr, bitmap.getSize(), usage);
bitmap.unlockPixels();
@@ -451,7 +451,7 @@ nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint
bitmap.lockPixels();
const void* ptr = bitmap.getPixels();
jint id = (jint)rsaAllocationCubeCreateFromBitmap(con,
jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
(RsType)type, (RsAllocationMipmapControl)mip,
ptr, bitmap.getSize(), usage);
bitmap.unlockPixels();

View File

@@ -66,7 +66,7 @@ ContextDeinitToClient {
direct
}
aTypeCreate {
TypeCreate {
direct
param RsElement e
param uint32_t dimX
@@ -77,7 +77,7 @@ aTypeCreate {
ret RsType
}
aAllocationCreateTyped {
AllocationCreateTyped {
direct
param RsType vtype
param RsAllocationMipmapControl mips
@@ -85,7 +85,7 @@ aAllocationCreateTyped {
ret RsAllocation
}
aAllocationCreateFromBitmap {
AllocationCreateFromBitmap {
direct
param RsType vtype
param RsAllocationMipmapControl mips
@@ -94,7 +94,7 @@ aAllocationCreateFromBitmap {
ret RsAllocation
}
aAllocationCubeCreateFromBitmap {
AllocationCubeCreateFromBitmap {
direct
param RsType vtype
param RsAllocationMipmapControl mips

View File

@@ -649,11 +649,12 @@ void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) {
//
#ifndef ANDROID_RS_SERIALIZE
static void rsaAllocationGenerateScriptMips(RsContext con, RsAllocation va);
namespace android {
namespace renderscript {
static void AllocationGenerateScriptMips(RsContext con, RsAllocation va);
void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, bool genmip, uint32_t baseMipLevel) {
Allocation *alloc = static_cast<Allocation *>(va);
alloc->deferredUploadToTexture(rsc);
@@ -740,7 +741,7 @@ void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType
void rsi_AllocationGenerateMipmaps(Context *rsc, RsAllocation va) {
Allocation *texAlloc = static_cast<Allocation *>(va);
rsaAllocationGenerateScriptMips(rsc, texAlloc);
AllocationGenerateScriptMips(rsc, texAlloc);
}
void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t dataLen) {
@@ -795,10 +796,7 @@ void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32
a->resize2D(rsc, dimX, dimY);
}
}
}
static void rsaAllocationGenerateScriptMips(RsContext con, RsAllocation va) {
static void AllocationGenerateScriptMips(RsContext con, RsAllocation va) {
Context *rsc = static_cast<Context *>(con);
Allocation *texAlloc = static_cast<Allocation *>(va);
uint32_t numFaces = texAlloc->getType()->getDimFaces() ? 6 : 1;
@@ -815,29 +813,20 @@ static void rsaAllocationGenerateScriptMips(RsContext con, RsAllocation va) {
}
}
const void * rsaAllocationGetType(RsContext con, RsAllocation va) {
Allocation *a = static_cast<Allocation *>(va);
a->getType()->incUserRef();
return a->getType();
}
RsAllocation rsaAllocationCreateTyped(RsContext con, RsType vtype,
RsAllocationMipmapControl mips,
uint32_t usages) {
Context *rsc = static_cast<Context *>(con);
RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype,
RsAllocationMipmapControl mips,
uint32_t usages) {
Allocation * alloc = new Allocation(rsc, static_cast<Type *>(vtype), usages, mips);
alloc->incUserRef();
return alloc;
}
RsAllocation rsaAllocationCreateFromBitmap(RsContext con, RsType vtype,
RsAllocationMipmapControl mips,
const void *data, size_t data_length, uint32_t usages) {
Context *rsc = static_cast<Context *>(con);
RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype,
RsAllocationMipmapControl mips,
const void *data, size_t data_length, uint32_t usages) {
Type *t = static_cast<Type *>(vtype);
RsAllocation vTexAlloc = rsaAllocationCreateTyped(rsc, vtype, mips, usages);
RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages);
Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
if (texAlloc == NULL) {
LOGE("Memory allocation failure");
@@ -846,23 +835,22 @@ RsAllocation rsaAllocationCreateFromBitmap(RsContext con, RsType vtype,
memcpy(texAlloc->getPtr(), data, t->getDimX() * t->getDimY() * t->getElementSizeBytes());
if (mips == RS_ALLOCATION_MIPMAP_FULL) {
rsaAllocationGenerateScriptMips(rsc, texAlloc);
AllocationGenerateScriptMips(rsc, texAlloc);
}
texAlloc->deferredUploadToTexture(rsc);
return texAlloc;
}
RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype,
RsAllocationMipmapControl mips,
const void *data, size_t data_length, uint32_t usages) {
Context *rsc = static_cast<Context *>(con);
RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype,
RsAllocationMipmapControl mips,
const void *data, size_t data_length, uint32_t usages) {
Type *t = static_cast<Type *>(vtype);
// Cubemap allocation's faces should be Width by Width each.
// Source data should have 6 * Width by Width pixels
// Error checking is done in the java layer
RsAllocation vTexAlloc = rsaAllocationCreateTyped(rsc, t, mips, usages);
RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages);
Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
if (texAlloc == NULL) {
LOGE("Memory allocation failure");
@@ -887,11 +875,21 @@ RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype,
}
if (mips == RS_ALLOCATION_MIPMAP_FULL) {
rsaAllocationGenerateScriptMips(rsc, texAlloc);
AllocationGenerateScriptMips(rsc, texAlloc);
}
texAlloc->deferredUploadToTexture(rsc);
return texAlloc;
}
}
}
const void * rsaAllocationGetType(RsContext con, RsAllocation va) {
Allocation *a = static_cast<Allocation *>(va);
a->getType()->incUserRef();
return a->getType();
}
#endif //ANDROID_RS_SERIALIZE

View File

@@ -740,25 +740,21 @@ void rsi_ContextDestroyWorker(Context *rsc) {
rsc->destroyWorkerThreadResources();;
}
}
}
void rsContextDestroy(RsContext vcon) {
LOGV("rsContextDestroy %p", vcon);
Context *rsc = static_cast<Context *>(vcon);
void rsi_ContextDestroy(Context *rsc) {
LOGV("rsContextDestroy %p", rsc);
rsContextDestroyWorker(rsc);
delete rsc;
LOGV("rsContextDestroy 2 %p", vcon);
LOGV("rsContextDestroy 2 %p", rsc);
}
RsContext rsContextCreate(RsDevice vdev, uint32_t version) {
RsContext rsi_ContextCreate(RsDevice vdev, uint32_t version) {
LOGV("rsContextCreate %p", vdev);
Device * dev = static_cast<Device *>(vdev);
Context *rsc = Context::createContext(dev, NULL);
return rsc;
}
RsContext rsContextCreateGL(RsDevice vdev, uint32_t version,
RsContext rsi_ContextCreateGL(RsDevice vdev, uint32_t version,
RsSurfaceConfig sc, uint32_t dpi) {
LOGV("rsContextCreateGL %p", vdev);
Device * dev = static_cast<Device *>(vdev);
@@ -768,32 +764,31 @@ RsContext rsContextCreateGL(RsDevice vdev, uint32_t version,
return rsc;
}
RsMessageToClientType rsContextPeekMessage(RsContext vrsc,
RsMessageToClientType rsi_ContextPeekMessage(Context *rsc,
size_t * receiveLen, size_t receiveLen_length,
uint32_t * subID, size_t subID_length, bool wait) {
Context * rsc = static_cast<Context *>(vrsc);
return rsc->peekMessageToClient(receiveLen, subID, wait);
}
RsMessageToClientType rsContextGetMessage(RsContext vrsc, void * data, size_t data_length,
RsMessageToClientType rsi_ContextGetMessage(Context *rsc, void * data, size_t data_length,
size_t * receiveLen, size_t receiveLen_length,
uint32_t * subID, size_t subID_length, bool wait) {
Context * rsc = static_cast<Context *>(vrsc);
rsAssert(subID_length == sizeof(uint32_t));
rsAssert(receiveLen_length == sizeof(size_t));
return rsc->getMessageToClient(data, receiveLen, subID, data_length, wait);
}
void rsContextInitToClient(RsContext vrsc) {
Context * rsc = static_cast<Context *>(vrsc);
void rsi_ContextInitToClient(Context *rsc) {
rsc->initToClient();
}
void rsContextDeinitToClient(RsContext vrsc) {
Context * rsc = static_cast<Context *>(vrsc);
void rsi_ContextDeinitToClient(Context *rsc) {
rsc->deinitToClient();
}
}
}
// Only to be called at a3d load time, before object is visible to user
// not thread safe
void rsaGetName(RsContext con, void * obj, const char **name) {

View File

@@ -40,17 +40,20 @@ void Device::removeContext(Context *rsc) {
}
}
RsDevice rsDeviceCreate() {
namespace android {
namespace renderscript {
RsDevice rsi_DeviceCreate() {
Device * d = new Device();
return d;
}
void rsDeviceDestroy(RsDevice dev) {
void rsi_DeviceDestroy(RsDevice dev) {
Device * d = static_cast<Device *>(dev);
delete d;
}
void rsDeviceSetConfig(RsDevice dev, RsDeviceParam p, int32_t value) {
void rsi_DeviceSetConfig(RsDevice dev, RsDeviceParam p, int32_t value) {
Device * d = static_cast<Device *>(dev);
if (p == RS_DEVICE_PARAM_FORCE_SOFTWARE_GL) {
d->mForceSW = value != 0;
@@ -59,3 +62,5 @@ void rsDeviceSetConfig(RsDevice dev, RsDeviceParam p, int32_t value) {
rsAssert(0);
}
}
}

View File

@@ -274,17 +274,16 @@ Type * Type::cloneAndResize2D(Context *rsc,
namespace android {
namespace renderscript {
}
}
RsType rsaTypeCreate(RsContext con, RsElement _e, uint32_t dimX,
RsType rsi_TypeCreate(Context *rsc, RsElement _e, uint32_t dimX,
uint32_t dimY, uint32_t dimZ, bool mips, bool faces) {
Context *rsc = static_cast<Context *>(con);
Element *e = static_cast<Element *>(_e);
return Type::getType(rsc, e, dimX, dimY, dimZ, mips, faces);
}
}
}
void rsaTypeGetNativeData(RsContext con, RsType type, uint32_t *typeData, uint32_t typeDataSize) {
rsAssert(typeDataSize == 6);
// Pack the data in the follofing way mDimX; mDimY; mDimZ;

View File

@@ -97,9 +97,20 @@ void printStructures(FILE *f) {
}
}
void printFuncDecl(FILE *f, const ApiEntry *api, const char *prefix, int addContext) {
void printFuncDecl(FILE *f, const ApiEntry *api, const char *prefix, int addContext, int isFnPtr) {
printVarTypeAndName(f, &api->ret);
fprintf(f, " %s%s (", prefix, api->name);
if (isFnPtr) {
char t[1024];
strcpy(t, api->name);
if (strlen(prefix) == 0) {
if (t[0] > 'A' && t[0] < 'Z') {
t[0] -= 'A' - 'a';
}
}
fprintf(f, " (* %s%s) (", prefix, api->name);
} else {
fprintf(f, " %s%s (", prefix, api->name);
}
if (!api->nocontext) {
if (addContext) {
fprintf(f, "Context *");
@@ -114,12 +125,24 @@ void printFuncDecl(FILE *f, const ApiEntry *api, const char *prefix, int addCont
void printFuncDecls(FILE *f, const char *prefix, int addContext) {
int ct;
for (ct=0; ct < apiCount; ct++) {
printFuncDecl(f, &apis[ct], prefix, addContext);
printFuncDecl(f, &apis[ct], prefix, addContext, 0);
fprintf(f, ";\n");
}
fprintf(f, "\n\n");
}
void printFuncPointers(FILE *f, int addContext) {
fprintf(f, "\n");
fprintf(f, "typedef struct RsApiEntrypoints {\n");
int ct;
for (ct=0; ct < apiCount; ct++) {
fprintf(f, " ");
printFuncDecl(f, &apis[ct], "", addContext, 1);
fprintf(f, ";\n");
}
fprintf(f, "} RsApiEntrypoints_t;\n\n");
}
void printPlaybackFuncs(FILE *f, const char *prefix) {
int ct;
for (ct=0; ct < apiCount; ct++) {
@@ -172,21 +195,35 @@ void printApiCpp(FILE *f) {
fprintf(f, "#include \"rsHandcode.h\"\n");
fprintf(f, "\n");
printFuncPointers(f, 0);
// Generate RS funcs for local fifo
for (ct=0; ct < apiCount; ct++) {
int needFlush = 0;
const ApiEntry * api = &apis[ct];
if (api->direct) {
continue;
}
printFuncDecl(f, api, "rs", 0);
fprintf(f, "static ");
printFuncDecl(f, api, "LF_", 0, 0);
fprintf(f, "\n{\n");
if (api->handcodeApi) {
fprintf(f, " rsHCAPI_%s(rsc", api->name);
if (api->handcodeApi || api->direct) {
if (api->handcodeApi) {
fprintf(f, " rsHCAPI_%s(rsc", api->name);
} else {
fprintf(f, " ");
if (api->ret.typeName[0]) {
fprintf(f, "return ");
}
fprintf(f, "rsi_%s(", api->name);
if (!api->nocontext) {
fprintf(f, "(Context *)rsc");
}
}
for (ct2=0; ct2 < api->paramCount; ct2++) {
const VarType *vt = &api->params[ct2];
fprintf(f, ", %s", vt->name);
if (ct2 > 0 || !api->nocontext) {
fprintf(f, ", ");
}
fprintf(f, "%s", vt->name);
}
fprintf(f, ");\n");
} else {
@@ -252,6 +289,43 @@ void printApiCpp(FILE *f) {
}
fprintf(f, "};\n\n");
}
fprintf(f, "\n");
fprintf(f, "static RsApiEntrypoints_t s_LocalTable = {\n");
for (ct=0; ct < apiCount; ct++) {
fprintf(f, " LF_%s,\n", apis[ct].name);
}
fprintf(f, "};\n");
fprintf(f, "static RsApiEntrypoints_t *s_CurrentTable = &s_LocalTable;\n\n");
for (ct=0; ct < apiCount; ct++) {
int needFlush = 0;
const ApiEntry * api = &apis[ct];
printFuncDecl(f, api, "rs", 0, 0);
fprintf(f, "\n{\n");
fprintf(f, " ");
if (api->ret.typeName[0]) {
fprintf(f, "return ");
}
fprintf(f, "s_CurrentTable->%s(", api->name);
if (!api->nocontext) {
fprintf(f, "(Context *)rsc");
}
for (ct2=0; ct2 < api->paramCount; ct2++) {
const VarType *vt = &api->params[ct2];
if (ct2 > 0 || !api->nocontext) {
fprintf(f, ", ");
}
fprintf(f, "%s", vt->name);
}
fprintf(f, ");\n");
fprintf(f, "}\n\n");
}
}
void printPlaybackCpp(FILE *f) {
@@ -373,6 +447,19 @@ int main(int argc, char **argv) {
printPlaybackCpp(f);
}
break;
case '4': // rsgApiStream.cpp
{
printFileHeader(f);
printPlaybackCpp(f);
}
case '5': // rsgApiStreamReplay.cpp
{
printFileHeader(f);
printPlaybackCpp(f);
}
break;
}
fclose(f);
return 0;