blob: d8e146435d54c27d06506687a05d41f049e69c26 [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
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080027#include <androidfw/Asset.h>
28#include <androidfw/AssetManager.h>
29#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070030
Jason Samsd19f10d2009-05-22 14:03:28 -070031#include "jni.h"
32#include "JNIHelp.h"
33#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070034#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080035#include "android_runtime/android_util_AssetManager.h"
John Reckf4faeac2015-03-05 13:50:31 -080036#include "android/graphics/GraphicsJNI.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070037
Jason Sams1d6983a2012-02-16 16:07:49 -080038#include <rs.h>
39#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070040#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080041#include <gui/GLConsumer.h>
Mathias Agopian52800612013-02-14 17:11:20 -080042#include <gui/Surface.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070043#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070044
Steve Block3762c312012-01-06 19:20:56 +000045//#define LOG_API ALOGE
Andreas Gampe67333922014-11-10 20:35:59 -080046static constexpr bool kLogApi = false;
Jason Samsd19f10d2009-05-22 14:03:28 -070047
48using namespace android;
49
Andreas Gampe67333922014-11-10 20:35:59 -080050template <typename... T>
51void UNUSED(T... t) {}
52
Stephen Hines414fa2c2014-04-17 01:02:42 -070053#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \
Jason Samse729a942013-11-06 11:22:02 -080054 jint len = 0; \
Chris Wailes488230c32014-08-14 11:22:40 -070055 void *ptr = nullptr; \
Jason Sams21659ac2013-11-06 15:08:07 -080056 size_t typeBytes = 0; \
Stephen Hines414fa2c2014-04-17 01:02:42 -070057 jint relFlag = 0; \
58 if (readonly) { \
59 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
60 relFlag = JNI_ABORT; \
61 } \
Jason Samse729a942013-11-06 11:22:02 -080062 switch(dataType) { \
63 case RS_TYPE_FLOAT_32: \
64 len = _env->GetArrayLength((jfloatArray)data); \
65 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080066 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080067 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070068 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080069 return; \
70 case RS_TYPE_FLOAT_64: \
71 len = _env->GetArrayLength((jdoubleArray)data); \
72 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080073 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -080074 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070075 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080076 return; \
77 case RS_TYPE_SIGNED_8: \
78 case RS_TYPE_UNSIGNED_8: \
79 len = _env->GetArrayLength((jbyteArray)data); \
80 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080081 typeBytes = 1; \
Jason Samse729a942013-11-06 11:22:02 -080082 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070083 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080084 return; \
85 case RS_TYPE_SIGNED_16: \
86 case RS_TYPE_UNSIGNED_16: \
87 len = _env->GetArrayLength((jshortArray)data); \
88 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080089 typeBytes = 2; \
Jason Samse729a942013-11-06 11:22:02 -080090 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070091 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080092 return; \
93 case RS_TYPE_SIGNED_32: \
94 case RS_TYPE_UNSIGNED_32: \
95 len = _env->GetArrayLength((jintArray)data); \
96 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080097 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080098 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070099 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800100 return; \
101 case RS_TYPE_SIGNED_64: \
102 case RS_TYPE_UNSIGNED_64: \
103 len = _env->GetArrayLength((jlongArray)data); \
104 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800105 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -0800106 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700107 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800108 return; \
109 default: \
110 break; \
111 } \
Andreas Gampe67333922014-11-10 20:35:59 -0800112 UNUSED(len, ptr, typeBytes, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800113}
114
115
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800116class AutoJavaStringToUTF8 {
117public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800118 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Chris Wailes488230c32014-08-14 11:22:40 -0700119 fCStr = env->GetStringUTFChars(str, nullptr);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800120 fLength = env->GetStringUTFLength(str);
121 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800122 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800123 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
124 }
125 const char* c_str() const { return fCStr; }
126 jsize length() const { return fLength; }
127
128private:
129 JNIEnv* fEnv;
130 jstring fJStr;
131 const char* fCStr;
132 jsize fLength;
133};
134
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800135class AutoJavaStringArrayToUTF8 {
136public:
137 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
138 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
Chris Wailes488230c32014-08-14 11:22:40 -0700139 mCStrings = nullptr;
140 mSizeArray = nullptr;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800141 if (stringsLength > 0) {
142 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
143 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
144 for (jsize ct = 0; ct < stringsLength; ct ++) {
145 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
Chris Wailes488230c32014-08-14 11:22:40 -0700146 mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800147 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
148 }
149 }
150 }
151 ~AutoJavaStringArrayToUTF8() {
152 for (jsize ct=0; ct < mStringsLength; ct++) {
153 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
154 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
155 }
156 free(mCStrings);
157 free(mSizeArray);
158 }
159 const char **c_str() const { return mCStrings; }
160 size_t *c_str_len() const { return mSizeArray; }
161 jsize length() const { return mStringsLength; }
162
163private:
164 JNIEnv *mEnv;
165 jobjectArray mStrings;
166 const char **mCStrings;
167 size_t *mSizeArray;
168 jsize mStringsLength;
169};
170
Jason Samsd19f10d2009-05-22 14:03:28 -0700171// ---------------------------------------------------------------------------
172
Jason Samsffe9f482009-06-01 17:45:53 -0700173static jfieldID gContextId = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700174
175static void _nInit(JNIEnv *_env, jclass _this)
176{
Tim Murrayeff663f2013-11-15 13:08:30 -0800177 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700178}
179
Jason Samsd19f10d2009-05-22 14:03:28 -0700180// ---------------------------------------------------------------------------
181
Jason Sams3eaa338e2009-06-10 15:04:38 -0700182static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800183nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700184{
Andreas Gampe67333922014-11-10 20:35:59 -0800185 if (kLogApi) {
186 ALOGD("nContextFinish, con(%p)", (RsContext)con);
187 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800188 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700189}
190
Yang Ni281c3252014-10-24 08:52:24 -0700191static jlong
192nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID,
193 jlong returnValue, jlongArray fieldIDArray,
194 jlongArray valueArray, jintArray sizeArray,
195 jlongArray depClosureArray, jlongArray depFieldIDArray) {
196 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
197 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
198 RsScriptFieldID* fieldIDs =
199 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
200 for (int i = 0; i< fieldIDs_length; i++) {
201 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
202 }
203
204 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
205 jsize values_length = _env->GetArrayLength(valueArray);
206 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
207 for (int i = 0; i < values_length; i++) {
208 values[i] = (uintptr_t)jValues[i];
209 }
210
211 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
212 jsize sizes_length = _env->GetArrayLength(sizeArray);
213
214 jlong* jDepClosures =
215 _env->GetLongArrayElements(depClosureArray, nullptr);
216 jsize depClosures_length = _env->GetArrayLength(depClosureArray);
217 RsClosure* depClosures =
218 (RsClosure*)alloca(sizeof(RsClosure) * depClosures_length);
219 for (int i = 0; i < depClosures_length; i++) {
220 depClosures[i] = (RsClosure)jDepClosures[i];
221 }
222
223 jlong* jDepFieldIDs =
224 _env->GetLongArrayElements(depFieldIDArray, nullptr);
225 jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray);
226 RsScriptFieldID* depFieldIDs =
227 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * depFieldIDs_length);
228 for (int i = 0; i < depClosures_length; i++) {
229 depFieldIDs[i] = (RsClosure)jDepFieldIDs[i];
230 }
231
232 return (jlong)(uintptr_t)rsClosureCreate(
233 (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue,
234 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
235 (size_t*)sizes, (size_t)sizes_length,
236 depClosures, (size_t)depClosures_length,
237 depFieldIDs, (size_t)depFieldIDs_length);
238}
239
Yang Nibe392ad2015-01-23 17:16:02 -0800240static jlong
241nInvokeClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong invokeID,
242 jbyteArray paramArray, jlongArray fieldIDArray, jlongArray valueArray,
243 jintArray sizeArray) {
244 jbyte* jParams = _env->GetByteArrayElements(paramArray, nullptr);
245 jsize jParamLength = _env->GetArrayLength(paramArray);
246
247 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
248 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
249 RsScriptFieldID* fieldIDs =
250 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
251 for (int i = 0; i< fieldIDs_length; i++) {
252 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
253 }
254
255 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
256 jsize values_length = _env->GetArrayLength(valueArray);
257 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
258 for (int i = 0; i < values_length; i++) {
259 values[i] = (uintptr_t)jValues[i];
260 }
261
262 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
263 jsize sizes_length = _env->GetArrayLength(sizeArray);
264
265 return (jlong)(uintptr_t)rsInvokeClosureCreate(
266 (RsContext)con, (RsScriptInvokeID)invokeID, jParams, jParamLength,
267 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
268 (size_t*)sizes, (size_t)sizes_length);
269}
270
Yang Ni281c3252014-10-24 08:52:24 -0700271static void
272nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
273 jint index, jlong value, jint size) {
274 rsClosureSetArg((RsContext)con, (RsClosure)closureID, (uint32_t)index,
275 (uintptr_t)value, (size_t)size);
276}
277
278static void
279nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
280 jlong fieldID, jlong value, jint size) {
281 rsClosureSetGlobal((RsContext)con, (RsClosure)closureID,
282 (RsScriptFieldID)fieldID, (uintptr_t)value, (size_t)size);
283}
284
285static long
286nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con,
Yang Niebf63402015-01-16 11:06:26 -0800287 jstring cacheDir, jlongArray closureArray) {
288 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
289
Yang Ni281c3252014-10-24 08:52:24 -0700290 jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr);
291 jsize numClosures = _env->GetArrayLength(closureArray);
292 RsClosure* closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures);
293 for (int i = 0; i < numClosures; i++) {
294 closures[i] = (RsClosure)jClosures[i];
295 }
296
Yang Niebf63402015-01-16 11:06:26 -0800297 return (jlong)(uintptr_t)rsScriptGroup2Create(
298 (RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length(),
299 closures, numClosures);
Yang Ni281c3252014-10-24 08:52:24 -0700300}
301
302static void
303nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) {
304 rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID);
305}
306
Jason Sams96ed4cf2010-06-15 12:15:57 -0700307static void
Tim Murray25207df2015-01-12 16:47:56 -0800308nScriptIntrinsicBLAS_Single(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
309 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
310 jfloat alpha, jlong A, jlong B, jfloat beta, jlong C, jint incX, jint incY,
311 jint KL, jint KU) {
312 RsBlasCall call;
313 memset(&call, 0, sizeof(call));
314 call.func = (RsBlasFunction)func;
315 call.transA = (RsBlasTranspose)TransA;
316 call.transB = (RsBlasTranspose)TransB;
317 call.side = (RsBlasSide)Side;
318 call.uplo = (RsBlasUplo)Uplo;
319 call.diag = (RsBlasDiag)Diag;
320 call.M = M;
321 call.N = N;
322 call.K = K;
323 call.alpha.f = alpha;
324 call.beta.f = beta;
325 call.incX = incX;
326 call.incY = incY;
327 call.KL = KL;
328 call.KU = KU;
329
330 RsAllocation in_allocs[3];
331 in_allocs[0] = (RsAllocation)A;
332 in_allocs[1] = (RsAllocation)B;
333 in_allocs[2] = (RsAllocation)C;
334
335 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
336 in_allocs, sizeof(in_allocs), nullptr,
337 &call, sizeof(call), nullptr, 0);
338}
339
340static void
341nScriptIntrinsicBLAS_Double(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
342 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
343 jdouble alpha, jlong A, jlong B, jdouble beta, jlong C, jint incX, jint incY,
344 jint KL, jint KU) {
345 RsBlasCall call;
346 memset(&call, 0, sizeof(call));
347 call.func = (RsBlasFunction)func;
348 call.transA = (RsBlasTranspose)TransA;
349 call.transB = (RsBlasTranspose)TransB;
350 call.side = (RsBlasSide)Side;
351 call.uplo = (RsBlasUplo)Uplo;
352 call.diag = (RsBlasDiag)Diag;
353 call.M = M;
354 call.N = N;
355 call.K = K;
356 call.alpha.d = alpha;
357 call.beta.d = beta;
358 call.incX = incX;
359 call.incY = incY;
360 call.KL = KL;
361 call.KU = KU;
362
363 RsAllocation in_allocs[3];
364 in_allocs[0] = (RsAllocation)A;
365 in_allocs[1] = (RsAllocation)B;
366 in_allocs[2] = (RsAllocation)C;
367
368 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
369 in_allocs, sizeof(in_allocs), nullptr,
370 &call, sizeof(call), nullptr, 0);
371}
372
373static void
374nScriptIntrinsicBLAS_Complex(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
375 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
376 jfloat alphaX, jfloat alphaY, jlong A, jlong B, jfloat betaX,
377 jfloat betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
378 RsBlasCall call;
379 memset(&call, 0, sizeof(call));
380 call.func = (RsBlasFunction)func;
381 call.transA = (RsBlasTranspose)TransA;
382 call.transB = (RsBlasTranspose)TransB;
383 call.side = (RsBlasSide)Side;
384 call.uplo = (RsBlasUplo)Uplo;
385 call.diag = (RsBlasDiag)Diag;
386 call.M = M;
387 call.N = N;
388 call.K = K;
389 call.alpha.c.r = alphaX;
390 call.alpha.c.i = alphaY;
391 call.beta.c.r = betaX;
392 call.beta.c.r = betaY;
393 call.incX = incX;
394 call.incY = incY;
395 call.KL = KL;
396 call.KU = KU;
397
398 RsAllocation in_allocs[3];
399 in_allocs[0] = (RsAllocation)A;
400 in_allocs[1] = (RsAllocation)B;
401 in_allocs[2] = (RsAllocation)C;
402
403 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
404 in_allocs, sizeof(in_allocs), nullptr,
405 &call, sizeof(call), nullptr, 0);
406}
407
408static void
409nScriptIntrinsicBLAS_Z(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
410 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
411 jdouble alphaX, jdouble alphaY, jlong A, jlong B, jdouble betaX,
412 jdouble betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
413 RsBlasCall call;
414 memset(&call, 0, sizeof(call));
415 call.func = (RsBlasFunction)func;
416 call.transA = (RsBlasTranspose)TransA;
417 call.transB = (RsBlasTranspose)TransB;
418 call.side = (RsBlasSide)Side;
419 call.uplo = (RsBlasUplo)Uplo;
420 call.diag = (RsBlasDiag)Diag;
421 call.M = M;
422 call.N = N;
423 call.K = K;
424 call.alpha.z.r = alphaX;
425 call.alpha.z.i = alphaY;
426 call.beta.z.r = betaX;
427 call.beta.z.r = betaY;
428 call.incX = incX;
429 call.incY = incY;
430 call.KL = KL;
431 call.KU = KU;
432
433 RsAllocation in_allocs[3];
434 in_allocs[0] = (RsAllocation)A;
435 in_allocs[1] = (RsAllocation)B;
436 in_allocs[2] = (RsAllocation)C;
437
438 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
439 in_allocs, sizeof(in_allocs), nullptr,
440 &call, sizeof(call), nullptr, 0);
441}
442
443
444static void
Tim Murray460a0492013-11-19 12:45:54 -0800445nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700446{
Andreas Gampe67333922014-11-10 20:35:59 -0800447 if (kLogApi) {
448 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
449 }
Jason Sams3eaa338e2009-06-10 15:04:38 -0700450 jint len = _env->GetArrayLength(str);
451 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800452 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700453 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
454}
455
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700456static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800457nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700458{
Andreas Gampe67333922014-11-10 20:35:59 -0800459 if (kLogApi) {
460 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
461 }
Chris Wailes488230c32014-08-14 11:22:40 -0700462 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800463 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700464 if(name == nullptr || strlen(name) == 0) {
465 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700466 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700467 return _env->NewStringUTF(name);
468}
469
Jason Sams7ce033d2009-08-18 14:14:24 -0700470static void
Tim Murray460a0492013-11-19 12:45:54 -0800471nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700472{
Andreas Gampe67333922014-11-10 20:35:59 -0800473 if (kLogApi) {
474 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
475 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800476 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700477}
478
Jason Sams3eaa338e2009-06-10 15:04:38 -0700479// ---------------------------------------------------------------------------
480
Tim Murrayeff663f2013-11-15 13:08:30 -0800481static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700482nDeviceCreate(JNIEnv *_env, jobject _this)
483{
Andreas Gampe67333922014-11-10 20:35:59 -0800484 if (kLogApi) {
485 ALOGD("nDeviceCreate");
486 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700487 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700488}
489
490static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800491nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700492{
Andreas Gampe67333922014-11-10 20:35:59 -0800493 if (kLogApi) {
494 ALOGD("nDeviceDestroy");
495 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700496 return rsDeviceDestroy((RsDevice)dev);
497}
498
Jason Samsebfb4362009-09-23 13:57:02 -0700499static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800500nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700501{
Andreas Gampe67333922014-11-10 20:35:59 -0800502 if (kLogApi) {
503 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
504 }
Jason Samsebfb4362009-09-23 13:57:02 -0700505 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
506}
507
Tim Murrayeff663f2013-11-15 13:08:30 -0800508static jlong
Jason Sams81cd2b12014-12-02 12:36:43 -0800509nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700510{
Andreas Gampe67333922014-11-10 20:35:59 -0800511 if (kLogApi) {
512 ALOGD("nContextCreate");
513 }
Jason Sams81cd2b12014-12-02 12:36:43 -0800514 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags);
Jason Sams704ff642010-02-09 16:05:07 -0800515}
516
Tim Murrayeff663f2013-11-15 13:08:30 -0800517static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800518nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000519 jint colorMin, jint colorPref,
520 jint alphaMin, jint alphaPref,
521 jint depthMin, jint depthPref,
522 jint stencilMin, jint stencilPref,
523 jint samplesMin, jint samplesPref, jfloat samplesQ,
524 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800525{
Jason Sams11c8af92010-10-13 15:31:10 -0700526 RsSurfaceConfig sc;
527 sc.alphaMin = alphaMin;
528 sc.alphaPref = alphaPref;
529 sc.colorMin = colorMin;
530 sc.colorPref = colorPref;
531 sc.depthMin = depthMin;
532 sc.depthPref = depthPref;
533 sc.samplesMin = samplesMin;
534 sc.samplesPref = samplesPref;
535 sc.samplesQ = samplesQ;
536
Andreas Gampe67333922014-11-10 20:35:59 -0800537 if (kLogApi) {
538 ALOGD("nContextCreateGL");
539 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700540 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700541}
542
543static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800544nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800545{
Andreas Gampe67333922014-11-10 20:35:59 -0800546 if (kLogApi) {
547 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
548 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800549 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800550}
551
552
553
554static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800555nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800556{
Andreas Gampe67333922014-11-10 20:35:59 -0800557 if (kLogApi) {
558 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
559 width, height, (Surface *)wnd);
560 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800561
Chris Wailes488230c32014-08-14 11:22:40 -0700562 ANativeWindow * window = nullptr;
563 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800564
565 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700566 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800567 }
568
Tim Murrayeff663f2013-11-15 13:08:30 -0800569 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800570}
571
572static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800573nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700574{
Andreas Gampe67333922014-11-10 20:35:59 -0800575 if (kLogApi) {
576 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
577 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800578 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700579}
580
Jason Sams715333b2009-11-17 17:26:46 -0800581static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800582nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800583{
Andreas Gampe67333922014-11-10 20:35:59 -0800584 if (kLogApi) {
585 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
586 }
Jason Sams715333b2009-11-17 17:26:46 -0800587 rsContextDump((RsContext)con, bits);
588}
Jason Samsd19f10d2009-05-22 14:03:28 -0700589
590static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800591nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700592{
Andreas Gampe67333922014-11-10 20:35:59 -0800593 if (kLogApi) {
594 ALOGD("nContextPause, con(%p)", (RsContext)con);
595 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800596 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700597}
598
599static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800600nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700601{
Andreas Gampe67333922014-11-10 20:35:59 -0800602 if (kLogApi) {
603 ALOGD("nContextResume, con(%p)", (RsContext)con);
604 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800605 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700606}
607
Jason Sams1c415172010-11-08 17:06:46 -0800608
609static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800610nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800611{
Andreas Gampe67333922014-11-10 20:35:59 -0800612 if (kLogApi) {
613 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
614 }
Jason Sams1c415172010-11-08 17:06:46 -0800615 char buf[1024];
616
617 size_t receiveLen;
618 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800619 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700620 buf, sizeof(buf),
621 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700622 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800623 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100624 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800625 }
626 return _env->NewStringUTF(buf);
627}
628
Jason Samsedbfabd2011-05-17 15:01:29 -0700629static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800630nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700631{
Jason Sams516c3192009-10-06 13:58:47 -0700632 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800633 if (kLogApi) {
634 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
635 }
Chris Wailes488230c32014-08-14 11:22:40 -0700636 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700637 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800638 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800639 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700640 ptr, len * 4,
641 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700642 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700643 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100644 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700645 }
646 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000647 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800648}
649
650static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800651nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800652{
Andreas Gampe67333922014-11-10 20:35:59 -0800653 if (kLogApi) {
654 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
655 }
Chris Wailes488230c32014-08-14 11:22:40 -0700656 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800657 size_t receiveLen;
658 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800659 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700660 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800661 auxDataPtr[0] = (jint)subID;
662 auxDataPtr[1] = (jint)receiveLen;
663 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000664 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700665}
666
Tim Murrayeff663f2013-11-15 13:08:30 -0800667static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700668{
Andreas Gampe67333922014-11-10 20:35:59 -0800669 if (kLogApi) {
670 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
671 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800672 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700673}
674
Tim Murrayeff663f2013-11-15 13:08:30 -0800675static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700676{
Andreas Gampe67333922014-11-10 20:35:59 -0800677 if (kLogApi) {
678 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
679 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800680 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700681}
682
Jason Sams455d6442013-02-05 19:20:18 -0800683static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800684nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800685{
Chris Wailes488230c32014-08-14 11:22:40 -0700686 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800687 jint len = 0;
688 if (data) {
689 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700690 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800691 }
Andreas Gampe67333922014-11-10 20:35:59 -0800692 if (kLogApi) {
693 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
694 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800695 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800696 if (data) {
697 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
698 }
699}
700
701
Jason Sams516c3192009-10-06 13:58:47 -0700702
Tim Murray460a0492013-11-19 12:45:54 -0800703static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800704nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
705 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700706{
Andreas Gampe67333922014-11-10 20:35:59 -0800707 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100708 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con,
Andreas Gampe67333922014-11-10 20:35:59 -0800709 type, kind, norm, size);
710 }
711 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
712 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700713}
714
Tim Murray460a0492013-11-19 12:45:54 -0800715static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800716nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000717 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700718{
Jason Sams718cd1f2009-12-23 14:35:29 -0800719 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -0800720 if (kLogApi) {
721 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
722 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800723
Chris Wailes488230c32014-08-14 11:22:40 -0700724 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
725 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000726
727 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
728 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
729
730 for(int i = 0; i < fieldCount; i ++) {
731 ids[i] = (RsElement)jIds[i];
732 arraySizes[i] = (uint32_t)jArraySizes[i];
733 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800734
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800735 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
736
737 const char **nameArray = names.c_str();
738 size_t *sizeArray = names.c_str_len();
739
Tim Murray3aa89c12014-08-18 17:51:22 -0700740 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000741 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700742 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700743 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800744
Ashok Bhat98071552014-02-12 09:54:43 +0000745 free(ids);
746 free(arraySizes);
747 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
748 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
749
Tim Murray3aa89c12014-08-18 17:51:22 -0700750 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700751}
752
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700753static void
Tim Murray460a0492013-11-19 12:45:54 -0800754nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700755{
756 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -0800757 if (kLogApi) {
758 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
759 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700760
761 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
762 assert(dataSize == 5);
763
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000764 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800765 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700766
767 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000768 const jint data = (jint)elementData[i];
769 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700770 }
771}
772
773
774static void
Tim Murray460a0492013-11-19 12:45:54 -0800775nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000776 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700777 jobjectArray _names,
778 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700779{
Ashok Bhat98071552014-02-12 09:54:43 +0000780 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -0800781 if (kLogApi) {
782 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
783 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700784
Ashok Bhat98071552014-02-12 09:54:43 +0000785 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
786 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000787 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700788
Andreas Gampe67333922014-11-10 20:35:59 -0800789 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
790 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700791
Ashok Bhat98071552014-02-12 09:54:43 +0000792 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700793 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000794 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700795 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000796 _env->SetLongArrayRegion(_IDs, i, 1, &id);
797 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700798 }
799
800 free(ids);
801 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700802 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700803}
804
Jason Samsd19f10d2009-05-22 14:03:28 -0700805// -----------------------------------
806
Tim Murray460a0492013-11-19 12:45:54 -0800807static jlong
808nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800809 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700810{
Andreas Gampe67333922014-11-10 20:35:59 -0800811 if (kLogApi) {
812 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 +0100813 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv);
Andreas Gampe67333922014-11-10 20:35:59 -0800814 }
Jason Sams3b9c52a2010-10-14 17:48:46 -0700815
Andreas Gampe67333922014-11-10 20:35:59 -0800816 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
817 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700818}
819
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700820static void
Ashok Bhat98071552014-02-12 09:54:43 +0000821nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700822{
823 // We are packing 6 items: mDimX; mDimY; mDimZ;
824 // mDimLOD; mDimFaces; mElement; into typeData
825 int elementCount = _env->GetArrayLength(_typeData);
826
827 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -0800828 if (kLogApi) {
829 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
830 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700831
Ashok Bhat98071552014-02-12 09:54:43 +0000832 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -0800833 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700834
835 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700836 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000837 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700838 }
839}
840
Jason Samsd19f10d2009-05-22 14:03:28 -0700841// -----------------------------------
842
Tim Murray460a0492013-11-19 12:45:54 -0800843static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800844nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
845 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700846{
Andreas Gampe67333922014-11-10 20:35:59 -0800847 if (kLogApi) {
848 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
849 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
850 }
851 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
852 (RsAllocationMipmapControl)mips,
853 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700854}
855
Jason Samsd19f10d2009-05-22 14:03:28 -0700856static void
Tim Murray460a0492013-11-19 12:45:54 -0800857nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -0800858{
Andreas Gampe67333922014-11-10 20:35:59 -0800859 if (kLogApi) {
860 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
861 bits);
862 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800863 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -0800864}
865
Jason Sams72226e02013-02-22 12:45:54 -0800866static jobject
Tim Murray460a0492013-11-19 12:45:54 -0800867nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800868{
Andreas Gampe67333922014-11-10 20:35:59 -0800869 if (kLogApi) {
870 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
871 }
Jason Sams615e7ce2012-01-13 14:01:20 -0800872
Andreas Gampe67333922014-11-10 20:35:59 -0800873 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
874 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -0800875 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -0700876 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700877
Jason Sams72226e02013-02-22 12:45:54 -0800878 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
879 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700880}
881
882static void
Tim Murray460a0492013-11-19 12:45:54 -0800883nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800884{
Andreas Gampe67333922014-11-10 20:35:59 -0800885 if (kLogApi) {
886 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
887 (RsAllocation)alloc, (Surface *)sur);
888 }
Jason Sams163766c2012-02-15 12:04:24 -0800889
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700890 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800891 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700892 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800893 }
894
Andreas Gampe67333922014-11-10 20:35:59 -0800895 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
896 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800897}
898
899static void
Tim Murray460a0492013-11-19 12:45:54 -0800900nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800901{
Andreas Gampe67333922014-11-10 20:35:59 -0800902 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100903 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -0800904 }
Tim Murray460a0492013-11-19 12:45:54 -0800905 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800906}
907
908static void
Tim Murray460a0492013-11-19 12:45:54 -0800909nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800910{
Andreas Gampe67333922014-11-10 20:35:59 -0800911 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100912 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -0800913 }
Tim Murray460a0492013-11-19 12:45:54 -0800914 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800915}
916
917
918static void
Tim Murray460a0492013-11-19 12:45:54 -0800919nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -0800920{
Andreas Gampe67333922014-11-10 20:35:59 -0800921 if (kLogApi) {
922 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
923 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800924 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -0800925}
926
Tim Murray460a0492013-11-19 12:45:54 -0800927static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800928nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
929 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700930{
Jason Samsffe9f482009-06-01 17:45:53 -0700931 SkBitmap const * nativeBitmap =
John Reckf4faeac2015-03-05 13:50:31 -0800932 GraphicsJNI::getSkBitmap(_env, jbitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700933 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700934
Jason Sams5476b452010-12-08 16:14:36 -0800935 bitmap.lockPixels();
936 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700937 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700938 (RsType)type, (RsAllocationMipmapControl)mip,
939 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800940 bitmap.unlockPixels();
941 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700942}
Jason Samsfe08d992009-05-27 14:45:32 -0700943
Tim Murray460a0492013-11-19 12:45:54 -0800944static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800945nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
946 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -0800947{
948 SkBitmap const * nativeBitmap =
John Reckf4faeac2015-03-05 13:50:31 -0800949 GraphicsJNI::getSkBitmap(_env, jbitmap);
Tim Murraya3145512012-12-04 17:59:29 -0800950 const SkBitmap& bitmap(*nativeBitmap);
951
952 bitmap.lockPixels();
953 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700954 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -0800955 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +0000956 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -0800957 bitmap.unlockPixels();
958 return id;
959}
960
Tim Murray460a0492013-11-19 12:45:54 -0800961static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800962nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
963 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800964{
965 SkBitmap const * nativeBitmap =
John Reckf4faeac2015-03-05 13:50:31 -0800966 GraphicsJNI::getSkBitmap(_env, jbitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800967 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800968
Jason Sams5476b452010-12-08 16:14:36 -0800969 bitmap.lockPixels();
970 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700971 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700972 (RsType)type, (RsAllocationMipmapControl)mip,
973 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800974 bitmap.unlockPixels();
975 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800976}
977
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700978static void
Tim Murray460a0492013-11-19 12:45:54 -0800979nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700980{
981 SkBitmap const * nativeBitmap =
John Reckf4faeac2015-03-05 13:50:31 -0800982 GraphicsJNI::getSkBitmap(_env, jbitmap);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700983 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800984 int w = bitmap.width();
985 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700986
Jason Sams4ef66502010-12-10 16:03:15 -0800987 bitmap.lockPixels();
988 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800989 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700990 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800991 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800992 bitmap.unlockPixels();
993}
994
995static void
Tim Murray460a0492013-11-19 12:45:54 -0800996nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -0800997{
998 SkBitmap const * nativeBitmap =
John Reckf4faeac2015-03-05 13:50:31 -0800999 GraphicsJNI::getSkBitmap(_env, jbitmap);
Jason Sams4ef66502010-12-10 16:03:15 -08001000 const SkBitmap& bitmap(*nativeBitmap);
1001
1002 bitmap.lockPixels();
1003 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001004 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -08001005 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -07001006 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001007}
1008
Stephen Hines414fa2c2014-04-17 01:02:42 -07001009// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -07001010static void
Tim Murray460a0492013-11-19 12:45:54 -08001011nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001012 jint count, jobject data, jint sizeBytes, jint dataType)
Jason Samsd19f10d2009-05-22 14:03:28 -07001013{
Jason Samse729a942013-11-06 11:22:02 -08001014 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001015 if (kLogApi) {
1016 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1017 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
1018 dataType);
1019 }
1020 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count,
1021 ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -07001022}
1023
1024static void
Miao Wangc8e237e2015-02-20 18:36:32 -08001025nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1026 jint xoff, jint yoff, jint zoff,
1027 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -07001028{
1029 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -08001030 if (kLogApi) {
Miao Wangc8e237e2015-02-20 18:36:32 -08001031 ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1032 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
Andreas Gampe67333922014-11-10 20:35:59 -08001033 sizeBytes);
1034 }
Chris Wailes488230c32014-08-14 11:22:40 -07001035 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Miao Wangc8e237e2015-02-20 18:36:32 -08001036 rsAllocationElementData((RsContext)con, (RsAllocation)alloc,
1037 xoff, yoff, zoff,
1038 lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -07001039 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1040}
1041
Miao Wangc8e237e2015-02-20 18:36:32 -08001042
Stephen Hines414fa2c2014-04-17 01:02:42 -07001043// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -07001044static void
Tim Murray460a0492013-11-19 12:45:54 -08001045nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001046 jint w, jint h, jobject data, jint sizeBytes, jint dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001047{
Jason Samse729a942013-11-06 11:22:02 -08001048 RsAllocation *alloc = (RsAllocation *)_alloc;
1049 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001050 if (kLogApi) {
1051 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1052 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1053 }
Chris Wailes488230c32014-08-14 11:22:40 -07001054 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 -07001055}
1056
Stephen Hines414fa2c2014-04-17 01:02:42 -07001057// Copies from the Allocation pointed to by srcAlloc into the Allocation
1058// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -07001059static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001060nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001061 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001062 jint dstMip, jint dstFace,
1063 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -08001064 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001065 jint srcMip, jint srcFace)
1066{
Andreas Gampe67333922014-11-10 20:35:59 -08001067 if (kLogApi) {
1068 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1069 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
1070 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
1071 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
1072 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
1073 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001074
Tim Murrayeff663f2013-11-15 13:08:30 -08001075 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001076 (RsAllocation)dstAlloc,
1077 dstXoff, dstYoff,
1078 dstMip, dstFace,
1079 width, height,
1080 (RsAllocation)srcAlloc,
1081 srcXoff, srcYoff,
1082 srcMip, srcFace);
1083}
1084
Stephen Hines414fa2c2014-04-17 01:02:42 -07001085// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001086static void
Tim Murray460a0492013-11-19 12:45:54 -08001087nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Jason Samse729a942013-11-06 11:22:02 -08001088 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
Jason Samsb05d6892013-04-09 15:59:24 -07001089{
Jason Samse729a942013-11-06 11:22:02 -08001090 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001091 if (kLogApi) {
1092 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1093 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1094 lod, w, h, d, sizeBytes);
1095 }
Chris Wailes488230c32014-08-14 11:22:40 -07001096 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 -07001097}
1098
Stephen Hines414fa2c2014-04-17 01:02:42 -07001099// Copies from the Allocation pointed to by srcAlloc into the Allocation
1100// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -07001101static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001102nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001103 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001104 jint dstMip,
1105 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -08001106 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001107 jint srcMip)
1108{
Andreas Gampe67333922014-11-10 20:35:59 -08001109 if (kLogApi) {
1110 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1111 " dstMip(%i), width(%i), height(%i),"
1112 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
1113 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
1114 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
1115 }
Jason Samsb05d6892013-04-09 15:59:24 -07001116
Tim Murrayeff663f2013-11-15 13:08:30 -08001117 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -07001118 (RsAllocation)dstAlloc,
1119 dstXoff, dstYoff, dstZoff, dstMip,
1120 width, height, depth,
1121 (RsAllocation)srcAlloc,
1122 srcXoff, srcYoff, srcZoff, srcMip);
1123}
1124
Jason Sams21659ac2013-11-06 15:08:07 -08001125
Stephen Hines414fa2c2014-04-17 01:02:42 -07001126// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -07001127static void
Tim Murray460a0492013-11-19 12:45:54 -08001128nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType)
Jason Sams40a29e82009-08-10 14:55:26 -07001129{
Jason Sams21659ac2013-11-06 15:08:07 -08001130 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001131 if (kLogApi) {
1132 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
1133 }
Stephen Hines414fa2c2014-04-17 01:02:42 -07001134 PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -07001135}
1136
Stephen Hines414fa2c2014-04-17 01:02:42 -07001137// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -07001138static void
Tim Murray460a0492013-11-19 12:45:54 -08001139nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Jason Sams21659ac2013-11-06 15:08:07 -08001140 jint count, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001141{
Jason Sams21659ac2013-11-06 15:08:07 -08001142 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001143 if (kLogApi) {
1144 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1145 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
1146 }
Stephen Hines414fa2c2014-04-17 01:02:42 -07001147 PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -08001148}
1149
Miao Wangc8e237e2015-02-20 18:36:32 -08001150// Copies from the Element in the Allocation pointed to by _alloc into the Java array data.
1151static void
1152nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc,
1153 jint xoff, jint yoff, jint zoff,
1154 jint lod, jint compIdx, jobject data, jint sizeBytes, int dataType)
1155{
1156 RsAllocation *alloc = (RsAllocation *)_alloc;
1157 if (kLogApi) {
1158 ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), "
1159 "sizeBytes(%i)", (RsContext)con, alloc, xoff, yoff, zoff, compIdx, sizeBytes);
1160 }
1161 PER_ARRAY_TYPE(0, rsAllocationElementRead, false, (RsContext)con, alloc,
1162 xoff, yoff, zoff, lod, ptr, sizeBytes, compIdx);
1163}
1164
Stephen Hines414fa2c2014-04-17 01:02:42 -07001165// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -08001166static void
Tim Murray460a0492013-11-19 12:45:54 -08001167nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Jason Sams21659ac2013-11-06 15:08:07 -08001168 jint w, jint h, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001169{
Jason Sams21659ac2013-11-06 15:08:07 -08001170 RsAllocation *alloc = (RsAllocation *)_alloc;
1171 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001172 if (kLogApi) {
1173 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1174 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1175 }
1176 PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h,
1177 ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -07001178}
Miao Wangc8e237e2015-02-20 18:36:32 -08001179// Copies from the Allocation pointed to by _alloc into the Java object data.
1180static void
1181nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
1182 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
1183{
1184 RsAllocation *alloc = (RsAllocation *)_alloc;
1185 if (kLogApi) {
1186 ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1187 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1188 lod, w, h, d, sizeBytes);
1189 }
1190 PER_ARRAY_TYPE(0, rsAllocation3DRead, false, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d,
1191 ptr, sizeBytes, 0);
1192}
Jason Samsd19f10d2009-05-22 14:03:28 -07001193
Tim Murray460a0492013-11-19 12:45:54 -08001194static jlong
1195nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001196{
Andreas Gampe67333922014-11-10 20:35:59 -08001197 if (kLogApi) {
1198 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1199 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001200 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001201}
1202
Jason Sams5edc6082010-10-05 13:32:49 -07001203static void
Tim Murray460a0492013-11-19 12:45:54 -08001204nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -07001205{
Andreas Gampe67333922014-11-10 20:35:59 -08001206 if (kLogApi) {
1207 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
1208 (RsAllocation)alloc, dimX);
1209 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001210 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -07001211}
1212
Jason Sams46ba27e32015-02-06 17:45:15 -08001213
1214static jlong
1215nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type)
1216{
1217 if (kLogApi) {
1218 ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)",
1219 (RsContext)con, (RsAllocation)basealloc, (RsElement)type);
1220 }
1221 return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type,
1222 (RsAllocation)basealloc);
1223
1224}
1225
1226static void
1227nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1228 jint x, jint y, jint z, jint face, jint lod,
1229 jint a1, jint a2, jint a3, jint a4)
1230{
1231 uint32_t params[] = {
1232 (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face,
1233 (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4
1234 };
1235 if (kLogApi) {
1236 ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)",
1237 (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4);
1238 }
1239 rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc,
1240 params, sizeof(params));
1241}
1242
1243
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001244// -----------------------------------
1245
Tim Murray460a0492013-11-19 12:45:54 -08001246static jlong
1247nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001248{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001249 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001250 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001251
Tim Murray3aa89c12014-08-18 17:51:22 -07001252 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001253 return id;
1254}
1255
Tim Murray460a0492013-11-19 12:45:54 -08001256static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001257nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001258{
1259 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001260 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001261 return 0;
1262 }
1263
1264 AutoJavaStringToUTF8 str(_env, _path);
1265 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001266 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001267 return 0;
1268 }
1269
Tim Murray3aa89c12014-08-18 17:51:22 -07001270 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001271 return id;
1272}
1273
Tim Murray460a0492013-11-19 12:45:54 -08001274static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001275nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001276{
1277 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001278 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001279
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001280 return id;
1281}
1282
Tim Murray460a0492013-11-19 12:45:54 -08001283static jint
1284nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001285{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001286 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001287 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001288 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001289}
1290
1291static void
Tim Murray460a0492013-11-19 12:45:54 -08001292nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001293{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001294 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001295 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
1296
Tim Murrayeff663f2013-11-15 13:08:30 -08001297 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001298
1299 for(jint i = 0; i < numEntries; i ++) {
1300 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
1301 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
1302 }
1303
1304 free(fileEntries);
1305}
1306
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001307static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001308nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001309{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001310 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001311 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001312 return id;
1313}
Jason Samsd19f10d2009-05-22 14:03:28 -07001314
1315// -----------------------------------
1316
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001317static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001318nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001319 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001320{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001321 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001322 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001323 fileNameUTF.c_str(), fileNameUTF.length(),
1324 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001325
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001326 return id;
1327}
1328
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001329static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001330nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001331 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001332{
1333 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1334 AutoJavaStringToUTF8 nameUTF(_env, name);
1335
Tim Murray3aa89c12014-08-18 17:51:22 -07001336 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001337 nameUTF.c_str(), nameUTF.length(),
1338 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001339 asset->getBuffer(false), asset->getLength());
1340 return id;
1341}
1342
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001343static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001344nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001345 jfloat fontSize, jint dpi)
1346{
1347 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001348 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001349 return 0;
1350 }
1351
1352 AutoJavaStringToUTF8 str(_env, _path);
1353 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001354 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001355 return 0;
1356 }
1357
Tim Murray3aa89c12014-08-18 17:51:22 -07001358 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001359 str.c_str(), str.length(),
1360 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001361 asset->getBuffer(false), asset->getLength());
1362 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001363 return id;
1364}
1365
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001366// -----------------------------------
1367
1368static void
Tim Murray460a0492013-11-19 12:45:54 -08001369nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001370{
Andreas Gampe67333922014-11-10 20:35:59 -08001371 if (kLogApi) {
1372 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1373 (RsScript)script, (RsAllocation)alloc, slot);
1374 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001375 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001376}
1377
1378static void
Tim Murray460a0492013-11-19 12:45:54 -08001379nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001380{
Andreas Gampe67333922014-11-10 20:35:59 -08001381 if (kLogApi) {
1382 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1383 slot, val);
1384 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001385 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001386}
1387
Tim Murray7c4caad2013-04-10 16:21:40 -07001388static jint
Tim Murray460a0492013-11-19 12:45:54 -08001389nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001390{
Andreas Gampe67333922014-11-10 20:35:59 -08001391 if (kLogApi) {
1392 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1393 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001394 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001395 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001396 return value;
1397}
1398
Jason Sams4d339932010-05-11 14:03:58 -07001399static void
Tim Murray460a0492013-11-19 12:45:54 -08001400nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001401{
Andreas Gampe67333922014-11-10 20:35:59 -08001402 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001403 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001404 slot, val);
1405 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001406 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001407}
1408
1409static void
Tim Murray460a0492013-11-19 12:45:54 -08001410nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001411{
Andreas Gampe67333922014-11-10 20:35:59 -08001412 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001413 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001414 slot, val);
1415 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001416 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001417}
1418
Tim Murray7c4caad2013-04-10 16:21:40 -07001419static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001420nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001421{
Andreas Gampe67333922014-11-10 20:35:59 -08001422 if (kLogApi) {
1423 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1424 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001425 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001426 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001427 return value;
1428}
1429
Stephen Hines031ec58c2010-10-11 10:54:21 -07001430static void
Tim Murray460a0492013-11-19 12:45:54 -08001431nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001432{
Andreas Gampe67333922014-11-10 20:35:59 -08001433 if (kLogApi) {
1434 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1435 slot, val);
1436 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001437 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001438}
1439
Tim Murray7c4caad2013-04-10 16:21:40 -07001440static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001441nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001442{
Andreas Gampe67333922014-11-10 20:35:59 -08001443 if (kLogApi) {
1444 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1445 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001446 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001447 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001448 return value;
1449}
1450
Jason Sams4d339932010-05-11 14:03:58 -07001451static void
Tim Murray460a0492013-11-19 12:45:54 -08001452nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001453{
Andreas Gampe67333922014-11-10 20:35:59 -08001454 if (kLogApi) {
1455 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1456 slot, val);
1457 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001458 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001459}
1460
Tim Murray7c4caad2013-04-10 16:21:40 -07001461static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001462nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001463{
Andreas Gampe67333922014-11-10 20:35:59 -08001464 if (kLogApi) {
1465 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1466 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001467 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001468 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001469 return value;
1470}
1471
Stephen Hinesca54ec32010-09-20 17:20:30 -07001472static void
Tim Murray460a0492013-11-19 12:45:54 -08001473nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001474{
Andreas Gampe67333922014-11-10 20:35:59 -08001475 if (kLogApi) {
1476 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1477 }
Jason Sams4d339932010-05-11 14:03:58 -07001478 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001479 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001480 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001481 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1482}
1483
Stephen Hinesadeb8092012-04-20 14:26:06 -07001484static void
Tim Murray460a0492013-11-19 12:45:54 -08001485nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001486{
Andreas Gampe67333922014-11-10 20:35:59 -08001487 if (kLogApi) {
1488 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1489 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001490 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001491 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001492 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001493 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001494}
1495
1496static void
Andreas Gampe67333922014-11-10 20:35:59 -08001497nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1498 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001499{
Andreas Gampe67333922014-11-10 20:35:59 -08001500 if (kLogApi) {
1501 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1502 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001503 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001504 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001505 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001506 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001507 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001508 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001509 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1510 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1511}
1512
Jason Samsd19f10d2009-05-22 14:03:28 -07001513
1514static void
Tim Murray460a0492013-11-19 12:45:54 -08001515nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001516{
Andreas Gampe67333922014-11-10 20:35:59 -08001517 if (kLogApi) {
1518 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1519 }
Romain Guy584a3752009-07-30 18:45:01 -07001520
1521 jint length = _env->GetArrayLength(timeZone);
1522 jbyte* timeZone_ptr;
1523 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1524
Tim Murrayeff663f2013-11-15 13:08:30 -08001525 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001526
1527 if (timeZone_ptr) {
1528 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1529 }
1530}
1531
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001532static void
Tim Murray460a0492013-11-19 12:45:54 -08001533nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001534{
Andreas Gampe67333922014-11-10 20:35:59 -08001535 if (kLogApi) {
1536 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1537 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001538 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001539}
1540
1541static void
Tim Murray460a0492013-11-19 12:45:54 -08001542nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001543{
Andreas Gampe67333922014-11-10 20:35:59 -08001544 if (kLogApi) {
1545 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1546 }
Jason Sams4d339932010-05-11 14:03:58 -07001547 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001548 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001549 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001550 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1551}
1552
Jason Sams6e494d32011-04-27 16:33:11 -07001553static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001554nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1555 jlongArray ains, jlong aout, jbyteArray params,
1556 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001557{
Andreas Gampe67333922014-11-10 20:35:59 -08001558 if (kLogApi) {
1559 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1560 }
Jason Sams6e494d32011-04-27 16:33:11 -07001561
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001562 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001563 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001564
Chris Wailes488230c32014-08-14 11:22:40 -07001565 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001566
Chris Wailes488230c32014-08-14 11:22:40 -07001567 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001568 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001569 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001570
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001571 if (sizeof(RsAllocation) == sizeof(jlong)) {
1572 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001573
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001574 } else {
1575 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001576
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001577 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1578
1579 for (int index = in_len; --index >= 0;) {
1580 in_allocs[index] = (RsAllocation)in_ptr[index];
1581 }
1582 }
Chris Wailes94961062014-06-11 12:01:28 -07001583 }
1584
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001585 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001586 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001587
Chris Wailes488230c32014-08-14 11:22:40 -07001588 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001589 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001590 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001591 }
1592
Chris Wailes488230c32014-08-14 11:22:40 -07001593 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001594 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001595
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001596 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001597 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001598
Chris Wailes488230c32014-08-14 11:22:40 -07001599 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001600 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001601 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001602
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001603 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001604 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001605
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001606 sc.xStart = limit_ptr[0];
1607 sc.xEnd = limit_ptr[1];
1608 sc.yStart = limit_ptr[2];
1609 sc.yEnd = limit_ptr[3];
1610 sc.zStart = limit_ptr[4];
1611 sc.zEnd = limit_ptr[5];
1612 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Jason Sams14331ab2015-01-26 18:14:36 -08001613 sc.arrayStart = 0;
1614 sc.arrayEnd = 0;
1615 sc.array2Start = 0;
1616 sc.array2End = 0;
1617 sc.array3Start = 0;
1618 sc.array3End = 0;
1619 sc.array4Start = 0;
1620 sc.array4End = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001621
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001622 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001623 }
1624
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001625 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1626 in_allocs, in_len, (RsAllocation)aout,
1627 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001628
Chris Wailes488230c32014-08-14 11:22:40 -07001629 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001630 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001631 }
1632
Chris Wailes488230c32014-08-14 11:22:40 -07001633 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001634 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1635 }
1636
Chris Wailes488230c32014-08-14 11:22:40 -07001637 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001638 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1639 }
Chris Wailes94961062014-06-11 12:01:28 -07001640}
1641
Jason Sams22534172009-08-04 16:58:20 -07001642// -----------------------------------
1643
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001644static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001645nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001646 jstring resName, jstring cacheDir,
1647 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001648{
Andreas Gampe67333922014-11-10 20:35:59 -08001649 if (kLogApi) {
1650 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1651 }
Jason Sams22534172009-08-04 16:58:20 -07001652
Jason Samse4a06c52011-03-16 16:29:28 -07001653 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1654 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001655 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001656 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001657 jint _exception = 0;
1658 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001659 if (!scriptRef) {
1660 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001661 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001662 goto exit;
1663 }
Jack Palevich43702d82009-05-28 13:38:16 -07001664 if (length < 0) {
1665 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001666 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001667 goto exit;
1668 }
Jason Samse4a06c52011-03-16 16:29:28 -07001669 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001670 if (remaining < length) {
1671 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001672 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1673 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001674 goto exit;
1675 }
Jason Samse4a06c52011-03-16 16:29:28 -07001676 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001677 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001678
Tim Murrayeff663f2013-11-15 13:08:30 -08001679 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001680
Tim Murray3aa89c12014-08-18 17:51:22 -07001681 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001682 resNameUTF.c_str(), resNameUTF.length(),
1683 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001684 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001685
Jack Palevich43702d82009-05-28 13:38:16 -07001686exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001687 if (script_ptr) {
1688 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001689 _exception ? JNI_ABORT: 0);
1690 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001691
Tim Murray3aa89c12014-08-18 17:51:22 -07001692 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001693}
1694
Tim Murray460a0492013-11-19 12:45:54 -08001695static jlong
1696nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001697{
Andreas Gampe67333922014-11-10 20:35:59 -08001698 if (kLogApi) {
1699 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1700 (void *)eid);
1701 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001702 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001703}
1704
Tim Murray460a0492013-11-19 12:45:54 -08001705static jlong
1706nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001707{
Andreas Gampe67333922014-11-10 20:35:59 -08001708 if (kLogApi) {
1709 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1710 (void *)sid, slot, sig);
1711 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001712 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001713}
1714
Tim Murray460a0492013-11-19 12:45:54 -08001715static jlong
Yang Nibe392ad2015-01-23 17:16:02 -08001716nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
1717{
1718 if (kLogApi) {
Elliott Hughes7ff53fa2015-02-05 21:36:10 -08001719 ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con,
Yang Nibe392ad2015-01-23 17:16:02 -08001720 (void *)sid, slot);
1721 }
1722 return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot);
1723}
1724
1725static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001726nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001727{
Andreas Gampe67333922014-11-10 20:35:59 -08001728 if (kLogApi) {
1729 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1730 slot);
1731 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001732 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001733}
1734
Tim Murray460a0492013-11-19 12:45:54 -08001735static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001736nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1737 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001738{
Andreas Gampe67333922014-11-10 20:35:59 -08001739 if (kLogApi) {
1740 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1741 }
Jason Sams08a81582012-09-18 12:32:10 -07001742
Ashok Bhat98071552014-02-12 09:54:43 +00001743 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001744 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001745 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1746 for(int i = 0; i < kernelsLen; ++i) {
1747 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1748 }
Jason Sams08a81582012-09-18 12:32:10 -07001749
Ashok Bhat98071552014-02-12 09:54:43 +00001750 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001751 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001752 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1753 for(int i = 0; i < srcLen; ++i) {
1754 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1755 }
Jason Sams08a81582012-09-18 12:32:10 -07001756
Ashok Bhat98071552014-02-12 09:54:43 +00001757 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001758 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001759 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1760 for(int i = 0; i < dstkLen; ++i) {
1761 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1762 }
1763
1764 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001765 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001766 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1767 for(int i = 0; i < dstfLen; ++i) {
1768 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1769 }
1770
1771 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001772 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001773 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1774 for(int i = 0; i < typesLen; ++i) {
1775 typesPtr[i] = (RsType)jTypesPtr[i];
1776 }
1777
Tim Murray3aa89c12014-08-18 17:51:22 -07001778 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001779 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1780 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1781 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1782 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1783 (RsType *)typesPtr, typesLen * sizeof(RsType));
1784
1785 free(kernelsPtr);
1786 free(srcPtr);
1787 free(dstkPtr);
1788 free(dstfPtr);
1789 free(typesPtr);
1790 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1791 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1792 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1793 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1794 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001795 return id;
1796}
1797
1798static void
Tim Murray460a0492013-11-19 12:45:54 -08001799nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001800{
Andreas Gampe67333922014-11-10 20:35:59 -08001801 if (kLogApi) {
1802 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1803 (void *)gid, (void *)kid, (void *)alloc);
1804 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001805 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001806}
1807
1808static void
Tim Murray460a0492013-11-19 12:45:54 -08001809nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001810{
Andreas Gampe67333922014-11-10 20:35:59 -08001811 if (kLogApi) {
1812 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1813 (void *)gid, (void *)kid, (void *)alloc);
1814 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001815 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001816}
1817
1818static void
Tim Murray460a0492013-11-19 12:45:54 -08001819nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001820{
Andreas Gampe67333922014-11-10 20:35:59 -08001821 if (kLogApi) {
1822 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
1823 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001824 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001825}
1826
Jason Samsd19f10d2009-05-22 14:03:28 -07001827// ---------------------------------------------------------------------------
1828
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001829static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001830nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001831 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1832 jboolean depthMask, jboolean ditherEnable,
1833 jint srcFunc, jint destFunc,
1834 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001835{
Andreas Gampe67333922014-11-10 20:35:59 -08001836 if (kLogApi) {
1837 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
1838 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001839 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07001840 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1841 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001842}
1843
Jason Sams0011bcf2009-12-15 12:58:36 -08001844// ---------------------------------------------------------------------------
1845
1846static void
Tim Murray460a0492013-11-19 12:45:54 -08001847nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001848{
Andreas Gampe67333922014-11-10 20:35:59 -08001849 if (kLogApi) {
1850 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
1851 (RsProgramVertex)vpv, slot, (RsAllocation)a);
1852 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001853 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08001854}
Jason Sams54c0ec12009-11-30 14:49:55 -08001855
Jason Sams68afd012009-12-17 16:55:08 -08001856static void
Tim Murray460a0492013-11-19 12:45:54 -08001857nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001858{
Andreas Gampe67333922014-11-10 20:35:59 -08001859 if (kLogApi) {
1860 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1861 (RsProgramFragment)vpf, slot, (RsAllocation)a);
1862 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001863 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08001864}
1865
1866static void
Tim Murray460a0492013-11-19 12:45:54 -08001867nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001868{
Andreas Gampe67333922014-11-10 20:35:59 -08001869 if (kLogApi) {
1870 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1871 (RsProgramFragment)vpf, slot, (RsSampler)a);
1872 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001873 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08001874}
1875
Jason Samsd19f10d2009-05-22 14:03:28 -07001876// ---------------------------------------------------------------------------
1877
Tim Murray460a0492013-11-19 12:45:54 -08001878static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001879nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001880 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001881{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001882 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001883 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001884 jint paramLen = _env->GetArrayLength(params);
1885
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001886 int texCount = _env->GetArrayLength(texNames);
1887 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1888 const char ** nameArray = names.c_str();
1889 size_t* sizeArray = names.c_str_len();
1890
Andreas Gampe67333922014-11-10 20:35:59 -08001891 if (kLogApi) {
1892 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1893 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001894
Ashok Bhat98071552014-02-12 09:54:43 +00001895 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1896 for(int i = 0; i < paramLen; ++i) {
1897 paramPtr[i] = (uintptr_t)jParamPtr[i];
1898 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001899 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001900 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001901 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001902
Ashok Bhat98071552014-02-12 09:54:43 +00001903 free(paramPtr);
1904 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001905 return ret;
1906}
1907
1908
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001909// ---------------------------------------------------------------------------
1910
Tim Murray460a0492013-11-19 12:45:54 -08001911static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001912nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001913 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001914{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001915 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001916 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08001917 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001918
Andreas Gampe67333922014-11-10 20:35:59 -08001919 if (kLogApi) {
1920 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1921 }
Jason Sams0011bcf2009-12-15 12:58:36 -08001922
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001923 int texCount = _env->GetArrayLength(texNames);
1924 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1925 const char ** nameArray = names.c_str();
1926 size_t* sizeArray = names.c_str_len();
1927
Ashok Bhat98071552014-02-12 09:54:43 +00001928 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1929 for(int i = 0; i < paramLen; ++i) {
1930 paramPtr[i] = (uintptr_t)jParamPtr[i];
1931 }
1932
Tim Murray3aa89c12014-08-18 17:51:22 -07001933 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001934 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001935 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001936
Ashok Bhat98071552014-02-12 09:54:43 +00001937 free(paramPtr);
1938 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08001939 return ret;
1940}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001941
Jason Samsebfb4362009-09-23 13:57:02 -07001942// ---------------------------------------------------------------------------
1943
Tim Murray460a0492013-11-19 12:45:54 -08001944static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001945nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001946{
Andreas Gampe67333922014-11-10 20:35:59 -08001947 if (kLogApi) {
1948 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
1949 pointSprite, cull);
1950 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001951 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001952}
1953
Jason Samsd19f10d2009-05-22 14:03:28 -07001954
1955// ---------------------------------------------------------------------------
1956
1957static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001958nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001959{
Andreas Gampe67333922014-11-10 20:35:59 -08001960 if (kLogApi) {
1961 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
1962 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001963 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001964}
1965
1966static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001967nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001968{
Andreas Gampe67333922014-11-10 20:35:59 -08001969 if (kLogApi) {
1970 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
1971 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001972 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001973}
1974
1975static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001976nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001977{
Andreas Gampe67333922014-11-10 20:35:59 -08001978 if (kLogApi) {
1979 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
1980 (RsProgramFragment)pf);
1981 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001982 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001983}
1984
Jason Sams0826a6f2009-06-15 19:04:56 -07001985static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001986nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001987{
Andreas Gampe67333922014-11-10 20:35:59 -08001988 if (kLogApi) {
1989 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
1990 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001991 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001992}
1993
Joe Onoratod7b37742009-08-09 22:57:44 -07001994static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001995nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001996{
Andreas Gampe67333922014-11-10 20:35:59 -08001997 if (kLogApi) {
1998 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
1999 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002000 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07002001}
2002
Joe Onoratod7b37742009-08-09 22:57:44 -07002003
Jason Sams02fb2cb2009-05-28 15:37:57 -07002004// ---------------------------------------------------------------------------
2005
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002006static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002007nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002008 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07002009{
Andreas Gampe67333922014-11-10 20:35:59 -08002010 if (kLogApi) {
2011 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
2012 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002013 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002014 (RsSamplerValue)magFilter,
2015 (RsSamplerValue)minFilter,
2016 (RsSamplerValue)wrapS,
2017 (RsSamplerValue)wrapT,
2018 (RsSamplerValue)wrapR,
2019 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07002020}
2021
Jason Samsbba134c2009-06-22 15:49:21 -07002022// ---------------------------------------------------------------------------
2023
Tim Murray460a0492013-11-19 12:45:54 -08002024static jlong
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002025nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) {
Andreas Gampe67333922014-11-10 20:35:59 -08002026 if (kLogApi) {
2027 ALOGD("nPathCreate, con(%p)", (RsContext)con);
2028 }
Jason Samsf15ed012011-10-31 13:23:43 -07002029
Tim Murray3aa89c12014-08-18 17:51:22 -07002030 jlong id = (jlong)(uintptr_t)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic,
Tim Murray460a0492013-11-19 12:45:54 -08002031 (RsAllocation)_vtx,
2032 (RsAllocation)_loop, q);
Jason Samsf15ed012011-10-31 13:23:43 -07002033 return id;
2034}
2035
Tim Murray460a0492013-11-19 12:45:54 -08002036static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00002037nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07002038{
Andreas Gampe67333922014-11-10 20:35:59 -08002039 if (kLogApi) {
2040 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
2041 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002042
2043 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07002044 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002045 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
2046 for(int i = 0; i < vtxLen; ++i) {
2047 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
2048 }
2049
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002050 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07002051 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002052 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
2053 for(int i = 0; i < idxLen; ++i) {
2054 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
2055 }
2056
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002057 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07002058 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002059
Tim Murray3aa89c12014-08-18 17:51:22 -07002060 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002061 (RsAllocation *)vtxPtr, vtxLen,
2062 (RsAllocation *)idxPtr, idxLen,
2063 (uint32_t *)primPtr, primLen);
2064
Ashok Bhat98071552014-02-12 09:54:43 +00002065 free(vtxPtr);
2066 free(idxPtr);
2067 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
2068 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002069 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002070 return id;
2071}
2072
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002073static jint
Tim Murray460a0492013-11-19 12:45:54 -08002074nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002075{
Andreas Gampe67333922014-11-10 20:35:59 -08002076 if (kLogApi) {
2077 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2078 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002079 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002080 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002081 return vtxCount;
2082}
2083
2084static jint
Tim Murray460a0492013-11-19 12:45:54 -08002085nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002086{
Andreas Gampe67333922014-11-10 20:35:59 -08002087 if (kLogApi) {
2088 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2089 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002090 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002091 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002092 return idxCount;
2093}
2094
2095static void
Ashok Bhat98071552014-02-12 09:54:43 +00002096nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002097{
Andreas Gampe67333922014-11-10 20:35:59 -08002098 if (kLogApi) {
2099 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2100 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002101
2102 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08002103 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002104
2105 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002106 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002107 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002108 }
2109
2110 free(allocs);
2111}
2112
2113static void
Ashok Bhat98071552014-02-12 09:54:43 +00002114nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002115{
Andreas Gampe67333922014-11-10 20:35:59 -08002116 if (kLogApi) {
2117 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2118 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002119
2120 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
2121 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
2122
Tim Murrayeff663f2013-11-15 13:08:30 -08002123 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002124
2125 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002126 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002127 const jint prim = (jint)prims[i];
2128 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
2129 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002130 }
2131
2132 free(allocs);
2133 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002134}
2135
Tim Murray56f9e6f2014-05-16 11:47:26 -07002136static jint
2137nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
2138 return (jint)sizeof(void*);
2139}
2140
2141
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002142// ---------------------------------------------------------------------------
2143
Jason Samsd19f10d2009-05-22 14:03:28 -07002144
Jason Sams94d8e90a2009-06-10 16:09:05 -07002145static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07002146
2147static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08002148{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07002149
Tim Murrayeff663f2013-11-15 13:08:30 -08002150{"nDeviceCreate", "()J", (void*)nDeviceCreate },
2151{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
2152{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
2153{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
2154{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
2155{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08002156
Tim Murrayeff663f2013-11-15 13:08:30 -08002157{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
2158{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07002159
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07002160
Jason Sams2e1872f2010-08-17 16:25:41 -07002161// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08002162{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
2163{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
2164{"rsnContextFinish", "(J)V", (void*)nContextFinish },
2165{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
2166{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
2167{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
2168{"rsnContextDump", "(JI)V", (void*)nContextDump },
2169{"rsnContextPause", "(J)V", (void*)nContextPause },
2170{"rsnContextResume", "(J)V", (void*)nContextResume },
2171{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07002172{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002173{"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate },
Yang Ni281c3252014-10-24 08:52:24 -07002174{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
2175{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08002176{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
2177{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
2178{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07002179
Tim Murray460a0492013-11-19 12:45:54 -08002180{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002181{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08002182{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
2183{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
2184{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002185{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07002186
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002187{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
2188{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
2189{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07002190
Tim Murray460a0492013-11-19 12:45:54 -08002191{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002192{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08002193{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00002194{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07002195
Tim Murray460a0492013-11-19 12:45:54 -08002196{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002197{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07002198
Ashok Bhat98071552014-02-12 09:54:43 +00002199{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08002200{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
2201{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
2202{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08002203
Tim Murray460a0492013-11-19 12:45:54 -08002204{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
2205{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08002206
Tim Murray460a0492013-11-19 12:45:54 -08002207{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
2208{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
2209{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
2210{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
2211{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
2212{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002213{"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData },
Tim Murray460a0492013-11-19 12:45:54 -08002214{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
2215{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
2216{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
2217{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
2218{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead },
2219{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002220{"rsnAllocationElementRead", "(JJIIIIILjava/lang/Object;II)V", (void*)nAllocationElementRead },
Tim Murray460a0492013-11-19 12:45:54 -08002221{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002222{"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead3D },
Tim Murray460a0492013-11-19 12:45:54 -08002223{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
2224{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
2225{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07002226
Jason Sams46ba27e32015-02-06 17:45:15 -08002227{"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate },
2228{"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset },
2229
Tim Murray460a0492013-11-19 12:45:54 -08002230{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
2231{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
2232{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
2233{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07002234
2235{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
2236
Tim Murray460a0492013-11-19 12:45:54 -08002237{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
2238{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
2239{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
2240{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
2241{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
2242{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
2243{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
2244{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
2245{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
2246{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
2247{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
2248{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07002249
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002250{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002251{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2252{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002253{"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002254{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002255{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Niebf63402015-01-16 11:06:26 -08002256{"rsnScriptGroup2Create", "(JLjava/lang/String;[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002257{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2258{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2259{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002260{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002261
Tim Murray25207df2015-01-12 16:47:56 -08002262{"rsnScriptIntrinsicBLAS_Single", "(JJIIIIIIIIIFJJFJIIII)V", (void*)nScriptIntrinsicBLAS_Single },
2263{"rsnScriptIntrinsicBLAS_Double", "(JJIIIIIIIIIDJJDJIIII)V", (void*)nScriptIntrinsicBLAS_Double },
2264{"rsnScriptIntrinsicBLAS_Complex", "(JJIIIIIIIIIFFJJFFJIIII)V", (void*)nScriptIntrinsicBLAS_Complex },
2265{"rsnScriptIntrinsicBLAS_Z", "(JJIIIIIIIIIDDJJDDJIIII)V", (void*)nScriptIntrinsicBLAS_Z },
2266
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002267{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002268
Tim Murray460a0492013-11-19 12:45:54 -08002269{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2270{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2271{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002272
Ashok Bhat98071552014-02-12 09:54:43 +00002273{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002274{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002275{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002276
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002277{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2278{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2279{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2280{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2281{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002282
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002283{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002284
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002285{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002286{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002287
Tim Murray460a0492013-11-19 12:45:54 -08002288{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2289{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002290{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2291{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002292
Tim Murray56f9e6f2014-05-16 11:47:26 -07002293{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002294};
2295
2296static int registerFuncs(JNIEnv *_env)
2297{
2298 return android::AndroidRuntime::registerNativeMethods(
2299 _env, classPathName, methods, NELEM(methods));
2300}
2301
2302// ---------------------------------------------------------------------------
2303
2304jint JNI_OnLoad(JavaVM* vm, void* reserved)
2305{
Chris Wailes488230c32014-08-14 11:22:40 -07002306 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002307 jint result = -1;
2308
Jason Samsd19f10d2009-05-22 14:03:28 -07002309 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002310 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002311 goto bail;
2312 }
Chris Wailes488230c32014-08-14 11:22:40 -07002313 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002314
2315 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002316 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002317 goto bail;
2318 }
2319
2320 /* success -- return valid version number */
2321 result = JNI_VERSION_1_4;
2322
2323bail:
2324 return result;
2325}