Merge "ContextDestroy should go through FIFO"
diff --git a/api/rs_convert.spec b/api/rs_convert.spec
index c1539b5..b2719b9 100644
--- a/api/rs_convert.spec
+++ b/api/rs_convert.spec
@@ -78,7 +78,7 @@
 attrib: const
 w: 2, 3, 4
 t: f16
-t: u8, u16, u32, u64, i8, i16, i32, i64, f32, f64
+t: u8, u16, u32, u64, i8, i16, i32, i64, f16, f32, f64
 ret: #3#1
 arg: #2#1 v, compatible(#3)
 test: none
diff --git a/api/rs_object_types.spec b/api/rs_object_types.spec
index 4336dd2..883aa71 100644
--- a/api/rs_object_types.spec
+++ b/api/rs_object_types.spec
@@ -102,7 +102,7 @@
 version: 14
 enum:
 value: RS_ALLOCATION_USAGE_SCRIPT = 0x0001, "Allocation is bound to and accessed by scripts."
-value: RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002, "Deprecated."
+value: RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002, "Allocation is used as a texture source."
 value: RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004, "Deprecated."
 value: RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008, "Deprecated."
 value: RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010, "Deprecated."
diff --git a/api/rs_vector_math.spec b/api/rs_vector_math.spec
index 9a3e13d..a9f3583 100644
--- a/api/rs_vector_math.spec
+++ b/api/rs_vector_math.spec
@@ -210,6 +210,17 @@
 test: vector
 end:
 
+function: native_distance
+version: 24
+attrib: const
+w: 1, 2, 3, 4
+t: f16
+ret: #2
+arg: #2#1 left_vector
+arg: #2#1 right_vector
+test: none
+end:
+
 function: native_length
 version: 21
 attrib: const
diff --git a/driver/runtime/Android.mk b/driver/runtime/Android.mk
index 9720f06..8db4394 100755
--- a/driver/runtime/Android.mk
+++ b/driver/runtime/Android.mk
@@ -69,8 +69,7 @@
     $(clcore_base_files) \
     arch/generic.c \
     arch/x86_sse2.ll \
-    arch/x86_sse3.ll \
-    arch/x86_trunc.ll
+    arch/x86_sse3.ll
 
 # Grab the current value for $(RS_VERSION_DEFINE)
 include frameworks/compile/slang/rs_version.mk
@@ -151,7 +150,6 @@
 LOCAL_CFLAGS += $(clcore_cflags)
 LOCAL_CFLAGS += -g -O0
 LOCAL_SRC_FILES := $(clcore_base_files) $(clcore_g_files)
-LOCAL_SRC_FILES_x86 := arch/x86_trunc.ll
 LOCAL_SRC_FILES_32 := arch/generic.c
 
 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm64))
diff --git a/driver/runtime/arch/x86_trunc.ll b/driver/runtime/arch/x86_trunc.ll
deleted file mode 100644
index f8c1060..0000000
--- a/driver/runtime/arch/x86_trunc.ll
+++ /dev/null
@@ -1,11 +0,0 @@
-target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
-target triple = "i686-unknown-linux"
-
-; http://b/26165616 - As a WAR for this bug, define __truncxfhf2.  Note that
-; this exhibits the double-rounding problem.  This WAR will be removed once
-; a proper implementation is added to compiler-rt.
-define half @__truncxfhf2(x86_fp80 %v1) nounwind readnone alwaysinline {
-  %1 = fptrunc x86_fp80 %v1 to float
-  %2 = fptrunc float %1 to half
-  ret half %2
-}
diff --git a/java/tests/HealingBrush/src/rs/example/android/com/healingbrush/DrawView.java b/java/tests/HealingBrush/src/rs/example/android/com/healingbrush/DrawView.java
index 2995369..f091fc4 100644
--- a/java/tests/HealingBrush/src/rs/example/android/com/healingbrush/DrawView.java
+++ b/java/tests/HealingBrush/src/rs/example/android/com/healingbrush/DrawView.java
@@ -42,6 +42,8 @@
     Paint mPaint1;
     Paint mPaint2;
     private boolean mDone;
+    private boolean mUseDefaultRegion = true;
+
     ArrayList<Drawable> drawList = new ArrayList<Drawable>();
 
     private void setup(Context context) {
@@ -94,8 +96,16 @@
     }
 
     public Region getRegion(Bitmap img) {
-        Region ret = new Region(Arrays.copyOf(path, len), img);
-
+        Region ret;
+        if (mUseDefaultRegion) {
+            float[] defaultPath = {10.0f, 110.0f,
+                                   110.0f, 10.0f,
+                                   210.0f, 110.0f,
+                                   110.0f, 210.0f};
+            ret = new Region(Arrays.copyOf(defaultPath, defaultPath.length), img);
+        } else {
+            ret = new Region(Arrays.copyOf(path, len), img);
+        }
         invalidate();
         return ret;
     }
@@ -108,6 +118,7 @@
         mPoints_backup.addPath(mPoints);
         mPoints.reset();
         mPoints.moveTo(imgPoint[0], imgPoint[1]);
+        mUseDefaultRegion = false;
     }
 
     public void undo() {
diff --git a/java/tests/HealingBrush/src/rs/example/android/com/healingbrush/MainActivity.java b/java/tests/HealingBrush/src/rs/example/android/com/healingbrush/MainActivity.java
index 2f41ff7..be0a9ac 100644
--- a/java/tests/HealingBrush/src/rs/example/android/com/healingbrush/MainActivity.java
+++ b/java/tests/HealingBrush/src/rs/example/android/com/healingbrush/MainActivity.java
@@ -264,14 +264,16 @@
         folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
         mImagePath = folder.getPath();
         File[] files = folder.listFiles();
-        Log.v(TAG, "files" + files.length);
-        for (int i = 0; i < files.length; i++) {
-            Log.v(TAG, "[" + i + "]=" + files[i].getAbsolutePath());
-            if (files[i].getName().toLowerCase().endsWith(".jpg")) {
-                mDisplayedImage = BitmapFactory.decodeFile(files[i].getAbsolutePath());
-                mImagePath = files[i].getParentFile().getAbsolutePath();
-                mImageName = files[i].getName();
-                return;
+        if (files != null) {
+            Log.v(TAG, "files" + files.length);
+            for (int i = 0; i < files.length; i++) {
+                Log.v(TAG, "[" + i + "]=" + files[i].getAbsolutePath());
+                if (files[i].getName().toLowerCase().endsWith(".jpg")) {
+                    mDisplayedImage = BitmapFactory.decodeFile(files[i].getAbsolutePath());
+                    mImagePath = files[i].getParentFile().getAbsolutePath();
+                    mImageName = files[i].getName();
+                    return;
+                }
             }
         }
 
diff --git a/java/tests/RsTest/src/com/android/rs/test/math_fp16.rs b/java/tests/RsTest/src/com/android/rs/test/math_fp16.rs
index 331a871..eef3a8a 100644
--- a/java/tests/RsTest/src/com/android/rs/test/math_fp16.rs
+++ b/java/tests/RsTest/src/com/android/rs/test/math_fp16.rs
@@ -88,6 +88,12 @@
     h1 = fn(h3);            \
     h1 = fn(h4);
 
+#define TEST_H_FUNC_HN_HN(fn) \
+    h1 = fn(h1, h1);          \
+    h1 = fn(h2, h2);          \
+    h1 = fn(h3, h3);          \
+    h1 = fn(h4, h4);
+
 static bool testAPI() {
     TEST_HN_FUNC_HN(acos);
     TEST_HN_FUNC_HN(acosh);
@@ -138,7 +144,6 @@
     TEST_IN_FUNC_HN(ilogb);
     TEST_HN_FUNC_HN_IN(ldexp);
     TEST_HN_FUNC_HN_I(ldexp);
-    TEST_H_FUNC_HN(length);
     TEST_HN_FUNC_HN(lgamma);
     TEST_HN_FUNC_HN_PIN(lgamma);
 
@@ -191,7 +196,6 @@
     TEST_HN_FUNC_HN(native_log1p);
     TEST_HN_FUNC_HN(native_log2);
 
-    TEST_HN_FUNC_HN(native_normalize);
     TEST_HN_FUNC_HN_HN(native_powr);
     TEST_HN_FUNC_HN(native_recip);
     TEST_HN_FUNC_HN_IN(native_rootn);
@@ -207,7 +211,6 @@
     TEST_HN_FUNC_HN(native_tanpi);
 
     TEST_HN_FUNC_HN_HN(nextafter);
-    TEST_HN_FUNC_HN(normalize);
     TEST_HN_FUNC_HN_HN(pow);
     TEST_HN_FUNC_HN_IN(pown);
     TEST_HN_FUNC_HN_HN(powr);
@@ -241,6 +244,14 @@
     // Vector math functions
     h3 = cross(h3, h3);
     h4 = cross(h4, h4);
+
+    TEST_H_FUNC_HN_HN(distance);
+    TEST_H_FUNC_HN_HN(dot);
+    TEST_H_FUNC_HN(length);
+    TEST_H_FUNC_HN_HN(native_distance);
+    TEST_H_FUNC_HN(native_length);
+    TEST_HN_FUNC_HN(native_normalize);
+    TEST_HN_FUNC_HN(normalize);
     return true;
 }
 
diff --git a/libRS.map b/libRS.map
index 4440ad9..c288bf1 100644
--- a/libRS.map
+++ b/libRS.map
@@ -1,6 +1,7 @@
 libRS {
   global:
     rsaAllocationGetType;
+    rsaContextSetNativeLibDir;
     rsaElementGetNativeData;
     rsaElementGetSubElements;
     rsaGetName;
diff --git a/scriptc/rs_convert.rsh b/scriptc/rs_convert.rsh
index 9ffc183..146e192 100644
--- a/scriptc/rs_convert.rsh
+++ b/scriptc/rs_convert.rsh
@@ -1247,6 +1247,21 @@
 #endif
 
 #if (defined(RS_VERSION) && (RS_VERSION >= 24))
+extern half2 __attribute__((const, overloadable))
+    convert_half2(half2 v);
+#endif
+
+#if (defined(RS_VERSION) && (RS_VERSION >= 24))
+extern half3 __attribute__((const, overloadable))
+    convert_half3(half3 v);
+#endif
+
+#if (defined(RS_VERSION) && (RS_VERSION >= 24))
+extern half4 __attribute__((const, overloadable))
+    convert_half4(half4 v);
+#endif
+
+#if (defined(RS_VERSION) && (RS_VERSION >= 24))
 extern float2 __attribute__((const, overloadable))
     convert_float2(half2 v);
 #endif
diff --git a/scriptc/rs_object_types.rsh b/scriptc/rs_object_types.rsh
index 671873e..e6511a5 100644
--- a/scriptc/rs_object_types.rsh
+++ b/scriptc/rs_object_types.rsh
@@ -114,7 +114,7 @@
 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
 typedef enum {
     RS_ALLOCATION_USAGE_SCRIPT = 0x0001, // Allocation is bound to and accessed by scripts.
-    RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002, // Deprecated.
+    RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002, // Allocation is used as a texture source.
     RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004, // Deprecated.
     RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008, // Deprecated.
     RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010, // Deprecated.
diff --git a/scriptc/rs_vector_math.rsh b/scriptc/rs_vector_math.rsh
index d611464..2f5e8e7 100644
--- a/scriptc/rs_vector_math.rsh
+++ b/scriptc/rs_vector_math.rsh
@@ -294,6 +294,26 @@
     native_distance(float4 left_vector, float4 right_vector);
 #endif
 
+#if (defined(RS_VERSION) && (RS_VERSION >= 24))
+extern half __attribute__((const, overloadable))
+    native_distance(half left_vector, half right_vector);
+#endif
+
+#if (defined(RS_VERSION) && (RS_VERSION >= 24))
+extern half __attribute__((const, overloadable))
+    native_distance(half2 left_vector, half2 right_vector);
+#endif
+
+#if (defined(RS_VERSION) && (RS_VERSION >= 24))
+extern half __attribute__((const, overloadable))
+    native_distance(half3 left_vector, half3 right_vector);
+#endif
+
+#if (defined(RS_VERSION) && (RS_VERSION >= 24))
+extern half __attribute__((const, overloadable))
+    native_distance(half4 left_vector, half4 right_vector);
+#endif
+
 /*
  * native_length: Approximate length of a vector
  *