Add 64bit large object support

Add HAL hooks for filling in LO fields.

Change-Id: Ib9bdee714a062de519d2a9708c1016404a1b11a4

Conflicts:
	driver/rsdBcc.cpp
	driver/rsdCore.cpp
	rsAllocation.h
	rs_hal.h
diff --git a/driver/rsdAllocation.cpp b/driver/rsdAllocation.cpp
index 05951b9..248e7b6 100644
--- a/driver/rsdAllocation.cpp
+++ b/driver/rsdAllocation.cpp
@@ -1196,3 +1196,22 @@
     return 0;
 }
 
+void rsdAllocationUpdateCachedObject(const Context *rsc,
+                                     const Allocation *alloc,
+                                     rs_allocation *obj)
+{
+    obj->p = alloc;
+#ifdef __LP64__
+    if (alloc != NULL) {
+        obj->r = alloc->mHal.drvState.lod[0].mallocPtr;
+        obj->v1 = alloc->mHal.drv;
+        obj->v2 = (void *)alloc->mHal.drvState.lod[0].stride;
+    } else {
+        obj->r = NULL;
+        obj->v1 = NULL;
+        obj->v2 = NULL;
+    }
+#endif
+}
+
+
diff --git a/driver/rsdAllocation.h b/driver/rsdAllocation.h
index ff47f03..510b497 100644
--- a/driver/rsdAllocation.h
+++ b/driver/rsdAllocation.h
@@ -168,6 +168,9 @@
 void rsdAllocationGenerateMipmaps(const android::renderscript::Context *rsc,
                                   const android::renderscript::Allocation *alloc);
 
+void rsdAllocationUpdateCachedObject(const android::renderscript::Context *rsc,
+                                     const android::renderscript::Allocation *alloc,
+                                     android::renderscript::rs_allocation *obj);
 
 
 #endif
diff --git a/driver/rsdBcc.cpp b/driver/rsdBcc.cpp
index b62709e..27029cf 100644
--- a/driver/rsdBcc.cpp
+++ b/driver/rsdBcc.cpp
@@ -159,3 +159,19 @@
     RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)sc->mHal.drv;
     return cs->getAllocationForPointer(ptr);
 }
+
+void rsdScriptUpdateCachedObject(const Context *rsc,
+                                 const Script *script,
+                                 rs_script *obj)
+{
+    obj->p = script;
+#ifdef __LP64__
+    obj->r = NULL;
+    if (script != NULL) {
+        obj->v1 = script->mHal.drv;
+    } else {
+        obj->v1 = NULL;
+    }
+    obj->v2 = NULL;
+#endif
+}
diff --git a/driver/rsdBcc.h b/driver/rsdBcc.h
index 3932aeb..d51fb80 100644
--- a/driver/rsdBcc.h
+++ b/driver/rsdBcc.h
@@ -98,5 +98,10 @@
                         const android::renderscript::Script *script,
                         const void *);
 
+void rsdScriptUpdateCachedObject(const android::renderscript::Context *rsc,
+                                 const android::renderscript::Script *script,
+                                 android::renderscript::rs_script *obj);
+
+
 
 #endif
diff --git a/driver/rsdCore.cpp b/driver/rsdCore.cpp
index 065597a..37c9755 100644
--- a/driver/rsdCore.cpp
+++ b/driver/rsdCore.cpp
@@ -19,6 +19,8 @@
 #include "rsdCore.h"
 #include "rsdAllocation.h"
 #include "rsdBcc.h"
+#include "rsdElement.h"
+#include "rsdType.h"
 #ifndef RS_COMPATIBILITY_LIB
     #include "MemChunk.h"
     #include "rsdGL.h"
@@ -80,7 +82,8 @@
         rsdScriptSetGlobalBind,
         rsdScriptSetGlobalObj,
         rsdScriptDestroy,
-        rsdScriptInvokeForEachMulti
+        rsdScriptInvokeForEachMulti,
+        rsdScriptUpdateCachedObject
     },
 
     {
@@ -106,7 +109,8 @@
         rsdAllocationData3D_alloc,
         rsdAllocationElementData1D,
         rsdAllocationElementData2D,
-        rsdAllocationGenerateMipmaps
+        rsdAllocationGenerateMipmaps,
+        rsdAllocationUpdateCachedObject
     },
 
 
@@ -149,7 +153,8 @@
 
     {
         rsdSamplerInit,
-        rsdSamplerDestroy
+        rsdSamplerDestroy,
+        rsdSamplerUpdateCachedObject
     },
 
     {
@@ -163,7 +168,20 @@
         rsdScriptGroupSetInput,
         rsdScriptGroupSetOutput,
         rsdScriptGroupExecute,
-        rsdScriptGroupDestroy
+        rsdScriptGroupDestroy,
+        NULL
+    },
+
+    {
+        rsdTypeInit,
+        rsdTypeDestroy,
+        rsdTypeUpdateCachedObject
+    },
+
+    {
+        rsdElementInit,
+        rsdElementDestroy,
+        rsdElementUpdateCachedObject
     },
 
     NULL // finish
diff --git a/driver/rsdElement.cpp b/driver/rsdElement.cpp
new file mode 100644
index 0000000..c0413e4
--- /dev/null
+++ b/driver/rsdElement.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "rsdCore.h"
+#include "rsElement.h"
+
+using namespace android;
+using namespace android::renderscript;
+
+
+bool rsdElementInit(const Context *, const Element *e) {
+    return true;
+}
+
+void rsdElementDestroy(const Context *rsc, const Element *e) {
+}
+
+void rsdElementUpdateCachedObject(const Context *rsc,
+                                  const Element *element,
+                                  rs_element *obj)
+{
+    obj->p = element;
+#ifdef __LP64__
+    obj->r = NULL;
+    obj->v1 = NULL;
+    obj->v2 = NULL;
+#endif
+}
+
diff --git a/driver/rsdElement.h b/driver/rsdElement.h
new file mode 100644
index 0000000..312d70b
--- /dev/null
+++ b/driver/rsdElement.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef RSD_ELEMENT_H
+#define RSD_ELEMENT_H
+
+#include <rs_hal.h>
+
+
+bool rsdElementInit(const android::renderscript::Context *rsc,
+                    const android::renderscript::Element *);
+
+void rsdElementDestroy(const android::renderscript::Context *rsc,
+                       const android::renderscript::Element *);
+
+void rsdElementUpdateCachedObject(const android::renderscript::Context *rsc,
+                                  const android::renderscript::Element *,
+                                  android::renderscript::rs_element *obj);
+
+#endif // RSD_ELEMENT_H
diff --git a/driver/rsdRuntimeStubs.cpp b/driver/rsdRuntimeStubs.cpp
index d1f29f0..8f1020b 100644
--- a/driver/rsdRuntimeStubs.cpp
+++ b/driver/rsdRuntimeStubs.cpp
@@ -429,10 +429,19 @@
 //
 //////////////////////////////////////////////////////////////////////////////
 
-static void SC_SetObject(ObjectBase **dst, ObjectBase * src) {
+#ifndef RS_COMPATIBILITY_LIB
+static void SC_SetObject(ObjectBase **dst, rs_allocation src) {
+    //    ALOGE("SC_SetObject: dst = %p, src = %p", dst, src.p);
+    //    ALOGE("SC_SetObject: dst[0] = %p", dst[0]);
+    Context *rsc = RsdCpuReference::getTlsContext();
+    rsrSetObject(rsc, dst, (ObjectBase*)src.p);
+}
+#else
+static void SC_SetObject(ObjectBase **dst, ObjectBase *src) {
     Context *rsc = RsdCpuReference::getTlsContext();
     rsrSetObject(rsc, dst, src);
 }
+#endif
 
 static void SC_ClearObject(ObjectBase **dst) {
     Context *rsc = RsdCpuReference::getTlsContext();
@@ -1236,41 +1245,41 @@
         return SC_SetObject((ObjectBase**) dst, (ObjectBase*) src.p); \
     }
 
-IS_CLEAR_SET_OBJ(rs_element)
-IS_CLEAR_SET_OBJ(rs_type)
-IS_CLEAR_SET_OBJ(rs_allocation)
-IS_CLEAR_SET_OBJ(rs_sampler)
-IS_CLEAR_SET_OBJ(rs_script)
+IS_CLEAR_SET_OBJ(android::renderscript::rs_element)
+IS_CLEAR_SET_OBJ(android::renderscript::rs_type)
+IS_CLEAR_SET_OBJ(android::renderscript::rs_allocation)
+IS_CLEAR_SET_OBJ(android::renderscript::rs_sampler)
+IS_CLEAR_SET_OBJ(android::renderscript::rs_script)
 #undef IS_CLEAR_SET_OBJ
 
 const Allocation * rsGetAllocation(const void *ptr) {
     return SC_GetAllocation(ptr);
 }
 
-void __attribute__((overloadable)) rsAllocationIoSend(rs_allocation a) {
+void __attribute__((overloadable)) rsAllocationIoSend(::rs_allocation a) {
     SC_AllocationIoSend((Allocation *)a.p);
 }
 
-void __attribute__((overloadable)) rsAllocationIoReceive(rs_allocation a) {
+void __attribute__((overloadable)) rsAllocationIoReceive(::rs_allocation a) {
     SC_AllocationIoReceive((Allocation *)a.p);
 }
 
 
 void __attribute__((overloadable)) rsAllocationCopy1DRange(
-        rs_allocation dstAlloc,
+        ::rs_allocation dstAlloc,
         uint32_t dstOff, uint32_t dstMip, uint32_t count,
-        rs_allocation srcAlloc,
+        ::rs_allocation srcAlloc,
         uint32_t srcOff, uint32_t srcMip) {
     SC_AllocationCopy1DRange((Allocation *)dstAlloc.p, dstOff, dstMip, count,
                              (Allocation *)srcAlloc.p, srcOff, srcMip);
 }
 
 void __attribute__((overloadable)) rsAllocationCopy2DRange(
-        rs_allocation dstAlloc,
+        ::rs_allocation dstAlloc,
         uint32_t dstXoff, uint32_t dstYoff,
         uint32_t dstMip, rs_allocation_cubemap_face dstFace,
         uint32_t width, uint32_t height,
-        rs_allocation srcAlloc,
+        ::rs_allocation srcAlloc,
         uint32_t srcXoff, uint32_t srcYoff,
         uint32_t srcMip, rs_allocation_cubemap_face srcFace) {
     SC_AllocationCopy2DRange((Allocation *)dstAlloc.p, dstXoff, dstYoff,
@@ -1279,31 +1288,31 @@
                              srcMip, srcFace);
 }
 
-void __attribute__((overloadable)) rsForEach(rs_script script,
-                                             rs_allocation in,
-                                             rs_allocation out,
+void __attribute__((overloadable)) rsForEach(::rs_script script,
+                                             ::rs_allocation in,
+                                             ::rs_allocation out,
                                              const void *usr,
                                              const rs_script_call *call) {
     return SC_ForEach_SAAUS((Script *)script.p, (Allocation*)in.p, (Allocation*)out.p, usr, (RsScriptCall*)call);
 }
 
-void __attribute__((overloadable)) rsForEach(rs_script script,
-                                             rs_allocation in,
-                                             rs_allocation out) {
+void __attribute__((overloadable)) rsForEach(::rs_script script,
+                                             ::rs_allocation in,
+                                             ::rs_allocation out) {
     return SC_ForEach_SAA((Script *)script.p, (Allocation*)in.p, (Allocation*)out.p);
 }
 
-void __attribute__((overloadable)) rsForEach(rs_script script,
-                                             rs_allocation in,
-                                             rs_allocation out,
+void __attribute__((overloadable)) rsForEach(::rs_script script,
+                                             ::rs_allocation in,
+                                             ::rs_allocation out,
                                              const void *usr,
                                              uint32_t usrLen) {
     return SC_ForEach_SAAUL((Script *)script.p, (Allocation*)in.p, (Allocation*)out.p, usr, usrLen);
 }
 
-void __attribute__((overloadable)) rsForEach(rs_script script,
-                                             rs_allocation in,
-                                             rs_allocation out,
+void __attribute__((overloadable)) rsForEach(::rs_script script,
+                                             ::rs_allocation in,
+                                             ::rs_allocation out,
                                              const void *usr,
                                              uint32_t usrLen,
                                              const rs_script_call *call) {
diff --git a/driver/rsdSampler.cpp b/driver/rsdSampler.cpp
index 095fca1..1a72fd4 100644
--- a/driver/rsdSampler.cpp
+++ b/driver/rsdSampler.cpp
@@ -40,3 +40,20 @@
 void rsdSamplerDestroy(const android::renderscript::Context *rsc,
                        const android::renderscript::Sampler *s) {
 }
+
+void rsdSamplerUpdateCachedObject(const Context *rsc,
+                                  const Sampler *alloc,
+                                  rs_sampler *obj)
+{
+    obj->p = alloc;
+#ifdef __LP64__
+    obj->r = NULL;
+    if (alloc != NULL) {
+        obj->v1 = alloc->mHal.drv;
+    } else {
+        obj->v1 = NULL;
+    }
+    obj->v2 = NULL;
+#endif
+}
+
diff --git a/driver/rsdSampler.h b/driver/rsdSampler.h
index 3a64e9e..378e2ca 100644
--- a/driver/rsdSampler.h
+++ b/driver/rsdSampler.h
@@ -26,5 +26,8 @@
 void rsdSamplerDestroy(const android::renderscript::Context *rsc,
                        const android::renderscript::Sampler *);
 
+void rsdSamplerUpdateCachedObject(const android::renderscript::Context *rsc,
+                                  const android::renderscript::Sampler *,
+                                  android::renderscript::rs_sampler *obj);
 
 #endif // RSD_SAMPLER_H
diff --git a/driver/rsdScriptGroup.cpp b/driver/rsdScriptGroup.cpp
index ef802a2..6162c11 100644
--- a/driver/rsdScriptGroup.cpp
+++ b/driver/rsdScriptGroup.cpp
@@ -53,4 +53,20 @@
     delete sgi;
 }
 
+void rsdScriptGroupUpdateCachedObject(const Context *rsc,
+                                      const ScriptGroup *sg,
+                                      rs_script_group *obj)
+{
+    obj->p = sg;
+#ifdef __LP64__
+    obj->r = NULL;
+    if (sg != NULL) {
+        obj->v1 = sg->mHal.drv;
+    } else {
+        obj->v1 = NULL;
+    }
+    obj->v2 = NULL;
+#endif
+}
+
 
diff --git a/driver/rsdScriptGroup.h b/driver/rsdScriptGroup.h
index ee8cd69..db44e23 100644
--- a/driver/rsdScriptGroup.h
+++ b/driver/rsdScriptGroup.h
@@ -33,6 +33,8 @@
                            const android::renderscript::ScriptGroup *sg);
 void rsdScriptGroupDestroy(const android::renderscript::Context *rsc,
                            const android::renderscript::ScriptGroup *sg);
-
+void rsdScriptGroupUpdateCachedObject(const android::renderscript::Context *rsc,
+                                      const android::renderscript::ScriptGroup *sg,
+                                      android::renderscript::rs_script_group *obj);
 
 #endif // RSD_SCRIPT_GROUP_H
diff --git a/driver/rsdType.cpp b/driver/rsdType.cpp
new file mode 100644
index 0000000..fa7b46c
--- /dev/null
+++ b/driver/rsdType.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "rsdCore.h"
+#include "rsdSampler.h"
+
+#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;
+
+
+bool rsdTypeInit(const Context *, const Type *t) {
+    return true;
+}
+
+void rsdTypeDestroy(const Context *rsc, const Type *t) {
+}
+
+void rsdTypeUpdateCachedObject(const Context *rsc,
+                               const Type *t,
+                               rs_type *obj)
+{
+    obj->p = t;
+#ifdef __LP64__
+    obj->r = NULL;
+    obj->v1 = NULL;
+    obj->v2 = NULL;
+#endif
+}
+
diff --git a/driver/rsdType.h b/driver/rsdType.h
new file mode 100644
index 0000000..d5ac700
--- /dev/null
+++ b/driver/rsdType.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef RSD_TYPE_H
+#define RSD_TYPE_H
+
+#include <rs_hal.h>
+
+
+bool rsdTypeInit(const android::renderscript::Context *rsc,
+                 const android::renderscript::Type *);
+
+void rsdTypeDestroy(const android::renderscript::Context *rsc,
+                    const android::renderscript::Type *);
+
+void rsdTypeUpdateCachedObject(const android::renderscript::Context *rsc,
+                               const android::renderscript::Type *,
+                               android::renderscript::rs_type *obj);
+
+#endif // RSD_TYPE_H
diff --git a/driver/runtime/rs_allocation.c b/driver/runtime/rs_allocation.c
index bf37713..a5368cd 100644
--- a/driver/runtime/rs_allocation.c
+++ b/driver/runtime/rs_allocation.c
@@ -104,8 +104,12 @@
 rsOffset(rs_allocation a, uint32_t sizeOf, uint32_t x, uint32_t y,
          uint32_t z) {
     Allocation_t *alloc = (Allocation_t *)a.p;
+#ifdef __LP64__
+    uint8_t *p = (uint8_t *)a.r;
+#else
     uint8_t *p = (uint8_t *)alloc->mHal.drvState.lod[0].mallocPtr;
-    const uint32_t stride = alloc->mHal.drvState.lod[0].stride;
+#endif
+    const uint32_t stride = (uint32_t)alloc->mHal.drvState.lod[0].stride;
     const uint32_t dimY = alloc->mHal.drvState.lod[0].dimY;
     uint8_t *dp = &p[(sizeOf * x) + (y * stride) +
                      (z * stride * dimY)];
@@ -115,7 +119,11 @@
 uint8_t*
 rsOffsetNs(rs_allocation a, uint32_t x, uint32_t y, uint32_t z) {
     Allocation_t *alloc = (Allocation_t *)a.p;
+#ifdef __LP64__
+    uint8_t *p = (uint8_t *)a.r;
+#else
     uint8_t *p = (uint8_t *)alloc->mHal.drvState.lod[0].mallocPtr;
+#endif
     const uint32_t stride = alloc->mHal.drvState.lod[0].stride;
     const uint32_t dimY = alloc->mHal.drvState.lod[0].dimY;
     const uint32_t sizeOf = alloc->mHal.state.elementSizeBytes;;