Add x86 server support.

Change-Id: I674acaf15b67afa48bc736f72942a11e2e38e940
diff --git a/driver/rsdAllocation.cpp b/driver/rsdAllocation.cpp
index ed27dca..cdcf48f 100644
--- a/driver/rsdAllocation.cpp
+++ b/driver/rsdAllocation.cpp
@@ -14,15 +14,16 @@
  * limitations under the License.
  */
 
-
 #include "rsdCore.h"
 #include "rsdAllocation.h"
 
 #include "rsAllocation.h"
 
+#ifndef RS_SERVER
 #include "system/window.h"
 #include "ui/Rect.h"
 #include "ui/GraphicBufferMapper.h"
+#endif
 
 #ifndef RS_COMPATIBILITY_LIB
 #include "rsdFrameBufferObj.h"
@@ -36,6 +37,11 @@
 #include <GLES/glext.h>
 #endif
 
+#ifdef RS_SERVER
+// server requires malloc.h for memalign
+#include <malloc.h>
+#endif
+
 using namespace android;
 using namespace android::renderscript;
 
@@ -241,10 +247,12 @@
 #endif
 }
 
+
 static size_t DeriveYUVLayout(int yuv, Allocation::Hal::DrvState *state) {
     // YUV only supports basic 2d
     // so we can stash the plane pointers in the mipmap levels.
     size_t uvSize = 0;
+#ifndef RS_SERVER
     switch(yuv) {
     case HAL_PIXEL_FORMAT_YV12:
         state->lod[1].dimX = state->lod[0].dimX / 2;
@@ -275,6 +283,7 @@
     default:
         rsAssert(0);
     }
+#endif
     return uvSize;
 }
 
@@ -406,6 +415,7 @@
         rsAssert(!"Size mismatch");
     }
 
+#ifndef RS_SERVER
     drv->glTarget = GL_NONE;
     if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE) {
         if (alloc->mHal.state.hasFaces) {
@@ -418,6 +428,7 @@
             drv->glTarget = GL_ARRAY_BUFFER;
         }
     }
+#endif
 
 #ifndef RS_COMPATIBILITY_LIB
     drv->glType = rsdTypeToGLType(alloc->mHal.state.type->getElement()->getComponent().getType());
diff --git a/driver/rsdAllocation.h b/driver/rsdAllocation.h
index d8f46c5..c209203 100644
--- a/driver/rsdAllocation.h
+++ b/driver/rsdAllocation.h
@@ -22,11 +22,13 @@
 #include <rsAllocation.h>
 
 #include "../cpu_ref/rsd_cpu.h"
+
+#ifndef RS_SERVER
 #include "gui/CpuConsumer.h"
 #include "gui/GLConsumer.h"
-
 #include <GLES/gl.h>
 #include <GLES2/gl2.h>
+#endif
 
 class RsdFrameBufferObj;
 struct ANativeWindow;
@@ -65,8 +67,10 @@
     ANativeWindow *wnd;
     ANativeWindowBuffer *wndBuffer;
 
+#ifndef RS_SERVER
     android::sp< android::CpuConsumer > cpuConsumer;
     android::CpuConsumer::LockedBuffer lb;
+#endif
 };
 
 #ifndef RS_COMPATIBILITY_LIB
diff --git a/driver/rsdBcc.cpp b/driver/rsdBcc.cpp
index 436b9b2..77e0576 100644
--- a/driver/rsdBcc.cpp
+++ b/driver/rsdBcc.cpp
@@ -25,9 +25,11 @@
 #include "rsElement.h"
 #include "rsScriptC.h"
 
+#ifndef RS_SERVER
 #include "utils/Vector.h"
 #include "utils/Timers.h"
 #include "utils/StopWatch.h"
+#endif
 
 using namespace android;
 using namespace android::renderscript;
diff --git a/driver/rsdCore.cpp b/driver/rsdCore.cpp
index 367a50b..9e55524 100644
--- a/driver/rsdCore.cpp
+++ b/driver/rsdCore.cpp
@@ -38,10 +38,13 @@
 #include <sys/types.h>
 #include <sys/resource.h>
 #include <sched.h>
-#include <cutils/properties.h>
 #include <sys/syscall.h>
 #include <string.h>
 
+#ifndef RS_SERVER
+#include <cutils/properties.h>
+#endif
+
 using namespace android;
 using namespace android::renderscript;
 
diff --git a/driver/rsdRuntimeStubs.cpp b/driver/rsdRuntimeStubs.cpp
index 92af7ce..8e7d9ee 100644
--- a/driver/rsdRuntimeStubs.cpp
+++ b/driver/rsdRuntimeStubs.cpp
@@ -21,7 +21,6 @@
 #include "rsMatrix2x2.h"
 #include "rsRuntime.h"
 
-#include "utils/Timers.h"
 #include "rsdCore.h"
 #include "rsdBcc.h"
 
@@ -69,7 +68,9 @@
 typedef uint8_t uchar;
 typedef uint16_t ushort;
 typedef uint32_t uint;
+#ifndef RS_SERVER
 typedef uint64_t ulong;
+#endif
 
 //////////////////////////////////////////////////////////////////////////////
 // Allocation
@@ -1050,8 +1051,10 @@
     { "_Z20rsgAllocationSyncAll13rs_allocationj", (void *)&SC_AllocationSyncAll2, false },
     { "_Z20rsgAllocationSyncAll13rs_allocation24rs_allocation_usage_type", (void *)&SC_AllocationSyncAll2, false },
     { "_Z15rsGetAllocationPKv", (void *)&SC_GetAllocation, true },
+#ifndef RS_COMPATIBILITY_LIB
     { "_Z18rsAllocationIoSend13rs_allocation", (void *)&SC_AllocationIoSend, false },
     { "_Z21rsAllocationIoReceive13rs_allocation", (void *)&SC_AllocationIoReceive, false },
+#endif
     { "_Z23rsAllocationCopy1DRange13rs_allocationjjjS_jj", (void *)&SC_AllocationCopy1DRange, false },
     { "_Z23rsAllocationCopy2DRange13rs_allocationjjj26rs_allocation_cubemap_facejjS_jjjS0_", (void *)&SC_AllocationCopy2DRange, false },
 
@@ -1061,7 +1064,7 @@
     { "_Z14rsSendToClientiPKvj", (void *)&SC_ToClient2, false },
     { "_Z22rsSendToClientBlockingi", (void *)&SC_ToClientBlocking, false },
     { "_Z22rsSendToClientBlockingiPKvj", (void *)&SC_ToClientBlocking2, false },
-
+#ifndef RS_COMPATIBILITY_LIB
     { "_Z22rsgBindProgramFragment19rs_program_fragment", (void *)&SC_BindProgramFragment, false },
     { "_Z19rsgBindProgramStore16rs_program_store", (void *)&SC_BindProgramStore, false },
     { "_Z20rsgBindProgramVertex17rs_program_vertex", (void *)&SC_BindProgramVertex, false },
@@ -1111,6 +1114,7 @@
     { "_Z19rsgClearColorTargetj", (void *)&SC_ClearFrameBufferObjectColorTarget, false },
     { "_Z19rsgClearDepthTargetv", (void *)&SC_ClearFrameBufferObjectDepthTarget, false },
     { "_Z24rsgClearAllRenderTargetsv", (void *)&SC_ClearFrameBufferObjectTargets, false },
+#endif // RS_COMPATIBILITY_LIB
 
     { "_Z9rsForEach9rs_script13rs_allocationS0_", (void *)&SC_ForEach_SAA, true },
     { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach_SAAU, true },
@@ -1126,12 +1130,346 @@
     { "_Z7rsGetDtv", (void*)&SC_GetDt, false },
 
     // misc
+#ifndef RS_COMPATIBILITY_LIB
     { "_Z5colorffff", (void *)&SC_Color, false },
     { "_Z9rsgFinishv", (void *)&SC_Finish, false },
+#endif
 
     { NULL, NULL, false }
 };
 
+#ifdef RS_COMPATIBILITY_LIB
+
+uint32_t rsSendToClientBlocking(int cmdID) {
+    Context *rsc = RsdCpuReference::getTlsContext();
+    return rsrToClientBlocking(rsc, cmdID, NULL, 0);
+}
+
+static void SC_debugF(const char *s, float f) {
+    ALOGD("%s %f, 0x%08x", s, f, *((int *) (&f)));
+}
+static void SC_debugFv2(const char *s, float f1, float f2) {
+    ALOGD("%s {%f, %f}", s, f1, f2);
+}
+static void SC_debugFv3(const char *s, float f1, float f2, float f3) {
+    ALOGD("%s {%f, %f, %f}", s, f1, f2, f3);
+}
+static void SC_debugFv4(const char *s, float f1, float f2, float f3, float f4) {
+    ALOGD("%s {%f, %f, %f, %f}", s, f1, f2, f3, f4);
+}
+static void SC_debugF2(const char *s, float2 f) {
+    ALOGD("%s {%f, %f}", s, f.x, f.y);
+}
+static void SC_debugF3(const char *s, float3 f) {
+    ALOGD("%s {%f, %f, %f}", s, f.x, f.y, f.z);
+}
+static void SC_debugF4(const char *s, float4 f) {
+    ALOGD("%s {%f, %f, %f, %f}", s, f.x, f.y, f.z, f.w);
+}
+static void SC_debugD(const char *s, double d) {
+    ALOGD("%s %f, 0x%08llx", s, d, *((long long *) (&d)));
+}
+static void SC_debugFM4v4(const char *s, const float *f) {
+    ALOGD("%s {%f, %f, %f, %f", s, f[0], f[4], f[8], f[12]);
+    ALOGD("%s  %f, %f, %f, %f", s, f[1], f[5], f[9], f[13]);
+    ALOGD("%s  %f, %f, %f, %f", s, f[2], f[6], f[10], f[14]);
+    ALOGD("%s  %f, %f, %f, %f}", s, f[3], f[7], f[11], f[15]);
+}
+static void SC_debugFM3v3(const char *s, const float *f) {
+    ALOGD("%s {%f, %f, %f", s, f[0], f[3], f[6]);
+    ALOGD("%s  %f, %f, %f", s, f[1], f[4], f[7]);
+    ALOGD("%s  %f, %f, %f}",s, f[2], f[5], f[8]);
+}
+static void SC_debugFM2v2(const char *s, const float *f) {
+    ALOGD("%s {%f, %f", s, f[0], f[2]);
+    ALOGD("%s  %f, %f}",s, f[1], f[3]);
+}
+static void SC_debugI8(const char *s, char c) {
+    ALOGD("%s %hhd  0x%hhx", s, c, (unsigned char)c);
+}
+static void SC_debugC2(const char *s, char2 c) {
+    ALOGD("%s {%hhd, %hhd}  0x%hhx 0x%hhx", s, c.x, c.y, (unsigned char)c.x, (unsigned char)c.y);
+}
+static void SC_debugC3(const char *s, char3 c) {
+    ALOGD("%s {%hhd, %hhd, %hhd}  0x%hhx 0x%hhx 0x%hhx", s, c.x, c.y, c.z, (unsigned char)c.x, (unsigned char)c.y, (unsigned char)c.z);
+}
+static void SC_debugC4(const char *s, char4 c) {
+    ALOGD("%s {%hhd, %hhd, %hhd, %hhd}  0x%hhx 0x%hhx 0x%hhx 0x%hhx", s, c.x, c.y, c.z, c.w, (unsigned char)c.x, (unsigned char)c.y, (unsigned char)c.z, (unsigned char)c.w);
+}
+static void SC_debugU8(const char *s, unsigned char c) {
+    ALOGD("%s %hhu  0x%hhx", s, c, c);
+}
+static void SC_debugUC2(const char *s, uchar2 c) {
+    ALOGD("%s {%hhu, %hhu}  0x%hhx 0x%hhx", s, c.x, c.y, c.x, c.y);
+}
+static void SC_debugUC3(const char *s, uchar3 c) {
+    ALOGD("%s {%hhu, %hhu, %hhu}  0x%hhx 0x%hhx 0x%hhx", s, c.x, c.y, c.z, c.x, c.y, c.z);
+}
+static void SC_debugUC4(const char *s, uchar4 c) {
+    ALOGD("%s {%hhu, %hhu, %hhu, %hhu}  0x%hhx 0x%hhx 0x%hhx 0x%hhx", s, c.x, c.y, c.z, c.w, c.x, c.y, c.z, c.w);
+}
+static void SC_debugI16(const char *s, short c) {
+    ALOGD("%s %hd  0x%hx", s, c, c);
+}
+static void SC_debugS2(const char *s, short2 c) {
+    ALOGD("%s {%hd, %hd}  0x%hx 0x%hx", s, c.x, c.y, c.x, c.y);
+}
+static void SC_debugS3(const char *s, short3 c) {
+    ALOGD("%s {%hd, %hd, %hd}  0x%hx 0x%hx 0x%hx", s, c.x, c.y, c.z, c.x, c.y, c.z);
+}
+static void SC_debugS4(const char *s, short4 c) {
+    ALOGD("%s {%hd, %hd, %hd, %hd}  0x%hx 0x%hx 0x%hx 0x%hx", s, c.x, c.y, c.z, c.w, c.x, c.y, c.z, c.w);
+}
+static void SC_debugU16(const char *s, unsigned short c) {
+    ALOGD("%s %hu  0x%hx", s, c, c);
+}
+static void SC_debugUS2(const char *s, ushort2 c) {
+    ALOGD("%s {%hu, %hu}  0x%hx 0x%hx", s, c.x, c.y, c.x, c.y);
+}
+static void SC_debugUS3(const char *s, ushort3 c) {
+    ALOGD("%s {%hu, %hu, %hu}  0x%hx 0x%hx 0x%hx", s, c.x, c.y, c.z, c.x, c.y, c.z);
+}
+static void SC_debugUS4(const char *s, ushort4 c) {
+    ALOGD("%s {%hu, %hu, %hu, %hu}  0x%hx 0x%hx 0x%hx 0x%hx", s, c.x, c.y, c.z, c.w, c.x, c.y, c.z, c.w);
+}
+static void SC_debugI32(const char *s, int32_t i) {
+    ALOGD("%s %d  0x%x", s, i, i);
+}
+static void SC_debugI2(const char *s, int2 i) {
+    ALOGD("%s {%d, %d}  0x%x 0x%x", s, i.x, i.y, i.x, i.y);
+}
+static void SC_debugI3(const char *s, int3 i) {
+    ALOGD("%s {%d, %d, %d}  0x%x 0x%x 0x%x", s, i.x, i.y, i.z, i.x, i.y, i.z);
+}
+static void SC_debugI4(const char *s, int4 i) {
+    ALOGD("%s {%d, %d, %d, %d}  0x%x 0x%x 0x%x 0x%x", s, i.x, i.y, i.z, i.w, i.x, i.y, i.z, i.w);
+}
+static void SC_debugU32(const char *s, uint32_t i) {
+    ALOGD("%s %u  0x%x", s, i, i);
+}
+static void SC_debugUI2(const char *s, uint2 i) {
+    ALOGD("%s {%u, %u}  0x%x 0x%x", s, i.x, i.y, i.x, i.y);
+}
+static void SC_debugUI3(const char *s, uint3 i) {
+    ALOGD("%s {%u, %u, %u}  0x%x 0x%x 0x%x", s, i.x, i.y, i.z, i.x, i.y, i.z);
+}
+static void SC_debugUI4(const char *s, uint4 i) {
+    ALOGD("%s {%u, %u, %u, %u}  0x%x 0x%x 0x%x 0x%x", s, i.x, i.y, i.z, i.w, i.x, i.y, i.z, i.w);
+}
+static void SC_debugLL64(const char *s, long long ll) {
+    ALOGD("%s %lld  0x%llx", s, ll, ll);
+}
+static void SC_debugL2(const char *s, long2 ll) {
+    ALOGD("%s {%lld, %lld}  0x%llx 0x%llx", s, ll.x, ll.y, ll.x, ll.y);
+}
+static void SC_debugL3(const char *s, long3 ll) {
+    ALOGD("%s {%lld, %lld, %lld}  0x%llx 0x%llx 0x%llx", s, ll.x, ll.y, ll.z, ll.x, ll.y, ll.z);
+}
+static void SC_debugL4(const char *s, long4 ll) {
+    ALOGD("%s {%lld, %lld, %lld, %lld}  0x%llx 0x%llx 0x%llx 0x%llx", s, ll.x, ll.y, ll.z, ll.w, ll.x, ll.y, ll.z, ll.w);
+}
+static void SC_debugULL64(const char *s, unsigned long long ll) {
+    ALOGD("%s %llu  0x%llx", s, ll, ll);
+}
+static void SC_debugUL2(const char *s, ulong2 ll) {
+    ALOGD("%s {%llu, %llu}  0x%llx 0x%llx", s, ll.x, ll.y, ll.x, ll.y);
+}
+static void SC_debugUL3(const char *s, ulong3 ll) {
+    ALOGD("%s {%llu, %llu, %llu}  0x%llx 0x%llx 0x%llx", s, ll.x, ll.y, ll.z, ll.x, ll.y, ll.z);
+}
+static void SC_debugUL4(const char *s, ulong4 ll) {
+    ALOGD("%s {%llu, %llu, %llu, %llu}  0x%llx 0x%llx 0x%llx 0x%llx", s, ll.x, ll.y, ll.z, ll.w, ll.x, ll.y, ll.z, ll.w);
+}
+static void SC_debugP(const char *s, const void *p) {
+    ALOGD("%s %p", s, p);
+}
+
+// TODO: allocation ops, messaging, time
+
+void rsDebug(const char *s, float f) {
+    SC_debugF(s, f);
+}
+
+void rsDebug(const char *s, float f1, float f2) {
+    SC_debugFv2(s, f1, f2);
+}
+
+void rsDebug(const char *s, float f1, float f2, float f3) {
+    SC_debugFv3(s, f1, f2, f3);
+}
+
+void rsDebug(const char *s, float f1, float f2, float f3, float f4) {
+    SC_debugFv4(s, f1, f2, f3, f4);
+}
+
+void rsDebug(const char *s, float2 f) {
+    SC_debugF2(s, f);
+}
+
+void rsDebug(const char *s, float3 f) {
+    SC_debugF3(s, f);
+}
+
+void rsDebug(const char *s, float4 f) {
+    SC_debugF4(s, f);
+}
+
+void rsDebug(const char *s, double d) {
+    SC_debugD(s, d);
+}
+
+void rsDebug(const char *s, rs_matrix4x4 *m) {
+    SC_debugFM4v4(s, (float *) m);
+}
+
+void rsDebug(const char *s, rs_matrix3x3 *m) {
+    SC_debugFM4v4(s, (float *) m);
+}
+
+void rsDebug(const char *s, rs_matrix2x2 *m) {
+    SC_debugFM4v4(s, (float *) m);
+}
+
+void rsDebug(const char *s, char c) {
+    SC_debugI8(s, c);
+}
+
+void rsDebug(const char *s, char2 c) {
+    SC_debugC2(s, c);
+}
+
+void rsDebug(const char *s, char3 c) {
+    SC_debugC3(s, c);
+}
+
+void rsDebug(const char *s, char4 c) {
+    SC_debugC4(s, c);
+}
+
+void rsDebug(const char *s, unsigned char c) {
+    SC_debugU8(s, c);
+}
+
+void rsDebug(const char *s, uchar2 c) {
+    SC_debugUC2(s, c);
+}
+
+void rsDebug(const char *s, uchar3 c) {
+    SC_debugUC3(s, c);
+}
+
+void rsDebug(const char *s, uchar4 c) {
+    SC_debugUC4(s, c);
+}
+
+void rsDebug(const char *s, short c) {
+    SC_debugI16(s, c);
+}
+
+void rsDebug(const char *s, short2 c) {
+    SC_debugS2(s, c);
+}
+
+void rsDebug(const char *s, short3 c) {
+    SC_debugS3(s, c);
+}
+
+void rsDebug(const char *s, short4 c) {
+    SC_debugS4(s, c);
+}
+
+void rsDebug(const char *s, unsigned short c) {
+    SC_debugU16(s, c);
+}
+
+void rsDebug(const char *s, ushort2 c) {
+    SC_debugUS2(s, c);
+}
+
+void rsDebug(const char *s, ushort3 c) {
+    SC_debugUS3(s, c);
+}
+
+void rsDebug(const char *s, ushort4 c) {
+    SC_debugUS4(s, c);
+}
+
+void rsDebug(const char *s, int c) {
+    SC_debugI32(s, c);
+}
+
+void rsDebug(const char *s, int2 c) {
+    SC_debugI2(s, c);
+}
+
+void rsDebug(const char *s, int3 c) {
+    SC_debugI3(s, c);
+}
+
+void rsDebug(const char *s, int4 c) {
+    SC_debugI4(s, c);
+}
+
+void rsDebug(const char *s, unsigned int c) {
+    SC_debugU32(s, c);
+}
+
+void rsDebug(const char *s, uint2 c) {
+    SC_debugUI2(s, c);
+}
+
+void rsDebug(const char *s, uint3 c) {
+    SC_debugUI3(s, c);
+}
+
+void rsDebug(const char *s, uint4 c) {
+    SC_debugUI4(s, c);
+}
+
+void rsDebug(const char *s, long c) {
+    SC_debugLL64(s, c);
+}
+
+void rsDebug(const char *s, long long c) {
+    SC_debugLL64(s, c);
+}
+
+void rsDebug(const char *s, long2 c) {
+    SC_debugL2(s, c);
+}
+
+void rsDebug(const char *s, long3 c) {
+    SC_debugL3(s, c);
+}
+
+void rsDebug(const char *s, long4 c) {
+    SC_debugL4(s, c);
+}
+
+void rsDebug(const char *s, unsigned long c) {
+    SC_debugULL64(s, c);
+}
+
+void rsDebug(const char *s, unsigned long long c) {
+    SC_debugULL64(s, c);
+}
+
+void rsDebug(const char *s, ulong2 c) {
+    SC_debugUL2(s, c);
+}
+
+void rsDebug(const char *s, ulong3 c) {
+    SC_debugUL3(s, c);
+}
+
+void rsDebug(const char *s, ulong4 c) {
+    SC_debugUL4(s, c);
+}
+
+void rsDebug(const char *s, const void *p) {
+    SC_debugP(s, p);
+}
+#endif // RS_COMPATIBILITY_LIB
 
 extern const RsdCpuReference::CpuSymbol * rsdLookupRuntimeStub(Context * pContext, char const* name) {
     ScriptC *s = (ScriptC *)pContext;
diff --git a/driver/rsdShaderCache.h b/driver/rsdShaderCache.h
index 88aa32d..1ac1aa1 100644
--- a/driver/rsdShaderCache.h
+++ b/driver/rsdShaderCache.h
@@ -25,8 +25,12 @@
 }
 }
 
+#ifndef RS_SERVER
 #include <utils/String8.h>
 #include <utils/Vector.h>
+#else
+#include "rsUtils.h"
+#endif
 class RsdShader;
 
 // ---------------------------------------------------------------------------
diff --git a/driver/rsdVertexArray.h b/driver/rsdVertexArray.h
index 3e807a3..9c655df 100644
--- a/driver/rsdVertexArray.h
+++ b/driver/rsdVertexArray.h
@@ -17,6 +17,8 @@
 #ifndef ANDROID_RSD_VERTEX_ARRAY_H
 #define ANDROID_RSD_VERTEX_ARRAY_H
 
+#include "rsUtils.h"
+
 namespace android {
 namespace renderscript {
 
@@ -25,8 +27,6 @@
 }
 }
 
-#include <utils/String8.h>
-
 // An element is a group of Components that occupies one cell in a structure.
 class RsdVertexArray {
 public: