blob: 6d6757dfed7d1e3ad0dbe25acd49f67ae30463ef [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
Stephen Hines4cbe25a2012-01-18 18:46:27 -08002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Samsd19f10d2009-05-22 14:03:28 -07003 *
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
Jason Samsf29ca502009-06-23 12:22:47 -070017#define LOG_TAG "libRS_jni"
18
Jason Samsd19f10d2009-05-22 14:03:28 -070019#include <stdlib.h>
20#include <stdio.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <math.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070024#include <utils/misc.h>
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +010025#include <inttypes.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070026
Derek Sollenbergereece0dd2014-02-27 14:31:29 -050027#include <SkBitmap.h>
Jason Samsffe9f482009-06-01 17:45:53 -070028
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080029#include <androidfw/Asset.h>
30#include <androidfw/AssetManager.h>
31#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070032
Jason Samsd19f10d2009-05-22 14:03:28 -070033#include "jni.h"
34#include "JNIHelp.h"
35#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070036#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080037#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070038
Jason Sams1d6983a2012-02-16 16:07:49 -080039#include <rs.h>
40#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070041#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080042#include <gui/GLConsumer.h>
Mathias Agopian52800612013-02-14 17:11:20 -080043#include <gui/Surface.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070044#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070045
Steve Block3762c312012-01-06 19:20:56 +000046//#define LOG_API ALOGE
Andreas Gampe67333922014-11-10 20:35:59 -080047static constexpr bool kLogApi = false;
Jason Samsd19f10d2009-05-22 14:03:28 -070048
49using namespace android;
50
Andreas Gampe67333922014-11-10 20:35:59 -080051template <typename... T>
52void UNUSED(T... t) {}
53
Stephen Hines414fa2c2014-04-17 01:02:42 -070054#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \
Jason Samse729a942013-11-06 11:22:02 -080055 jint len = 0; \
Chris Wailes488230c32014-08-14 11:22:40 -070056 void *ptr = nullptr; \
Miao Wang87e908d2015-03-02 15:15:15 -080057 void *srcPtr = nullptr; \
Jason Sams21659ac2013-11-06 15:08:07 -080058 size_t typeBytes = 0; \
Stephen Hines414fa2c2014-04-17 01:02:42 -070059 jint relFlag = 0; \
60 if (readonly) { \
61 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
Miao Wang87e908d2015-03-02 15:15:15 -080062 /* readonly = true, also indicates we are copying to the allocation . */ \
Stephen Hines414fa2c2014-04-17 01:02:42 -070063 relFlag = JNI_ABORT; \
64 } \
Jason Samse729a942013-11-06 11:22:02 -080065 switch(dataType) { \
66 case RS_TYPE_FLOAT_32: \
67 len = _env->GetArrayLength((jfloatArray)data); \
68 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080069 typeBytes = 4; \
Miao Wang87e908d2015-03-02 15:15:15 -080070 if (usePadding) { \
71 srcPtr = ptr; \
72 len = len / 3 * 4; \
73 if (count == 0) { \
74 count = len / 4; \
75 } \
76 ptr = malloc (len * typeBytes); \
77 if (readonly) { \
78 copyWithPadding(ptr, srcPtr, mSize, count); \
79 fnc(__VA_ARGS__); \
80 } else { \
81 fnc(__VA_ARGS__); \
82 copyWithUnPadding(srcPtr, ptr, mSize, count); \
83 } \
84 free(ptr); \
85 ptr = srcPtr; \
86 } else { \
87 fnc(__VA_ARGS__); \
88 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -070089 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080090 return; \
91 case RS_TYPE_FLOAT_64: \
92 len = _env->GetArrayLength((jdoubleArray)data); \
93 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080094 typeBytes = 8; \
Miao Wang87e908d2015-03-02 15:15:15 -080095 if (usePadding) { \
96 srcPtr = ptr; \
97 len = len / 3 * 4; \
98 if (count == 0) { \
99 count = len / 4; \
100 } \
101 ptr = malloc (len * typeBytes); \
102 if (readonly) { \
103 copyWithPadding(ptr, srcPtr, mSize, count); \
104 fnc(__VA_ARGS__); \
105 } else { \
106 fnc(__VA_ARGS__); \
107 copyWithUnPadding(srcPtr, ptr, mSize, count); \
108 } \
109 free(ptr); \
110 ptr = srcPtr; \
111 } else { \
112 fnc(__VA_ARGS__); \
113 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700114 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800115 return; \
116 case RS_TYPE_SIGNED_8: \
117 case RS_TYPE_UNSIGNED_8: \
118 len = _env->GetArrayLength((jbyteArray)data); \
119 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800120 typeBytes = 1; \
Miao Wang87e908d2015-03-02 15:15:15 -0800121 if (usePadding) { \
122 srcPtr = ptr; \
123 len = len / 3 * 4; \
124 if (count == 0) { \
125 count = len / 4; \
126 } \
127 ptr = malloc (len * typeBytes); \
128 if (readonly) { \
129 copyWithPadding(ptr, srcPtr, mSize, count); \
130 fnc(__VA_ARGS__); \
131 } else { \
132 fnc(__VA_ARGS__); \
133 copyWithUnPadding(srcPtr, ptr, mSize, count); \
134 } \
135 free(ptr); \
136 ptr = srcPtr; \
137 } else { \
138 fnc(__VA_ARGS__); \
139 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700140 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800141 return; \
142 case RS_TYPE_SIGNED_16: \
143 case RS_TYPE_UNSIGNED_16: \
144 len = _env->GetArrayLength((jshortArray)data); \
145 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800146 typeBytes = 2; \
Miao Wang87e908d2015-03-02 15:15:15 -0800147 if (usePadding) { \
148 srcPtr = ptr; \
149 len = len / 3 * 4; \
150 if (count == 0) { \
151 count = len / 4; \
152 } \
153 ptr = malloc (len * typeBytes); \
154 if (readonly) { \
155 copyWithPadding(ptr, srcPtr, mSize, count); \
156 fnc(__VA_ARGS__); \
157 } else { \
158 fnc(__VA_ARGS__); \
159 copyWithUnPadding(srcPtr, ptr, mSize, count); \
160 } \
161 free(ptr); \
162 ptr = srcPtr; \
163 } else { \
164 fnc(__VA_ARGS__); \
165 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700166 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800167 return; \
168 case RS_TYPE_SIGNED_32: \
169 case RS_TYPE_UNSIGNED_32: \
170 len = _env->GetArrayLength((jintArray)data); \
171 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800172 typeBytes = 4; \
Miao Wang87e908d2015-03-02 15:15:15 -0800173 if (usePadding) { \
174 srcPtr = ptr; \
175 len = len / 3 * 4; \
176 if (count == 0) { \
177 count = len / 4; \
178 } \
179 ptr = malloc (len * typeBytes); \
180 if (readonly) { \
181 copyWithPadding(ptr, srcPtr, mSize, count); \
182 fnc(__VA_ARGS__); \
183 } else { \
184 fnc(__VA_ARGS__); \
185 copyWithUnPadding(srcPtr, ptr, mSize, count); \
186 } \
187 free(ptr); \
188 ptr = srcPtr; \
189 } else { \
190 fnc(__VA_ARGS__); \
191 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700192 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800193 return; \
194 case RS_TYPE_SIGNED_64: \
195 case RS_TYPE_UNSIGNED_64: \
196 len = _env->GetArrayLength((jlongArray)data); \
197 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800198 typeBytes = 8; \
Miao Wang87e908d2015-03-02 15:15:15 -0800199 if (usePadding) { \
200 srcPtr = ptr; \
201 len = len / 3 * 4; \
202 if (count == 0) { \
203 count = len / 4; \
204 } \
205 ptr = malloc (len * typeBytes); \
206 if (readonly) { \
207 copyWithPadding(ptr, srcPtr, mSize, count); \
208 fnc(__VA_ARGS__); \
209 } else { \
210 fnc(__VA_ARGS__); \
211 copyWithUnPadding(srcPtr, ptr, mSize, count); \
212 } \
213 free(ptr); \
214 ptr = srcPtr; \
215 } else { \
216 fnc(__VA_ARGS__); \
217 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700218 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800219 return; \
220 default: \
221 break; \
222 } \
Miao Wang87e908d2015-03-02 15:15:15 -0800223 UNUSED(len, ptr, srcPtr, typeBytes, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800224}
225
226
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800227class AutoJavaStringToUTF8 {
228public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800229 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Chris Wailes488230c32014-08-14 11:22:40 -0700230 fCStr = env->GetStringUTFChars(str, nullptr);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800231 fLength = env->GetStringUTFLength(str);
232 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800233 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800234 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
235 }
236 const char* c_str() const { return fCStr; }
237 jsize length() const { return fLength; }
238
239private:
240 JNIEnv* fEnv;
241 jstring fJStr;
242 const char* fCStr;
243 jsize fLength;
244};
245
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800246class AutoJavaStringArrayToUTF8 {
247public:
248 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
249 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
Chris Wailes488230c32014-08-14 11:22:40 -0700250 mCStrings = nullptr;
251 mSizeArray = nullptr;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800252 if (stringsLength > 0) {
253 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
254 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
255 for (jsize ct = 0; ct < stringsLength; ct ++) {
256 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
Chris Wailes488230c32014-08-14 11:22:40 -0700257 mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800258 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
259 }
260 }
261 }
262 ~AutoJavaStringArrayToUTF8() {
263 for (jsize ct=0; ct < mStringsLength; ct++) {
264 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
265 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
266 }
267 free(mCStrings);
268 free(mSizeArray);
269 }
270 const char **c_str() const { return mCStrings; }
271 size_t *c_str_len() const { return mSizeArray; }
272 jsize length() const { return mStringsLength; }
273
274private:
275 JNIEnv *mEnv;
276 jobjectArray mStrings;
277 const char **mCStrings;
278 size_t *mSizeArray;
279 jsize mStringsLength;
280};
281
Jason Samsd19f10d2009-05-22 14:03:28 -0700282// ---------------------------------------------------------------------------
283
Jason Samsffe9f482009-06-01 17:45:53 -0700284static jfieldID gContextId = 0;
285static jfieldID gNativeBitmapID = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700286
287static void _nInit(JNIEnv *_env, jclass _this)
288{
Tim Murrayeff663f2013-11-15 13:08:30 -0800289 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsffe9f482009-06-01 17:45:53 -0700290
291 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000292 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700293}
294
Jason Samsd19f10d2009-05-22 14:03:28 -0700295// ---------------------------------------------------------------------------
296
Miao Wang87e908d2015-03-02 15:15:15 -0800297static void copyWithPadding(void* ptr, void* srcPtr, int mSize, int count) {
298 int sizeBytesPad = mSize * 4;
299 int sizeBytes = mSize * 3;
300 uint8_t *dst = static_cast<uint8_t *>(ptr);
301 uint8_t *src = static_cast<uint8_t *>(srcPtr);
302 for (int i = 0; i < count; i++) {
303 memcpy(dst, src, sizeBytes);
304 dst += sizeBytesPad;
305 src += sizeBytes;
306 }
307}
308
309static void copyWithUnPadding(void* ptr, void* srcPtr, int mSize, int count) {
310 int sizeBytesPad = mSize * 4;
311 int sizeBytes = mSize * 3;
312 uint8_t *dst = static_cast<uint8_t *>(ptr);
313 uint8_t *src = static_cast<uint8_t *>(srcPtr);
314 for (int i = 0; i < count; i++) {
315 memcpy(dst, src, sizeBytes);
316 dst += sizeBytes;
317 src += sizeBytesPad;
318 }
319}
320
321
322// ---------------------------------------------------------------------------
Jason Sams3eaa338e2009-06-10 15:04:38 -0700323static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800324nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700325{
Andreas Gampe67333922014-11-10 20:35:59 -0800326 if (kLogApi) {
327 ALOGD("nContextFinish, con(%p)", (RsContext)con);
328 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800329 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700330}
331
Yang Ni281c3252014-10-24 08:52:24 -0700332static jlong
333nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID,
334 jlong returnValue, jlongArray fieldIDArray,
335 jlongArray valueArray, jintArray sizeArray,
336 jlongArray depClosureArray, jlongArray depFieldIDArray) {
337 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
338 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
339 RsScriptFieldID* fieldIDs =
340 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
341 for (int i = 0; i< fieldIDs_length; i++) {
342 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
343 }
344
345 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
346 jsize values_length = _env->GetArrayLength(valueArray);
347 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
348 for (int i = 0; i < values_length; i++) {
349 values[i] = (uintptr_t)jValues[i];
350 }
351
352 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
353 jsize sizes_length = _env->GetArrayLength(sizeArray);
354
355 jlong* jDepClosures =
356 _env->GetLongArrayElements(depClosureArray, nullptr);
357 jsize depClosures_length = _env->GetArrayLength(depClosureArray);
358 RsClosure* depClosures =
359 (RsClosure*)alloca(sizeof(RsClosure) * depClosures_length);
360 for (int i = 0; i < depClosures_length; i++) {
361 depClosures[i] = (RsClosure)jDepClosures[i];
362 }
363
364 jlong* jDepFieldIDs =
365 _env->GetLongArrayElements(depFieldIDArray, nullptr);
366 jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray);
367 RsScriptFieldID* depFieldIDs =
368 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * depFieldIDs_length);
369 for (int i = 0; i < depClosures_length; i++) {
370 depFieldIDs[i] = (RsClosure)jDepFieldIDs[i];
371 }
372
373 return (jlong)(uintptr_t)rsClosureCreate(
374 (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue,
375 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
376 (size_t*)sizes, (size_t)sizes_length,
377 depClosures, (size_t)depClosures_length,
378 depFieldIDs, (size_t)depFieldIDs_length);
379}
380
Yang Nibe392ad2015-01-23 17:16:02 -0800381static jlong
382nInvokeClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong invokeID,
383 jbyteArray paramArray, jlongArray fieldIDArray, jlongArray valueArray,
384 jintArray sizeArray) {
385 jbyte* jParams = _env->GetByteArrayElements(paramArray, nullptr);
386 jsize jParamLength = _env->GetArrayLength(paramArray);
387
388 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
389 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
390 RsScriptFieldID* fieldIDs =
391 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
392 for (int i = 0; i< fieldIDs_length; i++) {
393 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
394 }
395
396 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
397 jsize values_length = _env->GetArrayLength(valueArray);
398 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
399 for (int i = 0; i < values_length; i++) {
400 values[i] = (uintptr_t)jValues[i];
401 }
402
403 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
404 jsize sizes_length = _env->GetArrayLength(sizeArray);
405
406 return (jlong)(uintptr_t)rsInvokeClosureCreate(
407 (RsContext)con, (RsScriptInvokeID)invokeID, jParams, jParamLength,
408 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
409 (size_t*)sizes, (size_t)sizes_length);
410}
411
Yang Ni281c3252014-10-24 08:52:24 -0700412static void
413nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
414 jint index, jlong value, jint size) {
415 rsClosureSetArg((RsContext)con, (RsClosure)closureID, (uint32_t)index,
416 (uintptr_t)value, (size_t)size);
417}
418
419static void
420nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
421 jlong fieldID, jlong value, jint size) {
422 rsClosureSetGlobal((RsContext)con, (RsClosure)closureID,
423 (RsScriptFieldID)fieldID, (uintptr_t)value, (size_t)size);
424}
425
426static long
427nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con,
Yang Niebf63402015-01-16 11:06:26 -0800428 jstring cacheDir, jlongArray closureArray) {
429 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
430
Yang Ni281c3252014-10-24 08:52:24 -0700431 jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr);
432 jsize numClosures = _env->GetArrayLength(closureArray);
433 RsClosure* closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures);
434 for (int i = 0; i < numClosures; i++) {
435 closures[i] = (RsClosure)jClosures[i];
436 }
437
Yang Niebf63402015-01-16 11:06:26 -0800438 return (jlong)(uintptr_t)rsScriptGroup2Create(
439 (RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length(),
440 closures, numClosures);
Yang Ni281c3252014-10-24 08:52:24 -0700441}
442
443static void
444nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) {
445 rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID);
446}
447
Jason Sams96ed4cf2010-06-15 12:15:57 -0700448static void
Tim Murray25207df2015-01-12 16:47:56 -0800449nScriptIntrinsicBLAS_Single(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
450 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
451 jfloat alpha, jlong A, jlong B, jfloat beta, jlong C, jint incX, jint incY,
452 jint KL, jint KU) {
453 RsBlasCall call;
454 memset(&call, 0, sizeof(call));
455 call.func = (RsBlasFunction)func;
456 call.transA = (RsBlasTranspose)TransA;
457 call.transB = (RsBlasTranspose)TransB;
458 call.side = (RsBlasSide)Side;
459 call.uplo = (RsBlasUplo)Uplo;
460 call.diag = (RsBlasDiag)Diag;
461 call.M = M;
462 call.N = N;
463 call.K = K;
464 call.alpha.f = alpha;
465 call.beta.f = beta;
466 call.incX = incX;
467 call.incY = incY;
468 call.KL = KL;
469 call.KU = KU;
470
471 RsAllocation in_allocs[3];
472 in_allocs[0] = (RsAllocation)A;
473 in_allocs[1] = (RsAllocation)B;
474 in_allocs[2] = (RsAllocation)C;
475
476 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
477 in_allocs, sizeof(in_allocs), nullptr,
478 &call, sizeof(call), nullptr, 0);
479}
480
481static void
482nScriptIntrinsicBLAS_Double(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
483 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
484 jdouble alpha, jlong A, jlong B, jdouble beta, jlong C, jint incX, jint incY,
485 jint KL, jint KU) {
486 RsBlasCall call;
487 memset(&call, 0, sizeof(call));
488 call.func = (RsBlasFunction)func;
489 call.transA = (RsBlasTranspose)TransA;
490 call.transB = (RsBlasTranspose)TransB;
491 call.side = (RsBlasSide)Side;
492 call.uplo = (RsBlasUplo)Uplo;
493 call.diag = (RsBlasDiag)Diag;
494 call.M = M;
495 call.N = N;
496 call.K = K;
497 call.alpha.d = alpha;
498 call.beta.d = beta;
499 call.incX = incX;
500 call.incY = incY;
501 call.KL = KL;
502 call.KU = KU;
503
504 RsAllocation in_allocs[3];
505 in_allocs[0] = (RsAllocation)A;
506 in_allocs[1] = (RsAllocation)B;
507 in_allocs[2] = (RsAllocation)C;
508
509 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
510 in_allocs, sizeof(in_allocs), nullptr,
511 &call, sizeof(call), nullptr, 0);
512}
513
514static void
515nScriptIntrinsicBLAS_Complex(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
516 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
517 jfloat alphaX, jfloat alphaY, jlong A, jlong B, jfloat betaX,
518 jfloat betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
519 RsBlasCall call;
520 memset(&call, 0, sizeof(call));
521 call.func = (RsBlasFunction)func;
522 call.transA = (RsBlasTranspose)TransA;
523 call.transB = (RsBlasTranspose)TransB;
524 call.side = (RsBlasSide)Side;
525 call.uplo = (RsBlasUplo)Uplo;
526 call.diag = (RsBlasDiag)Diag;
527 call.M = M;
528 call.N = N;
529 call.K = K;
530 call.alpha.c.r = alphaX;
531 call.alpha.c.i = alphaY;
532 call.beta.c.r = betaX;
533 call.beta.c.r = betaY;
534 call.incX = incX;
535 call.incY = incY;
536 call.KL = KL;
537 call.KU = KU;
538
539 RsAllocation in_allocs[3];
540 in_allocs[0] = (RsAllocation)A;
541 in_allocs[1] = (RsAllocation)B;
542 in_allocs[2] = (RsAllocation)C;
543
544 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
545 in_allocs, sizeof(in_allocs), nullptr,
546 &call, sizeof(call), nullptr, 0);
547}
548
549static void
550nScriptIntrinsicBLAS_Z(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
551 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
552 jdouble alphaX, jdouble alphaY, jlong A, jlong B, jdouble betaX,
553 jdouble betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
554 RsBlasCall call;
555 memset(&call, 0, sizeof(call));
556 call.func = (RsBlasFunction)func;
557 call.transA = (RsBlasTranspose)TransA;
558 call.transB = (RsBlasTranspose)TransB;
559 call.side = (RsBlasSide)Side;
560 call.uplo = (RsBlasUplo)Uplo;
561 call.diag = (RsBlasDiag)Diag;
562 call.M = M;
563 call.N = N;
564 call.K = K;
565 call.alpha.z.r = alphaX;
566 call.alpha.z.i = alphaY;
567 call.beta.z.r = betaX;
568 call.beta.z.r = betaY;
569 call.incX = incX;
570 call.incY = incY;
571 call.KL = KL;
572 call.KU = KU;
573
574 RsAllocation in_allocs[3];
575 in_allocs[0] = (RsAllocation)A;
576 in_allocs[1] = (RsAllocation)B;
577 in_allocs[2] = (RsAllocation)C;
578
579 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
580 in_allocs, sizeof(in_allocs), nullptr,
581 &call, sizeof(call), nullptr, 0);
582}
583
584
585static void
Tim Murray460a0492013-11-19 12:45:54 -0800586nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700587{
Andreas Gampe67333922014-11-10 20:35:59 -0800588 if (kLogApi) {
589 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
590 }
Jason Sams3eaa338e2009-06-10 15:04:38 -0700591 jint len = _env->GetArrayLength(str);
592 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800593 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700594 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
595}
596
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700597static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800598nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700599{
Andreas Gampe67333922014-11-10 20:35:59 -0800600 if (kLogApi) {
601 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
602 }
Chris Wailes488230c32014-08-14 11:22:40 -0700603 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800604 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700605 if(name == nullptr || strlen(name) == 0) {
606 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700607 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700608 return _env->NewStringUTF(name);
609}
610
Jason Sams7ce033d2009-08-18 14:14:24 -0700611static void
Tim Murray460a0492013-11-19 12:45:54 -0800612nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700613{
Andreas Gampe67333922014-11-10 20:35:59 -0800614 if (kLogApi) {
615 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
616 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800617 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700618}
619
Jason Sams3eaa338e2009-06-10 15:04:38 -0700620// ---------------------------------------------------------------------------
621
Tim Murrayeff663f2013-11-15 13:08:30 -0800622static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700623nDeviceCreate(JNIEnv *_env, jobject _this)
624{
Andreas Gampe67333922014-11-10 20:35:59 -0800625 if (kLogApi) {
626 ALOGD("nDeviceCreate");
627 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700628 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700629}
630
631static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800632nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700633{
Andreas Gampe67333922014-11-10 20:35:59 -0800634 if (kLogApi) {
635 ALOGD("nDeviceDestroy");
636 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700637 return rsDeviceDestroy((RsDevice)dev);
638}
639
Jason Samsebfb4362009-09-23 13:57:02 -0700640static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800641nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700642{
Andreas Gampe67333922014-11-10 20:35:59 -0800643 if (kLogApi) {
644 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
645 }
Jason Samsebfb4362009-09-23 13:57:02 -0700646 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
647}
648
Tim Murrayeff663f2013-11-15 13:08:30 -0800649static jlong
Jason Sams81cd2b12014-12-02 12:36:43 -0800650nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700651{
Andreas Gampe67333922014-11-10 20:35:59 -0800652 if (kLogApi) {
653 ALOGD("nContextCreate");
654 }
Jason Sams81cd2b12014-12-02 12:36:43 -0800655 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags);
Jason Sams704ff642010-02-09 16:05:07 -0800656}
657
Tim Murrayeff663f2013-11-15 13:08:30 -0800658static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800659nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000660 jint colorMin, jint colorPref,
661 jint alphaMin, jint alphaPref,
662 jint depthMin, jint depthPref,
663 jint stencilMin, jint stencilPref,
664 jint samplesMin, jint samplesPref, jfloat samplesQ,
665 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800666{
Jason Sams11c8af92010-10-13 15:31:10 -0700667 RsSurfaceConfig sc;
668 sc.alphaMin = alphaMin;
669 sc.alphaPref = alphaPref;
670 sc.colorMin = colorMin;
671 sc.colorPref = colorPref;
672 sc.depthMin = depthMin;
673 sc.depthPref = depthPref;
674 sc.samplesMin = samplesMin;
675 sc.samplesPref = samplesPref;
676 sc.samplesQ = samplesQ;
677
Andreas Gampe67333922014-11-10 20:35:59 -0800678 if (kLogApi) {
679 ALOGD("nContextCreateGL");
680 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700681 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700682}
683
684static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800685nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800686{
Andreas Gampe67333922014-11-10 20:35:59 -0800687 if (kLogApi) {
688 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
689 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800690 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800691}
692
693
694
695static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800696nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800697{
Andreas Gampe67333922014-11-10 20:35:59 -0800698 if (kLogApi) {
699 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
700 width, height, (Surface *)wnd);
701 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800702
Chris Wailes488230c32014-08-14 11:22:40 -0700703 ANativeWindow * window = nullptr;
704 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800705
706 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700707 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800708 }
709
Tim Murrayeff663f2013-11-15 13:08:30 -0800710 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800711}
712
713static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800714nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700715{
Andreas Gampe67333922014-11-10 20:35:59 -0800716 if (kLogApi) {
717 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
718 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800719 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700720}
721
Jason Sams715333b2009-11-17 17:26:46 -0800722static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800723nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800724{
Andreas Gampe67333922014-11-10 20:35:59 -0800725 if (kLogApi) {
726 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
727 }
Jason Sams715333b2009-11-17 17:26:46 -0800728 rsContextDump((RsContext)con, bits);
729}
Jason Samsd19f10d2009-05-22 14:03:28 -0700730
731static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800732nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700733{
Andreas Gampe67333922014-11-10 20:35:59 -0800734 if (kLogApi) {
735 ALOGD("nContextPause, con(%p)", (RsContext)con);
736 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800737 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700738}
739
740static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800741nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700742{
Andreas Gampe67333922014-11-10 20:35:59 -0800743 if (kLogApi) {
744 ALOGD("nContextResume, con(%p)", (RsContext)con);
745 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800746 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700747}
748
Jason Sams1c415172010-11-08 17:06:46 -0800749
750static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800751nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800752{
Andreas Gampe67333922014-11-10 20:35:59 -0800753 if (kLogApi) {
754 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
755 }
Jason Sams1c415172010-11-08 17:06:46 -0800756 char buf[1024];
757
758 size_t receiveLen;
759 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800760 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700761 buf, sizeof(buf),
762 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700763 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800764 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100765 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800766 }
767 return _env->NewStringUTF(buf);
768}
769
Jason Samsedbfabd2011-05-17 15:01:29 -0700770static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800771nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700772{
Jason Sams516c3192009-10-06 13:58:47 -0700773 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800774 if (kLogApi) {
775 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
776 }
Chris Wailes488230c32014-08-14 11:22:40 -0700777 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700778 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800779 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800780 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700781 ptr, len * 4,
782 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700783 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700784 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100785 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700786 }
787 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000788 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800789}
790
791static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800792nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800793{
Andreas Gampe67333922014-11-10 20:35:59 -0800794 if (kLogApi) {
795 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
796 }
Chris Wailes488230c32014-08-14 11:22:40 -0700797 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800798 size_t receiveLen;
799 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800800 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700801 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800802 auxDataPtr[0] = (jint)subID;
803 auxDataPtr[1] = (jint)receiveLen;
804 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000805 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700806}
807
Tim Murrayeff663f2013-11-15 13:08:30 -0800808static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700809{
Andreas Gampe67333922014-11-10 20:35:59 -0800810 if (kLogApi) {
811 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
812 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800813 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700814}
815
Tim Murrayeff663f2013-11-15 13:08:30 -0800816static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700817{
Andreas Gampe67333922014-11-10 20:35:59 -0800818 if (kLogApi) {
819 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
820 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800821 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700822}
823
Jason Sams455d6442013-02-05 19:20:18 -0800824static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800825nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800826{
Chris Wailes488230c32014-08-14 11:22:40 -0700827 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800828 jint len = 0;
829 if (data) {
830 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700831 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800832 }
Andreas Gampe67333922014-11-10 20:35:59 -0800833 if (kLogApi) {
834 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
835 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800836 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800837 if (data) {
838 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
839 }
840}
841
842
Jason Sams516c3192009-10-06 13:58:47 -0700843
Tim Murray460a0492013-11-19 12:45:54 -0800844static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800845nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
846 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700847{
Andreas Gampe67333922014-11-10 20:35:59 -0800848 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100849 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con,
Andreas Gampe67333922014-11-10 20:35:59 -0800850 type, kind, norm, size);
851 }
852 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
853 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700854}
855
Tim Murray460a0492013-11-19 12:45:54 -0800856static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800857nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000858 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700859{
Jason Sams718cd1f2009-12-23 14:35:29 -0800860 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -0800861 if (kLogApi) {
862 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
863 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800864
Chris Wailes488230c32014-08-14 11:22:40 -0700865 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
866 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000867
868 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
869 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
870
871 for(int i = 0; i < fieldCount; i ++) {
872 ids[i] = (RsElement)jIds[i];
873 arraySizes[i] = (uint32_t)jArraySizes[i];
874 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800875
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800876 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
877
878 const char **nameArray = names.c_str();
879 size_t *sizeArray = names.c_str_len();
880
Tim Murray3aa89c12014-08-18 17:51:22 -0700881 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000882 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700883 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700884 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800885
Ashok Bhat98071552014-02-12 09:54:43 +0000886 free(ids);
887 free(arraySizes);
888 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
889 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
890
Tim Murray3aa89c12014-08-18 17:51:22 -0700891 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700892}
893
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700894static void
Tim Murray460a0492013-11-19 12:45:54 -0800895nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700896{
897 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -0800898 if (kLogApi) {
899 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
900 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700901
902 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
903 assert(dataSize == 5);
904
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000905 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800906 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700907
908 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000909 const jint data = (jint)elementData[i];
910 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700911 }
912}
913
914
915static void
Tim Murray460a0492013-11-19 12:45:54 -0800916nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000917 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700918 jobjectArray _names,
919 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700920{
Ashok Bhat98071552014-02-12 09:54:43 +0000921 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -0800922 if (kLogApi) {
923 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
924 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700925
Ashok Bhat98071552014-02-12 09:54:43 +0000926 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
927 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000928 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700929
Andreas Gampe67333922014-11-10 20:35:59 -0800930 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
931 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700932
Ashok Bhat98071552014-02-12 09:54:43 +0000933 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700934 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000935 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700936 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000937 _env->SetLongArrayRegion(_IDs, i, 1, &id);
938 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700939 }
940
941 free(ids);
942 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700943 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700944}
945
Jason Samsd19f10d2009-05-22 14:03:28 -0700946// -----------------------------------
947
Tim Murray460a0492013-11-19 12:45:54 -0800948static jlong
949nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800950 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700951{
Andreas Gampe67333922014-11-10 20:35:59 -0800952 if (kLogApi) {
953 ALOGD("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100954 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv);
Andreas Gampe67333922014-11-10 20:35:59 -0800955 }
Jason Sams3b9c52a2010-10-14 17:48:46 -0700956
Andreas Gampe67333922014-11-10 20:35:59 -0800957 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
958 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700959}
960
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700961static void
Ashok Bhat98071552014-02-12 09:54:43 +0000962nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700963{
964 // We are packing 6 items: mDimX; mDimY; mDimZ;
965 // mDimLOD; mDimFaces; mElement; into typeData
966 int elementCount = _env->GetArrayLength(_typeData);
967
968 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -0800969 if (kLogApi) {
970 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
971 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700972
Ashok Bhat98071552014-02-12 09:54:43 +0000973 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -0800974 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700975
976 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700977 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000978 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700979 }
980}
981
Jason Samsd19f10d2009-05-22 14:03:28 -0700982// -----------------------------------
983
Tim Murray460a0492013-11-19 12:45:54 -0800984static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800985nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
986 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700987{
Andreas Gampe67333922014-11-10 20:35:59 -0800988 if (kLogApi) {
989 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
990 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
991 }
992 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
993 (RsAllocationMipmapControl)mips,
994 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700995}
996
Jason Samsd19f10d2009-05-22 14:03:28 -0700997static void
Tim Murray460a0492013-11-19 12:45:54 -0800998nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -0800999{
Andreas Gampe67333922014-11-10 20:35:59 -08001000 if (kLogApi) {
1001 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
1002 bits);
1003 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001004 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -08001005}
1006
Jason Sams72226e02013-02-22 12:45:54 -08001007static jobject
Tim Murray460a0492013-11-19 12:45:54 -08001008nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -08001009{
Andreas Gampe67333922014-11-10 20:35:59 -08001010 if (kLogApi) {
1011 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1012 }
Jason Sams615e7ce2012-01-13 14:01:20 -08001013
Andreas Gampe67333922014-11-10 20:35:59 -08001014 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
1015 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -08001016 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -07001017 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001018
Jason Sams72226e02013-02-22 12:45:54 -08001019 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
1020 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001021}
1022
1023static void
Tim Murray460a0492013-11-19 12:45:54 -08001024nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -08001025{
Andreas Gampe67333922014-11-10 20:35:59 -08001026 if (kLogApi) {
1027 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
1028 (RsAllocation)alloc, (Surface *)sur);
1029 }
Jason Sams163766c2012-02-15 12:04:24 -08001030
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001031 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -08001032 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -07001033 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -08001034 }
1035
Andreas Gampe67333922014-11-10 20:35:59 -08001036 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
1037 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -08001038}
1039
1040static void
Tim Murray460a0492013-11-19 12:45:54 -08001041nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001042{
Andreas Gampe67333922014-11-10 20:35:59 -08001043 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001044 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001045 }
Tim Murray460a0492013-11-19 12:45:54 -08001046 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001047}
1048
1049static void
Tim Murray460a0492013-11-19 12:45:54 -08001050nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001051{
Andreas Gampe67333922014-11-10 20:35:59 -08001052 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001053 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001054 }
Tim Murray460a0492013-11-19 12:45:54 -08001055 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001056}
1057
1058
1059static void
Tim Murray460a0492013-11-19 12:45:54 -08001060nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -08001061{
Andreas Gampe67333922014-11-10 20:35:59 -08001062 if (kLogApi) {
1063 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
1064 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001065 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -08001066}
1067
Tim Murray460a0492013-11-19 12:45:54 -08001068static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001069nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1070 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -07001071{
Jason Samsffe9f482009-06-01 17:45:53 -07001072 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001073 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -07001074 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -07001075
Jason Sams5476b452010-12-08 16:14:36 -08001076 bitmap.lockPixels();
1077 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001078 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001079 (RsType)type, (RsAllocationMipmapControl)mip,
1080 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001081 bitmap.unlockPixels();
1082 return id;
Jason Samsffe9f482009-06-01 17:45:53 -07001083}
Jason Samsfe08d992009-05-27 14:45:32 -07001084
Tim Murray460a0492013-11-19 12:45:54 -08001085static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001086nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
1087 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -08001088{
1089 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001090 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -08001091 const SkBitmap& bitmap(*nativeBitmap);
1092
1093 bitmap.lockPixels();
1094 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001095 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -08001096 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +00001097 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -08001098 bitmap.unlockPixels();
1099 return id;
1100}
1101
Tim Murray460a0492013-11-19 12:45:54 -08001102static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001103nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1104 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001105{
1106 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001107 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001108 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001109
Jason Sams5476b452010-12-08 16:14:36 -08001110 bitmap.lockPixels();
1111 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001112 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001113 (RsType)type, (RsAllocationMipmapControl)mip,
1114 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001115 bitmap.unlockPixels();
1116 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001117}
1118
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001119static void
Tim Murray460a0492013-11-19 12:45:54 -08001120nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001121{
1122 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001123 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001124 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -08001125 int w = bitmap.width();
1126 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001127
Jason Sams4ef66502010-12-10 16:03:15 -08001128 bitmap.lockPixels();
1129 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001130 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001131 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -08001132 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -08001133 bitmap.unlockPixels();
1134}
1135
1136static void
Tim Murray460a0492013-11-19 12:45:54 -08001137nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -08001138{
1139 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001140 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -08001141 const SkBitmap& bitmap(*nativeBitmap);
1142
1143 bitmap.lockPixels();
1144 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001145 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -08001146 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -07001147 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001148}
1149
Stephen Hines414fa2c2014-04-17 01:02:42 -07001150// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -07001151static void
Tim Murray460a0492013-11-19 12:45:54 -08001152nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001153 jint count, jobject data, jint sizeBytes, jint dataType, jint mSize,
1154 jboolean usePadding)
Jason Samsd19f10d2009-05-22 14:03:28 -07001155{
Jason Samse729a942013-11-06 11:22:02 -08001156 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001157 if (kLogApi) {
1158 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1159 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
1160 dataType);
1161 }
Miao Wang87e908d2015-03-02 15:15:15 -08001162 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true,
1163 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -07001164}
1165
1166static void
Miao Wangc8e237e2015-02-20 18:36:32 -08001167nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1168 jint xoff, jint yoff, jint zoff,
1169 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -07001170{
1171 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -08001172 if (kLogApi) {
Miao Wangc8e237e2015-02-20 18:36:32 -08001173 ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1174 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
Andreas Gampe67333922014-11-10 20:35:59 -08001175 sizeBytes);
1176 }
Chris Wailes488230c32014-08-14 11:22:40 -07001177 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Miao Wangc8e237e2015-02-20 18:36:32 -08001178 rsAllocationElementData((RsContext)con, (RsAllocation)alloc,
1179 xoff, yoff, zoff,
1180 lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -07001181 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1182}
1183
Miao Wangc8e237e2015-02-20 18:36:32 -08001184
Stephen Hines414fa2c2014-04-17 01:02:42 -07001185// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -07001186static void
Tim Murray460a0492013-11-19 12:45:54 -08001187nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001188 jint w, jint h, jobject data, jint sizeBytes, jint dataType, jint mSize,
1189 jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001190{
Jason Samse729a942013-11-06 11:22:02 -08001191 RsAllocation *alloc = (RsAllocation *)_alloc;
1192 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001193 if (kLogApi) {
1194 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1195 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1196 }
Miao Wang87e908d2015-03-02 15:15:15 -08001197 int count = w * h;
1198 PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true,
1199 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -07001200}
1201
Stephen Hines414fa2c2014-04-17 01:02:42 -07001202// Copies from the Allocation pointed to by srcAlloc into the Allocation
1203// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -07001204static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001205nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001206 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001207 jint dstMip, jint dstFace,
1208 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -08001209 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001210 jint srcMip, jint srcFace)
1211{
Andreas Gampe67333922014-11-10 20:35:59 -08001212 if (kLogApi) {
1213 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1214 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
1215 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
1216 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
1217 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
1218 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001219
Tim Murrayeff663f2013-11-15 13:08:30 -08001220 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001221 (RsAllocation)dstAlloc,
1222 dstXoff, dstYoff,
1223 dstMip, dstFace,
1224 width, height,
1225 (RsAllocation)srcAlloc,
1226 srcXoff, srcYoff,
1227 srcMip, srcFace);
1228}
1229
Stephen Hines414fa2c2014-04-17 01:02:42 -07001230// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001231static void
Tim Murray460a0492013-11-19 12:45:54 -08001232nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001233 jint w, jint h, jint d, jobject data, jint sizeBytes, jint dataType,
1234 jint mSize, jboolean usePadding)
Jason Samsb05d6892013-04-09 15:59:24 -07001235{
Jason Samse729a942013-11-06 11:22:02 -08001236 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001237 if (kLogApi) {
1238 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1239 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1240 lod, w, h, d, sizeBytes);
1241 }
Miao Wang87e908d2015-03-02 15:15:15 -08001242 int count = w * h * d;
1243 PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true,
1244 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -07001245}
1246
Stephen Hines414fa2c2014-04-17 01:02:42 -07001247// Copies from the Allocation pointed to by srcAlloc into the Allocation
1248// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -07001249static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001250nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001251 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001252 jint dstMip,
1253 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -08001254 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001255 jint srcMip)
1256{
Andreas Gampe67333922014-11-10 20:35:59 -08001257 if (kLogApi) {
1258 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1259 " dstMip(%i), width(%i), height(%i),"
1260 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
1261 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
1262 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
1263 }
Jason Samsb05d6892013-04-09 15:59:24 -07001264
Tim Murrayeff663f2013-11-15 13:08:30 -08001265 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -07001266 (RsAllocation)dstAlloc,
1267 dstXoff, dstYoff, dstZoff, dstMip,
1268 width, height, depth,
1269 (RsAllocation)srcAlloc,
1270 srcXoff, srcYoff, srcZoff, srcMip);
1271}
1272
Jason Sams21659ac2013-11-06 15:08:07 -08001273
Stephen Hines414fa2c2014-04-17 01:02:42 -07001274// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -07001275static void
Miao Wang87e908d2015-03-02 15:15:15 -08001276nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, jint dataType,
1277 jint mSize, jboolean usePadding)
Jason Sams40a29e82009-08-10 14:55:26 -07001278{
Jason Sams21659ac2013-11-06 15:08:07 -08001279 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001280 if (kLogApi) {
1281 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
1282 }
Miao Wang87e908d2015-03-02 15:15:15 -08001283 int count = 0;
1284 PER_ARRAY_TYPE(0, rsAllocationRead, false,
1285 (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -07001286}
1287
Stephen Hines414fa2c2014-04-17 01:02:42 -07001288// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -07001289static void
Tim Murray460a0492013-11-19 12:45:54 -08001290nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001291 jint count, jobject data, jint sizeBytes, jint dataType,
1292 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001293{
Jason Sams21659ac2013-11-06 15:08:07 -08001294 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001295 if (kLogApi) {
1296 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1297 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
1298 }
Miao Wang87e908d2015-03-02 15:15:15 -08001299 PER_ARRAY_TYPE(0, rsAllocation1DRead, false,
1300 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -08001301}
1302
Miao Wangc8e237e2015-02-20 18:36:32 -08001303// Copies from the Element in the Allocation pointed to by _alloc into the Java array data.
1304static void
Miao Wang45cec0a2015-03-04 16:40:21 -08001305nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
Miao Wangc8e237e2015-02-20 18:36:32 -08001306 jint xoff, jint yoff, jint zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -08001307 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Miao Wangc8e237e2015-02-20 18:36:32 -08001308{
Miao Wang45cec0a2015-03-04 16:40:21 -08001309 jint len = _env->GetArrayLength(data);
Miao Wangc8e237e2015-02-20 18:36:32 -08001310 if (kLogApi) {
Miao Wang45cec0a2015-03-04 16:40:21 -08001311 ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1312 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
1313 sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -08001314 }
Miao Wang45cec0a2015-03-04 16:40:21 -08001315 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
1316 rsAllocationElementRead((RsContext)con, (RsAllocation)alloc,
1317 xoff, yoff, zoff,
Jason Samsa7e25092015-03-11 11:00:00 -07001318 lod, ptr, sizeBytes, compIdx);
Miao Wang45cec0a2015-03-04 16:40:21 -08001319 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
Miao Wangc8e237e2015-02-20 18:36:32 -08001320}
1321
Stephen Hines414fa2c2014-04-17 01:02:42 -07001322// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -08001323static void
Tim Murray460a0492013-11-19 12:45:54 -08001324nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001325 jint w, jint h, jobject data, jint sizeBytes, jint dataType,
1326 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001327{
Jason Sams21659ac2013-11-06 15:08:07 -08001328 RsAllocation *alloc = (RsAllocation *)_alloc;
1329 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001330 if (kLogApi) {
1331 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1332 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1333 }
Miao Wang87e908d2015-03-02 15:15:15 -08001334 int count = w * h;
1335 PER_ARRAY_TYPE(0, rsAllocation2DRead, false,
1336 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -07001337}
Miao Wang87e908d2015-03-02 15:15:15 -08001338
Miao Wangc8e237e2015-02-20 18:36:32 -08001339// Copies from the Allocation pointed to by _alloc into the Java object data.
1340static void
1341nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001342 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType,
1343 jint mSize, jboolean usePadding)
Miao Wangc8e237e2015-02-20 18:36:32 -08001344{
1345 RsAllocation *alloc = (RsAllocation *)_alloc;
1346 if (kLogApi) {
1347 ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1348 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1349 lod, w, h, d, sizeBytes);
1350 }
Miao Wang87e908d2015-03-02 15:15:15 -08001351 int count = w * h * d;
1352 PER_ARRAY_TYPE(nullptr, rsAllocation3DRead, false,
1353 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Miao Wangc8e237e2015-02-20 18:36:32 -08001354}
Jason Samsd19f10d2009-05-22 14:03:28 -07001355
Tim Murray460a0492013-11-19 12:45:54 -08001356static jlong
1357nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001358{
Andreas Gampe67333922014-11-10 20:35:59 -08001359 if (kLogApi) {
1360 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1361 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001362 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001363}
1364
Jason Sams5edc6082010-10-05 13:32:49 -07001365static void
Tim Murray460a0492013-11-19 12:45:54 -08001366nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -07001367{
Andreas Gampe67333922014-11-10 20:35:59 -08001368 if (kLogApi) {
1369 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
1370 (RsAllocation)alloc, dimX);
1371 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001372 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -07001373}
1374
Jason Sams46ba27e32015-02-06 17:45:15 -08001375
1376static jlong
1377nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type)
1378{
1379 if (kLogApi) {
1380 ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)",
1381 (RsContext)con, (RsAllocation)basealloc, (RsElement)type);
1382 }
1383 return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type,
1384 (RsAllocation)basealloc);
1385
1386}
1387
1388static void
1389nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1390 jint x, jint y, jint z, jint face, jint lod,
1391 jint a1, jint a2, jint a3, jint a4)
1392{
1393 uint32_t params[] = {
1394 (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face,
1395 (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4
1396 };
1397 if (kLogApi) {
1398 ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)",
1399 (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4);
1400 }
1401 rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc,
1402 params, sizeof(params));
1403}
1404
1405
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001406// -----------------------------------
1407
Tim Murray460a0492013-11-19 12:45:54 -08001408static jlong
1409nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001410{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001411 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001412 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001413
Tim Murray3aa89c12014-08-18 17:51:22 -07001414 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001415 return id;
1416}
1417
Tim Murray460a0492013-11-19 12:45:54 -08001418static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001419nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001420{
1421 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001422 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001423 return 0;
1424 }
1425
1426 AutoJavaStringToUTF8 str(_env, _path);
1427 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001428 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001429 return 0;
1430 }
1431
Tim Murray3aa89c12014-08-18 17:51:22 -07001432 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001433 return id;
1434}
1435
Tim Murray460a0492013-11-19 12:45:54 -08001436static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001437nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001438{
1439 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001440 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001441
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001442 return id;
1443}
1444
Tim Murray460a0492013-11-19 12:45:54 -08001445static jint
1446nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001447{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001448 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001449 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001450 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001451}
1452
1453static void
Tim Murray460a0492013-11-19 12:45:54 -08001454nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001455{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001456 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001457 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
1458
Tim Murrayeff663f2013-11-15 13:08:30 -08001459 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001460
1461 for(jint i = 0; i < numEntries; i ++) {
1462 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
1463 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
1464 }
1465
1466 free(fileEntries);
1467}
1468
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001469static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001470nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001471{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001472 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001473 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001474 return id;
1475}
Jason Samsd19f10d2009-05-22 14:03:28 -07001476
1477// -----------------------------------
1478
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001479static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001480nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001481 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001482{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001483 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001484 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001485 fileNameUTF.c_str(), fileNameUTF.length(),
1486 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001487
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001488 return id;
1489}
1490
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001491static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001492nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001493 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001494{
1495 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1496 AutoJavaStringToUTF8 nameUTF(_env, name);
1497
Tim Murray3aa89c12014-08-18 17:51:22 -07001498 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001499 nameUTF.c_str(), nameUTF.length(),
1500 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001501 asset->getBuffer(false), asset->getLength());
1502 return id;
1503}
1504
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001505static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001506nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001507 jfloat fontSize, jint dpi)
1508{
1509 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001510 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001511 return 0;
1512 }
1513
1514 AutoJavaStringToUTF8 str(_env, _path);
1515 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001516 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001517 return 0;
1518 }
1519
Tim Murray3aa89c12014-08-18 17:51:22 -07001520 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001521 str.c_str(), str.length(),
1522 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001523 asset->getBuffer(false), asset->getLength());
1524 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001525 return id;
1526}
1527
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001528// -----------------------------------
1529
1530static void
Tim Murray460a0492013-11-19 12:45:54 -08001531nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001532{
Andreas Gampe67333922014-11-10 20:35:59 -08001533 if (kLogApi) {
1534 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1535 (RsScript)script, (RsAllocation)alloc, slot);
1536 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001537 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001538}
1539
1540static void
Tim Murray460a0492013-11-19 12:45:54 -08001541nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001542{
Andreas Gampe67333922014-11-10 20:35:59 -08001543 if (kLogApi) {
1544 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1545 slot, val);
1546 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001547 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001548}
1549
Tim Murray7c4caad2013-04-10 16:21:40 -07001550static jint
Tim Murray460a0492013-11-19 12:45:54 -08001551nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001552{
Andreas Gampe67333922014-11-10 20:35:59 -08001553 if (kLogApi) {
1554 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1555 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001556 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001557 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001558 return value;
1559}
1560
Jason Sams4d339932010-05-11 14:03:58 -07001561static void
Tim Murray460a0492013-11-19 12:45:54 -08001562nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001563{
Andreas Gampe67333922014-11-10 20:35:59 -08001564 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001565 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001566 slot, val);
1567 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001568 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001569}
1570
1571static void
Tim Murray460a0492013-11-19 12:45:54 -08001572nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001573{
Andreas Gampe67333922014-11-10 20:35:59 -08001574 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001575 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001576 slot, val);
1577 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001578 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001579}
1580
Tim Murray7c4caad2013-04-10 16:21:40 -07001581static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001582nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001583{
Andreas Gampe67333922014-11-10 20:35:59 -08001584 if (kLogApi) {
1585 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1586 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001587 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001588 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001589 return value;
1590}
1591
Stephen Hines031ec58c2010-10-11 10:54:21 -07001592static void
Tim Murray460a0492013-11-19 12:45:54 -08001593nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001594{
Andreas Gampe67333922014-11-10 20:35:59 -08001595 if (kLogApi) {
1596 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1597 slot, val);
1598 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001599 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001600}
1601
Tim Murray7c4caad2013-04-10 16:21:40 -07001602static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001603nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001604{
Andreas Gampe67333922014-11-10 20:35:59 -08001605 if (kLogApi) {
1606 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1607 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001608 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001609 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001610 return value;
1611}
1612
Jason Sams4d339932010-05-11 14:03:58 -07001613static void
Tim Murray460a0492013-11-19 12:45:54 -08001614nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001615{
Andreas Gampe67333922014-11-10 20:35:59 -08001616 if (kLogApi) {
1617 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1618 slot, val);
1619 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001620 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001621}
1622
Tim Murray7c4caad2013-04-10 16:21:40 -07001623static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001624nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001625{
Andreas Gampe67333922014-11-10 20:35:59 -08001626 if (kLogApi) {
1627 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1628 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001629 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001630 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001631 return value;
1632}
1633
Stephen Hinesca54ec32010-09-20 17:20:30 -07001634static void
Tim Murray460a0492013-11-19 12:45:54 -08001635nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001636{
Andreas Gampe67333922014-11-10 20:35:59 -08001637 if (kLogApi) {
1638 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1639 }
Jason Sams4d339932010-05-11 14:03:58 -07001640 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001641 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001642 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001643 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1644}
1645
Stephen Hinesadeb8092012-04-20 14:26:06 -07001646static void
Tim Murray460a0492013-11-19 12:45:54 -08001647nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001648{
Andreas Gampe67333922014-11-10 20:35:59 -08001649 if (kLogApi) {
1650 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1651 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001652 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001653 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001654 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001655 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001656}
1657
1658static void
Andreas Gampe67333922014-11-10 20:35:59 -08001659nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1660 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001661{
Andreas Gampe67333922014-11-10 20:35:59 -08001662 if (kLogApi) {
1663 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1664 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001665 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001666 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001667 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001668 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001669 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001670 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001671 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1672 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1673}
1674
Jason Samsd19f10d2009-05-22 14:03:28 -07001675
1676static void
Tim Murray460a0492013-11-19 12:45:54 -08001677nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001678{
Andreas Gampe67333922014-11-10 20:35:59 -08001679 if (kLogApi) {
1680 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1681 }
Romain Guy584a3752009-07-30 18:45:01 -07001682
1683 jint length = _env->GetArrayLength(timeZone);
1684 jbyte* timeZone_ptr;
1685 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1686
Tim Murrayeff663f2013-11-15 13:08:30 -08001687 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001688
1689 if (timeZone_ptr) {
1690 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1691 }
1692}
1693
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001694static void
Tim Murray460a0492013-11-19 12:45:54 -08001695nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001696{
Andreas Gampe67333922014-11-10 20:35:59 -08001697 if (kLogApi) {
1698 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1699 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001700 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001701}
1702
1703static void
Tim Murray460a0492013-11-19 12:45:54 -08001704nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001705{
Andreas Gampe67333922014-11-10 20:35:59 -08001706 if (kLogApi) {
1707 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1708 }
Jason Sams4d339932010-05-11 14:03:58 -07001709 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001710 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001711 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001712 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1713}
1714
Jason Sams6e494d32011-04-27 16:33:11 -07001715static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001716nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1717 jlongArray ains, jlong aout, jbyteArray params,
1718 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001719{
Andreas Gampe67333922014-11-10 20:35:59 -08001720 if (kLogApi) {
1721 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1722 }
Jason Sams6e494d32011-04-27 16:33:11 -07001723
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001724 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001725 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001726
Chris Wailes488230c32014-08-14 11:22:40 -07001727 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001728
Chris Wailes488230c32014-08-14 11:22:40 -07001729 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001730 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001731 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001732
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001733 if (sizeof(RsAllocation) == sizeof(jlong)) {
1734 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001735
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001736 } else {
1737 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001738
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001739 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1740
1741 for (int index = in_len; --index >= 0;) {
1742 in_allocs[index] = (RsAllocation)in_ptr[index];
1743 }
1744 }
Chris Wailes94961062014-06-11 12:01:28 -07001745 }
1746
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001747 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001748 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001749
Chris Wailes488230c32014-08-14 11:22:40 -07001750 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001751 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001752 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001753 }
1754
Chris Wailes488230c32014-08-14 11:22:40 -07001755 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001756 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001757
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001758 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001759 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001760
Chris Wailes488230c32014-08-14 11:22:40 -07001761 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001762 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001763 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001764
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001765 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001766 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001767
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001768 sc.xStart = limit_ptr[0];
1769 sc.xEnd = limit_ptr[1];
1770 sc.yStart = limit_ptr[2];
1771 sc.yEnd = limit_ptr[3];
1772 sc.zStart = limit_ptr[4];
1773 sc.zEnd = limit_ptr[5];
1774 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Jason Sams14331ab2015-01-26 18:14:36 -08001775 sc.arrayStart = 0;
1776 sc.arrayEnd = 0;
1777 sc.array2Start = 0;
1778 sc.array2End = 0;
1779 sc.array3Start = 0;
1780 sc.array3End = 0;
1781 sc.array4Start = 0;
1782 sc.array4End = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001783
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001784 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001785 }
1786
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001787 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1788 in_allocs, in_len, (RsAllocation)aout,
1789 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001790
Chris Wailes488230c32014-08-14 11:22:40 -07001791 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001792 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001793 }
1794
Chris Wailes488230c32014-08-14 11:22:40 -07001795 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001796 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1797 }
1798
Chris Wailes488230c32014-08-14 11:22:40 -07001799 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001800 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1801 }
Chris Wailes94961062014-06-11 12:01:28 -07001802}
1803
Jason Sams22534172009-08-04 16:58:20 -07001804// -----------------------------------
1805
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001806static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001807nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001808 jstring resName, jstring cacheDir,
1809 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001810{
Andreas Gampe67333922014-11-10 20:35:59 -08001811 if (kLogApi) {
1812 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1813 }
Jason Sams22534172009-08-04 16:58:20 -07001814
Jason Samse4a06c52011-03-16 16:29:28 -07001815 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1816 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001817 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001818 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001819 jint _exception = 0;
1820 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001821 if (!scriptRef) {
1822 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001823 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001824 goto exit;
1825 }
Jack Palevich43702d82009-05-28 13:38:16 -07001826 if (length < 0) {
1827 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001828 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001829 goto exit;
1830 }
Jason Samse4a06c52011-03-16 16:29:28 -07001831 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001832 if (remaining < length) {
1833 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001834 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1835 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001836 goto exit;
1837 }
Jason Samse4a06c52011-03-16 16:29:28 -07001838 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001839 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001840
Tim Murrayeff663f2013-11-15 13:08:30 -08001841 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001842
Tim Murray3aa89c12014-08-18 17:51:22 -07001843 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001844 resNameUTF.c_str(), resNameUTF.length(),
1845 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001846 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001847
Jack Palevich43702d82009-05-28 13:38:16 -07001848exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001849 if (script_ptr) {
1850 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001851 _exception ? JNI_ABORT: 0);
1852 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001853
Tim Murray3aa89c12014-08-18 17:51:22 -07001854 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001855}
1856
Tim Murray460a0492013-11-19 12:45:54 -08001857static jlong
1858nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001859{
Andreas Gampe67333922014-11-10 20:35:59 -08001860 if (kLogApi) {
1861 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1862 (void *)eid);
1863 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001864 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001865}
1866
Tim Murray460a0492013-11-19 12:45:54 -08001867static jlong
1868nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001869{
Andreas Gampe67333922014-11-10 20:35:59 -08001870 if (kLogApi) {
1871 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1872 (void *)sid, slot, sig);
1873 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001874 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001875}
1876
Tim Murray460a0492013-11-19 12:45:54 -08001877static jlong
Yang Nibe392ad2015-01-23 17:16:02 -08001878nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
1879{
1880 if (kLogApi) {
Elliott Hughes7ff53fa2015-02-05 21:36:10 -08001881 ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con,
Yang Nibe392ad2015-01-23 17:16:02 -08001882 (void *)sid, slot);
1883 }
1884 return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot);
1885}
1886
1887static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001888nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001889{
Andreas Gampe67333922014-11-10 20:35:59 -08001890 if (kLogApi) {
1891 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1892 slot);
1893 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001894 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001895}
1896
Tim Murray460a0492013-11-19 12:45:54 -08001897static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001898nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1899 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001900{
Andreas Gampe67333922014-11-10 20:35:59 -08001901 if (kLogApi) {
1902 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1903 }
Jason Sams08a81582012-09-18 12:32:10 -07001904
Ashok Bhat98071552014-02-12 09:54:43 +00001905 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001906 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001907 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1908 for(int i = 0; i < kernelsLen; ++i) {
1909 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1910 }
Jason Sams08a81582012-09-18 12:32:10 -07001911
Ashok Bhat98071552014-02-12 09:54:43 +00001912 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001913 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001914 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1915 for(int i = 0; i < srcLen; ++i) {
1916 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1917 }
Jason Sams08a81582012-09-18 12:32:10 -07001918
Ashok Bhat98071552014-02-12 09:54:43 +00001919 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001920 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001921 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1922 for(int i = 0; i < dstkLen; ++i) {
1923 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1924 }
1925
1926 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001927 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001928 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1929 for(int i = 0; i < dstfLen; ++i) {
1930 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1931 }
1932
1933 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001934 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001935 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1936 for(int i = 0; i < typesLen; ++i) {
1937 typesPtr[i] = (RsType)jTypesPtr[i];
1938 }
1939
Tim Murray3aa89c12014-08-18 17:51:22 -07001940 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001941 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1942 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1943 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1944 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1945 (RsType *)typesPtr, typesLen * sizeof(RsType));
1946
1947 free(kernelsPtr);
1948 free(srcPtr);
1949 free(dstkPtr);
1950 free(dstfPtr);
1951 free(typesPtr);
1952 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1953 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1954 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1955 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1956 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001957 return id;
1958}
1959
1960static void
Tim Murray460a0492013-11-19 12:45:54 -08001961nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001962{
Andreas Gampe67333922014-11-10 20:35:59 -08001963 if (kLogApi) {
1964 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1965 (void *)gid, (void *)kid, (void *)alloc);
1966 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001967 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001968}
1969
1970static void
Tim Murray460a0492013-11-19 12:45:54 -08001971nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001972{
Andreas Gampe67333922014-11-10 20:35:59 -08001973 if (kLogApi) {
1974 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1975 (void *)gid, (void *)kid, (void *)alloc);
1976 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001977 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001978}
1979
1980static void
Tim Murray460a0492013-11-19 12:45:54 -08001981nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001982{
Andreas Gampe67333922014-11-10 20:35:59 -08001983 if (kLogApi) {
1984 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
1985 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001986 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001987}
1988
Jason Samsd19f10d2009-05-22 14:03:28 -07001989// ---------------------------------------------------------------------------
1990
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001991static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001992nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001993 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1994 jboolean depthMask, jboolean ditherEnable,
1995 jint srcFunc, jint destFunc,
1996 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001997{
Andreas Gampe67333922014-11-10 20:35:59 -08001998 if (kLogApi) {
1999 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
2000 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002001 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07002002 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
2003 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07002004}
2005
Jason Sams0011bcf2009-12-15 12:58:36 -08002006// ---------------------------------------------------------------------------
2007
2008static void
Tim Murray460a0492013-11-19 12:45:54 -08002009nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08002010{
Andreas Gampe67333922014-11-10 20:35:59 -08002011 if (kLogApi) {
2012 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
2013 (RsProgramVertex)vpv, slot, (RsAllocation)a);
2014 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002015 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08002016}
Jason Sams54c0ec12009-11-30 14:49:55 -08002017
Jason Sams68afd012009-12-17 16:55:08 -08002018static void
Tim Murray460a0492013-11-19 12:45:54 -08002019nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002020{
Andreas Gampe67333922014-11-10 20:35:59 -08002021 if (kLogApi) {
2022 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2023 (RsProgramFragment)vpf, slot, (RsAllocation)a);
2024 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002025 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08002026}
2027
2028static void
Tim Murray460a0492013-11-19 12:45:54 -08002029nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002030{
Andreas Gampe67333922014-11-10 20:35:59 -08002031 if (kLogApi) {
2032 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2033 (RsProgramFragment)vpf, slot, (RsSampler)a);
2034 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002035 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08002036}
2037
Jason Samsd19f10d2009-05-22 14:03:28 -07002038// ---------------------------------------------------------------------------
2039
Tim Murray460a0492013-11-19 12:45:54 -08002040static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002041nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002042 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002043{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002044 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002045 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002046 jint paramLen = _env->GetArrayLength(params);
2047
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002048 int texCount = _env->GetArrayLength(texNames);
2049 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2050 const char ** nameArray = names.c_str();
2051 size_t* sizeArray = names.c_str_len();
2052
Andreas Gampe67333922014-11-10 20:35:59 -08002053 if (kLogApi) {
2054 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2055 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002056
Ashok Bhat98071552014-02-12 09:54:43 +00002057 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2058 for(int i = 0; i < paramLen; ++i) {
2059 paramPtr[i] = (uintptr_t)jParamPtr[i];
2060 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002061 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002062 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002063 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002064
Ashok Bhat98071552014-02-12 09:54:43 +00002065 free(paramPtr);
2066 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002067 return ret;
2068}
2069
2070
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002071// ---------------------------------------------------------------------------
2072
Tim Murray460a0492013-11-19 12:45:54 -08002073static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002074nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002075 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002076{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002077 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002078 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08002079 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002080
Andreas Gampe67333922014-11-10 20:35:59 -08002081 if (kLogApi) {
2082 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2083 }
Jason Sams0011bcf2009-12-15 12:58:36 -08002084
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002085 int texCount = _env->GetArrayLength(texNames);
2086 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2087 const char ** nameArray = names.c_str();
2088 size_t* sizeArray = names.c_str_len();
2089
Ashok Bhat98071552014-02-12 09:54:43 +00002090 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2091 for(int i = 0; i < paramLen; ++i) {
2092 paramPtr[i] = (uintptr_t)jParamPtr[i];
2093 }
2094
Tim Murray3aa89c12014-08-18 17:51:22 -07002095 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002096 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002097 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002098
Ashok Bhat98071552014-02-12 09:54:43 +00002099 free(paramPtr);
2100 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08002101 return ret;
2102}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002103
Jason Samsebfb4362009-09-23 13:57:02 -07002104// ---------------------------------------------------------------------------
2105
Tim Murray460a0492013-11-19 12:45:54 -08002106static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002107nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07002108{
Andreas Gampe67333922014-11-10 20:35:59 -08002109 if (kLogApi) {
2110 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
2111 pointSprite, cull);
2112 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002113 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07002114}
2115
Jason Samsd19f10d2009-05-22 14:03:28 -07002116
2117// ---------------------------------------------------------------------------
2118
2119static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002120nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07002121{
Andreas Gampe67333922014-11-10 20:35:59 -08002122 if (kLogApi) {
2123 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
2124 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002125 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07002126}
2127
2128static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002129nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07002130{
Andreas Gampe67333922014-11-10 20:35:59 -08002131 if (kLogApi) {
2132 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
2133 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002134 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07002135}
2136
2137static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002138nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07002139{
Andreas Gampe67333922014-11-10 20:35:59 -08002140 if (kLogApi) {
2141 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
2142 (RsProgramFragment)pf);
2143 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002144 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07002145}
2146
Jason Sams0826a6f2009-06-15 19:04:56 -07002147static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002148nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07002149{
Andreas Gampe67333922014-11-10 20:35:59 -08002150 if (kLogApi) {
2151 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
2152 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002153 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07002154}
2155
Joe Onoratod7b37742009-08-09 22:57:44 -07002156static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002157nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07002158{
Andreas Gampe67333922014-11-10 20:35:59 -08002159 if (kLogApi) {
2160 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
2161 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002162 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07002163}
2164
Joe Onoratod7b37742009-08-09 22:57:44 -07002165
Jason Sams02fb2cb2009-05-28 15:37:57 -07002166// ---------------------------------------------------------------------------
2167
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002168static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002169nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002170 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07002171{
Andreas Gampe67333922014-11-10 20:35:59 -08002172 if (kLogApi) {
2173 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
2174 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002175 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002176 (RsSamplerValue)magFilter,
2177 (RsSamplerValue)minFilter,
2178 (RsSamplerValue)wrapS,
2179 (RsSamplerValue)wrapT,
2180 (RsSamplerValue)wrapR,
2181 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07002182}
2183
Jason Samsbba134c2009-06-22 15:49:21 -07002184// ---------------------------------------------------------------------------
2185
Tim Murray460a0492013-11-19 12:45:54 -08002186static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00002187nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07002188{
Andreas Gampe67333922014-11-10 20:35:59 -08002189 if (kLogApi) {
2190 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
2191 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002192
2193 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07002194 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002195 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
2196 for(int i = 0; i < vtxLen; ++i) {
2197 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
2198 }
2199
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002200 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07002201 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002202 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
2203 for(int i = 0; i < idxLen; ++i) {
2204 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
2205 }
2206
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002207 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07002208 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002209
Tim Murray3aa89c12014-08-18 17:51:22 -07002210 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002211 (RsAllocation *)vtxPtr, vtxLen,
2212 (RsAllocation *)idxPtr, idxLen,
2213 (uint32_t *)primPtr, primLen);
2214
Ashok Bhat98071552014-02-12 09:54:43 +00002215 free(vtxPtr);
2216 free(idxPtr);
2217 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
2218 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002219 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002220 return id;
2221}
2222
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002223static jint
Tim Murray460a0492013-11-19 12:45:54 -08002224nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002225{
Andreas Gampe67333922014-11-10 20:35:59 -08002226 if (kLogApi) {
2227 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2228 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002229 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002230 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002231 return vtxCount;
2232}
2233
2234static jint
Tim Murray460a0492013-11-19 12:45:54 -08002235nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002236{
Andreas Gampe67333922014-11-10 20:35:59 -08002237 if (kLogApi) {
2238 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2239 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002240 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002241 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002242 return idxCount;
2243}
2244
2245static void
Ashok Bhat98071552014-02-12 09:54:43 +00002246nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002247{
Andreas Gampe67333922014-11-10 20:35:59 -08002248 if (kLogApi) {
2249 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2250 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002251
2252 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08002253 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002254
2255 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002256 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002257 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002258 }
2259
2260 free(allocs);
2261}
2262
2263static void
Ashok Bhat98071552014-02-12 09:54:43 +00002264nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002265{
Andreas Gampe67333922014-11-10 20:35:59 -08002266 if (kLogApi) {
2267 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2268 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002269
2270 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
2271 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
2272
Tim Murrayeff663f2013-11-15 13:08:30 -08002273 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002274
2275 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002276 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002277 const jint prim = (jint)prims[i];
2278 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
2279 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002280 }
2281
2282 free(allocs);
2283 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002284}
2285
Tim Murray56f9e6f2014-05-16 11:47:26 -07002286static jint
2287nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
2288 return (jint)sizeof(void*);
2289}
2290
2291
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002292// ---------------------------------------------------------------------------
2293
Jason Samsd19f10d2009-05-22 14:03:28 -07002294
Jason Sams94d8e90a2009-06-10 16:09:05 -07002295static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07002296
2297static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08002298{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07002299
Tim Murrayeff663f2013-11-15 13:08:30 -08002300{"nDeviceCreate", "()J", (void*)nDeviceCreate },
2301{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
2302{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
2303{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
2304{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
2305{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08002306
Tim Murrayeff663f2013-11-15 13:08:30 -08002307{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
2308{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07002309
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07002310
Jason Sams2e1872f2010-08-17 16:25:41 -07002311// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08002312{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
2313{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
2314{"rsnContextFinish", "(J)V", (void*)nContextFinish },
2315{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
2316{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
2317{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
2318{"rsnContextDump", "(JI)V", (void*)nContextDump },
2319{"rsnContextPause", "(J)V", (void*)nContextPause },
2320{"rsnContextResume", "(J)V", (void*)nContextResume },
2321{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07002322{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002323{"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate },
Yang Ni281c3252014-10-24 08:52:24 -07002324{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
2325{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08002326{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
2327{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
2328{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07002329
Tim Murray460a0492013-11-19 12:45:54 -08002330{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002331{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08002332{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
2333{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
2334{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002335{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07002336
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002337{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
2338{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
2339{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07002340
Tim Murray460a0492013-11-19 12:45:54 -08002341{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002342{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08002343{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00002344{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07002345
Tim Murray460a0492013-11-19 12:45:54 -08002346{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002347{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07002348
Ashok Bhat98071552014-02-12 09:54:43 +00002349{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08002350{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
2351{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
2352{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08002353
Tim Murray460a0492013-11-19 12:45:54 -08002354{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
2355{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08002356
Tim Murray460a0492013-11-19 12:45:54 -08002357{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
2358{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
2359{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
2360{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
2361{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
Miao Wang87e908d2015-03-02 15:15:15 -08002362{"rsnAllocationData1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData1D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002363{"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData },
Miao Wang87e908d2015-03-02 15:15:15 -08002364{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData2D },
Tim Murray460a0492013-11-19 12:45:54 -08002365{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002366{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData3D },
Tim Murray460a0492013-11-19 12:45:54 -08002367{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002368{"rsnAllocationRead", "(JJLjava/lang/Object;IIZ)V", (void*)nAllocationRead },
2369{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead1D },
Miao Wang45cec0a2015-03-04 16:40:21 -08002370{"rsnAllocationElementRead", "(JJIIIII[BI)V", (void*)nAllocationElementRead },
Miao Wang87e908d2015-03-02 15:15:15 -08002371{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead2D },
2372{"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead3D },
Tim Murray460a0492013-11-19 12:45:54 -08002373{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
2374{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
2375{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07002376
Jason Sams46ba27e32015-02-06 17:45:15 -08002377{"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate },
2378{"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset },
2379
Tim Murray460a0492013-11-19 12:45:54 -08002380{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
2381{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
2382{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
2383{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07002384
2385{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
2386
Tim Murray460a0492013-11-19 12:45:54 -08002387{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
2388{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
2389{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
2390{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
2391{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
2392{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
2393{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
2394{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
2395{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
2396{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
2397{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
2398{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07002399
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002400{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002401{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2402{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002403{"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002404{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002405{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Niebf63402015-01-16 11:06:26 -08002406{"rsnScriptGroup2Create", "(JLjava/lang/String;[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002407{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2408{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2409{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002410{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002411
Tim Murray25207df2015-01-12 16:47:56 -08002412{"rsnScriptIntrinsicBLAS_Single", "(JJIIIIIIIIIFJJFJIIII)V", (void*)nScriptIntrinsicBLAS_Single },
2413{"rsnScriptIntrinsicBLAS_Double", "(JJIIIIIIIIIDJJDJIIII)V", (void*)nScriptIntrinsicBLAS_Double },
2414{"rsnScriptIntrinsicBLAS_Complex", "(JJIIIIIIIIIFFJJFFJIIII)V", (void*)nScriptIntrinsicBLAS_Complex },
2415{"rsnScriptIntrinsicBLAS_Z", "(JJIIIIIIIIIDDJJDDJIIII)V", (void*)nScriptIntrinsicBLAS_Z },
2416
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002417{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002418
Tim Murray460a0492013-11-19 12:45:54 -08002419{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2420{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2421{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002422
Ashok Bhat98071552014-02-12 09:54:43 +00002423{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002424{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002425{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002426
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002427{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2428{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2429{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2430{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2431{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002432
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002433{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002434
Ashok Bhat98071552014-02-12 09:54:43 +00002435{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002436
Tim Murray460a0492013-11-19 12:45:54 -08002437{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2438{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002439{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2440{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002441
Tim Murray56f9e6f2014-05-16 11:47:26 -07002442{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002443};
2444
2445static int registerFuncs(JNIEnv *_env)
2446{
2447 return android::AndroidRuntime::registerNativeMethods(
2448 _env, classPathName, methods, NELEM(methods));
2449}
2450
2451// ---------------------------------------------------------------------------
2452
2453jint JNI_OnLoad(JavaVM* vm, void* reserved)
2454{
Chris Wailes488230c32014-08-14 11:22:40 -07002455 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002456 jint result = -1;
2457
Jason Samsd19f10d2009-05-22 14:03:28 -07002458 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002459 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002460 goto bail;
2461 }
Chris Wailes488230c32014-08-14 11:22:40 -07002462 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002463
2464 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002465 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002466 goto bail;
2467 }
2468
2469 /* success -- return valid version number */
2470 result = JNI_VERSION_1_4;
2471
2472bail:
2473 return result;
2474}