Cleanup diff with compat.

Change-Id: Ieedcdec03ccb05cac68cbebbd398e07cb885f4d3
diff --git a/cpu_ref/rsCpuScriptGroup.cpp b/cpu_ref/rsCpuScriptGroup.cpp
index 765057d..d418c22 100644
--- a/cpu_ref/rsCpuScriptGroup.cpp
+++ b/cpu_ref/rsCpuScriptGroup.cpp
@@ -229,8 +229,4 @@
     }
 }
 
-void rsdScriptGroupDestroy(const android::renderscript::Context *rsc,
-                           const android::renderscript::ScriptGroup *sg) {
-}
-
 
diff --git a/cpu_ref/rsCpuScriptGroup.h b/cpu_ref/rsCpuScriptGroup.h
index f6fa2ac..78e179d 100644
--- a/cpu_ref/rsCpuScriptGroup.h
+++ b/cpu_ref/rsCpuScriptGroup.h
@@ -17,7 +17,7 @@
 #ifndef RSD_SCRIPT_GROUP_H
 #define RSD_SCRIPT_GROUP_H
 
-#include <rsd_cpu.h>
+#include "rsd_cpu.h"
 
 namespace android {
 namespace renderscript {
diff --git a/driver/rsdAllocation.cpp b/driver/rsdAllocation.cpp
index 090c376..25a3d55 100644
--- a/driver/rsdAllocation.cpp
+++ b/driver/rsdAllocation.cpp
@@ -17,25 +17,28 @@
 
 #include "rsdCore.h"
 #include "rsdAllocation.h"
-#include "rsdFrameBufferObj.h"
 
 #include "rsAllocation.h"
 
 #include "system/window.h"
-#include "hardware/gralloc.h"
 #include "ui/Rect.h"
 #include "ui/GraphicBufferMapper.h"
+
+#ifndef RS_COMPATIBILITY_LIB
+#include "rsdFrameBufferObj.h"
 #include "gui/GLConsumer.h"
+#include "hardware/gralloc.h"
 
 #include <GLES/gl.h>
 #include <GLES2/gl2.h>
 #include <GLES/glext.h>
+#endif
 
 using namespace android;
 using namespace android::renderscript;
 
 
-
+#ifndef RS_COMPATIBILITY_LIB
 const static GLenum gFaceOrder[] = {
     GL_TEXTURE_CUBE_MAP_POSITIVE_X,
     GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
@@ -45,7 +48,6 @@
     GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
 };
 
-
 GLenum rsdTypeToGLType(RsDataType t) {
     switch (t) {
     case RS_TYPE_UNSIGNED_5_6_5:    return GL_UNSIGNED_SHORT_5_6_5;
@@ -75,6 +77,7 @@
     }
     return 0;
 }
+#endif
 
 uint8_t *GetOffsetPtr(const android::renderscript::Allocation *alloc,
                       uint32_t xoff, uint32_t yoff, uint32_t lod,
@@ -90,6 +93,7 @@
 static void Update2DTexture(const Context *rsc, const Allocation *alloc, const void *ptr,
                             uint32_t xoff, uint32_t yoff, uint32_t lod,
                             RsAllocationCubemapFace face, uint32_t w, uint32_t h) {
+#ifndef RS_COMPATIBILITY_LIB
     DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
 
     rsAssert(drv->textureID);
@@ -100,9 +104,11 @@
         t = gFaceOrder[face];
     }
     RSD_CALL_GL(glTexSubImage2D, t, lod, xoff, yoff, w, h, drv->glFormat, drv->glType, ptr);
+#endif
 }
 
 
+#ifndef RS_COMPATIBILITY_LIB
 static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool isFirstUpload) {
     DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
 
@@ -143,8 +149,10 @@
     }
     rsdGLCheckError(rsc, "Upload2DTexture");
 }
+#endif
 
 static void UploadToTexture(const Context *rsc, const Allocation *alloc) {
+#ifndef RS_COMPATIBILITY_LIB
     DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
 
     if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_INPUT) {
@@ -178,9 +186,11 @@
         }
     }
     rsdGLCheckError(rsc, "UploadToTexture");
+#endif
 }
 
 static void AllocateRenderTarget(const Context *rsc, const Allocation *alloc) {
+#ifndef RS_COMPATIBILITY_LIB
     DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
 
     if (!drv->glFormat) {
@@ -201,9 +211,11 @@
                               alloc->mHal.state.dimensionX, alloc->mHal.state.dimensionY);
     }
     rsdGLCheckError(rsc, "AllocateRenderTarget");
+#endif
 }
 
 static void UploadToBufferObject(const Context *rsc, const Allocation *alloc) {
+#ifndef RS_COMPATIBILITY_LIB
     DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
 
     rsAssert(!alloc->mHal.state.type->getDimY());
@@ -224,6 +236,7 @@
                  alloc->mHal.drvState.lod[0].mallocPtr, GL_DYNAMIC_DRAW);
     RSD_CALL_GL(glBindBuffer, drv->glTarget, 0);
     rsdGLCheckError(rsc, "UploadToBufferObject");
+#endif
 }
 
 static size_t AllocationBuildPointerTable(const Context *rsc, const Allocation *alloc,
@@ -326,8 +339,13 @@
         }
     }
 
+#ifndef RS_COMPATIBILITY_LIB
     drv->glType = rsdTypeToGLType(alloc->mHal.state.type->getElement()->getComponent().getType());
     drv->glFormat = rsdKindToGLFormat(alloc->mHal.state.type->getElement()->getComponent().getKind());
+#else
+    drv->glType = 0;
+    drv->glFormat = 0;
+#endif
 
     if (alloc->mHal.state.usageFlags & ~RS_ALLOCATION_USAGE_SCRIPT) {
         drv->uploadDeferred = true;
@@ -342,6 +360,7 @@
 void rsdAllocationDestroy(const Context *rsc, Allocation *alloc) {
     DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
 
+#ifndef RS_COMPATIBILITY_LIB
     if (drv->bufferID) {
         // Causes a SW crash....
         //ALOGV(" mBufferID %i", mBufferID);
@@ -356,6 +375,7 @@
         RSD_CALL_GL(glDeleteRenderbuffers, 1, &drv->renderTargetID);
         drv->renderTargetID = 0;
     }
+#endif
 
     if (alloc->mHal.drvState.lod[0].mallocPtr) {
         // don't free user-allocated ptrs
@@ -364,10 +384,14 @@
         }
         alloc->mHal.drvState.lod[0].mallocPtr = NULL;
     }
+
+#ifndef RS_COMPATIBILITY_LIB
     if (drv->readBackFBO != NULL) {
         delete drv->readBackFBO;
         drv->readBackFBO = NULL;
     }
+#endif
+
     free(drv);
     alloc->mHal.drv = NULL;
 }
@@ -400,6 +424,7 @@
 }
 
 static void rsdAllocationSyncFromFBO(const Context *rsc, const Allocation *alloc) {
+#ifndef RS_COMPATIBILITY_LIB
     if (!alloc->getIsScript()) {
         return; // nothing to sync
     }
@@ -428,6 +453,7 @@
 
     // Revert framebuffer to its original
     lastFbo->setActive(rsc);
+#endif
 }
 
 
@@ -472,11 +498,16 @@
 }
 
 int32_t rsdAllocationInitSurfaceTexture(const Context *rsc, const Allocation *alloc) {
+#ifndef RS_COMPATIBILITY_LIB
     DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
     UploadToTexture(rsc, alloc);
     return drv->textureID;
+#else
+    return 0;
+#endif
 }
 
+#ifndef RS_COMPATIBILITY_LIB
 static bool IoGetBuffer(const Context *rsc, Allocation *alloc, ANativeWindow *nw) {
     DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
 
@@ -499,8 +530,10 @@
 
     return true;
 }
+#endif
 
 void rsdAllocationSetSurfaceTexture(const Context *rsc, Allocation *alloc, ANativeWindow *nw) {
+#ifndef RS_COMPATIBILITY_LIB
     DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
 
     //ALOGE("rsdAllocationSetSurfaceTexture %p  %p", alloc, nw);
@@ -551,9 +584,11 @@
 
         IoGetBuffer(rsc, alloc, nw);
     }
+#endif
 }
 
 void rsdAllocationIoSend(const Context *rsc, Allocation *alloc) {
+#ifndef RS_COMPATIBILITY_LIB
     DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
     ANativeWindow *nw = alloc->mHal.state.wndSurface;
 
@@ -574,11 +609,14 @@
 
         IoGetBuffer(rsc, alloc, nw);
     }
+#endif
 }
 
 void rsdAllocationIoReceive(const Context *rsc, Allocation *alloc) {
+#ifndef RS_COMPATIBILITY_LIB
     DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
     alloc->mHal.state.surfaceTexture->updateTexImage();
+#endif
 }
 
 
diff --git a/driver/rsdAllocation.h b/driver/rsdAllocation.h
index 5f916d1..d506dc4 100644
--- a/driver/rsdAllocation.h
+++ b/driver/rsdAllocation.h
@@ -42,9 +42,15 @@
     // Is this a legal structure to be used as an FBO render target
     uint32_t renderTargetID;
 
+#ifndef RS_COMPATIBILITY_LIB
     GLenum glTarget;
     GLenum glType;
     GLenum glFormat;
+#else
+    int glTarget;
+    int glType;
+    int glFormat;
+#endif
 
     bool uploadDeferred;
 
@@ -53,8 +59,10 @@
     ANativeWindowBuffer *wndBuffer;
 };
 
+#ifndef RS_COMPATIBILITY_LIB
 GLenum rsdTypeToGLType(RsDataType t);
 GLenum rsdKindToGLFormat(RsDataKind k);
+#endif
 
 
 bool rsdAllocationInit(const android::renderscript::Context *rsc,
diff --git a/driver/rsdCore.h b/driver/rsdCore.h
index 0a46460..8b6ebf7 100644
--- a/driver/rsdCore.h
+++ b/driver/rsdCore.h
@@ -24,10 +24,13 @@
 #include "rsMutex.h"
 #include "rsSignal.h"
 
+#ifndef RS_COMPATIBILITY_LIB
 #include "rsdGL.h"
+#endif
 
 typedef void (* InvokeFunc_t)(void);
 typedef void (* ForEachFunc_t)(void);
+typedef int (* RootFunc_t)(void);
 typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
 
 typedef struct ScriptTLSStructRec {
@@ -43,7 +46,9 @@
     ScriptTLSStruct mTlsStruct;
     android::renderscript::RsdCpuReference *mCpuRef;
 
+#ifndef RS_COMPATIBILITY_LIB
     RsdGL gl;
+#endif
 } RsdHal;
 
 void rsdLaunchThreads(android::renderscript::Context *rsc, WorkerCallback_t cbk, void *data);
diff --git a/driver/rsdSampler.cpp b/driver/rsdSampler.cpp
index af48c61..96b27d4 100644
--- a/driver/rsdSampler.cpp
+++ b/driver/rsdSampler.cpp
@@ -20,12 +20,14 @@
 
 #include "rsContext.h"
 #include "rsSampler.h"
+
+#ifndef RS_COMPATIBILITY_LIB
 #include "rsProgramVertex.h"
 #include "rsProgramFragment.h"
 
 #include <GLES/gl.h>
 #include <GLES/glext.h>
-
+#endif
 
 using namespace android;
 using namespace android::renderscript;
diff --git a/rsAllocation.cpp b/rsAllocation.cpp
index db3b958..f928170 100644
--- a/rsAllocation.cpp
+++ b/rsAllocation.cpp
@@ -409,9 +409,11 @@
 }
 
 void Allocation::sendDirty(const Context *rsc) const {
+#ifndef RS_COMPATIBILITY_LIB
     for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
         mToDirtyList[ct]->forceDirty();
     }
+#endif
     mRSC->mHal.funcs.allocation.markDirty(rsc, this);
 }
 
diff --git a/rsContext.cpp b/rsContext.cpp
index 80021d5..1ade010 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -18,9 +18,12 @@
 #include "rsDevice.h"
 #include "rsContext.h"
 #include "rsThreadIO.h"
+
+#ifndef RS_COMPATIBILITY_LIB
 #include "rsMesh.h"
 #include <ui/FramebufferNativeWindow.h>
 #include <gui/DisplayEventReceiver.h>
+#endif
 
 #include <sys/types.h>
 #include <sys/resource.h>
@@ -29,7 +32,7 @@
 #include <cutils/properties.h>
 
 #include <sys/syscall.h>
-
+#include <string.h>
 #include <dlfcn.h>
 
 using namespace android;
@@ -52,11 +55,14 @@
 }
 
 void Context::deinitEGL() {
+#ifndef RS_COMPATIBILITY_LIB
     mHal.funcs.shutdownGraphics(this);
+#endif
 }
 
 Context::PushState::PushState(Context *con) {
     mRsc = con;
+#ifndef RS_COMPATIBILITY_LIB
     if (con->mIsGraphicsContext) {
         mFragment.set(con->getProgramFragment());
         mVertex.set(con->getProgramVertex());
@@ -64,9 +70,11 @@
         mRaster.set(con->getProgramRaster());
         mFont.set(con->getFont());
     }
+#endif
 }
 
 Context::PushState::~PushState() {
+#ifndef RS_COMPATIBILITY_LIB
     if (mRsc->mIsGraphicsContext) {
         mRsc->setProgramFragment(mFragment.get());
         mRsc->setProgramVertex(mVertex.get());
@@ -74,6 +82,7 @@
         mRsc->setProgramRaster(mRaster.get());
         mRsc->setFont(mFont.get());
     }
+#endif
 }
 
 
@@ -86,7 +95,9 @@
 
 uint32_t Context::runRootScript() {
     timerSet(RS_TIMER_SCRIPT);
+#ifndef RS_COMPATIBILITY_LIB
     mStateFragmentStore.mLast.clear();
+#endif
     watchdog.inRoot = true;
     uint32_t ret = runScript(mRootScript.get());
     watchdog.inRoot = false;
@@ -166,18 +177,21 @@
 }
 
 bool Context::setupCheck() {
-
+#ifndef RS_COMPATIBILITY_LIB
     mFragmentStore->setup(this, &mStateFragmentStore);
     mFragment->setup(this, &mStateFragment);
     mRaster->setup(this, &mStateRaster);
     mVertex->setup(this, &mStateVertex);
     mFBOCache.setup(this);
+#endif
     return true;
 }
 
+#ifndef RS_COMPATIBILITY_LIB
 void Context::setupProgramStore() {
     mFragmentStore->setup(this, &mStateFragmentStore);
 }
+#endif
 
 static uint32_t getProp(const char *str) {
     char buf[PROPERTY_VALUE_MAX];
@@ -186,6 +200,7 @@
 }
 
 void Context::displayDebugStats() {
+#ifndef RS_COMPATIBILITY_LIB
     char buffer[128];
     sprintf(buffer, "Avg fps %u, Frame %i ms, Script %i ms", mAverageFPS, mTimeMSLastFrame, mTimeMSLastScript);
     float oldR, oldG, oldB, oldA;
@@ -203,6 +218,7 @@
 
     setFont(lastFont.get());
     mStateFont.setFontColor(oldR, oldG, oldB, oldA);
+#endif
 }
 
 bool Context::loadRuntime(const char* filename, Context* rsc) {
@@ -250,10 +266,17 @@
     Context *rsc = static_cast<Context *>(vrsc);
 #ifndef ANDROID_RS_SERIALIZE
     rsc->mNativeThreadId = gettid();
+#ifndef RS_COMPATIBILITY_LIB
     if (!rsc->isSynchronous()) {
         setpriority(PRIO_PROCESS, rsc->mNativeThreadId, ANDROID_PRIORITY_DISPLAY);
     }
     rsc->mThreadPriority = ANDROID_PRIORITY_DISPLAY;
+#else
+    if (!rsc->isSynchronous()) {
+        setpriority(PRIO_PROCESS, rsc->mNativeThreadId, -4);
+    }
+    rsc->mThreadPriority = -4;
+#endif
 #endif //ANDROID_RS_SERIALIZE
     rsc->props.mLogTimes = getProp("debug.rs.profile") != 0;
     rsc->props.mLogScripts = getProp("debug.rs.script") != 0;
@@ -299,6 +322,7 @@
 
     rsc->mHal.funcs.setPriority(rsc, rsc->mThreadPriority);
 
+#ifndef RS_COMPATIBILITY_LIB
     if (rsc->mIsGraphicsContext) {
         if (!rsc->initGLThread()) {
             rsc->setError(RS_ERROR_OUT_OF_MEMORY, "Failed initializing GL");
@@ -318,6 +342,7 @@
         rsc->mStateSampler.init(rsc);
         rsc->mFBOCache.init(rsc);
     }
+#endif
 
     rsc->mRunning = true;
 
@@ -329,6 +354,7 @@
         while (!rsc->mExit) {
             rsc->mIO.playCoreCommands(rsc, -1);
         }
+#ifndef RS_COMPATIBILITY_LIB
     } else {
 #ifndef ANDROID_RS_SERIALIZE
         DisplayEventReceiver displayEvent;
@@ -379,15 +405,18 @@
                 rsc->timerReset();
             }
         }
+#endif
     }
 
     ALOGV("%p RS Thread exiting", rsc);
 
+#ifndef RS_COMPATIBILITY_LIB
     if (rsc->mIsGraphicsContext) {
         pthread_mutex_lock(&gInitMutex);
         rsc->deinitEGL();
         pthread_mutex_unlock(&gInitMutex);
     }
+#endif
 
     ALOGV("%p RS Thread exited", rsc);
     return NULL;
@@ -396,6 +425,7 @@
 void Context::destroyWorkerThreadResources() {
     //ALOGV("destroyWorkerThreadResources 1");
     ObjectBase::zeroAllUserRef(this);
+#ifndef RS_COMPATIBILITY_LIB
     if (mIsGraphicsContext) {
          mRaster.clear();
          mFragment.clear();
@@ -411,6 +441,7 @@
          mStateSampler.deinit(this);
          mFBOCache.deinit(this);
     }
+#endif
     ObjectBase::freeAllChildren(this);
     mExit = true;
     //ALOGV("destroyWorkerThreadResources 2");
@@ -553,6 +584,7 @@
     ALOGV("%p Context::~Context done", this);
 }
 
+#ifndef RS_COMPATIBILITY_LIB
 void Context::setSurface(uint32_t w, uint32_t h, RsNativeWindow sur) {
     rsAssert(mIsGraphicsContext);
     mHal.funcs.setSurface(this, w, h, sur);
@@ -650,6 +682,7 @@
         mFont.set(f);
     }
 }
+#endif
 
 void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) {
     rsAssert(!obj->getName());
@@ -715,8 +748,10 @@
 }
 
 void rsi_ContextBindRootScript(Context *rsc, RsScript vs) {
+#ifndef RS_COMPATIBILITY_LIB
     Script *s = static_cast<Script *>(vs);
     rsc->setRootScript(s);
+#endif
 }
 
 void rsi_ContextBindSampler(Context *rsc, uint32_t slot, RsSampler vs) {
@@ -730,6 +765,7 @@
     s->bindToContext(&rsc->mStateSampler, slot);
 }
 
+#ifndef RS_COMPATIBILITY_LIB
 void rsi_ContextBindProgramStore(Context *rsc, RsProgramStore vpfs) {
     ProgramStore *pfs = static_cast<ProgramStore *>(vpfs);
     rsc->setProgramStore(pfs);
@@ -754,6 +790,7 @@
     Font *font = static_cast<Font *>(vfont);
     rsc->setFont(font);
 }
+#endif
 
 void rsi_AssignName(Context *rsc, RsObjectBase obj, const char *name, size_t name_length) {
     ObjectBase *ob = static_cast<ObjectBase *>(obj);
@@ -766,6 +803,7 @@
     ob->decUserRef();
 }
 
+#ifndef RS_COMPATIBILITY_LIB
 void rsi_ContextPause(Context *rsc) {
     rsc->pause();
 }
@@ -777,6 +815,7 @@
 void rsi_ContextSetSurface(Context *rsc, uint32_t w, uint32_t h, RsNativeWindow sur) {
     rsc->setSurface(w, h, sur);
 }
+#endif
 
 void rsi_ContextSetPriority(Context *rsc, int32_t p) {
     rsc->setPriority(p);
@@ -840,6 +879,7 @@
     return rsc;
 }
 
+#ifndef RS_COMPATIBILITY_LIB
 RsContext rsContextCreateGL(RsDevice vdev, uint32_t version,
                             uint32_t sdkVersion, RsSurfaceConfig sc,
                             uint32_t dpi) {
@@ -853,6 +893,7 @@
     ALOGV("%p rsContextCreateGL ret", rsc);
     return rsc;
 }
+#endif
 
 // Only to be called at a3d load time, before object is visible to user
 // not thread safe
diff --git a/rsContext.h b/rsContext.h
index bc0c63e..df10d33 100644
--- a/rsContext.h
+++ b/rsContext.h
@@ -19,11 +19,14 @@
 
 #include "rsUtils.h"
 #include "rs_hal.h"
+#include <string.h>
 
 #include "rsThreadIO.h"
 #include "rsScriptC.h"
 #include "rsScriptGroup.h"
 #include "rsSampler.h"
+
+#ifndef RS_COMPATIBILITY_LIB
 #include "rsFont.h"
 #include "rsPath.h"
 #include "rsProgramFragment.h"
@@ -31,7 +34,8 @@
 #include "rsProgramRaster.h"
 #include "rsProgramVertex.h"
 #include "rsFBOCache.h"
-#include <string.h>
+#endif
+
 
 // ---------------------------------------------------------------------------
 namespace android {
@@ -81,11 +85,13 @@
         ~PushState();
 
     private:
+#ifndef RS_COMPATIBILITY_LIB
         ObjectBaseRef<ProgramFragment> mFragment;
         ObjectBaseRef<ProgramVertex> mVertex;
         ObjectBaseRef<ProgramStore> mStore;
         ObjectBaseRef<ProgramRaster> mRaster;
         ObjectBaseRef<Font> mFont;
+#endif
         Context *mRsc;
     };
 
@@ -94,16 +100,19 @@
     ElementState mStateElement;
     TypeState mStateType;
     SamplerState mStateSampler;
+
+    ScriptCState mScriptC;
+    bool isSynchronous() {return mSynchronous;}
+    bool setupCheck();
+
+#ifndef RS_COMPATIBILITY_LIB
+    FBOCache mFBOCache;
     ProgramFragmentState mStateFragment;
     ProgramStoreState mStateFragmentStore;
     ProgramRasterState mStateRaster;
     ProgramVertexState mStateVertex;
     FontState mStateFont;
 
-    ScriptCState mScriptC;
-    FBOCache mFBOCache;
-
-    bool isSynchronous() {return mSynchronous;}
 
     void swapBuffers();
     void setRootScript(Script *);
@@ -121,12 +130,13 @@
     ProgramVertex * getProgramVertex() {return mVertex.get();}
     Font * getFont() {return mFont.get();}
 
-    bool setupCheck();
     void setupProgramStore();
 
     void pause();
     void resume();
     void setSurface(uint32_t w, uint32_t h, RsNativeWindow sur);
+#endif
+
     void setPriority(int32_t p);
     void destroyWorkerThreadResources();
 
@@ -141,6 +151,7 @@
     void initToClient();
     void deinitToClient();
 
+#ifndef RS_COMPATIBILITY_LIB
     ProgramFragment * getDefaultProgramFragment() const {
         return mStateFragment.mDefault.get();
     }
@@ -163,6 +174,13 @@
     uint32_t getCurrentSurfaceWidth() const;
     uint32_t getCurrentSurfaceHeight() const;
 
+    void setWatchdogGL(const char *cmd, uint32_t line, const char *file) const {
+        watchdog.command = cmd;
+        watchdog.file = file;
+        watchdog.line = line;
+    }
+#endif
+
     mutable ThreadIO mIO;
 
     // Timers
@@ -198,11 +216,6 @@
         uint32_t line;
     } watchdog;
     static void printWatchdogInfo(void *ctx);
-    void setWatchdogGL(const char *cmd, uint32_t line, const char *file) const {
-        watchdog.command = cmd;
-        watchdog.file = file;
-        watchdog.line = line;
-    }
 
     void dumpDebug() const;
     void setError(RsError e, const char *msg = NULL) const;
@@ -236,11 +249,13 @@
     pid_t mNativeThreadId;
 
     ObjectBaseRef<Script> mRootScript;
+#ifndef RS_COMPATIBILITY_LIB
     ObjectBaseRef<ProgramFragment> mFragment;
     ObjectBaseRef<ProgramVertex> mVertex;
     ObjectBaseRef<ProgramStore> mFragmentStore;
     ObjectBaseRef<ProgramRaster> mRaster;
     ObjectBaseRef<Font> mFont;
+#endif
 
     void displayDebugStats();
 
diff --git a/rsRuntime.h b/rsRuntime.h
index 3a20cb0..390338b 100644
--- a/rsRuntime.h
+++ b/rsRuntime.h
@@ -29,6 +29,9 @@
 // Context
 //////////////////////////////////////////////////////////////////////////////
 
+void rsrAllocationSyncAll(Context *, Script *, Allocation *);
+
+#ifndef RS_COMPATIBILITY_LIB
 void rsrBindTexture(Context *, ProgramFragment *, uint32_t slot, Allocation *);
 void rsrBindConstant(Context *, ProgramFragment *, uint32_t slot, Allocation *);
 void rsrBindConstant(Context *, ProgramVertex*, uint32_t slot, Allocation *);
@@ -73,6 +76,7 @@
 
 
 void rsrColor(Context *, float r, float g, float b, float a);
+#endif
 
 void rsrAllocationCopy1DRange(Context *, Allocation *dstAlloc,
                               uint32_t dstOff,
@@ -88,6 +92,7 @@
                               uint32_t srcXoff, uint32_t srcYoff,
                               uint32_t srcMip, uint32_t srcFace);
 
+#ifndef RS_COMPATIBILITY_LIB
 void rsrPrepareClear(Context *);
 uint32_t rsrGetWidth(Context *);
 uint32_t rsrGetHeight(Context *);
@@ -101,6 +106,7 @@
                     int32_t *left, int32_t *right, int32_t *top, int32_t *bottom);
 void rsrBindFont(Context *, Font *);
 void rsrFontColor(Context *, float r, float g, float b, float a);
+#endif
 
 //////////////////////////////////////////////////////////////////////////////
 // Time routines
diff --git a/rsScript.h b/rsScript.h
index 8afd3bc..b6173bb 100644
--- a/rsScript.h
+++ b/rsScript.h
@@ -24,10 +24,12 @@
 namespace android {
 namespace renderscript {
 
+#ifndef RS_COMPATIBILITY_LIB
 class ProgramVertex;
 class ProgramFragment;
 class ProgramRaster;
 class ProgramStore;
+#endif
 
 class ScriptKernelID : public ObjectBase {
 public:
@@ -86,10 +88,12 @@
         int64_t mStartTimeMillis;
         mutable int64_t mLastDtTime;
 
+#ifndef RS_COMPATIBILITY_LIB
         ObjectBaseRef<ProgramVertex> mVertex;
         ObjectBaseRef<ProgramFragment> mFragment;
         ObjectBaseRef<ProgramRaster> mRaster;
         ObjectBaseRef<ProgramStore> mFragmentStore;
+#endif
     };
     Enviroment_t mEnviroment;
 
diff --git a/rsScriptC.cpp b/rsScriptC.cpp
index 18e4af2..757d3ca 100644
--- a/rsScriptC.cpp
+++ b/rsScriptC.cpp
@@ -19,10 +19,12 @@
 #include "utils/Timers.h"
 #include "utils/StopWatch.h"
 
+#ifndef RS_COMPATIBILITY_LIB
 #ifndef ANDROID_RS_SERIALIZE
 #include <bcinfo/BitcodeTranslator.h>
 #include <bcinfo/BitcodeWrapper.h>
 #endif
+#endif
 
 #include <sys/stat.h>
 
@@ -35,24 +37,29 @@
     ScriptC * sc = (ScriptC *) tls->mScript
 
 ScriptC::ScriptC(Context *rsc) : Script(rsc) {
+#ifndef RS_COMPATIBILITY_LIB
 #ifndef ANDROID_RS_SERIALIZE
     BT = NULL;
 #endif
+#endif
 }
 
 ScriptC::~ScriptC() {
+#ifndef RS_COMPATIBILITY_LIB
 #ifndef ANDROID_RS_SERIALIZE
     if (BT) {
         delete BT;
         BT = NULL;
     }
 #endif
+#endif
     if (mInitialized) {
         mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this);
         mRSC->mHal.funcs.script.destroy(mRSC, this);
     }
 }
 
+#ifndef RS_COMPATIBILITY_LIB
 bool ScriptC::createCacheDir(const char *cacheDir) {
     String8 cacheDirString, currentDir;
     struct stat statBuf;
@@ -89,6 +96,7 @@
     }
     return true;
 }
+#endif
 
 void ScriptC::setupScript(Context *rsc) {
     mEnviroment.mStartTimeMillis
@@ -106,6 +114,7 @@
 }
 
 void ScriptC::setupGLState(Context *rsc) {
+#ifndef RS_COMPATIBILITY_LIB
     if (mEnviroment.mFragmentStore.get()) {
         rsc->setProgramStore(mEnviroment.mFragmentStore.get());
     }
@@ -118,6 +127,7 @@
     if (mEnviroment.mRaster.get()) {
         rsc->setProgramRaster(mEnviroment.mRaster.get());
     }
+#endif
 }
 
 uint32_t ScriptC::run(Context *rsc) {
@@ -217,6 +227,7 @@
                           size_t bitcodeLen) {
 
     //ALOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen);
+#ifndef RS_COMPATIBILITY_LIB
 #ifndef ANDROID_RS_SERIALIZE
     uint32_t sdkVersion = 0;
     bcinfo::BitcodeWrapper bcWrapper((const char *)bitcode, bitcodeLen);
@@ -260,16 +271,19 @@
     if (cacheDir && !createCacheDir(cacheDir)) {
       return false;
     }
+#endif
 
     if (!rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0)) {
         return false;
     }
 
     mInitialized = true;
+#ifndef RS_COMPATIBILITY_LIB
     mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
     mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
     mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore());
     mEnviroment.mRaster.set(rsc->getDefaultProgramRaster());
+#endif
 
     rsc->mHal.funcs.script.invokeInit(rsc, this);
 
@@ -285,6 +299,7 @@
             return false;
         }
 
+#ifndef RS_COMPATIBILITY_LIB
         if (!strcmp(key, "stateVertex")) {
             if (!strcmp(value, "default")) {
                 continue;
@@ -332,6 +347,8 @@
             ALOGE("Unrecognized value %s passed to stateStore", value);
             return false;
         }
+#endif
+
     }
 
     mSlots = new ObjectBaseRef<Allocation>[mHal.info.exportedVariableCount];
diff --git a/rsScriptC.h b/rsScriptC.h
index 75fb0f4..c1e3301 100644
--- a/rsScriptC.h
+++ b/rsScriptC.h
@@ -21,9 +21,11 @@
 
 #include "rsEnv.h"
 
+#ifndef RS_COMPATIBILITY_LIB
 #ifndef ANDROID_RS_SERIALIZE
 #include "bcinfo/BitcodeTranslator.h"
 #endif
+#endif
 
 // ---------------------------------------------------------------------------
 namespace android {
@@ -61,10 +63,13 @@
     void setupScript(Context *);
     void setupGLState(Context *);
 private:
+#ifndef RS_COMPATIBILITY_LIB
 #ifndef ANDROID_RS_SERIALIZE
     bcinfo::BitcodeTranslator *BT;
 #endif
+
     bool createCacheDir(const char *cacheDir);
+#endif
 };
 
 class ScriptCState {