Add 3D allocation support.

bug 10427951

Change-Id: I95f2d4ede5120831a5b547ecb6837dbd20b99c8c
diff --git a/cpp/Allocation.cpp b/cpp/Allocation.cpp
index 9727a6e..c8e7182 100644
--- a/cpp/Allocation.cpp
+++ b/cpp/Allocation.cpp
@@ -283,6 +283,35 @@
     copy2DStridedTo(0, 0, mCurrentDimX, mCurrentDimY, data, stride);
 }
 
+void Allocation::validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
+                                 uint32_t h, uint32_t d) {
+    if (mAdaptedAllocation != NULL) {
+
+    } else {
+        if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY) || ((zoff + d) > mCurrentDimZ)) {
+            mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Updated region larger than allocation.");
+        }
+    }
+}
+
+void Allocation::copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
+                                 uint32_t h, uint32_t d, const void* data) {
+    validate3DRange(xoff, yoff, zoff, w, h, d);
+    tryDispatch(mRS, RS::dispatch->Allocation3DData(mRS->getContext(), getIDSafe(), xoff, yoff, zoff,
+                                                    mSelectedLOD, w, h, d, data,
+                                                    w * h * d * mType->getElement()->getSizeBytes(),
+                                                    w * mType->getElement()->getSizeBytes()));
+}
+
+void Allocation::copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, uint32_t h, uint32_t d,
+                                 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff) {
+    validate3DRange(xoff, yoff, zoff, dataXoff, dataYoff, dataZoff);
+    tryDispatch(mRS, RS::dispatch->AllocationCopy3DRange(mRS->getContext(), getIDSafe(), xoff, yoff, zoff,
+                                                         mSelectedLOD, w, h, d, data->getIDSafe(),
+                                                         dataXoff, dataYoff, dataZoff, data->mSelectedLOD));
+}
+
+
 sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type,
                                     RsAllocationMipmapControl mips, uint32_t usage) {
     void *id = 0;
diff --git a/cpp/rsCppStructs.h b/cpp/rsCppStructs.h
index 913fd91..66ea50a 100644
--- a/cpp/rsCppStructs.h
+++ b/cpp/rsCppStructs.h
@@ -244,6 +244,8 @@
     virtual void updateFromNative();
 
     void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
+    void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff,
+                         uint32_t w, uint32_t h, uint32_t d);
 
 public:
     sp<const Type> getType() const {
@@ -281,8 +283,13 @@
                          void *data, size_t stride);
     void copy2DStridedTo(void *data, size_t stride);
 
-    void resize(int dimX);
-    void resize(int dimX, int dimY);
+    void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
+                         uint32_t h, uint32_t d, const void* data);
+
+    void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff,
+                         uint32_t w, uint32_t h, uint32_t d,
+                         sp<const Allocation> data,
+                         uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff);
 
     static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
                                    RsAllocationMipmapControl mips, uint32_t usage);