Merge "Adds support for multi-input kernels to Slang."
diff --git a/slang_rs_reflection.cpp b/slang_rs_reflection.cpp
index 4abfd35..dcf8422 100644
--- a/slang_rs_reflection.cpp
+++ b/slang_rs_reflection.cpp
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2010-2014, The Android Open Source Project
  *
@@ -45,6 +46,9 @@
 
 #define RS_TYPE_ITEM_CLASS_NAME "Item"
 
+#define RS_TYPE_ITEM_SIZEOF_LEGACY "Item.sizeof"
+#define RS_TYPE_ITEM_SIZEOF_CURRENT "mElement.getBytesSize()"
+
 #define RS_TYPE_ITEM_BUFFER_NAME "mItemArray"
 #define RS_TYPE_ITEM_BUFFER_PACKER_NAME "mIOBuffer"
 #define RS_TYPE_ELEMENT_REF_NAME "mElementCache"
@@ -300,6 +304,13 @@
   mOutputDirectory = RSSlangReflectUtils::ComputePackagedPath(
                          OutputBaseDirectory.c_str(), mPackageName.c_str()) +
                      OS_PATH_SEPARATOR_STR;
+
+  // mElement.getBytesSize only exists on JB+
+  if (mRSContext->getTargetAPI() >= SLANG_JB_TARGET_API) {
+      mItemSizeof = RS_TYPE_ITEM_SIZEOF_CURRENT;
+  } else {
+      mItemSizeof = RS_TYPE_ITEM_SIZEOF_LEGACY;
+  }
 }
 
 bool RSReflectionJava::genScriptClass(const std::string &ClassName,
@@ -1378,8 +1389,7 @@
 void RSReflectionJava::genNewItemBufferPackerIfNull() {
   mOut.indent() << "if (" << RS_TYPE_ITEM_BUFFER_PACKER_NAME << " == null) ";
   mOut << RS_TYPE_ITEM_BUFFER_PACKER_NAME " = new FieldPacker("
-       << RS_TYPE_ITEM_CLASS_NAME
-       << ".sizeof * getType().getX()/* count */);\n";
+       <<  mItemSizeof << " * getType().getX()/* count */);\n";
 }
 
 /********************** Methods to generate type class  **********************/
@@ -1431,8 +1441,11 @@
   mOut.indent() << "static public class " RS_TYPE_ITEM_CLASS_NAME;
   mOut.startBlock();
 
-  mOut.indent() << "public static final int sizeof = " << ERT->getAllocSize()
-                << ";\n";
+  // Sizeof should not be exposed for 64-bit; it is not accurate
+  if (mRSContext->getTargetAPI() < 21) {
+      mOut.indent() << "public static final int sizeof = " << ERT->getAllocSize()
+                    << ";\n";
+  }
 
   // Member elements
   mOut << "\n";
@@ -1582,7 +1595,7 @@
 
   genNewItemBufferPackerIfNull();
   mOut.indent() << RS_TYPE_ITEM_BUFFER_PACKER_NAME << ".reset(index * "
-                << RS_TYPE_ITEM_CLASS_NAME << ".sizeof);\n";
+                << mItemSizeof << ");\n";
 
   mOut.indent() << "copyToArrayLocal(i, " RS_TYPE_ITEM_BUFFER_PACKER_NAME
                    ");\n";
@@ -1611,8 +1624,7 @@
   mOut.startBlock();
 
   mOut.indent() << "copyToArray(i, index);\n";
-  mOut.indent() << "FieldPacker fp = new FieldPacker(" RS_TYPE_ITEM_CLASS_NAME
-                   ".sizeof);\n";
+  mOut.indent() << "FieldPacker fp = new FieldPacker(" << mItemSizeof << ");\n";
   mOut.indent() << "copyToArrayLocal(i, fp);\n";
   mOut.indent() << "mAllocation.setFromFieldPacker(index, fp);\n";
 
@@ -1654,11 +1666,11 @@
 
     if (FieldOffset > 0) {
       mOut.indent() << RS_TYPE_ITEM_BUFFER_PACKER_NAME << ".reset(index * "
-                    << RS_TYPE_ITEM_CLASS_NAME << ".sizeof + " << FieldOffset
+                    << mItemSizeof << " + " << FieldOffset
                     << ");\n";
     } else {
       mOut.indent() << RS_TYPE_ITEM_BUFFER_PACKER_NAME << ".reset(index * "
-                    << RS_TYPE_ITEM_CLASS_NAME << ".sizeof);\n";
+                    << mItemSizeof << ");\n";
     }
     genPackVarOfType(F->getType(), "v", RS_TYPE_ITEM_BUFFER_PACKER_NAME);
 
@@ -1722,8 +1734,7 @@
 
   mOut.indent() << "if (" RS_TYPE_ITEM_BUFFER_PACKER_NAME
                    " != null) " RS_TYPE_ITEM_BUFFER_PACKER_NAME " = "
-                   "new FieldPacker(" RS_TYPE_ITEM_CLASS_NAME
-                   ".sizeof * getType().getX()/* count */);\n";
+                   "new FieldPacker(" << mItemSizeof << " * getType().getX()/* count */);\n";
 
   endFunction();
 }
diff --git a/slang_rs_reflection.h b/slang_rs_reflection.h
index e95c092..0c2b773 100644
--- a/slang_rs_reflection.h
+++ b/slang_rs_reflection.h
@@ -73,6 +73,9 @@
   // This is set by startClass() and will change for the multiple classes generated.
   std::string mClassName;
 
+  // This is the token used for determining the size of a given ScriptField.Item.
+  std::string mItemSizeof;
+
   bool mEmbedBitcodeInJava;
 
   int mNextExportVarSlot;