Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.os; |
| 18 | |
Andreas Huber | 906a679 | 2016-09-22 18:14:17 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
Andreas Huber | 906a679 | 2016-09-22 18:14:17 -0700 | [diff] [blame] | 21 | |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 22 | import libcore.util.NativeAllocationRegistry; |
| 23 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 24 | /** |
| 25 | * Represents fixed sized allocation of marshalled data used. Helper methods |
| 26 | * allow for access to the unmarshalled data in a variety of ways. |
| 27 | * |
| 28 | * @hide |
| 29 | */ |
| 30 | @SystemApi |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 31 | public class HwBlob { |
| 32 | private static final String TAG = "HwBlob"; |
| 33 | |
| 34 | private static final NativeAllocationRegistry sNativeRegistry; |
| 35 | |
| 36 | public HwBlob(int size) { |
| 37 | native_setup(size); |
| 38 | |
| 39 | sNativeRegistry.registerNativeAllocation( |
| 40 | this, |
| 41 | mNativeContext); |
| 42 | } |
| 43 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 44 | /** |
| 45 | * @param offset offset to unmarshall a boolean from |
| 46 | * @return the unmarshalled boolean value |
| 47 | * @throws IndexOutOfBoundsException when offset is out of this HwBlob |
| 48 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 49 | public native final boolean getBool(long offset); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 50 | /** |
| 51 | * @param offset offset to unmarshall a byte from |
| 52 | * @return the unmarshalled byte value |
| 53 | * @throws IndexOutOfBoundsException when offset is out of this HwBlob |
| 54 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 55 | public native final byte getInt8(long offset); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 56 | /** |
| 57 | * @param offset offset to unmarshall a short from |
| 58 | * @return the unmarshalled short value |
| 59 | * @throws IndexOutOfBoundsException when offset is out of this HwBlob |
| 60 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 61 | public native final short getInt16(long offset); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 62 | /** |
| 63 | * @param offset offset to unmarshall an int from |
| 64 | * @return the unmarshalled int value |
| 65 | * @throws IndexOutOfBoundsException when offset is out of this HwBlob |
| 66 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 67 | public native final int getInt32(long offset); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 68 | /** |
| 69 | * @param offset offset to unmarshall a long from |
| 70 | * @return the unmarshalled long value |
| 71 | * @throws IndexOutOfBoundsException when offset is out of this HwBlob |
| 72 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 73 | public native final long getInt64(long offset); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 74 | /** |
| 75 | * @param offset offset to unmarshall a float from |
| 76 | * @return the unmarshalled float value |
| 77 | * @throws IndexOutOfBoundsException when offset is out of this HwBlob |
| 78 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 79 | public native final float getFloat(long offset); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 80 | /** |
| 81 | * @param offset offset to unmarshall a double from |
| 82 | * @return the unmarshalled double value |
| 83 | * @throws IndexOutOfBoundsException when offset is out of this HwBlob |
| 84 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 85 | public native final double getDouble(long offset); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 86 | /** |
| 87 | * @param offset offset to unmarshall a string from |
| 88 | * @return the unmarshalled string value |
| 89 | * @throws IndexOutOfBoundsException when offset is out of this HwBlob |
| 90 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 91 | public native final String getString(long offset); |
| 92 | |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 93 | /** |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 94 | * Copy the blobs data starting from the given byte offset into the range, copying |
| 95 | * a total of size elements. |
| 96 | * |
| 97 | * @param offset starting location in blob |
| 98 | * @param array destination array |
| 99 | * @param size total number of elements to copy |
| 100 | * @throws IllegalArgumentException array.length < size |
| 101 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jboolean)] out of the blob. |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 102 | */ |
| 103 | public native final void copyToBoolArray(long offset, boolean[] array, int size); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 104 | /** |
| 105 | * Copy the blobs data starting from the given byte offset into the range, copying |
| 106 | * a total of size elements. |
| 107 | * |
| 108 | * @param offset starting location in blob |
| 109 | * @param array destination array |
| 110 | * @param size total number of elements to copy |
| 111 | * @throws IllegalArgumentException array.length < size |
| 112 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jbyte)] out of the blob. |
| 113 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 114 | public native final void copyToInt8Array(long offset, byte[] array, int size); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 115 | /** |
| 116 | * Copy the blobs data starting from the given byte offset into the range, copying |
| 117 | * a total of size elements. |
| 118 | * |
| 119 | * @param offset starting location in blob |
| 120 | * @param array destination array |
| 121 | * @param size total number of elements to copy |
| 122 | * @throws IllegalArgumentException array.length < size |
| 123 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jshort)] out of the blob. |
| 124 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 125 | public native final void copyToInt16Array(long offset, short[] array, int size); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 126 | /** |
| 127 | * Copy the blobs data starting from the given byte offset into the range, copying |
| 128 | * a total of size elements. |
| 129 | * |
| 130 | * @param offset starting location in blob |
| 131 | * @param array destination array |
| 132 | * @param size total number of elements to copy |
| 133 | * @throws IllegalArgumentException array.length < size |
| 134 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jint)] out of the blob. |
| 135 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 136 | public native final void copyToInt32Array(long offset, int[] array, int size); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 137 | /** |
| 138 | * Copy the blobs data starting from the given byte offset into the range, copying |
| 139 | * a total of size elements. |
| 140 | * |
| 141 | * @param offset starting location in blob |
| 142 | * @param array destination array |
| 143 | * @param size total number of elements to copy |
| 144 | * @throws IllegalArgumentException array.length < size |
| 145 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jlong)] out of the blob. |
| 146 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 147 | public native final void copyToInt64Array(long offset, long[] array, int size); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 148 | /** |
| 149 | * Copy the blobs data starting from the given byte offset into the range, copying |
| 150 | * a total of size elements. |
| 151 | * |
| 152 | * @param offset starting location in blob |
| 153 | * @param array destination array |
| 154 | * @param size total number of elements to copy |
| 155 | * @throws IllegalArgumentException array.length < size |
| 156 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jfloat)] out of the blob. |
| 157 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 158 | public native final void copyToFloatArray(long offset, float[] array, int size); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 159 | /** |
| 160 | * Copy the blobs data starting from the given byte offset into the range, copying |
| 161 | * a total of size elements. |
| 162 | * |
| 163 | * @param offset starting location in blob |
| 164 | * @param array destination array |
| 165 | * @param size total number of elements to copy |
| 166 | * @throws IllegalArgumentException array.length < size |
| 167 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jdouble)] out of the blob. |
| 168 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 169 | public native final void copyToDoubleArray(long offset, double[] array, int size); |
| 170 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 171 | /** |
| 172 | * Writes a boolean value at an offset. |
| 173 | * |
| 174 | * @param offset location to write value |
| 175 | * @param x value to write |
| 176 | * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jboolean)] is out of range |
| 177 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 178 | public native final void putBool(long offset, boolean x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 179 | /** |
| 180 | * Writes a byte value at an offset. |
| 181 | * |
| 182 | * @param offset location to write value |
| 183 | * @param x value to write |
| 184 | * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jbyte)] is out of range |
| 185 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 186 | public native final void putInt8(long offset, byte x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 187 | /** |
| 188 | * Writes a short value at an offset. |
| 189 | * |
| 190 | * @param offset location to write value |
| 191 | * @param x value to write |
| 192 | * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jshort)] is out of range |
| 193 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 194 | public native final void putInt16(long offset, short x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 195 | /** |
| 196 | * Writes a int value at an offset. |
| 197 | * |
| 198 | * @param offset location to write value |
| 199 | * @param x value to write |
| 200 | * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jint)] is out of range |
| 201 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 202 | public native final void putInt32(long offset, int x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 203 | /** |
| 204 | * Writes a long value at an offset. |
| 205 | * |
| 206 | * @param offset location to write value |
| 207 | * @param x value to write |
| 208 | * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jlong)] is out of range |
| 209 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 210 | public native final void putInt64(long offset, long x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 211 | /** |
| 212 | * Writes a float value at an offset. |
| 213 | * |
| 214 | * @param offset location to write value |
| 215 | * @param x value to write |
| 216 | * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jfloat)] is out of range |
| 217 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 218 | public native final void putFloat(long offset, float x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 219 | /** |
| 220 | * Writes a double value at an offset. |
| 221 | * |
| 222 | * @param offset location to write value |
| 223 | * @param x value to write |
| 224 | * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jdouble)] is out of range |
| 225 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 226 | public native final void putDouble(long offset, double x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 227 | /** |
| 228 | * Writes a string value at an offset. |
| 229 | * |
| 230 | * @param offset location to write value |
| 231 | * @param x value to write |
| 232 | * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jstring)] is out of range |
| 233 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 234 | public native final void putString(long offset, String x); |
| 235 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 236 | /** |
| 237 | * Put a boolean array contiguously at an offset in the blob. |
| 238 | * |
| 239 | * @param offset location to write values |
| 240 | * @param x array to write |
| 241 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jboolean)] out of the blob. |
| 242 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 243 | public native final void putBoolArray(long offset, boolean[] x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 244 | /** |
| 245 | * Put a byte array contiguously at an offset in the blob. |
| 246 | * |
| 247 | * @param offset location to write values |
| 248 | * @param x array to write |
| 249 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jbyte)] out of the blob. |
| 250 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 251 | public native final void putInt8Array(long offset, byte[] x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 252 | /** |
| 253 | * Put a short array contiguously at an offset in the blob. |
| 254 | * |
| 255 | * @param offset location to write values |
| 256 | * @param x array to write |
| 257 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jshort)] out of the blob. |
| 258 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 259 | public native final void putInt16Array(long offset, short[] x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 260 | /** |
| 261 | * Put a int array contiguously at an offset in the blob. |
| 262 | * |
| 263 | * @param offset location to write values |
| 264 | * @param x array to write |
| 265 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jint)] out of the blob. |
| 266 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 267 | public native final void putInt32Array(long offset, int[] x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 268 | /** |
| 269 | * Put a long array contiguously at an offset in the blob. |
| 270 | * |
| 271 | * @param offset location to write values |
| 272 | * @param x array to write |
| 273 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jlong)] out of the blob. |
| 274 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 275 | public native final void putInt64Array(long offset, long[] x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 276 | /** |
| 277 | * Put a float array contiguously at an offset in the blob. |
| 278 | * |
| 279 | * @param offset location to write values |
| 280 | * @param x array to write |
| 281 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jfloat)] out of the blob. |
| 282 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 283 | public native final void putFloatArray(long offset, float[] x); |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 284 | /** |
| 285 | * Put a double array contiguously at an offset in the blob. |
| 286 | * |
| 287 | * @param offset location to write values |
| 288 | * @param x array to write |
| 289 | * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jdouble)] out of the blob. |
| 290 | */ |
Andreas Huber | 0eb37e0 | 2017-10-31 11:51:50 -0700 | [diff] [blame] | 291 | public native final void putDoubleArray(long offset, double[] x); |
| 292 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 293 | /** |
| 294 | * Write another HwBlob into this blob at the specified location. |
| 295 | * |
| 296 | * @param offset location to write value |
| 297 | * @param blob data to write |
| 298 | * @throws IndexOutOfBoundsException if [offset, offset + blob's size] outside of the range of |
| 299 | * this blob. |
| 300 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 301 | public native final void putBlob(long offset, HwBlob blob); |
| 302 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 303 | /** |
| 304 | * @return current handle of HwBlob for reference in a parcelled binder transaction |
| 305 | */ |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 306 | public native final long handle(); |
| 307 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 308 | /** |
| 309 | * Convert a primitive to a wrapped array for boolean. |
| 310 | * |
| 311 | * @param array from array |
| 312 | * @return transformed array |
| 313 | */ |
Andreas Huber | 906a679 | 2016-09-22 18:14:17 -0700 | [diff] [blame] | 314 | public static Boolean[] wrapArray(@NonNull boolean[] array) { |
| 315 | final int n = array.length; |
| 316 | Boolean[] wrappedArray = new Boolean[n]; |
| 317 | for (int i = 0; i < n; ++i) { |
| 318 | wrappedArray[i] = array[i]; |
| 319 | } |
| 320 | return wrappedArray; |
| 321 | } |
| 322 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 323 | /** |
| 324 | * Convert a primitive to a wrapped array for long. |
| 325 | * |
| 326 | * @param array from array |
| 327 | * @return transformed array |
| 328 | */ |
Andreas Huber | 906a679 | 2016-09-22 18:14:17 -0700 | [diff] [blame] | 329 | public static Long[] wrapArray(@NonNull long[] array) { |
| 330 | final int n = array.length; |
| 331 | Long[] wrappedArray = new Long[n]; |
| 332 | for (int i = 0; i < n; ++i) { |
| 333 | wrappedArray[i] = array[i]; |
| 334 | } |
| 335 | return wrappedArray; |
| 336 | } |
| 337 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 338 | /** |
| 339 | * Convert a primitive to a wrapped array for byte. |
| 340 | * |
| 341 | * @param array from array |
| 342 | * @return transformed array |
| 343 | */ |
Andreas Huber | 906a679 | 2016-09-22 18:14:17 -0700 | [diff] [blame] | 344 | public static Byte[] wrapArray(@NonNull byte[] array) { |
| 345 | final int n = array.length; |
| 346 | Byte[] wrappedArray = new Byte[n]; |
| 347 | for (int i = 0; i < n; ++i) { |
| 348 | wrappedArray[i] = array[i]; |
| 349 | } |
| 350 | return wrappedArray; |
| 351 | } |
| 352 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 353 | /** |
| 354 | * Convert a primitive to a wrapped array for short. |
| 355 | * |
| 356 | * @param array from array |
| 357 | * @return transformed array |
| 358 | */ |
Andreas Huber | 906a679 | 2016-09-22 18:14:17 -0700 | [diff] [blame] | 359 | public static Short[] wrapArray(@NonNull short[] array) { |
| 360 | final int n = array.length; |
| 361 | Short[] wrappedArray = new Short[n]; |
| 362 | for (int i = 0; i < n; ++i) { |
| 363 | wrappedArray[i] = array[i]; |
| 364 | } |
| 365 | return wrappedArray; |
| 366 | } |
| 367 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 368 | /** |
| 369 | * Convert a primitive to a wrapped array for int. |
| 370 | * |
| 371 | * @param array from array |
| 372 | * @return transformed array |
| 373 | */ |
Andreas Huber | 906a679 | 2016-09-22 18:14:17 -0700 | [diff] [blame] | 374 | public static Integer[] wrapArray(@NonNull int[] array) { |
| 375 | final int n = array.length; |
| 376 | Integer[] wrappedArray = new Integer[n]; |
| 377 | for (int i = 0; i < n; ++i) { |
| 378 | wrappedArray[i] = array[i]; |
| 379 | } |
| 380 | return wrappedArray; |
| 381 | } |
| 382 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 383 | /** |
| 384 | * Convert a primitive to a wrapped array for float. |
| 385 | * |
| 386 | * @param array from array |
| 387 | * @return transformed array |
| 388 | */ |
Andreas Huber | 906a679 | 2016-09-22 18:14:17 -0700 | [diff] [blame] | 389 | public static Float[] wrapArray(@NonNull float[] array) { |
| 390 | final int n = array.length; |
| 391 | Float[] wrappedArray = new Float[n]; |
| 392 | for (int i = 0; i < n; ++i) { |
| 393 | wrappedArray[i] = array[i]; |
| 394 | } |
| 395 | return wrappedArray; |
| 396 | } |
| 397 | |
Steven Moreland | e8e63aa | 2018-01-10 15:45:36 -0800 | [diff] [blame] | 398 | /** |
| 399 | * Convert a primitive to a wrapped array for double. |
| 400 | * |
| 401 | * @param array from array |
| 402 | * @return transformed array |
| 403 | */ |
Andreas Huber | 906a679 | 2016-09-22 18:14:17 -0700 | [diff] [blame] | 404 | public static Double[] wrapArray(@NonNull double[] array) { |
| 405 | final int n = array.length; |
| 406 | Double[] wrappedArray = new Double[n]; |
| 407 | for (int i = 0; i < n; ++i) { |
| 408 | wrappedArray[i] = array[i]; |
| 409 | } |
| 410 | return wrappedArray; |
| 411 | } |
| 412 | |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 413 | // Returns address of the "freeFunction". |
| 414 | private static native final long native_init(); |
| 415 | |
| 416 | private native final void native_setup(int size); |
| 417 | |
| 418 | static { |
| 419 | long freeFunction = native_init(); |
| 420 | |
| 421 | sNativeRegistry = new NativeAllocationRegistry( |
| 422 | HwBlob.class.getClassLoader(), |
| 423 | freeFunction, |
| 424 | 128 /* size */); |
| 425 | } |
| 426 | |
| 427 | private long mNativeContext; |
| 428 | } |
| 429 | |
| 430 | |