From c576537166fa3f829e4b5d8c6617a36b47e75fc3 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Thu, 28 Apr 2011 18:26:48 -0700 Subject: Pipe rsa function though the RS api table. Change-Id: Ic8a3bef5d337be1d8fc5ca961eec6be4761701c5 --- libs/rs/rs.spec | 8 ++-- libs/rs/rsAllocation.cpp | 56 ++++++++++++------------ libs/rs/rsContext.cpp | 29 ++++++------- libs/rs/rsDevice.cpp | 11 +++-- libs/rs/rsType.cpp | 9 ++-- libs/rs/rsg_generator.c | 109 ++++++++++++++++++++++++++++++++++++++++++----- 6 files changed, 153 insertions(+), 69 deletions(-) (limited to 'libs/rs') diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index 6310cf6..0c4e1ed 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -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 diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index 743b2c4..b5f6f56 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -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(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(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(con); Allocation *texAlloc = static_cast(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(va); - a->getType()->incUserRef(); - - return a->getType(); -} - -RsAllocation rsaAllocationCreateTyped(RsContext con, RsType vtype, - RsAllocationMipmapControl mips, - uint32_t usages) { - Context *rsc = static_cast(con); +RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype, + RsAllocationMipmapControl mips, + uint32_t usages) { Allocation * alloc = new Allocation(rsc, static_cast(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(con); +RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype, + RsAllocationMipmapControl mips, + const void *data, size_t data_length, uint32_t usages) { Type *t = static_cast(vtype); - RsAllocation vTexAlloc = rsaAllocationCreateTyped(rsc, vtype, mips, usages); + RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages); Allocation *texAlloc = static_cast(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(con); +RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype, + RsAllocationMipmapControl mips, + const void *data, size_t data_length, uint32_t usages) { Type *t = static_cast(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(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(va); + a->getType()->incUserRef(); + + return a->getType(); +} + #endif //ANDROID_RS_SERIALIZE diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index 50f5f55..cffe9e4 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -740,25 +740,21 @@ void rsi_ContextDestroyWorker(Context *rsc) { rsc->destroyWorkerThreadResources();; } -} -} - -void rsContextDestroy(RsContext vcon) { - LOGV("rsContextDestroy %p", vcon); - Context *rsc = static_cast(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(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(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(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(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(vrsc); +void rsi_ContextInitToClient(Context *rsc) { rsc->initToClient(); } -void rsContextDeinitToClient(RsContext vrsc) { - Context * rsc = static_cast(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) { diff --git a/libs/rs/rsDevice.cpp b/libs/rs/rsDevice.cpp index d7d03f6..849fd98 100644 --- a/libs/rs/rsDevice.cpp +++ b/libs/rs/rsDevice.cpp @@ -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(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(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); } +} +} diff --git a/libs/rs/rsType.cpp b/libs/rs/rsType.cpp index cd2be94..10e3182 100644 --- a/libs/rs/rsType.cpp +++ b/libs/rs/rsType.cpp @@ -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(con); Element *e = static_cast(_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; diff --git a/libs/rs/rsg_generator.c b/libs/rs/rsg_generator.c index 0059f19..ed20fef 100644 --- a/libs/rs/rsg_generator.c +++ b/libs/rs/rsg_generator.c @@ -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; -- cgit v1.1