More work to make libRS buildable on the host.

Change-Id: I239585ef7c1334f7fc19fa6423535dea7b9a753f
diff --git a/Android.mk b/Android.mk
index 9c9fae3..9fabf8d 100644
--- a/Android.mk
+++ b/Android.mk
@@ -149,24 +149,82 @@
 
 # Now build a host version for serialization
 include $(CLEAR_VARS)
+LOCAL_MODULE:= libRS
+LOCAL_MODULE_TAGS := optional
+
+intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,HOST,)
+
+# Generate custom headers
+
+GEN := $(addprefix $(intermediates)/, \
+            rsgApiStructs.h \
+            rsgApiFuncDecl.h \
+        )
+
+$(GEN) : PRIVATE_PATH := $(LOCAL_PATH)
+$(GEN) : PRIVATE_CUSTOM_TOOL = $(RSG_GENERATOR) $< $@ <$(PRIVATE_PATH)/rs.spec
+$(GEN) : $(RSG_GENERATOR) $(LOCAL_PATH)/rs.spec
+$(GEN): $(intermediates)/%.h : $(LOCAL_PATH)/%.h.rsg
+	$(transform-generated-source)
+
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+# Generate custom source files
+
+GEN := $(addprefix $(intermediates)/, \
+            rsgApi.cpp \
+            rsgApiReplay.cpp \
+        )
+
+$(GEN) : PRIVATE_PATH := $(LOCAL_PATH)
+$(GEN) : PRIVATE_CUSTOM_TOOL = $(RSG_GENERATOR) $< $@ <$(PRIVATE_PATH)/rs.spec
+$(GEN) : $(RSG_GENERATOR) $(LOCAL_PATH)/rs.spec
+$(GEN): $(intermediates)/%.cpp : $(LOCAL_PATH)/%.cpp.rsg
+	$(transform-generated-source)
+
+LOCAL_GENERATED_SOURCES += $(GEN)
+
 LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-unused-variable
 LOCAL_CFLAGS += -DANDROID_RS_SERIALIZE
+LOCAL_CFLAGS += -fPIC
 
 LOCAL_SRC_FILES:= \
+	rsAdapter.cpp \
 	rsAllocation.cpp \
+	rsAnimation.cpp \
 	rsComponent.cpp \
+	rsContext.cpp \
+	rsDevice.cpp \
 	rsElement.cpp \
+	rsFBOCache.cpp \
+	rsFifoSocket.cpp \
 	rsFileA3D.cpp \
+	rsFont.cpp \
+	rsLocklessFifo.cpp \
 	rsObjectBase.cpp \
+	rsMatrix2x2.cpp \
+	rsMatrix3x3.cpp \
+	rsMatrix4x4.cpp \
 	rsMesh.cpp \
+	rsMutex.cpp \
+	rsProgram.cpp \
+	rsProgramFragment.cpp \
+	rsProgramStore.cpp \
+	rsProgramRaster.cpp \
+	rsProgramVertex.cpp \
+	rsSampler.cpp \
+	rsScript.cpp \
+	rsScriptC.cpp \
+	rsScriptC_Lib.cpp \
+	rsScriptC_LibGL.cpp \
+	rsSignal.cpp \
 	rsStream.cpp \
+	rsThreadIO.cpp \
 	rsType.cpp
 
 LOCAL_STATIC_LIBRARIES := libcutils libutils
 
 LOCAL_LDLIBS := -lpthread
-LOCAL_MODULE:= libRSserialize
-LOCAL_MODULE_TAGS := optional
 
 include $(BUILD_HOST_STATIC_LIBRARY)
 
diff --git a/RenderScript.h b/RenderScript.h
index 3f2d67a..535f713 100644
--- a/RenderScript.h
+++ b/RenderScript.h
@@ -55,15 +55,7 @@
 RsContext rsContextCreate(RsDevice dev, uint32_t version);
 RsContext rsContextCreateGL(RsDevice dev, uint32_t version, RsSurfaceConfig sc, uint32_t dpi);
 
-
-
-#ifdef ANDROID_RS_SERIALIZE
-#define NO_RS_FUNCS
-#endif
-
-#ifndef NO_RS_FUNCS
 #include "rsgApiFuncDecl.h"
-#endif
 
 #ifdef __cplusplus
 };
diff --git a/driver/rsdCore.cpp b/driver/rsdCore.cpp
index 94d55a6..01cc369 100644
--- a/driver/rsdCore.cpp
+++ b/driver/rsdCore.cpp
@@ -36,6 +36,7 @@
 #include <cutils/sched_policy.h>
 #include <sys/syscall.h>
 #include <string.h>
+#include <bcc/bcc.h>
 
 using namespace android;
 using namespace android::renderscript;
diff --git a/driver/rsdCore.h b/driver/rsdCore.h
index 422bb1b..f393b60 100644
--- a/driver/rsdCore.h
+++ b/driver/rsdCore.h
@@ -18,7 +18,6 @@
 #define RSD_CORE_H
 
 #include <rs_hal.h>
-#include <bcc/bcc.h>
 
 #include "rsMutex.h"
 #include "rsSignal.h"
diff --git a/rsAllocation.cpp b/rsAllocation.cpp
index 05412c7..bff3660 100644
--- a/rsAllocation.cpp
+++ b/rsAllocation.cpp
@@ -168,13 +168,10 @@
 }
 
 void Allocation::addProgramToDirty(const Program *p) {
-#ifndef ANDROID_RS_SERIALIZE
     mToDirtyList.push(p);
-#endif //ANDROID_RS_SERIALIZE
 }
 
 void Allocation::removeProgramToDirty(const Program *p) {
-#ifndef ANDROID_RS_SERIALIZE
     for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
         if (mToDirtyList[ct] == p) {
             mToDirtyList.removeAt(ct);
@@ -182,7 +179,6 @@
         }
     }
     rsAssert(0);
-#endif //ANDROID_RS_SERIALIZE
 }
 
 void Allocation::dumpLOGV(const char *prefix) const {
@@ -254,11 +250,9 @@
 }
 
 void Allocation::sendDirty(const Context *rsc) const {
-#ifndef ANDROID_RS_SERIALIZE
     for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
         mToDirtyList[ct]->forceDirty();
     }
-#endif //ANDROID_RS_SERIALIZE
     mRSC->mHal.funcs.allocation.markDirty(rsc, this);
 }
 
@@ -312,8 +306,6 @@
 
 /////////////////
 //
-#ifndef ANDROID_RS_SERIALIZE
-
 
 namespace android {
 namespace renderscript {
@@ -413,25 +405,25 @@
 }
 
 void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
-                          uint32_t count, const void *data, uint32_t sizeBytes) {
+                          uint32_t count, const void *data, size_t sizeBytes) {
     Allocation *a = static_cast<Allocation *>(va);
     a->data(rsc, xoff, lod, count, data, sizeBytes);
 }
 
 void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face,
-                                 const void *data, uint32_t eoff, uint32_t sizeBytes) {
+                                 const void *data, size_t eoff, uint32_t sizeBytes) { // TODO: this seems wrong, eoff and sizeBytes may be swapped
     Allocation *a = static_cast<Allocation *>(va);
     a->elementData(rsc, x, y, data, eoff, sizeBytes);
 }
 
 void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod,
-                                 const void *data, uint32_t eoff, uint32_t sizeBytes) {
+                                 const void *data, size_t eoff, uint32_t sizeBytes) { // TODO: this seems wrong, eoff and sizeBytes may be swapped
     Allocation *a = static_cast<Allocation *>(va);
     a->elementData(rsc, x, data, eoff, sizeBytes);
 }
 
 void rsi_Allocation2DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
-                          uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes) {
+                          uint32_t w, uint32_t h, const void *data, size_t sizeBytes) {
     Allocation *a = static_cast<Allocation *>(va);
     a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes);
 }
@@ -549,5 +541,3 @@
 
     return a->getType();
 }
-
-#endif //ANDROID_RS_SERIALIZE
diff --git a/rsAllocation.h b/rsAllocation.h
index 5cf6292..f538dd1 100644
--- a/rsAllocation.h
+++ b/rsAllocation.h
@@ -59,7 +59,6 @@
 
     static Allocation * createAllocation(Context *rsc, const Type *, uint32_t usages,
                                   RsAllocationMipmapControl mc = RS_ALLOCATION_MIPMAP_NONE);
-
     virtual ~Allocation();
     void updateCache();
 
@@ -121,14 +120,6 @@
 
 private:
     Allocation(Context *rsc, const Type *, uint32_t usages, RsAllocationMipmapControl mc);
-
-    void upload2DTexture(bool isFirstUpload);
-    void update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff,
-                         uint32_t lod, RsAllocationCubemapFace face, uint32_t w, uint32_t h);
-
-    void allocScriptMemory();
-    void freeScriptMemory();
-
 };
 
 }
diff --git a/rsContext.cpp b/rsContext.cpp
index bab5c58..44e9d89 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -92,9 +92,13 @@
 }
 
 uint64_t Context::getTime() const {
+#ifndef ANDROID_RS_SERIALIZE
     struct timespec t;
     clock_gettime(CLOCK_MONOTONIC, &t);
     return t.tv_nsec + ((uint64_t)t.tv_sec * 1000 * 1000 * 1000);
+#else
+    return 0;
+#endif //ANDROID_RS_SERIALIZE
 }
 
 void Context::timerReset() {
@@ -200,11 +204,11 @@
 
 void * Context::threadProc(void *vrsc) {
     Context *rsc = static_cast<Context *>(vrsc);
+#ifndef ANDROID_RS_SERIALIZE
     rsc->mNativeThreadId = gettid();
-
     setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY);
     rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY;
-
+#endif //ANDROID_RS_SERIALIZE
     rsc->props.mLogTimes = getProp("debug.rs.profile");
     rsc->props.mLogScripts = getProp("debug.rs.script");
     rsc->props.mLogObjects = getProp("debug.rs.object");
@@ -330,10 +334,16 @@
     mObjHead = NULL;
     mError = RS_ERROR_NONE;
     mDPI = 96;
+    mIsContextLite = false;
 }
 
 Context * Context::createContext(Device *dev, const RsSurfaceConfig *sc) {
     Context * rsc = new Context();
+
+    // Temporary to avoid breaking the tools
+    if (!dev) {
+        return rsc;
+    }
     if (!rsc->initContext(dev, sc)) {
         delete rsc;
         return NULL;
@@ -341,6 +351,12 @@
     return rsc;
 }
 
+Context * Context::createContextLite() {
+    Context * rsc = new Context();
+    rsc->mIsContextLite = true;
+    return rsc;
+}
+
 bool Context::initContext(Device *dev, const RsSurfaceConfig *sc) {
     pthread_mutex_lock(&gInitMutex);
 
@@ -395,26 +411,28 @@
 Context::~Context() {
     LOGV("Context::~Context");
 
-    mIO.coreFlush();
-    rsAssert(mExit);
-    mExit = true;
-    mPaused = false;
-    void *res;
+    if (!mIsContextLite) {
+        mIO.coreFlush();
+        rsAssert(mExit);
+        mExit = true;
+        mPaused = false;
+        void *res;
 
-    mIO.shutdown();
-    int status = pthread_join(mThreadId, &res);
+        mIO.shutdown();
+        int status = pthread_join(mThreadId, &res);
 
-    if (mHal.funcs.shutdownDriver) {
-        mHal.funcs.shutdownDriver(this);
+        if (mHal.funcs.shutdownDriver) {
+            mHal.funcs.shutdownDriver(this);
+        }
+
+        // Global structure cleanup.
+        pthread_mutex_lock(&gInitMutex);
+        if (mDev) {
+            mDev->removeContext(this);
+            mDev = NULL;
+        }
+        pthread_mutex_unlock(&gInitMutex);
     }
-
-    // Global structure cleanup.
-    pthread_mutex_lock(&gInitMutex);
-    if (mDev) {
-        mDev->removeContext(this);
-        mDev = NULL;
-    }
-    pthread_mutex_unlock(&gInitMutex);
     LOGV("Context::~Context done");
 }
 
@@ -542,7 +560,7 @@
 
     LOGE(" RS width %i, height %i", mWidth, mHeight);
     LOGE(" RS running %i, exit %i, paused %i", mRunning, mExit, mPaused);
-    LOGE(" RS pThreadID %li, nativeThreadID %i", mThreadId, mNativeThreadId);
+    LOGE(" RS pThreadID %li, nativeThreadID %i", (long int)mThreadId, mNativeThreadId);
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////
@@ -595,7 +613,7 @@
     rsc->setFont(font);
 }
 
-void rsi_AssignName(Context *rsc, RsObjectBase obj, const char *name, uint32_t name_length) {
+void rsi_AssignName(Context *rsc, RsObjectBase obj, const char *name, size_t name_length) {
     ObjectBase *ob = static_cast<ObjectBase *>(obj);
     rsc->assignName(ob, name, name_length);
 }
@@ -627,7 +645,7 @@
 }
 
 void rsi_ContextDestroyWorker(Context *rsc) {
-    rsc->destroyWorkerThreadResources();;
+    rsc->destroyWorkerThreadResources();
 }
 
 void rsi_ContextDestroy(Context *rsc) {
diff --git a/rsContext.h b/rsContext.h
index 4ba00fe..309fe95 100644
--- a/rsContext.h
+++ b/rsContext.h
@@ -24,7 +24,6 @@
 
 #include "rs_hal.h"
 
-#ifndef ANDROID_RS_SERIALIZE
 #include "rsMutex.h"
 #include "rsThreadIO.h"
 #include "rsMatrix4x4.h"
@@ -42,8 +41,6 @@
 #include "rsgApiStructs.h"
 #include "rsLocklessFifo.h"
 
-#endif // ANDROID_RS_SERIALIZE
-
 // ---------------------------------------------------------------------------
 namespace android {
 
@@ -67,8 +64,6 @@
 #define CHECK_OBJ_OR_NULL(o)
 #endif
 
-#ifndef ANDROID_RS_SERIALIZE
-
 class Context {
 public:
     struct Hal {
@@ -79,6 +74,7 @@
     Hal mHal;
 
     static Context * createContext(Device *, const RsSurfaceConfig *sc);
+    static Context * createContextLite();
     ~Context();
 
     static pthread_mutex_t gInitMutex;
@@ -243,6 +239,7 @@
     static void * helperThreadProc(void *);
 
     bool mHasSurface;
+    bool mIsContextLite;
 
     Vector<ObjectBase *> mNames;
 
@@ -259,46 +256,6 @@
     uint32_t mAverageFPS;
 };
 
-#else
-
-class Context {
-public:
-    Context() {
-        mObjHead = NULL;
-    }
-    ~Context() {
-        ObjectBase::zeroAllUserRef(this);
-    }
-
-    struct Hal {
-        void * drv;
-
-        RsdHalFunctions funcs;
-    };
-    Hal mHal;
-
-    ElementState mStateElement;
-    TypeState mStateType;
-
-    struct {
-        bool mLogTimes;
-        bool mLogScripts;
-        bool mLogObjects;
-        bool mLogShaders;
-        bool mLogShadersAttr;
-        bool mLogShadersUniforms;
-        bool mLogVisual;
-    } props;
-
-    void setError(RsError e, const char *msg = NULL) {  }
-
-    mutable const ObjectBase * mObjHead;
-
-protected:
-
-};
-#endif //ANDROID_RS_SERIALIZE
-
 } // renderscript
 } // android
 #endif
diff --git a/rsFifoSocket.cpp b/rsFifoSocket.cpp
index 848bba5..8b8008d 100644
--- a/rsFifoSocket.cpp
+++ b/rsFifoSocket.cpp
@@ -70,9 +70,9 @@
 }
 
 void FifoSocket::readReturn(const void *data, size_t bytes) {
-    LOGE("readReturn %p %i", data, bytes);
+    LOGE("readReturn %p %Zu", data, bytes);
     size_t ret = ::send(sv[1], data, bytes, 0);
-    LOGE("readReturn %i", ret);
+    LOGE("readReturn %Zu", ret);
     rsAssert(ret == bytes);
 }
 
diff --git a/rsFont.cpp b/rsFont.cpp
index b625504..ce674f4 100644
--- a/rsFont.cpp
+++ b/rsFont.cpp
@@ -21,9 +21,11 @@
 #include "rsProgramFragment.h"
 #include <cutils/properties.h>
 
+#ifndef ANDROID_RS_SERIALIZE
 #include <ft2build.h>
 #include FT_FREETYPE_H
 #include FT_BITMAP_H
+#endif //ANDROID_RS_SERIALIZE
 
 using namespace android;
 using namespace android::renderscript;
@@ -35,6 +37,7 @@
 }
 
 bool Font::init(const char *name, float fontSize, uint32_t dpi, const void *data, uint32_t dataLen) {
+#ifndef ANDROID_RS_SERIALIZE
     if (mInitialized) {
         LOGE("Reinitialization of fonts not supported");
         return false;
@@ -65,6 +68,7 @@
     mHasKerning = FT_HAS_KERNING(mFace);
 
     mInitialized = true;
+#endif //ANDROID_RS_SERIALIZE
     return true;
 }
 
@@ -230,6 +234,7 @@
 }
 
 void Font::updateGlyphCache(CachedGlyphInfo *glyph) {
+#ifndef ANDROID_RS_SERIALIZE
     FT_Error error = FT_Load_Glyph( mFace, glyph->mGlyphIndex, FT_LOAD_RENDER );
     if (error) {
         LOGE("Couldn't load glyph.");
@@ -270,15 +275,16 @@
     glyph->mBitmapMinV = (float)startY / (float)cacheHeight;
     glyph->mBitmapMaxU = (float)endX / (float)cacheWidth;
     glyph->mBitmapMaxV = (float)endY / (float)cacheHeight;
+#endif //ANDROID_RS_SERIALIZE
 }
 
 Font::CachedGlyphInfo *Font::cacheGlyph(uint32_t glyph) {
     CachedGlyphInfo *newGlyph = new CachedGlyphInfo();
     mCachedGlyphs.add(glyph, newGlyph);
-
+#ifndef ANDROID_RS_SERIALIZE
     newGlyph->mGlyphIndex = FT_Get_Char_Index(mFace, glyph);
     newGlyph->mIsValid = false;
-
+#endif //ANDROID_RS_SERIALIZE
     updateGlyphCache(newGlyph);
 
     return newGlyph;
@@ -309,9 +315,11 @@
 }
 
 Font::~Font() {
+#ifndef ANDROID_RS_SERIALIZE
     if (mFace) {
         FT_Done_Face(mFace);
     }
+#endif
 
     for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) {
         CachedGlyphInfo *glyph = mCachedGlyphs.valueAt(i);
@@ -324,7 +332,9 @@
     mMaxNumberOfQuads = 1024;
     mCurrentQuadIndex = 0;
     mRSC = NULL;
+#ifndef ANDROID_RS_SERIALIZE
     mLibrary = NULL;
+#endif //ANDROID_RS_SERIALIZE
 
     // Get the renderer properties
     char property[PROPERTY_VALUE_MAX];
@@ -363,7 +373,7 @@
 
     rsAssert(!mActiveFonts.size());
 }
-
+#ifndef ANDROID_RS_SERIALIZE
 FT_Library FontState::getLib() {
     if (!mLibrary) {
         FT_Error error = FT_Init_FreeType(&mLibrary);
@@ -375,6 +385,8 @@
 
     return mLibrary;
 }
+#endif //ANDROID_RS_SERIALIZE
+
 
 void FontState::init(Context *rsc) {
     mRSC = rsc;
@@ -393,6 +405,7 @@
     }
 }
 
+#ifndef ANDROID_RS_SERIALIZE
 bool FontState::cacheBitmap(FT_Bitmap *bitmap, uint32_t *retOriginX, uint32_t *retOriginY) {
     // If the glyph is too tall, don't cache it
     if ((uint32_t)bitmap->rows > mCacheLines[mCacheLines.size()-1]->mMaxHeight) {
@@ -466,6 +479,7 @@
 
     return true;
 }
+#endif //ANDROID_RS_SERIALIZE
 
 void FontState::initRenderState() {
     String8 shaderString("varying vec2 varTex0;\n");
@@ -791,13 +805,15 @@
     mCacheLines.clear();
 
     mDefault.clear();
-
+#ifndef ANDROID_RS_SERIALIZE
     if (mLibrary) {
         FT_Done_FreeType( mLibrary );
         mLibrary = NULL;
     }
+#endif //ANDROID_RS_SERIALIZE
 }
 
+#ifndef ANDROID_RS_SERIALIZE
 bool FontState::CacheTextureLine::fitBitmap(FT_Bitmap_ *bitmap, uint32_t *retOriginX, uint32_t *retOriginY) {
     if ((uint32_t)bitmap->rows > mMaxHeight) {
         return false;
@@ -813,6 +829,7 @@
 
     return false;
 }
+#endif //ANDROID_RS_SERIALIZE
 
 namespace android {
 namespace renderscript {
diff --git a/rsFont.h b/rsFont.h
index d18c0d9..b0e1430 100644
--- a/rsFont.h
+++ b/rsFont.h
@@ -199,8 +199,10 @@
     float mWhiteThreshold;
 
     // Free type library, we only need one copy
+#ifndef ANDROID_RS_SERIALIZE
     FT_LibraryRec_ *mLibrary;
     FT_LibraryRec_ *getLib();
+#endif //ANDROID_RS_SERIALIZE
     Vector<Font*> mActiveFonts;
 
     // Render state for the font
@@ -217,7 +219,9 @@
         return (uint8_t*)mTextTexture->getPtr();
     }
 
+#ifndef ANDROID_RS_SERIALIZE
     bool cacheBitmap(FT_Bitmap_ *bitmap, uint32_t *retOriginX, uint32_t *retOriginY);
+#endif //ANDROID_RS_SERIALIZE
     const Type* getCacheTextureType() {
         return mTextTexture->getType();
     }
diff --git a/rsMesh.cpp b/rsMesh.cpp
index 62e388c..359d09f 100644
--- a/rsMesh.cpp
+++ b/rsMesh.cpp
@@ -161,8 +161,6 @@
     return mesh;
 }
 
-#ifndef ANDROID_RS_SERIALIZE
-
 void Mesh::render(Context *rsc) const {
     for (uint32_t ct = 0; ct < mHal.state.primitivesCount; ct ++) {
         renderPrimitive(rsc, ct);
@@ -255,9 +253,9 @@
 namespace renderscript {
 
 RsMesh rsi_MeshCreate(Context *rsc,
-                      RsAllocation *vtx, uint32_t vtxCount,
-                      RsAllocation *idx, uint32_t idxCount,
-                      uint32_t *primType, uint32_t primTypeCount) {
+                      RsAllocation * vtx, size_t vtxCount,
+                      RsAllocation * idx, size_t idxCount,
+                      uint32_t * primType, size_t primTypeCount) {
     rsAssert(idxCount == primTypeCount);
     Mesh *sm = new Mesh(rsc, vtxCount, idxCount);
     sm->incUserRef();
@@ -309,5 +307,3 @@
         }
     }
 }
-
-#endif
diff --git a/rsProgramFragment.cpp b/rsProgramFragment.cpp
index 0823d82..356ff77 100644
--- a/rsProgramFragment.cpp
+++ b/rsProgramFragment.cpp
@@ -127,8 +127,8 @@
 namespace renderscript {
 
 RsProgramFragment rsi_ProgramFragmentCreate(Context *rsc, const char * shaderText,
-                             uint32_t shaderLength, const uint32_t * params,
-                             uint32_t paramLength) {
+                             size_t shaderLength, const uint32_t * params,
+                             size_t paramLength) {
     ProgramFragment *pf = new ProgramFragment(rsc, shaderText, shaderLength, params, paramLength);
     pf->incUserRef();
     //LOGE("rsi_ProgramFragmentCreate %p", pf);
diff --git a/rsProgramVertex.cpp b/rsProgramVertex.cpp
index e6790cb..058a456 100644
--- a/rsProgramVertex.cpp
+++ b/rsProgramVertex.cpp
@@ -223,8 +223,8 @@
 namespace renderscript {
 
 RsProgramVertex rsi_ProgramVertexCreate(Context *rsc, const char * shaderText,
-                             uint32_t shaderLength, const uint32_t * params,
-                             uint32_t paramLength) {
+                             size_t shaderLength, const uint32_t * params,
+                             size_t paramLength) {
     ProgramVertex *pv = new ProgramVertex(rsc, shaderText, shaderLength, params, paramLength);
     pv->incUserRef();
     return pv;
diff --git a/rsScript.cpp b/rsScript.cpp
index 7641cab..f62c72e 100644
--- a/rsScript.cpp
+++ b/rsScript.cpp
@@ -53,7 +53,7 @@
     }
 }
 
-void Script::setVar(uint32_t slot, const void *val, uint32_t len) {
+void Script::setVar(uint32_t slot, const void *val, size_t len) {
     //LOGE("setVar %i %p %i", slot, val, len);
     if (slot >= mHal.info.exportedVariableCount) {
         LOGE("Script::setVar unable to set allocation, invalid slot index");
@@ -82,14 +82,14 @@
     //LOGE("rsi_ScriptBindAllocation %i  %p  %p", slot, a, a->getPtr());
 }
 
-void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length) {
+void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) {
     Script *s = static_cast<Script *>(vs);
     s->mEnviroment.mTimeZone = timeZone;
 }
 
 void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot,
                        RsAllocation vain, RsAllocation vaout,
-                       const void *params, uint32_t paramLen) {
+                       const void *params, size_t paramLen) {
     Script *s = static_cast<Script *>(vs);
     s->runForEach(rsc,
                   static_cast<const Allocation *>(vain), static_cast<Allocation *>(vaout),
@@ -108,7 +108,7 @@
     s->Invoke(rsc, slot, NULL, 0);
 }
 
-void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) {
+void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
     Script *s = static_cast<Script *>(vs);
     s->Invoke(rsc, slot, data, len);
 }
@@ -139,7 +139,7 @@
     s->setVar(slot, &value, sizeof(value));
 }
 
-void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) {
+void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
     Script *s = static_cast<Script *>(vs);
     s->setVar(slot, data, len);
 }
diff --git a/rsScript.h b/rsScript.h
index 088c8d1..c0324dd 100644
--- a/rsScript.h
+++ b/rsScript.h
@@ -70,7 +70,7 @@
 
     void initSlots();
     void setSlot(uint32_t slot, Allocation *a);
-    void setVar(uint32_t slot, const void *val, uint32_t len);
+    void setVar(uint32_t slot, const void *val, size_t len);
     void setVarObj(uint32_t slot, ObjectBase *val);
 
     virtual void runForEach(Context *rsc,
@@ -80,7 +80,7 @@
                             size_t usrBytes,
                             const RsScriptCall *sc = NULL) = 0;
 
-    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) = 0;
+    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
     virtual void setupScript(Context *rsc) = 0;
     virtual uint32_t run(Context *) = 0;
 protected:
diff --git a/rsScriptC.cpp b/rsScriptC.cpp
index 6d0701d..b230bb5 100644
--- a/rsScriptC.cpp
+++ b/rsScriptC.cpp
@@ -19,11 +19,6 @@
 #include "utils/Timers.h"
 #include "utils/StopWatch.h"
 
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-
-#include <bcc/bcc.h>
-
 using namespace android;
 using namespace android::renderscript;
 
@@ -129,7 +124,7 @@
     rsc->mHal.funcs.script.invokeForEach(rsc, this, ain, aout, usr, usrBytes, sc);
 }
 
-void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) {
+void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) {
     if (slot >= mHal.info.exportedFunctionCount) {
         rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script");
         return;
@@ -269,7 +264,7 @@
 RsScript rsi_ScriptCCreate(Context *rsc,
                            const char *resName, size_t resName_length,
                            const char *cacheDir, size_t cacheDir_length,
-                           const char *text, uint32_t text_length)
+                           const char *text, size_t text_length)
 {
     ScriptC *s = new ScriptC(rsc);
 
diff --git a/rsScriptC.h b/rsScriptC.h
index 4c85745..5c191d9 100644
--- a/rsScriptC.h
+++ b/rsScriptC.h
@@ -39,7 +39,7 @@
     const Allocation *ptrToAllocation(const void *) const;
 
 
-    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len);
+    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len);
 
     virtual uint32_t run(Context *);
 
diff --git a/rsThreadIO.cpp b/rsThreadIO.cpp
index 4429556..ab164c3 100644
--- a/rsThreadIO.cpp
+++ b/rsThreadIO.cpp
@@ -149,7 +149,7 @@
         mToClientSocket.read(&mLastClientHeader, sizeof(mLastClientHeader));
     } else {
         size_t bytesData = 0;
-        const uint32_t *d = (const uint32_t *)mToClient.get(&mLastClientHeader.cmdID, &bytesData);
+        const uint32_t *d = (const uint32_t *)mToClient.get(&mLastClientHeader.cmdID, (uint32_t*)&bytesData);
         if (bytesData >= sizeof(uint32_t)) {
             mLastClientHeader.userID = d[0];
             mLastClientHeader.bytes = bytesData - sizeof(uint32_t);
diff --git a/rs_hal.h b/rs_hal.h
index 44c7e71..7bb09bb 100644
--- a/rs_hal.h
+++ b/rs_hal.h
@@ -18,7 +18,6 @@
 #define RS_HAL_H
 
 #include <RenderScriptDefines.h>
-#include <ui/egl/android_natives.h>
 
 namespace android {
 namespace renderscript {