Merge "Cleanup rs.spec file and code generator."
diff --git a/RenderScript.h b/RenderScript.h
index cb6d7e0..f4e3f57 100644
--- a/RenderScript.h
+++ b/RenderScript.h
@@ -26,20 +26,6 @@
 
 #include "RenderScriptDefines.h"
 
-RsDevice rsDeviceCreate();
-void rsDeviceDestroy(RsDevice);
-void rsDeviceSetConfig(RsDevice, RsDeviceParam, int32_t value);
-
-RsContext rsContextCreate(RsDevice, uint32_t version);
-RsContext rsContextCreateGL(RsDevice, uint32_t version,
-                            RsSurfaceConfig sc, uint32_t dpi);
-void rsContextDestroy(RsContext);
-
-RsMessageToClientType rsContextGetMessage(RsContext vrsc, void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen, bool wait);
-RsMessageToClientType rsContextPeekMessage(RsContext vrsc, size_t *receiveLen, uint32_t *subID, bool wait);
-void rsContextInitToClient(RsContext);
-void rsContextDeinitToClient(RsContext);
-
 //
 // A3D loading and object update code.
 // Should only be called at object creation, not thread safe
@@ -63,18 +49,8 @@
 void rsaElementGetNativeData(RsContext, RsElement, uint32_t *elemData, uint32_t elemDataSize);
 void rsaElementGetSubElements(RsContext, RsElement, uint32_t *ids, const char **names, uint32_t dataSize);
 
-// Async commands for returning new IDS
-RsType rsaTypeCreate(RsContext, RsElement, uint32_t dimX, uint32_t dimY,
-                     uint32_t dimZ, bool mips, bool faces);
-RsAllocation rsaAllocationCreateTyped(RsContext rsc, RsType vtype,
-                                      RsAllocationMipmapControl mips,
-                                      uint32_t usages);
-RsAllocation rsaAllocationCreateFromBitmap(RsContext con, RsType vtype,
-                                           RsAllocationMipmapControl mips,
-                                           const void *data, uint32_t usages);
-RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype,
-                                               RsAllocationMipmapControl mips,
-                                               const void *data, uint32_t usages);
+
+
 #ifdef ANDROID_RS_SERIALIZE
 #define NO_RS_FUNCS
 #endif
diff --git a/rs.spec b/rs.spec
index dac5cec..998296b 100644
--- a/rs.spec
+++ b/rs.spec
@@ -1,4 +1,110 @@
 
+DeviceCreate {
+    direct
+    nocontext
+    ret RsDevice
+}
+
+DeviceDestroy {
+    direct
+    nocontext
+    param RsDevice dev
+}
+
+DeviceSetConfig {
+    direct
+    nocontext
+    param RsDevice dev
+    param RsDeviceParam p
+    param int32_t value
+}
+
+ContextCreate {
+    direct
+    nocontext
+    param RsDevice dev
+    param uint32_t version
+    ret RsContext
+}
+
+ContextCreateGL {
+    direct
+    nocontext
+    param RsDevice dev
+    param uint32_t version
+    param RsSurfaceConfig sc
+    param uint32_t dpi
+    ret RsContext
+}
+
+ContextDestroy {
+    direct
+}
+
+ContextGetMessage {
+    direct
+    param void *data
+    param size_t *receiveLen
+    param uint32_t *subID
+    param bool wait
+    ret RsMessageToClientType
+}
+
+ContextPeekMessage {
+    direct
+    param size_t *receiveLen
+    param uint32_t *subID
+    param bool wait
+    ret RsMessageToClientType
+}
+
+ContextInitToClient {
+    direct
+}
+
+ContextDeinitToClient {
+    direct
+}
+
+aTypeCreate {
+    direct
+    param RsElement e
+    param uint32_t dimX
+    param uint32_t dimY
+    param uint32_t dimZ
+    param bool mips
+    param bool faces
+    ret RsType
+}
+
+aAllocationCreateTyped {
+    direct
+    param RsType vtype
+    param RsAllocationMipmapControl mips
+    param uint32_t usages
+    ret RsAllocation
+}
+
+aAllocationCreateFromBitmap {
+    direct
+    param RsType vtype
+    param RsAllocationMipmapControl mips
+    param const void *data
+    param uint32_t usages
+    ret RsAllocation
+}
+
+aAllocationCubeCreateFromBitmap {
+    direct
+    param RsType vtype
+    param RsAllocationMipmapControl mips
+    param const void *data
+    param uint32_t usages
+    ret RsAllocation
+}
+
+
+
 ContextFinish {
 	handcodeApi
 	}
@@ -82,23 +188,21 @@
 
 
 Allocation1DData {
+	handcodeApi
 	param RsAllocation va
 	param uint32_t xoff
 	param uint32_t lod
 	param uint32_t count
 	param const void *data
-	handcodeApi
-	togglePlay
 	}
 
 Allocation1DElementData {
+	handcodeApi
 	param RsAllocation va
 	param uint32_t x
 	param uint32_t lod
 	param const void *data
 	param uint32_t comp_offset
-	handcodeApi
-	togglePlay
 	}
 
 Allocation2DData {
@@ -186,11 +290,10 @@
 	}
 
 ScriptInvokeV {
+	handcodeApi
 	param RsScript s
 	param uint32_t slot
 	param const void * data
-	handcodeApi
-	togglePlay
 	}
 
 ScriptSetVarI {
@@ -224,11 +327,10 @@
 	}
 
 ScriptSetVarV {
+	handcodeApi
 	param RsScript s
 	param uint32_t slot
 	param const void * data
-	handcodeApi
-	togglePlay
 	}
 
 
@@ -330,3 +432,4 @@
 MeshInitVertexAttribs {
 	param RsMesh mesh
 	}
+
diff --git a/rsAllocation.cpp b/rsAllocation.cpp
index a759004..743b2c4 100644
--- a/rsAllocation.cpp
+++ b/rsAllocation.cpp
@@ -833,7 +833,7 @@
 
 RsAllocation rsaAllocationCreateFromBitmap(RsContext con, RsType vtype,
                                            RsAllocationMipmapControl mips,
-                                           const void *data, uint32_t usages) {
+                                           const void *data, size_t data_length, uint32_t usages) {
     Context *rsc = static_cast<Context *>(con);
     Type *t = static_cast<Type *>(vtype);
 
@@ -855,7 +855,7 @@
 
 RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype,
                                                RsAllocationMipmapControl mips,
-                                               const void *data, uint32_t usages) {
+                                               const void *data, size_t data_length, uint32_t usages) {
     Context *rsc = static_cast<Context *>(con);
     Type *t = static_cast<Type *>(vtype);
 
diff --git a/rsContext.cpp b/rsContext.cpp
index 0ca892d..50f5f55 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -768,14 +768,20 @@
     return rsc;
 }
 
-RsMessageToClientType rsContextPeekMessage(RsContext vrsc, size_t *receiveLen, uint32_t *subID, bool wait) {
+RsMessageToClientType rsContextPeekMessage(RsContext vrsc,
+                                           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 *receiveLen, uint32_t *subID, size_t bufferLen, bool wait) {
+RsMessageToClientType rsContextGetMessage(RsContext vrsc, 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);
-    return rsc->getMessageToClient(data, receiveLen, subID, bufferLen, wait);
+    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) {
diff --git a/rsg_generator.c b/rsg_generator.c
index 4ac5b7f..14b380a 100644
--- a/rsg_generator.c
+++ b/rsg_generator.c
@@ -4,7 +4,7 @@
 
 void printFileHeader(FILE *f) {
     fprintf(f, "/*\n");
-    fprintf(f, " * Copyright (C) 2010 The Android Open Source Project\n");
+    fprintf(f, " * Copyright (C) 2011 The Android Open Source Project\n");
     fprintf(f, " *\n");
     fprintf(f, " * Licensed under the Apache License, Version 2.0 (the \"License\");\n");
     fprintf(f, " * you may not use this file except in compliance with the License.\n");
@@ -96,12 +96,14 @@
 void printFuncDecl(FILE *f, const ApiEntry *api, const char *prefix, int addContext) {
     printVarType(f, &api->ret);
     fprintf(f, " %s%s (", prefix, api->name);
-    if (addContext) {
-        fprintf(f, "Context *");
-    } else {
-        fprintf(f, "RsContext rsc");
+    if (!api->nocontext) {
+        if (addContext) {
+            fprintf(f, "Context *");
+        } else {
+            fprintf(f, "RsContext rsc");
+        }
     }
-    printArgList(f, api, 1);
+    printArgList(f, api, !api->nocontext);
     fprintf(f, ")");
 }
 
@@ -117,6 +119,10 @@
 void printPlaybackFuncs(FILE *f, const char *prefix) {
     int ct;
     for (ct=0; ct < apiCount; ct++) {
+        if (apis[ct].direct) {
+            continue;
+        }
+
         fprintf(f, "void %s%s (Context *, const void *);\n", prefix, apis[ct].name);
     }
 }
@@ -140,6 +146,10 @@
         int needFlush = 0;
         const ApiEntry * api = &apis[ct];
 
+        if (api->direct) {
+            continue;
+        }
+
         printFuncDecl(f, api, "rs", 0);
         fprintf(f, "\n{\n");
         if (api->handcodeApi) {
@@ -198,31 +208,37 @@
     for (ct=0; ct < apiCount; ct++) {
         const ApiEntry * api = &apis[ct];
 
+        if (api->direct) {
+            continue;
+        }
+
         fprintf(f, "void rsp_%s(Context *con, const void *vp)\n", api->name);
         fprintf(f, "{\n");
-        if (api->handcodePlay) {
-            fprintf(f, "    rsHCPLAY_%s(con, vp);\n", api->name);
-        } else {
-            //fprintf(f, "    LOGE(\"play command %s\\n\");\n", api->name);
-            fprintf(f, "    const RS_CMD_%s *cmd = static_cast<const RS_CMD_%s *>(vp);\n", api->name, api->name);
-            fprintf(f, "    ");
-            if (api->ret.typeName[0]) {
-                fprintf(f, "con->mIO.mToCoreRet = (intptr_t)");
-            }
-            fprintf(f, "rsi_%s(con", api->name);
-            for (ct2=0; ct2 < api->paramCount; ct2++) {
-                const VarType *vt = &api->params[ct2];
-                fprintf(f, ",\n           cmd->%s", vt->name);
-            }
-            fprintf(f, ");\n");
+
+        //fprintf(f, "    LOGE(\"play command %s\\n\");\n", api->name);
+        fprintf(f, "    const RS_CMD_%s *cmd = static_cast<const RS_CMD_%s *>(vp);\n", api->name, api->name);
+        fprintf(f, "    ");
+        if (api->ret.typeName[0]) {
+            fprintf(f, "con->mIO.mToCoreRet = (intptr_t)");
         }
+        fprintf(f, "rsi_%s(con", api->name);
+        for (ct2=0; ct2 < api->paramCount; ct2++) {
+            const VarType *vt = &api->params[ct2];
+            fprintf(f, ",\n           cmd->%s", vt->name);
+        }
+        fprintf(f, ");\n");
+
         fprintf(f, "};\n\n");
     }
 
     fprintf(f, "RsPlaybackFunc gPlaybackFuncs[%i] = {\n", apiCount + 1);
     fprintf(f, "    NULL,\n");
     for (ct=0; ct < apiCount; ct++) {
-        fprintf(f, "    %s%s,\n", "rsp_", apis[ct].name);
+        if (apis[ct].direct) {
+            fprintf(f, "    NULL,\n");
+        } else {
+            fprintf(f, "    %s%s,\n", "rsp_", apis[ct].name);
+        }
     }
     fprintf(f, "};\n");
 
diff --git a/spec.h b/spec.h
index 82650a7..ecc5cc7 100644
--- a/spec.h
+++ b/spec.h
@@ -25,7 +25,8 @@
   char name[256];
   int sync;
   int handcodeApi;
-  int handcodePlay;
+  int direct;
+  int nocontext;
   int paramCount;
   VarType ret;
   VarType params[16];
diff --git a/spec.l b/spec.l
index c8af891..dcd4435 100644
--- a/spec.l
+++ b/spec.l
@@ -44,6 +44,7 @@
 <comment>"*"+"/"        BEGIN(INITIAL);
 
 <*>" "   //printf("found ' '\n");
+<*>"\t"   //printf("found ' '\n");
 <*>"\n"  ++num_lines; //printf("found lf \n");
 
 {ID} {
@@ -64,8 +65,12 @@
     apis[apiCount].handcodeApi = 1;
     }
 
-<api_entry2>"handcodePlay" {
-    apis[apiCount].handcodePlay = 1;
+<api_entry2>"direct" {
+    apis[apiCount].direct = 1;
+    }
+
+<api_entry2>"nocontext" {
+    apis[apiCount].nocontext = 1;
     }
 
 <api_entry2>"ret" {