blob: a145166f79a75fe3b581d73fe21ddbe03f14dc8b [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; \
Jason Sams21659ac2013-11-06 15:08:07 -080057 size_t typeBytes = 0; \
Stephen Hines414fa2c2014-04-17 01:02:42 -070058 jint relFlag = 0; \
59 if (readonly) { \
60 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
61 relFlag = JNI_ABORT; \
62 } \
Jason Samse729a942013-11-06 11:22:02 -080063 switch(dataType) { \
64 case RS_TYPE_FLOAT_32: \
65 len = _env->GetArrayLength((jfloatArray)data); \
66 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080067 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080068 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070069 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080070 return; \
71 case RS_TYPE_FLOAT_64: \
72 len = _env->GetArrayLength((jdoubleArray)data); \
73 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080074 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -080075 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070076 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080077 return; \
78 case RS_TYPE_SIGNED_8: \
79 case RS_TYPE_UNSIGNED_8: \
80 len = _env->GetArrayLength((jbyteArray)data); \
81 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080082 typeBytes = 1; \
Jason Samse729a942013-11-06 11:22:02 -080083 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070084 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080085 return; \
86 case RS_TYPE_SIGNED_16: \
87 case RS_TYPE_UNSIGNED_16: \
88 len = _env->GetArrayLength((jshortArray)data); \
89 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080090 typeBytes = 2; \
Jason Samse729a942013-11-06 11:22:02 -080091 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070092 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080093 return; \
94 case RS_TYPE_SIGNED_32: \
95 case RS_TYPE_UNSIGNED_32: \
96 len = _env->GetArrayLength((jintArray)data); \
97 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080098 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080099 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700100 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800101 return; \
102 case RS_TYPE_SIGNED_64: \
103 case RS_TYPE_UNSIGNED_64: \
104 len = _env->GetArrayLength((jlongArray)data); \
105 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800106 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -0800107 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700108 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800109 return; \
110 default: \
111 break; \
112 } \
Andreas Gampe67333922014-11-10 20:35:59 -0800113 UNUSED(len, ptr, typeBytes, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800114}
115
116
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800117class AutoJavaStringToUTF8 {
118public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800119 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Chris Wailes488230c32014-08-14 11:22:40 -0700120 fCStr = env->GetStringUTFChars(str, nullptr);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800121 fLength = env->GetStringUTFLength(str);
122 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800123 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800124 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
125 }
126 const char* c_str() const { return fCStr; }
127 jsize length() const { return fLength; }
128
129private:
130 JNIEnv* fEnv;
131 jstring fJStr;
132 const char* fCStr;
133 jsize fLength;
134};
135
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800136class AutoJavaStringArrayToUTF8 {
137public:
138 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
139 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
Chris Wailes488230c32014-08-14 11:22:40 -0700140 mCStrings = nullptr;
141 mSizeArray = nullptr;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800142 if (stringsLength > 0) {
143 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
144 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
145 for (jsize ct = 0; ct < stringsLength; ct ++) {
146 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
Chris Wailes488230c32014-08-14 11:22:40 -0700147 mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800148 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
149 }
150 }
151 }
152 ~AutoJavaStringArrayToUTF8() {
153 for (jsize ct=0; ct < mStringsLength; ct++) {
154 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
155 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
156 }
157 free(mCStrings);
158 free(mSizeArray);
159 }
160 const char **c_str() const { return mCStrings; }
161 size_t *c_str_len() const { return mSizeArray; }
162 jsize length() const { return mStringsLength; }
163
164private:
165 JNIEnv *mEnv;
166 jobjectArray mStrings;
167 const char **mCStrings;
168 size_t *mSizeArray;
169 jsize mStringsLength;
170};
171
Jason Samsd19f10d2009-05-22 14:03:28 -0700172// ---------------------------------------------------------------------------
173
Jason Samsffe9f482009-06-01 17:45:53 -0700174static jfieldID gContextId = 0;
175static jfieldID gNativeBitmapID = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700176
177static void _nInit(JNIEnv *_env, jclass _this)
178{
Tim Murrayeff663f2013-11-15 13:08:30 -0800179 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsffe9f482009-06-01 17:45:53 -0700180
181 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000182 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700183}
184
Jason Samsd19f10d2009-05-22 14:03:28 -0700185// ---------------------------------------------------------------------------
186
Jason Sams3eaa338e2009-06-10 15:04:38 -0700187static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800188nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700189{
Andreas Gampe67333922014-11-10 20:35:59 -0800190 if (kLogApi) {
191 ALOGD("nContextFinish, con(%p)", (RsContext)con);
192 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800193 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700194}
195
Yang Ni281c3252014-10-24 08:52:24 -0700196static jlong
197nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID,
198 jlong returnValue, jlongArray fieldIDArray,
199 jlongArray valueArray, jintArray sizeArray,
200 jlongArray depClosureArray, jlongArray depFieldIDArray) {
201 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
202 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
203 RsScriptFieldID* fieldIDs =
204 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
205 for (int i = 0; i< fieldIDs_length; i++) {
206 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
207 }
208
209 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
210 jsize values_length = _env->GetArrayLength(valueArray);
211 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
212 for (int i = 0; i < values_length; i++) {
213 values[i] = (uintptr_t)jValues[i];
214 }
215
216 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
217 jsize sizes_length = _env->GetArrayLength(sizeArray);
218
219 jlong* jDepClosures =
220 _env->GetLongArrayElements(depClosureArray, nullptr);
221 jsize depClosures_length = _env->GetArrayLength(depClosureArray);
222 RsClosure* depClosures =
223 (RsClosure*)alloca(sizeof(RsClosure) * depClosures_length);
224 for (int i = 0; i < depClosures_length; i++) {
225 depClosures[i] = (RsClosure)jDepClosures[i];
226 }
227
228 jlong* jDepFieldIDs =
229 _env->GetLongArrayElements(depFieldIDArray, nullptr);
230 jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray);
231 RsScriptFieldID* depFieldIDs =
232 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * depFieldIDs_length);
233 for (int i = 0; i < depClosures_length; i++) {
234 depFieldIDs[i] = (RsClosure)jDepFieldIDs[i];
235 }
236
237 return (jlong)(uintptr_t)rsClosureCreate(
238 (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue,
239 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
240 (size_t*)sizes, (size_t)sizes_length,
241 depClosures, (size_t)depClosures_length,
242 depFieldIDs, (size_t)depFieldIDs_length);
243}
244
Yang Nibe392ad2015-01-23 17:16:02 -0800245static jlong
246nInvokeClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong invokeID,
247 jbyteArray paramArray, jlongArray fieldIDArray, jlongArray valueArray,
248 jintArray sizeArray) {
249 jbyte* jParams = _env->GetByteArrayElements(paramArray, nullptr);
250 jsize jParamLength = _env->GetArrayLength(paramArray);
251
252 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
253 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
254 RsScriptFieldID* fieldIDs =
255 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
256 for (int i = 0; i< fieldIDs_length; i++) {
257 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
258 }
259
260 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
261 jsize values_length = _env->GetArrayLength(valueArray);
262 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
263 for (int i = 0; i < values_length; i++) {
264 values[i] = (uintptr_t)jValues[i];
265 }
266
267 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
268 jsize sizes_length = _env->GetArrayLength(sizeArray);
269
270 return (jlong)(uintptr_t)rsInvokeClosureCreate(
271 (RsContext)con, (RsScriptInvokeID)invokeID, jParams, jParamLength,
272 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
273 (size_t*)sizes, (size_t)sizes_length);
274}
275
Yang Ni281c3252014-10-24 08:52:24 -0700276static void
277nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
278 jint index, jlong value, jint size) {
279 rsClosureSetArg((RsContext)con, (RsClosure)closureID, (uint32_t)index,
280 (uintptr_t)value, (size_t)size);
281}
282
283static void
284nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
285 jlong fieldID, jlong value, jint size) {
286 rsClosureSetGlobal((RsContext)con, (RsClosure)closureID,
287 (RsScriptFieldID)fieldID, (uintptr_t)value, (size_t)size);
288}
289
290static long
291nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con,
Yang Niebf63402015-01-16 11:06:26 -0800292 jstring cacheDir, jlongArray closureArray) {
293 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
294
Yang Ni281c3252014-10-24 08:52:24 -0700295 jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr);
296 jsize numClosures = _env->GetArrayLength(closureArray);
297 RsClosure* closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures);
298 for (int i = 0; i < numClosures; i++) {
299 closures[i] = (RsClosure)jClosures[i];
300 }
301
Yang Niebf63402015-01-16 11:06:26 -0800302 return (jlong)(uintptr_t)rsScriptGroup2Create(
303 (RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length(),
304 closures, numClosures);
Yang Ni281c3252014-10-24 08:52:24 -0700305}
306
307static void
308nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) {
309 rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID);
310}
311
Jason Sams96ed4cf2010-06-15 12:15:57 -0700312static void
Tim Murray25207df2015-01-12 16:47:56 -0800313nScriptIntrinsicBLAS_Single(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
314 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
315 jfloat alpha, jlong A, jlong B, jfloat beta, jlong C, jint incX, jint incY,
316 jint KL, jint KU) {
317 RsBlasCall call;
318 memset(&call, 0, sizeof(call));
319 call.func = (RsBlasFunction)func;
320 call.transA = (RsBlasTranspose)TransA;
321 call.transB = (RsBlasTranspose)TransB;
322 call.side = (RsBlasSide)Side;
323 call.uplo = (RsBlasUplo)Uplo;
324 call.diag = (RsBlasDiag)Diag;
325 call.M = M;
326 call.N = N;
327 call.K = K;
328 call.alpha.f = alpha;
329 call.beta.f = beta;
330 call.incX = incX;
331 call.incY = incY;
332 call.KL = KL;
333 call.KU = KU;
334
335 RsAllocation in_allocs[3];
336 in_allocs[0] = (RsAllocation)A;
337 in_allocs[1] = (RsAllocation)B;
338 in_allocs[2] = (RsAllocation)C;
339
340 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
341 in_allocs, sizeof(in_allocs), nullptr,
342 &call, sizeof(call), nullptr, 0);
343}
344
345static void
346nScriptIntrinsicBLAS_Double(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
347 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
348 jdouble alpha, jlong A, jlong B, jdouble beta, jlong C, jint incX, jint incY,
349 jint KL, jint KU) {
350 RsBlasCall call;
351 memset(&call, 0, sizeof(call));
352 call.func = (RsBlasFunction)func;
353 call.transA = (RsBlasTranspose)TransA;
354 call.transB = (RsBlasTranspose)TransB;
355 call.side = (RsBlasSide)Side;
356 call.uplo = (RsBlasUplo)Uplo;
357 call.diag = (RsBlasDiag)Diag;
358 call.M = M;
359 call.N = N;
360 call.K = K;
361 call.alpha.d = alpha;
362 call.beta.d = beta;
363 call.incX = incX;
364 call.incY = incY;
365 call.KL = KL;
366 call.KU = KU;
367
368 RsAllocation in_allocs[3];
369 in_allocs[0] = (RsAllocation)A;
370 in_allocs[1] = (RsAllocation)B;
371 in_allocs[2] = (RsAllocation)C;
372
373 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
374 in_allocs, sizeof(in_allocs), nullptr,
375 &call, sizeof(call), nullptr, 0);
376}
377
378static void
379nScriptIntrinsicBLAS_Complex(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
380 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
381 jfloat alphaX, jfloat alphaY, jlong A, jlong B, jfloat betaX,
382 jfloat betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
383 RsBlasCall call;
384 memset(&call, 0, sizeof(call));
385 call.func = (RsBlasFunction)func;
386 call.transA = (RsBlasTranspose)TransA;
387 call.transB = (RsBlasTranspose)TransB;
388 call.side = (RsBlasSide)Side;
389 call.uplo = (RsBlasUplo)Uplo;
390 call.diag = (RsBlasDiag)Diag;
391 call.M = M;
392 call.N = N;
393 call.K = K;
394 call.alpha.c.r = alphaX;
395 call.alpha.c.i = alphaY;
396 call.beta.c.r = betaX;
397 call.beta.c.r = betaY;
398 call.incX = incX;
399 call.incY = incY;
400 call.KL = KL;
401 call.KU = KU;
402
403 RsAllocation in_allocs[3];
404 in_allocs[0] = (RsAllocation)A;
405 in_allocs[1] = (RsAllocation)B;
406 in_allocs[2] = (RsAllocation)C;
407
408 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
409 in_allocs, sizeof(in_allocs), nullptr,
410 &call, sizeof(call), nullptr, 0);
411}
412
413static void
414nScriptIntrinsicBLAS_Z(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
415 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
416 jdouble alphaX, jdouble alphaY, jlong A, jlong B, jdouble betaX,
417 jdouble betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
418 RsBlasCall call;
419 memset(&call, 0, sizeof(call));
420 call.func = (RsBlasFunction)func;
421 call.transA = (RsBlasTranspose)TransA;
422 call.transB = (RsBlasTranspose)TransB;
423 call.side = (RsBlasSide)Side;
424 call.uplo = (RsBlasUplo)Uplo;
425 call.diag = (RsBlasDiag)Diag;
426 call.M = M;
427 call.N = N;
428 call.K = K;
429 call.alpha.z.r = alphaX;
430 call.alpha.z.i = alphaY;
431 call.beta.z.r = betaX;
432 call.beta.z.r = betaY;
433 call.incX = incX;
434 call.incY = incY;
435 call.KL = KL;
436 call.KU = KU;
437
438 RsAllocation in_allocs[3];
439 in_allocs[0] = (RsAllocation)A;
440 in_allocs[1] = (RsAllocation)B;
441 in_allocs[2] = (RsAllocation)C;
442
443 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
444 in_allocs, sizeof(in_allocs), nullptr,
445 &call, sizeof(call), nullptr, 0);
446}
447
448
449static void
Tim Murray460a0492013-11-19 12:45:54 -0800450nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700451{
Andreas Gampe67333922014-11-10 20:35:59 -0800452 if (kLogApi) {
453 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
454 }
Jason Sams3eaa338e2009-06-10 15:04:38 -0700455 jint len = _env->GetArrayLength(str);
456 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800457 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700458 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
459}
460
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700461static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800462nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700463{
Andreas Gampe67333922014-11-10 20:35:59 -0800464 if (kLogApi) {
465 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
466 }
Chris Wailes488230c32014-08-14 11:22:40 -0700467 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800468 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700469 if(name == nullptr || strlen(name) == 0) {
470 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700471 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700472 return _env->NewStringUTF(name);
473}
474
Jason Sams7ce033d2009-08-18 14:14:24 -0700475static void
Tim Murray460a0492013-11-19 12:45:54 -0800476nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700477{
Andreas Gampe67333922014-11-10 20:35:59 -0800478 if (kLogApi) {
479 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
480 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800481 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700482}
483
Jason Sams3eaa338e2009-06-10 15:04:38 -0700484// ---------------------------------------------------------------------------
485
Tim Murrayeff663f2013-11-15 13:08:30 -0800486static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700487nDeviceCreate(JNIEnv *_env, jobject _this)
488{
Andreas Gampe67333922014-11-10 20:35:59 -0800489 if (kLogApi) {
490 ALOGD("nDeviceCreate");
491 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700492 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700493}
494
495static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800496nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700497{
Andreas Gampe67333922014-11-10 20:35:59 -0800498 if (kLogApi) {
499 ALOGD("nDeviceDestroy");
500 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700501 return rsDeviceDestroy((RsDevice)dev);
502}
503
Jason Samsebfb4362009-09-23 13:57:02 -0700504static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800505nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700506{
Andreas Gampe67333922014-11-10 20:35:59 -0800507 if (kLogApi) {
508 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
509 }
Jason Samsebfb4362009-09-23 13:57:02 -0700510 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
511}
512
Tim Murrayeff663f2013-11-15 13:08:30 -0800513static jlong
Jason Sams81cd2b12014-12-02 12:36:43 -0800514nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700515{
Andreas Gampe67333922014-11-10 20:35:59 -0800516 if (kLogApi) {
517 ALOGD("nContextCreate");
518 }
Jason Sams81cd2b12014-12-02 12:36:43 -0800519 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags);
Jason Sams704ff642010-02-09 16:05:07 -0800520}
521
Tim Murrayeff663f2013-11-15 13:08:30 -0800522static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800523nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000524 jint colorMin, jint colorPref,
525 jint alphaMin, jint alphaPref,
526 jint depthMin, jint depthPref,
527 jint stencilMin, jint stencilPref,
528 jint samplesMin, jint samplesPref, jfloat samplesQ,
529 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800530{
Jason Sams11c8af92010-10-13 15:31:10 -0700531 RsSurfaceConfig sc;
532 sc.alphaMin = alphaMin;
533 sc.alphaPref = alphaPref;
534 sc.colorMin = colorMin;
535 sc.colorPref = colorPref;
536 sc.depthMin = depthMin;
537 sc.depthPref = depthPref;
538 sc.samplesMin = samplesMin;
539 sc.samplesPref = samplesPref;
540 sc.samplesQ = samplesQ;
541
Andreas Gampe67333922014-11-10 20:35:59 -0800542 if (kLogApi) {
543 ALOGD("nContextCreateGL");
544 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700545 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700546}
547
548static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800549nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800550{
Andreas Gampe67333922014-11-10 20:35:59 -0800551 if (kLogApi) {
552 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
553 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800554 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800555}
556
557
558
559static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800560nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800561{
Andreas Gampe67333922014-11-10 20:35:59 -0800562 if (kLogApi) {
563 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
564 width, height, (Surface *)wnd);
565 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800566
Chris Wailes488230c32014-08-14 11:22:40 -0700567 ANativeWindow * window = nullptr;
568 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800569
570 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700571 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800572 }
573
Tim Murrayeff663f2013-11-15 13:08:30 -0800574 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800575}
576
577static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800578nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700579{
Andreas Gampe67333922014-11-10 20:35:59 -0800580 if (kLogApi) {
581 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
582 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800583 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700584}
585
Jason Sams715333b2009-11-17 17:26:46 -0800586static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800587nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800588{
Andreas Gampe67333922014-11-10 20:35:59 -0800589 if (kLogApi) {
590 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
591 }
Jason Sams715333b2009-11-17 17:26:46 -0800592 rsContextDump((RsContext)con, bits);
593}
Jason Samsd19f10d2009-05-22 14:03:28 -0700594
595static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800596nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700597{
Andreas Gampe67333922014-11-10 20:35:59 -0800598 if (kLogApi) {
599 ALOGD("nContextPause, con(%p)", (RsContext)con);
600 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800601 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700602}
603
604static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800605nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700606{
Andreas Gampe67333922014-11-10 20:35:59 -0800607 if (kLogApi) {
608 ALOGD("nContextResume, con(%p)", (RsContext)con);
609 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800610 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700611}
612
Jason Sams1c415172010-11-08 17:06:46 -0800613
614static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800615nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800616{
Andreas Gampe67333922014-11-10 20:35:59 -0800617 if (kLogApi) {
618 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
619 }
Jason Sams1c415172010-11-08 17:06:46 -0800620 char buf[1024];
621
622 size_t receiveLen;
623 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800624 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700625 buf, sizeof(buf),
626 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700627 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800628 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100629 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800630 }
631 return _env->NewStringUTF(buf);
632}
633
Jason Samsedbfabd2011-05-17 15:01:29 -0700634static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800635nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700636{
Jason Sams516c3192009-10-06 13:58:47 -0700637 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800638 if (kLogApi) {
639 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
640 }
Chris Wailes488230c32014-08-14 11:22:40 -0700641 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700642 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800643 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800644 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700645 ptr, len * 4,
646 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700647 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700648 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100649 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700650 }
651 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000652 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800653}
654
655static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800656nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800657{
Andreas Gampe67333922014-11-10 20:35:59 -0800658 if (kLogApi) {
659 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
660 }
Chris Wailes488230c32014-08-14 11:22:40 -0700661 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800662 size_t receiveLen;
663 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800664 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700665 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800666 auxDataPtr[0] = (jint)subID;
667 auxDataPtr[1] = (jint)receiveLen;
668 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000669 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700670}
671
Tim Murrayeff663f2013-11-15 13:08:30 -0800672static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700673{
Andreas Gampe67333922014-11-10 20:35:59 -0800674 if (kLogApi) {
675 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
676 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800677 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700678}
679
Tim Murrayeff663f2013-11-15 13:08:30 -0800680static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700681{
Andreas Gampe67333922014-11-10 20:35:59 -0800682 if (kLogApi) {
683 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
684 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800685 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700686}
687
Jason Sams455d6442013-02-05 19:20:18 -0800688static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800689nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800690{
Chris Wailes488230c32014-08-14 11:22:40 -0700691 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800692 jint len = 0;
693 if (data) {
694 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700695 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800696 }
Andreas Gampe67333922014-11-10 20:35:59 -0800697 if (kLogApi) {
698 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
699 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800700 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800701 if (data) {
702 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
703 }
704}
705
706
Jason Sams516c3192009-10-06 13:58:47 -0700707
Tim Murray460a0492013-11-19 12:45:54 -0800708static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800709nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
710 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700711{
Andreas Gampe67333922014-11-10 20:35:59 -0800712 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100713 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con,
Andreas Gampe67333922014-11-10 20:35:59 -0800714 type, kind, norm, size);
715 }
716 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
717 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700718}
719
Tim Murray460a0492013-11-19 12:45:54 -0800720static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800721nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000722 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700723{
Jason Sams718cd1f2009-12-23 14:35:29 -0800724 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -0800725 if (kLogApi) {
726 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
727 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800728
Chris Wailes488230c32014-08-14 11:22:40 -0700729 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
730 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000731
732 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
733 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
734
735 for(int i = 0; i < fieldCount; i ++) {
736 ids[i] = (RsElement)jIds[i];
737 arraySizes[i] = (uint32_t)jArraySizes[i];
738 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800739
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800740 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
741
742 const char **nameArray = names.c_str();
743 size_t *sizeArray = names.c_str_len();
744
Tim Murray3aa89c12014-08-18 17:51:22 -0700745 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000746 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700747 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700748 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800749
Ashok Bhat98071552014-02-12 09:54:43 +0000750 free(ids);
751 free(arraySizes);
752 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
753 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
754
Tim Murray3aa89c12014-08-18 17:51:22 -0700755 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700756}
757
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700758static void
Tim Murray460a0492013-11-19 12:45:54 -0800759nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700760{
761 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -0800762 if (kLogApi) {
763 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
764 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700765
766 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
767 assert(dataSize == 5);
768
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000769 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800770 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700771
772 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000773 const jint data = (jint)elementData[i];
774 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700775 }
776}
777
778
779static void
Tim Murray460a0492013-11-19 12:45:54 -0800780nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000781 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700782 jobjectArray _names,
783 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700784{
Ashok Bhat98071552014-02-12 09:54:43 +0000785 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -0800786 if (kLogApi) {
787 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
788 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700789
Ashok Bhat98071552014-02-12 09:54:43 +0000790 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
791 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000792 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700793
Andreas Gampe67333922014-11-10 20:35:59 -0800794 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
795 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700796
Ashok Bhat98071552014-02-12 09:54:43 +0000797 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700798 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000799 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700800 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000801 _env->SetLongArrayRegion(_IDs, i, 1, &id);
802 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700803 }
804
805 free(ids);
806 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700807 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700808}
809
Jason Samsd19f10d2009-05-22 14:03:28 -0700810// -----------------------------------
811
Tim Murray460a0492013-11-19 12:45:54 -0800812static jlong
813nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800814 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700815{
Andreas Gampe67333922014-11-10 20:35:59 -0800816 if (kLogApi) {
817 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 +0100818 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv);
Andreas Gampe67333922014-11-10 20:35:59 -0800819 }
Jason Sams3b9c52a2010-10-14 17:48:46 -0700820
Andreas Gampe67333922014-11-10 20:35:59 -0800821 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
822 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700823}
824
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700825static void
Ashok Bhat98071552014-02-12 09:54:43 +0000826nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700827{
828 // We are packing 6 items: mDimX; mDimY; mDimZ;
829 // mDimLOD; mDimFaces; mElement; into typeData
830 int elementCount = _env->GetArrayLength(_typeData);
831
832 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -0800833 if (kLogApi) {
834 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
835 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700836
Ashok Bhat98071552014-02-12 09:54:43 +0000837 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -0800838 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700839
840 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700841 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000842 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700843 }
844}
845
Jason Samsd19f10d2009-05-22 14:03:28 -0700846// -----------------------------------
847
Tim Murray460a0492013-11-19 12:45:54 -0800848static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800849nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
850 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700851{
Andreas Gampe67333922014-11-10 20:35:59 -0800852 if (kLogApi) {
853 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
854 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
855 }
856 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
857 (RsAllocationMipmapControl)mips,
858 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700859}
860
Jason Samsd19f10d2009-05-22 14:03:28 -0700861static void
Tim Murray460a0492013-11-19 12:45:54 -0800862nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -0800863{
Andreas Gampe67333922014-11-10 20:35:59 -0800864 if (kLogApi) {
865 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
866 bits);
867 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800868 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -0800869}
870
Jason Sams72226e02013-02-22 12:45:54 -0800871static jobject
Tim Murray460a0492013-11-19 12:45:54 -0800872nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800873{
Andreas Gampe67333922014-11-10 20:35:59 -0800874 if (kLogApi) {
875 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
876 }
Jason Sams615e7ce2012-01-13 14:01:20 -0800877
Andreas Gampe67333922014-11-10 20:35:59 -0800878 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
879 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -0800880 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -0700881 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700882
Jason Sams72226e02013-02-22 12:45:54 -0800883 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
884 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700885}
886
887static void
Tim Murray460a0492013-11-19 12:45:54 -0800888nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800889{
Andreas Gampe67333922014-11-10 20:35:59 -0800890 if (kLogApi) {
891 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
892 (RsAllocation)alloc, (Surface *)sur);
893 }
Jason Sams163766c2012-02-15 12:04:24 -0800894
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700895 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800896 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700897 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800898 }
899
Andreas Gampe67333922014-11-10 20:35:59 -0800900 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
901 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800902}
903
904static void
Tim Murray460a0492013-11-19 12:45:54 -0800905nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800906{
Andreas Gampe67333922014-11-10 20:35:59 -0800907 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100908 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -0800909 }
Tim Murray460a0492013-11-19 12:45:54 -0800910 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800911}
912
913static void
Tim Murray460a0492013-11-19 12:45:54 -0800914nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800915{
Andreas Gampe67333922014-11-10 20:35:59 -0800916 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100917 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -0800918 }
Tim Murray460a0492013-11-19 12:45:54 -0800919 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800920}
921
922
923static void
Tim Murray460a0492013-11-19 12:45:54 -0800924nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -0800925{
Andreas Gampe67333922014-11-10 20:35:59 -0800926 if (kLogApi) {
927 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
928 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800929 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -0800930}
931
Tim Murray460a0492013-11-19 12:45:54 -0800932static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800933nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
934 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700935{
Jason Samsffe9f482009-06-01 17:45:53 -0700936 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000937 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -0700938 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700939
Jason Sams5476b452010-12-08 16:14:36 -0800940 bitmap.lockPixels();
941 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700942 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700943 (RsType)type, (RsAllocationMipmapControl)mip,
944 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800945 bitmap.unlockPixels();
946 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700947}
Jason Samsfe08d992009-05-27 14:45:32 -0700948
Tim Murray460a0492013-11-19 12:45:54 -0800949static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800950nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
951 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -0800952{
953 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000954 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -0800955 const SkBitmap& bitmap(*nativeBitmap);
956
957 bitmap.lockPixels();
958 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700959 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -0800960 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +0000961 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -0800962 bitmap.unlockPixels();
963 return id;
964}
965
Tim Murray460a0492013-11-19 12:45:54 -0800966static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800967nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
968 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800969{
970 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000971 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800972 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800973
Jason Sams5476b452010-12-08 16:14:36 -0800974 bitmap.lockPixels();
975 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700976 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700977 (RsType)type, (RsAllocationMipmapControl)mip,
978 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800979 bitmap.unlockPixels();
980 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800981}
982
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700983static void
Tim Murray460a0492013-11-19 12:45:54 -0800984nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700985{
986 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000987 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700988 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800989 int w = bitmap.width();
990 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700991
Jason Sams4ef66502010-12-10 16:03:15 -0800992 bitmap.lockPixels();
993 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800994 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700995 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800996 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800997 bitmap.unlockPixels();
998}
999
1000static void
Tim Murray460a0492013-11-19 12:45:54 -08001001nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -08001002{
1003 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001004 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -08001005 const SkBitmap& bitmap(*nativeBitmap);
1006
1007 bitmap.lockPixels();
1008 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001009 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -08001010 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -07001011 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001012}
1013
Stephen Hines414fa2c2014-04-17 01:02:42 -07001014// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -07001015static void
Tim Murray460a0492013-11-19 12:45:54 -08001016nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001017 jint count, jobject data, jint sizeBytes, jint dataType)
Jason Samsd19f10d2009-05-22 14:03:28 -07001018{
Jason Samse729a942013-11-06 11:22:02 -08001019 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001020 if (kLogApi) {
1021 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1022 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
1023 dataType);
1024 }
1025 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count,
1026 ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -07001027}
1028
1029static void
Miao Wangc8e237e2015-02-20 18:36:32 -08001030nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1031 jint xoff, jint yoff, jint zoff,
1032 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -07001033{
1034 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -08001035 if (kLogApi) {
Miao Wangc8e237e2015-02-20 18:36:32 -08001036 ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1037 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
Andreas Gampe67333922014-11-10 20:35:59 -08001038 sizeBytes);
1039 }
Chris Wailes488230c32014-08-14 11:22:40 -07001040 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Miao Wangc8e237e2015-02-20 18:36:32 -08001041 rsAllocationElementData((RsContext)con, (RsAllocation)alloc,
1042 xoff, yoff, zoff,
1043 lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -07001044 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1045}
1046
Miao Wangc8e237e2015-02-20 18:36:32 -08001047
Stephen Hines414fa2c2014-04-17 01:02:42 -07001048// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -07001049static void
Tim Murray460a0492013-11-19 12:45:54 -08001050nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001051 jint w, jint h, jobject data, jint sizeBytes, jint dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001052{
Jason Samse729a942013-11-06 11:22:02 -08001053 RsAllocation *alloc = (RsAllocation *)_alloc;
1054 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001055 if (kLogApi) {
1056 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1057 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1058 }
Chris Wailes488230c32014-08-14 11:22:40 -07001059 PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -07001060}
1061
Stephen Hines414fa2c2014-04-17 01:02:42 -07001062// Copies from the Allocation pointed to by srcAlloc into the Allocation
1063// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -07001064static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001065nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001066 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001067 jint dstMip, jint dstFace,
1068 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -08001069 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001070 jint srcMip, jint srcFace)
1071{
Andreas Gampe67333922014-11-10 20:35:59 -08001072 if (kLogApi) {
1073 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1074 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
1075 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
1076 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
1077 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
1078 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001079
Tim Murrayeff663f2013-11-15 13:08:30 -08001080 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001081 (RsAllocation)dstAlloc,
1082 dstXoff, dstYoff,
1083 dstMip, dstFace,
1084 width, height,
1085 (RsAllocation)srcAlloc,
1086 srcXoff, srcYoff,
1087 srcMip, srcFace);
1088}
1089
Stephen Hines414fa2c2014-04-17 01:02:42 -07001090// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001091static void
Tim Murray460a0492013-11-19 12:45:54 -08001092nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Jason Samse729a942013-11-06 11:22:02 -08001093 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
Jason Samsb05d6892013-04-09 15:59:24 -07001094{
Jason Samse729a942013-11-06 11:22:02 -08001095 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001096 if (kLogApi) {
1097 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1098 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1099 lod, w, h, d, sizeBytes);
1100 }
Chris Wailes488230c32014-08-14 11:22:40 -07001101 PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -07001102}
1103
Stephen Hines414fa2c2014-04-17 01:02:42 -07001104// Copies from the Allocation pointed to by srcAlloc into the Allocation
1105// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -07001106static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001107nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001108 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001109 jint dstMip,
1110 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -08001111 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001112 jint srcMip)
1113{
Andreas Gampe67333922014-11-10 20:35:59 -08001114 if (kLogApi) {
1115 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1116 " dstMip(%i), width(%i), height(%i),"
1117 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
1118 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
1119 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
1120 }
Jason Samsb05d6892013-04-09 15:59:24 -07001121
Tim Murrayeff663f2013-11-15 13:08:30 -08001122 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -07001123 (RsAllocation)dstAlloc,
1124 dstXoff, dstYoff, dstZoff, dstMip,
1125 width, height, depth,
1126 (RsAllocation)srcAlloc,
1127 srcXoff, srcYoff, srcZoff, srcMip);
1128}
1129
Jason Sams21659ac2013-11-06 15:08:07 -08001130
Stephen Hines414fa2c2014-04-17 01:02:42 -07001131// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -07001132static void
Tim Murray460a0492013-11-19 12:45:54 -08001133nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType)
Jason Sams40a29e82009-08-10 14:55:26 -07001134{
Jason Sams21659ac2013-11-06 15:08:07 -08001135 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001136 if (kLogApi) {
1137 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
1138 }
Stephen Hines414fa2c2014-04-17 01:02:42 -07001139 PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -07001140}
1141
Stephen Hines414fa2c2014-04-17 01:02:42 -07001142// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -07001143static void
Tim Murray460a0492013-11-19 12:45:54 -08001144nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Jason Sams21659ac2013-11-06 15:08:07 -08001145 jint count, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001146{
Jason Sams21659ac2013-11-06 15:08:07 -08001147 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001148 if (kLogApi) {
1149 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1150 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
1151 }
Stephen Hines414fa2c2014-04-17 01:02:42 -07001152 PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -08001153}
1154
Miao Wangc8e237e2015-02-20 18:36:32 -08001155// Copies from the Element in the Allocation pointed to by _alloc into the Java array data.
1156static void
1157nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc,
1158 jint xoff, jint yoff, jint zoff,
1159 jint lod, jint compIdx, jobject data, jint sizeBytes, int dataType)
1160{
1161 RsAllocation *alloc = (RsAllocation *)_alloc;
1162 if (kLogApi) {
1163 ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), "
1164 "sizeBytes(%i)", (RsContext)con, alloc, xoff, yoff, zoff, compIdx, sizeBytes);
1165 }
1166 PER_ARRAY_TYPE(0, rsAllocationElementRead, false, (RsContext)con, alloc,
1167 xoff, yoff, zoff, lod, ptr, sizeBytes, compIdx);
1168}
1169
Stephen Hines414fa2c2014-04-17 01:02:42 -07001170// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -08001171static void
Tim Murray460a0492013-11-19 12:45:54 -08001172nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Jason Sams21659ac2013-11-06 15:08:07 -08001173 jint w, jint h, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001174{
Jason Sams21659ac2013-11-06 15:08:07 -08001175 RsAllocation *alloc = (RsAllocation *)_alloc;
1176 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001177 if (kLogApi) {
1178 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1179 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1180 }
1181 PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h,
1182 ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -07001183}
Miao Wangc8e237e2015-02-20 18:36:32 -08001184// Copies from the Allocation pointed to by _alloc into the Java object data.
1185static void
1186nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
1187 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
1188{
1189 RsAllocation *alloc = (RsAllocation *)_alloc;
1190 if (kLogApi) {
1191 ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1192 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1193 lod, w, h, d, sizeBytes);
1194 }
1195 PER_ARRAY_TYPE(0, rsAllocation3DRead, false, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d,
1196 ptr, sizeBytes, 0);
1197}
Jason Samsd19f10d2009-05-22 14:03:28 -07001198
Tim Murray460a0492013-11-19 12:45:54 -08001199static jlong
1200nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001201{
Andreas Gampe67333922014-11-10 20:35:59 -08001202 if (kLogApi) {
1203 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1204 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001205 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001206}
1207
Jason Sams5edc6082010-10-05 13:32:49 -07001208static void
Tim Murray460a0492013-11-19 12:45:54 -08001209nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -07001210{
Andreas Gampe67333922014-11-10 20:35:59 -08001211 if (kLogApi) {
1212 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
1213 (RsAllocation)alloc, dimX);
1214 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001215 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -07001216}
1217
Jason Sams46ba27e32015-02-06 17:45:15 -08001218
1219static jlong
1220nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type)
1221{
1222 if (kLogApi) {
1223 ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)",
1224 (RsContext)con, (RsAllocation)basealloc, (RsElement)type);
1225 }
1226 return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type,
1227 (RsAllocation)basealloc);
1228
1229}
1230
1231static void
1232nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1233 jint x, jint y, jint z, jint face, jint lod,
1234 jint a1, jint a2, jint a3, jint a4)
1235{
1236 uint32_t params[] = {
1237 (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face,
1238 (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4
1239 };
1240 if (kLogApi) {
1241 ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)",
1242 (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4);
1243 }
1244 rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc,
1245 params, sizeof(params));
1246}
1247
1248
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001249// -----------------------------------
1250
Tim Murray460a0492013-11-19 12:45:54 -08001251static jlong
1252nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001253{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001254 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001255 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001256
Tim Murray3aa89c12014-08-18 17:51:22 -07001257 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001258 return id;
1259}
1260
Tim Murray460a0492013-11-19 12:45:54 -08001261static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001262nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001263{
1264 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001265 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001266 return 0;
1267 }
1268
1269 AutoJavaStringToUTF8 str(_env, _path);
1270 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001271 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001272 return 0;
1273 }
1274
Tim Murray3aa89c12014-08-18 17:51:22 -07001275 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001276 return id;
1277}
1278
Tim Murray460a0492013-11-19 12:45:54 -08001279static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001280nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001281{
1282 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001283 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001284
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001285 return id;
1286}
1287
Tim Murray460a0492013-11-19 12:45:54 -08001288static jint
1289nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001290{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001291 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001292 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001293 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001294}
1295
1296static void
Tim Murray460a0492013-11-19 12:45:54 -08001297nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001298{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001299 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001300 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
1301
Tim Murrayeff663f2013-11-15 13:08:30 -08001302 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001303
1304 for(jint i = 0; i < numEntries; i ++) {
1305 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
1306 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
1307 }
1308
1309 free(fileEntries);
1310}
1311
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001312static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001313nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001314{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001315 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001316 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001317 return id;
1318}
Jason Samsd19f10d2009-05-22 14:03:28 -07001319
1320// -----------------------------------
1321
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001322static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001323nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001324 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001325{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001326 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001327 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001328 fileNameUTF.c_str(), fileNameUTF.length(),
1329 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001330
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001331 return id;
1332}
1333
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001334static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001335nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001336 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001337{
1338 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1339 AutoJavaStringToUTF8 nameUTF(_env, name);
1340
Tim Murray3aa89c12014-08-18 17:51:22 -07001341 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001342 nameUTF.c_str(), nameUTF.length(),
1343 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001344 asset->getBuffer(false), asset->getLength());
1345 return id;
1346}
1347
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001348static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001349nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001350 jfloat fontSize, jint dpi)
1351{
1352 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001353 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001354 return 0;
1355 }
1356
1357 AutoJavaStringToUTF8 str(_env, _path);
1358 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001359 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001360 return 0;
1361 }
1362
Tim Murray3aa89c12014-08-18 17:51:22 -07001363 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001364 str.c_str(), str.length(),
1365 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001366 asset->getBuffer(false), asset->getLength());
1367 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001368 return id;
1369}
1370
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001371// -----------------------------------
1372
1373static void
Tim Murray460a0492013-11-19 12:45:54 -08001374nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001375{
Andreas Gampe67333922014-11-10 20:35:59 -08001376 if (kLogApi) {
1377 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1378 (RsScript)script, (RsAllocation)alloc, slot);
1379 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001380 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001381}
1382
1383static void
Tim Murray460a0492013-11-19 12:45:54 -08001384nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001385{
Andreas Gampe67333922014-11-10 20:35:59 -08001386 if (kLogApi) {
1387 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1388 slot, val);
1389 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001390 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001391}
1392
Tim Murray7c4caad2013-04-10 16:21:40 -07001393static jint
Tim Murray460a0492013-11-19 12:45:54 -08001394nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001395{
Andreas Gampe67333922014-11-10 20:35:59 -08001396 if (kLogApi) {
1397 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1398 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001399 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001400 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001401 return value;
1402}
1403
Jason Sams4d339932010-05-11 14:03:58 -07001404static void
Tim Murray460a0492013-11-19 12:45:54 -08001405nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001406{
Andreas Gampe67333922014-11-10 20:35:59 -08001407 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001408 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001409 slot, val);
1410 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001411 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001412}
1413
1414static void
Tim Murray460a0492013-11-19 12:45:54 -08001415nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001416{
Andreas Gampe67333922014-11-10 20:35:59 -08001417 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001418 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001419 slot, val);
1420 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001421 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001422}
1423
Tim Murray7c4caad2013-04-10 16:21:40 -07001424static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001425nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001426{
Andreas Gampe67333922014-11-10 20:35:59 -08001427 if (kLogApi) {
1428 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1429 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001430 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001431 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001432 return value;
1433}
1434
Stephen Hines031ec58c2010-10-11 10:54:21 -07001435static void
Tim Murray460a0492013-11-19 12:45:54 -08001436nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001437{
Andreas Gampe67333922014-11-10 20:35:59 -08001438 if (kLogApi) {
1439 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1440 slot, val);
1441 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001442 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001443}
1444
Tim Murray7c4caad2013-04-10 16:21:40 -07001445static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001446nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001447{
Andreas Gampe67333922014-11-10 20:35:59 -08001448 if (kLogApi) {
1449 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1450 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001451 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001452 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001453 return value;
1454}
1455
Jason Sams4d339932010-05-11 14:03:58 -07001456static void
Tim Murray460a0492013-11-19 12:45:54 -08001457nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001458{
Andreas Gampe67333922014-11-10 20:35:59 -08001459 if (kLogApi) {
1460 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1461 slot, val);
1462 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001463 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001464}
1465
Tim Murray7c4caad2013-04-10 16:21:40 -07001466static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001467nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001468{
Andreas Gampe67333922014-11-10 20:35:59 -08001469 if (kLogApi) {
1470 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1471 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001472 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001473 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001474 return value;
1475}
1476
Stephen Hinesca54ec32010-09-20 17:20:30 -07001477static void
Tim Murray460a0492013-11-19 12:45:54 -08001478nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001479{
Andreas Gampe67333922014-11-10 20:35:59 -08001480 if (kLogApi) {
1481 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1482 }
Jason Sams4d339932010-05-11 14:03:58 -07001483 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001484 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001485 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001486 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1487}
1488
Stephen Hinesadeb8092012-04-20 14:26:06 -07001489static void
Tim Murray460a0492013-11-19 12:45:54 -08001490nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001491{
Andreas Gampe67333922014-11-10 20:35:59 -08001492 if (kLogApi) {
1493 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1494 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001495 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001496 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001497 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001498 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001499}
1500
1501static void
Andreas Gampe67333922014-11-10 20:35:59 -08001502nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1503 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001504{
Andreas Gampe67333922014-11-10 20:35:59 -08001505 if (kLogApi) {
1506 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1507 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001508 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001509 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001510 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001511 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001512 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001513 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001514 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1515 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1516}
1517
Jason Samsd19f10d2009-05-22 14:03:28 -07001518
1519static void
Tim Murray460a0492013-11-19 12:45:54 -08001520nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001521{
Andreas Gampe67333922014-11-10 20:35:59 -08001522 if (kLogApi) {
1523 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1524 }
Romain Guy584a3752009-07-30 18:45:01 -07001525
1526 jint length = _env->GetArrayLength(timeZone);
1527 jbyte* timeZone_ptr;
1528 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1529
Tim Murrayeff663f2013-11-15 13:08:30 -08001530 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001531
1532 if (timeZone_ptr) {
1533 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1534 }
1535}
1536
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001537static void
Tim Murray460a0492013-11-19 12:45:54 -08001538nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001539{
Andreas Gampe67333922014-11-10 20:35:59 -08001540 if (kLogApi) {
1541 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1542 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001543 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001544}
1545
1546static void
Tim Murray460a0492013-11-19 12:45:54 -08001547nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001548{
Andreas Gampe67333922014-11-10 20:35:59 -08001549 if (kLogApi) {
1550 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1551 }
Jason Sams4d339932010-05-11 14:03:58 -07001552 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001553 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001554 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001555 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1556}
1557
Jason Sams6e494d32011-04-27 16:33:11 -07001558static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001559nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1560 jlongArray ains, jlong aout, jbyteArray params,
1561 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001562{
Andreas Gampe67333922014-11-10 20:35:59 -08001563 if (kLogApi) {
1564 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1565 }
Jason Sams6e494d32011-04-27 16:33:11 -07001566
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001567 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001568 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001569
Chris Wailes488230c32014-08-14 11:22:40 -07001570 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001571
Chris Wailes488230c32014-08-14 11:22:40 -07001572 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001573 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001574 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001575
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001576 if (sizeof(RsAllocation) == sizeof(jlong)) {
1577 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001578
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001579 } else {
1580 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001581
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001582 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1583
1584 for (int index = in_len; --index >= 0;) {
1585 in_allocs[index] = (RsAllocation)in_ptr[index];
1586 }
1587 }
Chris Wailes94961062014-06-11 12:01:28 -07001588 }
1589
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001590 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001591 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001592
Chris Wailes488230c32014-08-14 11:22:40 -07001593 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001594 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001595 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001596 }
1597
Chris Wailes488230c32014-08-14 11:22:40 -07001598 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001599 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001600
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001601 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001602 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001603
Chris Wailes488230c32014-08-14 11:22:40 -07001604 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001605 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001606 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001607
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001608 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001609 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001610
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001611 sc.xStart = limit_ptr[0];
1612 sc.xEnd = limit_ptr[1];
1613 sc.yStart = limit_ptr[2];
1614 sc.yEnd = limit_ptr[3];
1615 sc.zStart = limit_ptr[4];
1616 sc.zEnd = limit_ptr[5];
1617 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Jason Sams14331ab2015-01-26 18:14:36 -08001618 sc.arrayStart = 0;
1619 sc.arrayEnd = 0;
1620 sc.array2Start = 0;
1621 sc.array2End = 0;
1622 sc.array3Start = 0;
1623 sc.array3End = 0;
1624 sc.array4Start = 0;
1625 sc.array4End = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001626
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001627 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001628 }
1629
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001630 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1631 in_allocs, in_len, (RsAllocation)aout,
1632 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001633
Chris Wailes488230c32014-08-14 11:22:40 -07001634 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001635 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001636 }
1637
Chris Wailes488230c32014-08-14 11:22:40 -07001638 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001639 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1640 }
1641
Chris Wailes488230c32014-08-14 11:22:40 -07001642 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001643 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1644 }
Chris Wailes94961062014-06-11 12:01:28 -07001645}
1646
Jason Sams22534172009-08-04 16:58:20 -07001647// -----------------------------------
1648
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001649static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001650nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001651 jstring resName, jstring cacheDir,
1652 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001653{
Andreas Gampe67333922014-11-10 20:35:59 -08001654 if (kLogApi) {
1655 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1656 }
Jason Sams22534172009-08-04 16:58:20 -07001657
Jason Samse4a06c52011-03-16 16:29:28 -07001658 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1659 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001660 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001661 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001662 jint _exception = 0;
1663 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001664 if (!scriptRef) {
1665 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001666 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001667 goto exit;
1668 }
Jack Palevich43702d82009-05-28 13:38:16 -07001669 if (length < 0) {
1670 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001671 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001672 goto exit;
1673 }
Jason Samse4a06c52011-03-16 16:29:28 -07001674 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001675 if (remaining < length) {
1676 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001677 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1678 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001679 goto exit;
1680 }
Jason Samse4a06c52011-03-16 16:29:28 -07001681 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001682 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001683
Tim Murrayeff663f2013-11-15 13:08:30 -08001684 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001685
Tim Murray3aa89c12014-08-18 17:51:22 -07001686 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001687 resNameUTF.c_str(), resNameUTF.length(),
1688 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001689 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001690
Jack Palevich43702d82009-05-28 13:38:16 -07001691exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001692 if (script_ptr) {
1693 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001694 _exception ? JNI_ABORT: 0);
1695 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001696
Tim Murray3aa89c12014-08-18 17:51:22 -07001697 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001698}
1699
Tim Murray460a0492013-11-19 12:45:54 -08001700static jlong
1701nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001702{
Andreas Gampe67333922014-11-10 20:35:59 -08001703 if (kLogApi) {
1704 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1705 (void *)eid);
1706 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001707 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001708}
1709
Tim Murray460a0492013-11-19 12:45:54 -08001710static jlong
1711nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001712{
Andreas Gampe67333922014-11-10 20:35:59 -08001713 if (kLogApi) {
1714 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1715 (void *)sid, slot, sig);
1716 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001717 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001718}
1719
Tim Murray460a0492013-11-19 12:45:54 -08001720static jlong
Yang Nibe392ad2015-01-23 17:16:02 -08001721nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
1722{
1723 if (kLogApi) {
Elliott Hughes7ff53fa2015-02-05 21:36:10 -08001724 ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con,
Yang Nibe392ad2015-01-23 17:16:02 -08001725 (void *)sid, slot);
1726 }
1727 return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot);
1728}
1729
1730static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001731nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001732{
Andreas Gampe67333922014-11-10 20:35:59 -08001733 if (kLogApi) {
1734 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1735 slot);
1736 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001737 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001738}
1739
Tim Murray460a0492013-11-19 12:45:54 -08001740static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001741nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1742 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001743{
Andreas Gampe67333922014-11-10 20:35:59 -08001744 if (kLogApi) {
1745 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1746 }
Jason Sams08a81582012-09-18 12:32:10 -07001747
Ashok Bhat98071552014-02-12 09:54:43 +00001748 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001749 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001750 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1751 for(int i = 0; i < kernelsLen; ++i) {
1752 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1753 }
Jason Sams08a81582012-09-18 12:32:10 -07001754
Ashok Bhat98071552014-02-12 09:54:43 +00001755 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001756 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001757 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1758 for(int i = 0; i < srcLen; ++i) {
1759 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1760 }
Jason Sams08a81582012-09-18 12:32:10 -07001761
Ashok Bhat98071552014-02-12 09:54:43 +00001762 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001763 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001764 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1765 for(int i = 0; i < dstkLen; ++i) {
1766 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1767 }
1768
1769 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001770 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001771 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1772 for(int i = 0; i < dstfLen; ++i) {
1773 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1774 }
1775
1776 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001777 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001778 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1779 for(int i = 0; i < typesLen; ++i) {
1780 typesPtr[i] = (RsType)jTypesPtr[i];
1781 }
1782
Tim Murray3aa89c12014-08-18 17:51:22 -07001783 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001784 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1785 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1786 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1787 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1788 (RsType *)typesPtr, typesLen * sizeof(RsType));
1789
1790 free(kernelsPtr);
1791 free(srcPtr);
1792 free(dstkPtr);
1793 free(dstfPtr);
1794 free(typesPtr);
1795 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1796 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1797 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1798 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1799 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001800 return id;
1801}
1802
1803static void
Tim Murray460a0492013-11-19 12:45:54 -08001804nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001805{
Andreas Gampe67333922014-11-10 20:35:59 -08001806 if (kLogApi) {
1807 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1808 (void *)gid, (void *)kid, (void *)alloc);
1809 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001810 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001811}
1812
1813static void
Tim Murray460a0492013-11-19 12:45:54 -08001814nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001815{
Andreas Gampe67333922014-11-10 20:35:59 -08001816 if (kLogApi) {
1817 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1818 (void *)gid, (void *)kid, (void *)alloc);
1819 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001820 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001821}
1822
1823static void
Tim Murray460a0492013-11-19 12:45:54 -08001824nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001825{
Andreas Gampe67333922014-11-10 20:35:59 -08001826 if (kLogApi) {
1827 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
1828 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001829 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001830}
1831
Jason Samsd19f10d2009-05-22 14:03:28 -07001832// ---------------------------------------------------------------------------
1833
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001834static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001835nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001836 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1837 jboolean depthMask, jboolean ditherEnable,
1838 jint srcFunc, jint destFunc,
1839 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001840{
Andreas Gampe67333922014-11-10 20:35:59 -08001841 if (kLogApi) {
1842 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
1843 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001844 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07001845 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1846 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001847}
1848
Jason Sams0011bcf2009-12-15 12:58:36 -08001849// ---------------------------------------------------------------------------
1850
1851static void
Tim Murray460a0492013-11-19 12:45:54 -08001852nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001853{
Andreas Gampe67333922014-11-10 20:35:59 -08001854 if (kLogApi) {
1855 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
1856 (RsProgramVertex)vpv, slot, (RsAllocation)a);
1857 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001858 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08001859}
Jason Sams54c0ec12009-11-30 14:49:55 -08001860
Jason Sams68afd012009-12-17 16:55:08 -08001861static void
Tim Murray460a0492013-11-19 12:45:54 -08001862nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001863{
Andreas Gampe67333922014-11-10 20:35:59 -08001864 if (kLogApi) {
1865 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1866 (RsProgramFragment)vpf, slot, (RsAllocation)a);
1867 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001868 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08001869}
1870
1871static void
Tim Murray460a0492013-11-19 12:45:54 -08001872nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001873{
Andreas Gampe67333922014-11-10 20:35:59 -08001874 if (kLogApi) {
1875 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1876 (RsProgramFragment)vpf, slot, (RsSampler)a);
1877 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001878 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08001879}
1880
Jason Samsd19f10d2009-05-22 14:03:28 -07001881// ---------------------------------------------------------------------------
1882
Tim Murray460a0492013-11-19 12:45:54 -08001883static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001884nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001885 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001886{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001887 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001888 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001889 jint paramLen = _env->GetArrayLength(params);
1890
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001891 int texCount = _env->GetArrayLength(texNames);
1892 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1893 const char ** nameArray = names.c_str();
1894 size_t* sizeArray = names.c_str_len();
1895
Andreas Gampe67333922014-11-10 20:35:59 -08001896 if (kLogApi) {
1897 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1898 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001899
Ashok Bhat98071552014-02-12 09:54:43 +00001900 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1901 for(int i = 0; i < paramLen; ++i) {
1902 paramPtr[i] = (uintptr_t)jParamPtr[i];
1903 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001904 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001905 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001906 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001907
Ashok Bhat98071552014-02-12 09:54:43 +00001908 free(paramPtr);
1909 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001910 return ret;
1911}
1912
1913
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001914// ---------------------------------------------------------------------------
1915
Tim Murray460a0492013-11-19 12:45:54 -08001916static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001917nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001918 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001919{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001920 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001921 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08001922 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001923
Andreas Gampe67333922014-11-10 20:35:59 -08001924 if (kLogApi) {
1925 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1926 }
Jason Sams0011bcf2009-12-15 12:58:36 -08001927
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001928 int texCount = _env->GetArrayLength(texNames);
1929 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1930 const char ** nameArray = names.c_str();
1931 size_t* sizeArray = names.c_str_len();
1932
Ashok Bhat98071552014-02-12 09:54:43 +00001933 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1934 for(int i = 0; i < paramLen; ++i) {
1935 paramPtr[i] = (uintptr_t)jParamPtr[i];
1936 }
1937
Tim Murray3aa89c12014-08-18 17:51:22 -07001938 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001939 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001940 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001941
Ashok Bhat98071552014-02-12 09:54:43 +00001942 free(paramPtr);
1943 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08001944 return ret;
1945}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001946
Jason Samsebfb4362009-09-23 13:57:02 -07001947// ---------------------------------------------------------------------------
1948
Tim Murray460a0492013-11-19 12:45:54 -08001949static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001950nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001951{
Andreas Gampe67333922014-11-10 20:35:59 -08001952 if (kLogApi) {
1953 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
1954 pointSprite, cull);
1955 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001956 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001957}
1958
Jason Samsd19f10d2009-05-22 14:03:28 -07001959
1960// ---------------------------------------------------------------------------
1961
1962static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001963nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001964{
Andreas Gampe67333922014-11-10 20:35:59 -08001965 if (kLogApi) {
1966 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
1967 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001968 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001969}
1970
1971static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001972nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001973{
Andreas Gampe67333922014-11-10 20:35:59 -08001974 if (kLogApi) {
1975 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
1976 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001977 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001978}
1979
1980static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001981nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001982{
Andreas Gampe67333922014-11-10 20:35:59 -08001983 if (kLogApi) {
1984 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
1985 (RsProgramFragment)pf);
1986 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001987 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001988}
1989
Jason Sams0826a6f2009-06-15 19:04:56 -07001990static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001991nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001992{
Andreas Gampe67333922014-11-10 20:35:59 -08001993 if (kLogApi) {
1994 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
1995 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001996 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001997}
1998
Joe Onoratod7b37742009-08-09 22:57:44 -07001999static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002000nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07002001{
Andreas Gampe67333922014-11-10 20:35:59 -08002002 if (kLogApi) {
2003 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
2004 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002005 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07002006}
2007
Joe Onoratod7b37742009-08-09 22:57:44 -07002008
Jason Sams02fb2cb2009-05-28 15:37:57 -07002009// ---------------------------------------------------------------------------
2010
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002011static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002012nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002013 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07002014{
Andreas Gampe67333922014-11-10 20:35:59 -08002015 if (kLogApi) {
2016 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
2017 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002018 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002019 (RsSamplerValue)magFilter,
2020 (RsSamplerValue)minFilter,
2021 (RsSamplerValue)wrapS,
2022 (RsSamplerValue)wrapT,
2023 (RsSamplerValue)wrapR,
2024 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07002025}
2026
Jason Samsbba134c2009-06-22 15:49:21 -07002027// ---------------------------------------------------------------------------
2028
Tim Murray460a0492013-11-19 12:45:54 -08002029static jlong
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002030nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) {
Andreas Gampe67333922014-11-10 20:35:59 -08002031 if (kLogApi) {
2032 ALOGD("nPathCreate, con(%p)", (RsContext)con);
2033 }
Jason Samsf15ed012011-10-31 13:23:43 -07002034
Tim Murray3aa89c12014-08-18 17:51:22 -07002035 jlong id = (jlong)(uintptr_t)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic,
Tim Murray460a0492013-11-19 12:45:54 -08002036 (RsAllocation)_vtx,
2037 (RsAllocation)_loop, q);
Jason Samsf15ed012011-10-31 13:23:43 -07002038 return id;
2039}
2040
Tim Murray460a0492013-11-19 12:45:54 -08002041static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00002042nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07002043{
Andreas Gampe67333922014-11-10 20:35:59 -08002044 if (kLogApi) {
2045 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
2046 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002047
2048 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07002049 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002050 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
2051 for(int i = 0; i < vtxLen; ++i) {
2052 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
2053 }
2054
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002055 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07002056 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002057 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
2058 for(int i = 0; i < idxLen; ++i) {
2059 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
2060 }
2061
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002062 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07002063 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002064
Tim Murray3aa89c12014-08-18 17:51:22 -07002065 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002066 (RsAllocation *)vtxPtr, vtxLen,
2067 (RsAllocation *)idxPtr, idxLen,
2068 (uint32_t *)primPtr, primLen);
2069
Ashok Bhat98071552014-02-12 09:54:43 +00002070 free(vtxPtr);
2071 free(idxPtr);
2072 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
2073 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002074 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002075 return id;
2076}
2077
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002078static jint
Tim Murray460a0492013-11-19 12:45:54 -08002079nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002080{
Andreas Gampe67333922014-11-10 20:35:59 -08002081 if (kLogApi) {
2082 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2083 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002084 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002085 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002086 return vtxCount;
2087}
2088
2089static jint
Tim Murray460a0492013-11-19 12:45:54 -08002090nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002091{
Andreas Gampe67333922014-11-10 20:35:59 -08002092 if (kLogApi) {
2093 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2094 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002095 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002096 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002097 return idxCount;
2098}
2099
2100static void
Ashok Bhat98071552014-02-12 09:54:43 +00002101nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002102{
Andreas Gampe67333922014-11-10 20:35:59 -08002103 if (kLogApi) {
2104 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2105 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002106
2107 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08002108 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002109
2110 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002111 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002112 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002113 }
2114
2115 free(allocs);
2116}
2117
2118static void
Ashok Bhat98071552014-02-12 09:54:43 +00002119nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002120{
Andreas Gampe67333922014-11-10 20:35:59 -08002121 if (kLogApi) {
2122 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2123 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002124
2125 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
2126 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
2127
Tim Murrayeff663f2013-11-15 13:08:30 -08002128 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002129
2130 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002131 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002132 const jint prim = (jint)prims[i];
2133 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
2134 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002135 }
2136
2137 free(allocs);
2138 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002139}
2140
Tim Murray56f9e6f2014-05-16 11:47:26 -07002141static jint
2142nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
2143 return (jint)sizeof(void*);
2144}
2145
2146
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002147// ---------------------------------------------------------------------------
2148
Jason Samsd19f10d2009-05-22 14:03:28 -07002149
Jason Sams94d8e90a2009-06-10 16:09:05 -07002150static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07002151
2152static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08002153{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07002154
Tim Murrayeff663f2013-11-15 13:08:30 -08002155{"nDeviceCreate", "()J", (void*)nDeviceCreate },
2156{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
2157{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
2158{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
2159{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
2160{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08002161
Tim Murrayeff663f2013-11-15 13:08:30 -08002162{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
2163{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07002164
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07002165
Jason Sams2e1872f2010-08-17 16:25:41 -07002166// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08002167{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
2168{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
2169{"rsnContextFinish", "(J)V", (void*)nContextFinish },
2170{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
2171{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
2172{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
2173{"rsnContextDump", "(JI)V", (void*)nContextDump },
2174{"rsnContextPause", "(J)V", (void*)nContextPause },
2175{"rsnContextResume", "(J)V", (void*)nContextResume },
2176{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07002177{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002178{"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate },
Yang Ni281c3252014-10-24 08:52:24 -07002179{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
2180{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08002181{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
2182{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
2183{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07002184
Tim Murray460a0492013-11-19 12:45:54 -08002185{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002186{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08002187{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
2188{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
2189{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002190{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07002191
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002192{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
2193{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
2194{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07002195
Tim Murray460a0492013-11-19 12:45:54 -08002196{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002197{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08002198{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00002199{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07002200
Tim Murray460a0492013-11-19 12:45:54 -08002201{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002202{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07002203
Ashok Bhat98071552014-02-12 09:54:43 +00002204{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08002205{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
2206{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
2207{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08002208
Tim Murray460a0492013-11-19 12:45:54 -08002209{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
2210{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08002211
Tim Murray460a0492013-11-19 12:45:54 -08002212{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
2213{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
2214{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
2215{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
2216{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
2217{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002218{"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData },
Tim Murray460a0492013-11-19 12:45:54 -08002219{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
2220{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
2221{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
2222{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
2223{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead },
2224{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002225{"rsnAllocationElementRead", "(JJIIIIILjava/lang/Object;II)V", (void*)nAllocationElementRead },
Tim Murray460a0492013-11-19 12:45:54 -08002226{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002227{"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead3D },
Tim Murray460a0492013-11-19 12:45:54 -08002228{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
2229{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
2230{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07002231
Jason Sams46ba27e32015-02-06 17:45:15 -08002232{"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate },
2233{"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset },
2234
Tim Murray460a0492013-11-19 12:45:54 -08002235{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
2236{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
2237{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
2238{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07002239
2240{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
2241
Tim Murray460a0492013-11-19 12:45:54 -08002242{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
2243{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
2244{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
2245{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
2246{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
2247{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
2248{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
2249{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
2250{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
2251{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
2252{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
2253{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07002254
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002255{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002256{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2257{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002258{"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002259{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002260{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Niebf63402015-01-16 11:06:26 -08002261{"rsnScriptGroup2Create", "(JLjava/lang/String;[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002262{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2263{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2264{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002265{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002266
Tim Murray25207df2015-01-12 16:47:56 -08002267{"rsnScriptIntrinsicBLAS_Single", "(JJIIIIIIIIIFJJFJIIII)V", (void*)nScriptIntrinsicBLAS_Single },
2268{"rsnScriptIntrinsicBLAS_Double", "(JJIIIIIIIIIDJJDJIIII)V", (void*)nScriptIntrinsicBLAS_Double },
2269{"rsnScriptIntrinsicBLAS_Complex", "(JJIIIIIIIIIFFJJFFJIIII)V", (void*)nScriptIntrinsicBLAS_Complex },
2270{"rsnScriptIntrinsicBLAS_Z", "(JJIIIIIIIIIDDJJDDJIIII)V", (void*)nScriptIntrinsicBLAS_Z },
2271
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002272{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002273
Tim Murray460a0492013-11-19 12:45:54 -08002274{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2275{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2276{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002277
Ashok Bhat98071552014-02-12 09:54:43 +00002278{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002279{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002280{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002281
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002282{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2283{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2284{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2285{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2286{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002287
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002288{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002289
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002290{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002291{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002292
Tim Murray460a0492013-11-19 12:45:54 -08002293{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2294{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002295{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2296{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002297
Tim Murray56f9e6f2014-05-16 11:47:26 -07002298{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002299};
2300
2301static int registerFuncs(JNIEnv *_env)
2302{
2303 return android::AndroidRuntime::registerNativeMethods(
2304 _env, classPathName, methods, NELEM(methods));
2305}
2306
2307// ---------------------------------------------------------------------------
2308
2309jint JNI_OnLoad(JavaVM* vm, void* reserved)
2310{
Chris Wailes488230c32014-08-14 11:22:40 -07002311 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002312 jint result = -1;
2313
Jason Samsd19f10d2009-05-22 14:03:28 -07002314 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002315 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002316 goto bail;
2317 }
Chris Wailes488230c32014-08-14 11:22:40 -07002318 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002319
2320 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002321 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002322 goto bail;
2323 }
2324
2325 /* success -- return valid version number */
2326 result = JNI_VERSION_1_4;
2327
2328bail:
2329 return result;
2330}