Move adapter2D to a derived class from Allocation.

Change-Id: I7e9d8b0028ba95956476f253da38dbe64564d0da
diff --git a/RenderScript.h b/RenderScript.h
index 3ad453f..87758e5 100644
--- a/RenderScript.h
+++ b/RenderScript.h
@@ -111,6 +111,15 @@
     RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE = 2
 };
 
+enum RsAllocationCubemapFace {
+    RS_ALLOCATION_CUBMAP_FACE_POSITVE_X = 0,
+    RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_X = 1,
+    RS_ALLOCATION_CUBMAP_FACE_POSITVE_Y = 2,
+    RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_Y = 3,
+    RS_ALLOCATION_CUBMAP_FACE_POSITVE_Z = 4,
+    RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_Z = 5
+};
+
 enum RsDataType {
     RS_TYPE_NONE,
     RS_TYPE_FLOAT_16,
diff --git a/rs.spec b/rs.spec
index a5810d4..3483a5d 100644
--- a/rs.spec
+++ b/rs.spec
@@ -89,28 +89,11 @@
 	param size_t dataLen
 	}
 
-AllocationUploadToTexture {
-	param RsAllocation alloc
-	param bool genMipMaps
-	param uint32_t baseMipLevel
-	}
 
-AllocationUploadToBufferObject {
-	param RsAllocation alloc
-	}
-
-
-AllocationData {
-	param RsAllocation va
-	param const void * data
-	param uint32_t bytes
-	handcodeApi
-	togglePlay
-	}
-
-Allocation1DSubData {
+Allocation1DData {
 	param RsAllocation va
 	param uint32_t xoff
+	param uint32_t lod
 	param uint32_t count
 	param const void *data
 	param uint32_t bytes
@@ -118,9 +101,10 @@
 	togglePlay
 	}
 
-Allocation1DSubElementData {
+Allocation1DElementData {
 	param RsAllocation va
 	param uint32_t x
+	param uint32_t lod
 	param const void *data
 	param uint32_t comp_offset
 	param uint32_t bytes
@@ -128,20 +112,24 @@
 	togglePlay
 	}
 
-Allocation2DSubData {
+Allocation2DData {
 	param RsAllocation va
 	param uint32_t xoff
 	param uint32_t yoff
+	param uint32_t lod
+	param RsAllocationCubemapFace face
 	param uint32_t w
 	param uint32_t h
 	param const void *data
 	param uint32_t bytes
 	}
 
-Allocation2DSubElementData {
+Allocation2DElementData {
 	param RsAllocation va
 	param uint32_t x
 	param uint32_t y
+	param uint32_t lod
+	param RsAllocationCubemapFace face
 	param const void *data
 	param uint32_t element_offset
 	param uint32_t bytes
@@ -157,61 +145,6 @@
 	param RsAllocationUsageType src
 }
 
-Adapter1DCreate {
-	ret RsAdapter1D
-	}
-
-Adapter1DBindAllocation {
-	param RsAdapter1D adapt
-	param RsAllocation alloc
-	}
-
-Adapter1DSetConstraint {
-	param RsAdapter1D adapter
-	param RsDimension dim
-	param uint32_t value
-	}
-
-Adapter1DData {
-	param RsAdapter1D adapter
-	param const void * data
-	}
-
-Adapter1DSubData {
-	param RsAdapter1D adapter
-	param uint32_t xoff
-	param uint32_t count
-	param const void *data
-	}
-
-Adapter2DCreate {
-	ret RsAdapter2D
-	}
-
-Adapter2DBindAllocation {
-	param RsAdapter2D adapt
-	param RsAllocation alloc
-	}
-
-Adapter2DSetConstraint {
-	param RsAdapter2D adapter
-	param RsDimension dim
-	param uint32_t value
-	}
-
-Adapter2DData {
-	param RsAdapter2D adapter
-	param const void *data
-	}
-
-Adapter2DSubData {
-	param RsAdapter2D adapter
-	param uint32_t xoff
-	param uint32_t yoff
-	param uint32_t w
-	param uint32_t h
-	param const void *data
-	}
 
 AllocationResize1D {
 	param RsAllocation va
diff --git a/rsAllocation.cpp b/rsAllocation.cpp
index ec1f684..3608e43 100644
--- a/rsAllocation.cpp
+++ b/rsAllocation.cpp
@@ -307,29 +307,12 @@
     }
 }
 
-
-void Allocation::data(Context *rsc, const void *data, uint32_t sizeBytes) {
-    uint32_t size = mType->getSizeBytes();
-    if (size != sizeBytes) {
-        LOGE("Allocation::data called with mismatched size expected %i, got %i", size, sizeBytes);
-        return;
-    }
-
-    if (mType->getElement()->getHasReferences()) {
-        incRefs(data, sizeBytes / mType->getElement()->getSizeBytes());
-        decRefs(mPtr, sizeBytes / mType->getElement()->getSizeBytes());
-    }
-
-    memcpy(mPtr, data, size);
-    sendDirty();
-    mUploadDefered = true;
-}
-
 void Allocation::read(void *data) {
     memcpy(data, mPtr, mType->getSizeBytes());
 }
 
-void Allocation::subData(Context *rsc, uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes) {
+void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod,
+                         uint32_t count, const void *data, uint32_t sizeBytes) {
     uint32_t eSize = mType->getElementSizeBytes();
     uint8_t * ptr = static_cast<uint8_t *>(mPtr);
     ptr += eSize * xoff;
@@ -351,7 +334,7 @@
     mUploadDefered = true;
 }
 
-void Allocation::subData(Context *rsc, uint32_t xoff, uint32_t yoff,
+void Allocation::data(Context *rsc, 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 eSize = mType->getElementSizeBytes();
     uint32_t lineSize = eSize * w;
@@ -379,11 +362,11 @@
     mUploadDefered = true;
 }
 
-void Allocation::subData(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff,
+void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, RsAllocationCubemapFace face,
              uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes) {
 }
 
-void Allocation::subElementData(Context *rsc, uint32_t x, const void *data,
+void Allocation::elementData(Context *rsc, uint32_t x, const void *data,
                                 uint32_t cIdx, uint32_t sizeBytes) {
     uint32_t eSize = mType->getElementSizeBytes();
     uint8_t * ptr = static_cast<uint8_t *>(mPtr);
@@ -420,7 +403,7 @@
     mUploadDefered = true;
 }
 
-void Allocation::subElementData(Context *rsc, uint32_t x, uint32_t y,
+void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,
                                 const void *data, uint32_t cIdx, uint32_t sizeBytes) {
     uint32_t eSize = mType->getElementSizeBytes();
     uint8_t * ptr = static_cast<uint8_t *>(mPtr);
@@ -539,8 +522,10 @@
     Allocation *alloc = new Allocation(rsc, type, RS_ALLOCATION_USAGE_SCRIPT);
     alloc->setName(name.string(), name.size());
 
+    uint32_t count = dataSize / type->getElementSizeBytes();
+
     // Read in all of our allocation data
-    alloc->data(rsc, stream->getPtr() + stream->getPos(), dataSize);
+    alloc->data(rsc, 0, 0, count, stream->getPtr() + stream->getPos(), dataSize);
     stream->reset(stream->getPos() + dataSize);
 
     return alloc;
@@ -741,29 +726,28 @@
     memcpy(data, texAlloc->getPtr(), s);
 }
 
-void rsi_AllocationData(Context *rsc, RsAllocation va, const void *data, uint32_t sizeBytes) {
+void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
+                          uint32_t count, const void *data, uint32_t sizeBytes) {
     Allocation *a = static_cast<Allocation *>(va);
-    a->data(rsc, data, sizeBytes);
+    a->data(rsc, xoff, lod, count, data, sizeBytes);
 }
 
-void rsi_Allocation1DSubData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t count, const void *data, uint32_t 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) {
     Allocation *a = static_cast<Allocation *>(va);
-    a->subData(rsc, xoff, count, data, sizeBytes);
+    a->elementData(rsc, x, y, data, eoff, sizeBytes);
 }
 
-void rsi_Allocation2DSubElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, const void *data, uint32_t eoff, uint32_t sizeBytes) {
+void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod,
+                                 const void *data, uint32_t eoff, uint32_t sizeBytes) {
     Allocation *a = static_cast<Allocation *>(va);
-    a->subElementData(rsc, x, y, data, eoff, sizeBytes);
+    a->elementData(rsc, x, data, eoff, sizeBytes);
 }
 
-void rsi_Allocation1DSubElementData(Context *rsc, RsAllocation va, uint32_t x, const void *data, uint32_t eoff, uint32_t 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) {
     Allocation *a = static_cast<Allocation *>(va);
-    a->subElementData(rsc, x, data, eoff, sizeBytes);
-}
-
-void rsi_Allocation2DSubData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes) {
-    Allocation *a = static_cast<Allocation *>(va);
-    a->subData(rsc, xoff, yoff, w, h, data, sizeBytes);
+    a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes);
 }
 
 void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data) {
diff --git a/rsAllocation.h b/rsAllocation.h
index 44dce0d..a8d086e 100644
--- a/rsAllocation.h
+++ b/rsAllocation.h
@@ -61,16 +61,15 @@
     void resize1D(Context *rsc, uint32_t dimX);
     void resize2D(Context *rsc, uint32_t dimX, uint32_t dimY);
 
-    void data(Context *rsc, const void *data, uint32_t sizeBytes);
-    void subData(Context *rsc, uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes);
-    void subData(Context *rsc, uint32_t xoff, uint32_t yoff,
+    void data(Context *rsc, uint32_t xoff, uint32_t lod, uint32_t count, const void *data, uint32_t sizeBytes);
+    void data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
                  uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes);
-    void subData(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff,
+    void data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, RsAllocationCubemapFace face,
                  uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes);
 
-    void subElementData(Context *rsc, uint32_t x,
+    void elementData(Context *rsc, uint32_t x,
                         const void *data, uint32_t elementOff, uint32_t sizeBytes);
-    void subElementData(Context *rsc, uint32_t x, uint32_t y,
+    void elementData(Context *rsc, uint32_t x, uint32_t y,
                         const void *data, uint32_t elementOff, uint32_t sizeBytes);
 
     void read(void *data);
diff --git a/rsFont.cpp b/rsFont.cpp
index 80bca43..3dcf743 100644
--- a/rsFont.cpp
+++ b/rsFont.cpp
@@ -606,7 +606,7 @@
     mRSC->setProgramStore(mFontProgramStore.get());
 
     if (mConstantsDirty) {
-        mFontShaderFConstant->data(mRSC, &mConstants, sizeof(mConstants));
+        mFontShaderFConstant->data(mRSC, 0, 0, 1, &mConstants, sizeof(mConstants));
         mConstantsDirty = false;
     }
 
diff --git a/rsHandcode.h b/rsHandcode.h
index 122a9ed..6f21a35 100644
--- a/rsHandcode.h
+++ b/rsHandcode.h
@@ -49,64 +49,49 @@
     }
 }
 
-static inline void rsHCAPI_AllocationData (RsContext rsc, RsAllocation va, const void * data, uint32_t sizeBytes) {
+static inline void rsHCAPI_Allocation1DData (RsContext rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
+                                             uint32_t count, const void * data, uint32_t sizeBytes) {
     ThreadIO *io = &((Context *)rsc)->mIO;
-    uint32_t size = sizeof(RS_CMD_AllocationData);
+    uint32_t size = sizeof(RS_CMD_Allocation1DData);
     if (sizeBytes < DATA_SYNC_SIZE) {
         size += (sizeBytes + 3) & ~3;
     }
-    RS_CMD_AllocationData *cmd = static_cast<RS_CMD_AllocationData *>(io->mToCore.reserve(size));
-    cmd->va = va;
-    cmd->bytes = sizeBytes;
-    cmd->data = data;
-    if (sizeBytes < DATA_SYNC_SIZE) {
-        cmd->data = (void *)(cmd+1);
-        memcpy(cmd+1, data, sizeBytes);
-        io->mToCore.commit(RS_CMD_ID_AllocationData, size);
-    } else {
-        io->mToCore.commitSync(RS_CMD_ID_AllocationData, size);
-    }
-}
-
-static inline void rsHCAPI_Allocation1DSubData (RsContext rsc, RsAllocation va, uint32_t xoff, uint32_t count, const void * data, uint32_t sizeBytes) {
-    ThreadIO *io = &((Context *)rsc)->mIO;
-    uint32_t size = sizeof(RS_CMD_Allocation1DSubData);
-    if (sizeBytes < DATA_SYNC_SIZE) {
-        size += (sizeBytes + 3) & ~3;
-    }
-    RS_CMD_Allocation1DSubData *cmd = static_cast<RS_CMD_Allocation1DSubData *>(io->mToCore.reserve(size));
+    RS_CMD_Allocation1DData *cmd = static_cast<RS_CMD_Allocation1DData *>(io->mToCore.reserve(size));
     cmd->va = va;
     cmd->xoff = xoff;
+    cmd->lod = lod;
     cmd->count = count;
     cmd->data = data;
     cmd->bytes = sizeBytes;
     if (sizeBytes < DATA_SYNC_SIZE) {
         cmd->data = (void *)(cmd+1);
         memcpy(cmd+1, data, sizeBytes);
-        io->mToCore.commit(RS_CMD_ID_Allocation1DSubData, size);
+        io->mToCore.commit(RS_CMD_ID_Allocation1DData, size);
     } else {
-        io->mToCore.commitSync(RS_CMD_ID_Allocation1DSubData, size);
+        io->mToCore.commitSync(RS_CMD_ID_Allocation1DData, size);
     }
 }
 
-static inline void rsHCAPI_Allocation1DSubElementData (RsContext rsc, RsAllocation va, uint32_t x, const void * data, uint32_t comp_offset, uint32_t sizeBytes) {
+static inline void rsHCAPI_Allocation1DElementData (RsContext rsc, RsAllocation va, uint32_t x, uint32_t lod,
+                                                    const void * data, uint32_t comp_offset, uint32_t sizeBytes) {
     ThreadIO *io = &((Context *)rsc)->mIO;
-    uint32_t size = sizeof(RS_CMD_Allocation1DSubElementData);
+    uint32_t size = sizeof(RS_CMD_Allocation1DElementData);
     if (sizeBytes < DATA_SYNC_SIZE) {
         size += (sizeBytes + 3) & ~3;
     }
-    RS_CMD_Allocation1DSubElementData *cmd = static_cast<RS_CMD_Allocation1DSubElementData *>(io->mToCore.reserve(size));
+    RS_CMD_Allocation1DElementData *cmd = static_cast<RS_CMD_Allocation1DElementData *>(io->mToCore.reserve(size));
     cmd->va = va;
     cmd->x = x;
+    cmd->lod = lod;
     cmd->data = data;
     cmd->comp_offset = comp_offset;
     cmd->bytes = sizeBytes;
     if (sizeBytes < DATA_SYNC_SIZE) {
         cmd->data = (void *)(cmd+1);
         memcpy(cmd+1, data, sizeBytes);
-        io->mToCore.commit(RS_CMD_ID_Allocation1DSubElementData, size);
+        io->mToCore.commit(RS_CMD_ID_Allocation1DElementData, size);
     } else {
-        io->mToCore.commitSync(RS_CMD_ID_Allocation1DSubElementData, size);
+        io->mToCore.commitSync(RS_CMD_ID_Allocation1DElementData, size);
     }
 }