From 5b2a8ab2b476ddb213cce91976b14c0bfd2383f2 Mon Sep 17 00:00:00 2001 From: Pirama Arumuga Nainar Date: Fri, 26 Feb 2016 09:16:17 -0800 Subject: [PATCH 1/2] [RenderScript] Allow copyTo(short[]) etc for Float16 Allocations http://b/27251511 Allow copyTo(short[]), copyFrom(short[]), and their 1D range and 2D range variants to copy data between short[] arrays and Float16 Allocations. Change-Id: I370584685c3b773c165bd718974ca736ed548339 (cherry picked from commit f51bb356deeb8a22414fb44cede4b8618c4b57ba) --- rs/java/android/renderscript/Allocation.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/rs/java/android/renderscript/Allocation.java b/rs/java/android/renderscript/Allocation.java index 4bda87e918dea..6bcb5b6afc72f 100644 --- a/rs/java/android/renderscript/Allocation.java +++ b/rs/java/android/renderscript/Allocation.java @@ -115,7 +115,7 @@ public class Allocation extends BaseObj { if (cmp == Short.TYPE) { if (checkType) { - validateIsInt16(); + validateIsInt16OrFloat16(); return mType.mElement.mType; } return Element.DataType.SIGNED_16; @@ -402,9 +402,10 @@ public class Allocation extends BaseObj { "32 bit integer source does not match allocation type " + mType.mElement.mType); } - private void validateIsInt16() { + private void validateIsInt16OrFloat16() { if ((mType.mElement.mType == Element.DataType.SIGNED_16) || - (mType.mElement.mType == Element.DataType.UNSIGNED_16)) { + (mType.mElement.mType == Element.DataType.UNSIGNED_16) || + (mType.mElement.mType == Element.DataType.FLOAT_16)) { return; } throw new RSIllegalArgumentException( @@ -751,7 +752,7 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copyFrom(short[] d) { - validateIsInt16(); + validateIsInt16OrFloat16(); copyFromUnchecked(d, Element.DataType.SIGNED_16, d.length); } @@ -1060,7 +1061,7 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copy1DRangeFrom(int off, int count, short[] d) { - validateIsInt16(); + validateIsInt16OrFloat16(); copy1DRangeFromUnchecked(off, count, d, Element.DataType.SIGNED_16, d.length); } @@ -1204,7 +1205,7 @@ public class Allocation extends BaseObj { * @param data to be placed into the Allocation */ public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) { - validateIsInt16(); + validateIsInt16OrFloat16(); copy2DRangeFromUnchecked(xoff, yoff, w, h, data, Element.DataType.SIGNED_16, data.length); } @@ -1473,7 +1474,7 @@ public class Allocation extends BaseObj { * @param d The array to be set from the Allocation. */ public void copyTo(short[] d) { - validateIsInt16(); + validateIsInt16OrFloat16(); copyTo(d, Element.DataType.SIGNED_16, d.length); } @@ -1693,7 +1694,7 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copy1DRangeTo(int off, int count, short[] d) { - validateIsInt16(); + validateIsInt16OrFloat16(); copy1DRangeToUnchecked(off, count, d, Element.DataType.SIGNED_16, d.length); } @@ -1794,7 +1795,7 @@ public class Allocation extends BaseObj { * @param data Dest Array to be copied into */ public void copy2DRangeTo(int xoff, int yoff, int w, int h, short[] data) { - validateIsInt16(); + validateIsInt16OrFloat16(); copy2DRangeToUnchecked(xoff, yoff, w, h, data, Element.DataType.SIGNED_16, data.length); } From 1333215d8e61c1cbcabb551ac9a49a801f90ca76 Mon Sep 17 00:00:00 2001 From: Pirama Arumuga Nainar Date: Tue, 1 Mar 2016 20:37:19 -0800 Subject: [PATCH 2/2] [RenderScript] Enable untyped variants of Allocation-copy functions for FLOAT_16 http://b/27251511 Handle FLOAT_16 case to PER_ARRAY_TYPE macro to enable untyped variants of Allocation-copy functions. Untyped variants of Allocation-copy functions call validateObjectIsPrimitiveArray(), with checkType parameter set to true, to validate and obtain the Element type of the Allocation. When checkType is true, validateObjectIsPrimitiveArray() returns the actual Element type of the Allocation (instead of the canonical SIGNED type). Because of this, FLOAT_16 element type can reach the JNI layer, necessitating this change to PER_ARRAY_TYPE macro. Change-Id: I3651e5ae0ab0cd6bb4ad3157841e2910ac8699dc (cherry picked from commit 85e8c51dbf8dc774ecfd09981ac6a8bf1b75f464) --- rs/jni/android_renderscript_RenderScript.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp index 316e5302deb2e..4877a378aaf4a 100644 --- a/rs/jni/android_renderscript_RenderScript.cpp +++ b/rs/jni/android_renderscript_RenderScript.cpp @@ -151,6 +151,7 @@ void UNUSED(T... t) {} return; \ case RS_TYPE_SIGNED_16: \ case RS_TYPE_UNSIGNED_16: \ + case RS_TYPE_FLOAT_16: \ len = _env->GetArrayLength((jshortArray)data); \ ptr = _env->GetShortArrayElements((jshortArray)data, flag); \ if (ptr == nullptr) { \