blob: ba194ee224b03f21eca424cd5e16b061aea5f85c [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
Stephen Hines4cbe25a2012-01-18 18:46:27 -08002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Samsd19f10d2009-05-22 14:03:28 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jason Samsf29ca502009-06-23 12:22:47 -070017#define LOG_TAG "libRS_jni"
18
Jason Samsd19f10d2009-05-22 14:03:28 -070019#include <stdlib.h>
20#include <stdio.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <math.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070024#include <utils/misc.h>
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +010025#include <inttypes.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070026
Derek Sollenbergereece0dd2014-02-27 14:31:29 -050027#include <SkBitmap.h>
Jason Samsffe9f482009-06-01 17:45:53 -070028
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080029#include <androidfw/Asset.h>
30#include <androidfw/AssetManager.h>
31#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070032
Jason Samsd19f10d2009-05-22 14:03:28 -070033#include "jni.h"
34#include "JNIHelp.h"
35#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070036#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080037#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070038
Jason Sams1d6983a2012-02-16 16:07:49 -080039#include <rs.h>
40#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070041#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080042#include <gui/GLConsumer.h>
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; \
Miao Wang87e908d2015-03-02 15:15:15 -080056 void *srcPtr = nullptr; \
Jason Sams21659ac2013-11-06 15:08:07 -080057 size_t typeBytes = 0; \
Stephen Hines414fa2c2014-04-17 01:02:42 -070058 jint relFlag = 0; \
59 if (readonly) { \
60 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
Miao Wang87e908d2015-03-02 15:15:15 -080061 /* readonly = true, also indicates we are copying to the allocation . */ \
Stephen Hines414fa2c2014-04-17 01:02:42 -070062 relFlag = JNI_ABORT; \
63 } \
Jason Samse729a942013-11-06 11:22:02 -080064 switch(dataType) { \
65 case RS_TYPE_FLOAT_32: \
66 len = _env->GetArrayLength((jfloatArray)data); \
67 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080068 typeBytes = 4; \
Miao Wang87e908d2015-03-02 15:15:15 -080069 if (usePadding) { \
70 srcPtr = ptr; \
71 len = len / 3 * 4; \
72 if (count == 0) { \
73 count = len / 4; \
74 } \
75 ptr = malloc (len * typeBytes); \
76 if (readonly) { \
77 copyWithPadding(ptr, srcPtr, mSize, count); \
78 fnc(__VA_ARGS__); \
79 } else { \
80 fnc(__VA_ARGS__); \
81 copyWithUnPadding(srcPtr, ptr, mSize, count); \
82 } \
83 free(ptr); \
84 ptr = srcPtr; \
85 } else { \
86 fnc(__VA_ARGS__); \
87 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -070088 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080089 return; \
90 case RS_TYPE_FLOAT_64: \
91 len = _env->GetArrayLength((jdoubleArray)data); \
92 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080093 typeBytes = 8; \
Miao Wang87e908d2015-03-02 15:15:15 -080094 if (usePadding) { \
95 srcPtr = ptr; \
96 len = len / 3 * 4; \
97 if (count == 0) { \
98 count = len / 4; \
99 } \
100 ptr = malloc (len * typeBytes); \
101 if (readonly) { \
102 copyWithPadding(ptr, srcPtr, mSize, count); \
103 fnc(__VA_ARGS__); \
104 } else { \
105 fnc(__VA_ARGS__); \
106 copyWithUnPadding(srcPtr, ptr, mSize, count); \
107 } \
108 free(ptr); \
109 ptr = srcPtr; \
110 } else { \
111 fnc(__VA_ARGS__); \
112 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700113 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800114 return; \
115 case RS_TYPE_SIGNED_8: \
116 case RS_TYPE_UNSIGNED_8: \
117 len = _env->GetArrayLength((jbyteArray)data); \
118 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800119 typeBytes = 1; \
Miao Wang87e908d2015-03-02 15:15:15 -0800120 if (usePadding) { \
121 srcPtr = ptr; \
122 len = len / 3 * 4; \
123 if (count == 0) { \
124 count = len / 4; \
125 } \
126 ptr = malloc (len * typeBytes); \
127 if (readonly) { \
128 copyWithPadding(ptr, srcPtr, mSize, count); \
129 fnc(__VA_ARGS__); \
130 } else { \
131 fnc(__VA_ARGS__); \
132 copyWithUnPadding(srcPtr, ptr, mSize, count); \
133 } \
134 free(ptr); \
135 ptr = srcPtr; \
136 } else { \
137 fnc(__VA_ARGS__); \
138 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700139 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800140 return; \
141 case RS_TYPE_SIGNED_16: \
142 case RS_TYPE_UNSIGNED_16: \
143 len = _env->GetArrayLength((jshortArray)data); \
144 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800145 typeBytes = 2; \
Miao Wang87e908d2015-03-02 15:15:15 -0800146 if (usePadding) { \
147 srcPtr = ptr; \
148 len = len / 3 * 4; \
149 if (count == 0) { \
150 count = len / 4; \
151 } \
152 ptr = malloc (len * typeBytes); \
153 if (readonly) { \
154 copyWithPadding(ptr, srcPtr, mSize, count); \
155 fnc(__VA_ARGS__); \
156 } else { \
157 fnc(__VA_ARGS__); \
158 copyWithUnPadding(srcPtr, ptr, mSize, count); \
159 } \
160 free(ptr); \
161 ptr = srcPtr; \
162 } else { \
163 fnc(__VA_ARGS__); \
164 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700165 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800166 return; \
167 case RS_TYPE_SIGNED_32: \
168 case RS_TYPE_UNSIGNED_32: \
169 len = _env->GetArrayLength((jintArray)data); \
170 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800171 typeBytes = 4; \
Miao Wang87e908d2015-03-02 15:15:15 -0800172 if (usePadding) { \
173 srcPtr = ptr; \
174 len = len / 3 * 4; \
175 if (count == 0) { \
176 count = len / 4; \
177 } \
178 ptr = malloc (len * typeBytes); \
179 if (readonly) { \
180 copyWithPadding(ptr, srcPtr, mSize, count); \
181 fnc(__VA_ARGS__); \
182 } else { \
183 fnc(__VA_ARGS__); \
184 copyWithUnPadding(srcPtr, ptr, mSize, count); \
185 } \
186 free(ptr); \
187 ptr = srcPtr; \
188 } else { \
189 fnc(__VA_ARGS__); \
190 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700191 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800192 return; \
193 case RS_TYPE_SIGNED_64: \
194 case RS_TYPE_UNSIGNED_64: \
195 len = _env->GetArrayLength((jlongArray)data); \
196 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800197 typeBytes = 8; \
Miao Wang87e908d2015-03-02 15:15:15 -0800198 if (usePadding) { \
199 srcPtr = ptr; \
200 len = len / 3 * 4; \
201 if (count == 0) { \
202 count = len / 4; \
203 } \
204 ptr = malloc (len * typeBytes); \
205 if (readonly) { \
206 copyWithPadding(ptr, srcPtr, mSize, count); \
207 fnc(__VA_ARGS__); \
208 } else { \
209 fnc(__VA_ARGS__); \
210 copyWithUnPadding(srcPtr, ptr, mSize, count); \
211 } \
212 free(ptr); \
213 ptr = srcPtr; \
214 } else { \
215 fnc(__VA_ARGS__); \
216 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700217 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800218 return; \
219 default: \
220 break; \
221 } \
Miao Wang87e908d2015-03-02 15:15:15 -0800222 UNUSED(len, ptr, srcPtr, typeBytes, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800223}
224
225
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800226class AutoJavaStringToUTF8 {
227public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800228 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Chris Wailes488230c32014-08-14 11:22:40 -0700229 fCStr = env->GetStringUTFChars(str, nullptr);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800230 fLength = env->GetStringUTFLength(str);
231 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800232 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800233 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
234 }
235 const char* c_str() const { return fCStr; }
236 jsize length() const { return fLength; }
237
238private:
239 JNIEnv* fEnv;
240 jstring fJStr;
241 const char* fCStr;
242 jsize fLength;
243};
244
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800245class AutoJavaStringArrayToUTF8 {
246public:
247 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
248 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
Chris Wailes488230c32014-08-14 11:22:40 -0700249 mCStrings = nullptr;
250 mSizeArray = nullptr;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800251 if (stringsLength > 0) {
252 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
253 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
254 for (jsize ct = 0; ct < stringsLength; ct ++) {
255 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
Chris Wailes488230c32014-08-14 11:22:40 -0700256 mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800257 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
258 }
259 }
260 }
261 ~AutoJavaStringArrayToUTF8() {
262 for (jsize ct=0; ct < mStringsLength; ct++) {
263 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
264 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
265 }
266 free(mCStrings);
267 free(mSizeArray);
268 }
269 const char **c_str() const { return mCStrings; }
270 size_t *c_str_len() const { return mSizeArray; }
271 jsize length() const { return mStringsLength; }
272
273private:
274 JNIEnv *mEnv;
275 jobjectArray mStrings;
276 const char **mCStrings;
277 size_t *mSizeArray;
278 jsize mStringsLength;
279};
280
Jason Samsd19f10d2009-05-22 14:03:28 -0700281// ---------------------------------------------------------------------------
282
Jason Samsffe9f482009-06-01 17:45:53 -0700283static jfieldID gContextId = 0;
284static jfieldID gNativeBitmapID = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700285
286static void _nInit(JNIEnv *_env, jclass _this)
287{
Tim Murrayeff663f2013-11-15 13:08:30 -0800288 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsffe9f482009-06-01 17:45:53 -0700289
290 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000291 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700292}
293
Jason Samsd19f10d2009-05-22 14:03:28 -0700294// ---------------------------------------------------------------------------
295
Miao Wang87e908d2015-03-02 15:15:15 -0800296static void copyWithPadding(void* ptr, void* srcPtr, int mSize, int count) {
297 int sizeBytesPad = mSize * 4;
298 int sizeBytes = mSize * 3;
299 uint8_t *dst = static_cast<uint8_t *>(ptr);
300 uint8_t *src = static_cast<uint8_t *>(srcPtr);
301 for (int i = 0; i < count; i++) {
302 memcpy(dst, src, sizeBytes);
303 dst += sizeBytesPad;
304 src += sizeBytes;
305 }
306}
307
308static void copyWithUnPadding(void* ptr, void* srcPtr, int mSize, int count) {
309 int sizeBytesPad = mSize * 4;
310 int sizeBytes = mSize * 3;
311 uint8_t *dst = static_cast<uint8_t *>(ptr);
312 uint8_t *src = static_cast<uint8_t *>(srcPtr);
313 for (int i = 0; i < count; i++) {
314 memcpy(dst, src, sizeBytes);
315 dst += sizeBytes;
316 src += sizeBytesPad;
317 }
318}
319
320
321// ---------------------------------------------------------------------------
Jason Sams3eaa338e2009-06-10 15:04:38 -0700322static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800323nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700324{
Andreas Gampe67333922014-11-10 20:35:59 -0800325 if (kLogApi) {
326 ALOGD("nContextFinish, con(%p)", (RsContext)con);
327 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800328 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700329}
330
Yang Ni281c3252014-10-24 08:52:24 -0700331static jlong
332nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID,
333 jlong returnValue, jlongArray fieldIDArray,
334 jlongArray valueArray, jintArray sizeArray,
335 jlongArray depClosureArray, jlongArray depFieldIDArray) {
336 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
337 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
338 RsScriptFieldID* fieldIDs =
339 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
340 for (int i = 0; i< fieldIDs_length; i++) {
341 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
342 }
343
344 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
345 jsize values_length = _env->GetArrayLength(valueArray);
346 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
347 for (int i = 0; i < values_length; i++) {
348 values[i] = (uintptr_t)jValues[i];
349 }
350
351 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
352 jsize sizes_length = _env->GetArrayLength(sizeArray);
353
354 jlong* jDepClosures =
355 _env->GetLongArrayElements(depClosureArray, nullptr);
356 jsize depClosures_length = _env->GetArrayLength(depClosureArray);
357 RsClosure* depClosures =
358 (RsClosure*)alloca(sizeof(RsClosure) * depClosures_length);
359 for (int i = 0; i < depClosures_length; i++) {
360 depClosures[i] = (RsClosure)jDepClosures[i];
361 }
362
363 jlong* jDepFieldIDs =
364 _env->GetLongArrayElements(depFieldIDArray, nullptr);
365 jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray);
366 RsScriptFieldID* depFieldIDs =
367 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * depFieldIDs_length);
368 for (int i = 0; i < depClosures_length; i++) {
369 depFieldIDs[i] = (RsClosure)jDepFieldIDs[i];
370 }
371
372 return (jlong)(uintptr_t)rsClosureCreate(
373 (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue,
374 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
Yang Ni4c93c8c2015-03-26 14:35:22 -0700375 (int*)sizes, (size_t)sizes_length,
Yang Ni281c3252014-10-24 08:52:24 -0700376 depClosures, (size_t)depClosures_length,
377 depFieldIDs, (size_t)depFieldIDs_length);
378}
379
Yang Nibe392ad2015-01-23 17:16:02 -0800380static jlong
381nInvokeClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong invokeID,
382 jbyteArray paramArray, jlongArray fieldIDArray, jlongArray valueArray,
383 jintArray sizeArray) {
384 jbyte* jParams = _env->GetByteArrayElements(paramArray, nullptr);
385 jsize jParamLength = _env->GetArrayLength(paramArray);
386
387 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
388 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
389 RsScriptFieldID* fieldIDs =
390 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
391 for (int i = 0; i< fieldIDs_length; i++) {
392 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
393 }
394
395 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
396 jsize values_length = _env->GetArrayLength(valueArray);
397 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
398 for (int i = 0; i < values_length; i++) {
399 values[i] = (uintptr_t)jValues[i];
400 }
401
402 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
403 jsize sizes_length = _env->GetArrayLength(sizeArray);
404
405 return (jlong)(uintptr_t)rsInvokeClosureCreate(
406 (RsContext)con, (RsScriptInvokeID)invokeID, jParams, jParamLength,
407 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
Yang Ni4c93c8c2015-03-26 14:35:22 -0700408 (int*)sizes, (size_t)sizes_length);
Yang Nibe392ad2015-01-23 17:16:02 -0800409}
410
Yang Ni281c3252014-10-24 08:52:24 -0700411static void
412nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
413 jint index, jlong value, jint size) {
414 rsClosureSetArg((RsContext)con, (RsClosure)closureID, (uint32_t)index,
415 (uintptr_t)value, (size_t)size);
416}
417
418static void
419nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
420 jlong fieldID, jlong value, jint size) {
421 rsClosureSetGlobal((RsContext)con, (RsClosure)closureID,
422 (RsScriptFieldID)fieldID, (uintptr_t)value, (size_t)size);
423}
424
425static long
Yang Ni35be56c2015-04-02 17:47:56 -0700426nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con, jstring name,
Yang Niebf63402015-01-16 11:06:26 -0800427 jstring cacheDir, jlongArray closureArray) {
Yang Ni35be56c2015-04-02 17:47:56 -0700428 AutoJavaStringToUTF8 nameUTF(_env, name);
Yang Niebf63402015-01-16 11:06:26 -0800429 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
430
Yang Ni281c3252014-10-24 08:52:24 -0700431 jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr);
432 jsize numClosures = _env->GetArrayLength(closureArray);
433 RsClosure* closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures);
434 for (int i = 0; i < numClosures; i++) {
435 closures[i] = (RsClosure)jClosures[i];
436 }
437
Yang Niebf63402015-01-16 11:06:26 -0800438 return (jlong)(uintptr_t)rsScriptGroup2Create(
Yang Ni35be56c2015-04-02 17:47:56 -0700439 (RsContext)con, nameUTF.c_str(), nameUTF.length(),
440 cacheDirUTF.c_str(), cacheDirUTF.length(),
Yang Niebf63402015-01-16 11:06:26 -0800441 closures, numClosures);
Yang Ni281c3252014-10-24 08:52:24 -0700442}
443
444static void
445nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) {
446 rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID);
447}
448
Jason Sams96ed4cf2010-06-15 12:15:57 -0700449static void
Tim Murray25207df2015-01-12 16:47:56 -0800450nScriptIntrinsicBLAS_Single(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
451 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
452 jfloat alpha, jlong A, jlong B, jfloat beta, jlong C, jint incX, jint incY,
453 jint KL, jint KU) {
454 RsBlasCall call;
455 memset(&call, 0, sizeof(call));
456 call.func = (RsBlasFunction)func;
457 call.transA = (RsBlasTranspose)TransA;
458 call.transB = (RsBlasTranspose)TransB;
459 call.side = (RsBlasSide)Side;
460 call.uplo = (RsBlasUplo)Uplo;
461 call.diag = (RsBlasDiag)Diag;
462 call.M = M;
463 call.N = N;
464 call.K = K;
465 call.alpha.f = alpha;
466 call.beta.f = beta;
467 call.incX = incX;
468 call.incY = incY;
469 call.KL = KL;
470 call.KU = KU;
471
472 RsAllocation in_allocs[3];
473 in_allocs[0] = (RsAllocation)A;
474 in_allocs[1] = (RsAllocation)B;
475 in_allocs[2] = (RsAllocation)C;
476
477 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
478 in_allocs, sizeof(in_allocs), nullptr,
479 &call, sizeof(call), nullptr, 0);
480}
481
482static void
483nScriptIntrinsicBLAS_Double(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
484 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
485 jdouble alpha, jlong A, jlong B, jdouble beta, jlong C, jint incX, jint incY,
486 jint KL, jint KU) {
487 RsBlasCall call;
488 memset(&call, 0, sizeof(call));
489 call.func = (RsBlasFunction)func;
490 call.transA = (RsBlasTranspose)TransA;
491 call.transB = (RsBlasTranspose)TransB;
492 call.side = (RsBlasSide)Side;
493 call.uplo = (RsBlasUplo)Uplo;
494 call.diag = (RsBlasDiag)Diag;
495 call.M = M;
496 call.N = N;
497 call.K = K;
498 call.alpha.d = alpha;
499 call.beta.d = beta;
500 call.incX = incX;
501 call.incY = incY;
502 call.KL = KL;
503 call.KU = KU;
504
505 RsAllocation in_allocs[3];
506 in_allocs[0] = (RsAllocation)A;
507 in_allocs[1] = (RsAllocation)B;
508 in_allocs[2] = (RsAllocation)C;
509
510 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
511 in_allocs, sizeof(in_allocs), nullptr,
512 &call, sizeof(call), nullptr, 0);
513}
514
515static void
516nScriptIntrinsicBLAS_Complex(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
517 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
518 jfloat alphaX, jfloat alphaY, jlong A, jlong B, jfloat betaX,
519 jfloat betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
520 RsBlasCall call;
521 memset(&call, 0, sizeof(call));
522 call.func = (RsBlasFunction)func;
523 call.transA = (RsBlasTranspose)TransA;
524 call.transB = (RsBlasTranspose)TransB;
525 call.side = (RsBlasSide)Side;
526 call.uplo = (RsBlasUplo)Uplo;
527 call.diag = (RsBlasDiag)Diag;
528 call.M = M;
529 call.N = N;
530 call.K = K;
531 call.alpha.c.r = alphaX;
532 call.alpha.c.i = alphaY;
533 call.beta.c.r = betaX;
534 call.beta.c.r = betaY;
535 call.incX = incX;
536 call.incY = incY;
537 call.KL = KL;
538 call.KU = KU;
539
540 RsAllocation in_allocs[3];
541 in_allocs[0] = (RsAllocation)A;
542 in_allocs[1] = (RsAllocation)B;
543 in_allocs[2] = (RsAllocation)C;
544
545 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
546 in_allocs, sizeof(in_allocs), nullptr,
547 &call, sizeof(call), nullptr, 0);
548}
549
550static void
551nScriptIntrinsicBLAS_Z(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
552 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
553 jdouble alphaX, jdouble alphaY, jlong A, jlong B, jdouble betaX,
554 jdouble betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
555 RsBlasCall call;
556 memset(&call, 0, sizeof(call));
557 call.func = (RsBlasFunction)func;
558 call.transA = (RsBlasTranspose)TransA;
559 call.transB = (RsBlasTranspose)TransB;
560 call.side = (RsBlasSide)Side;
561 call.uplo = (RsBlasUplo)Uplo;
562 call.diag = (RsBlasDiag)Diag;
563 call.M = M;
564 call.N = N;
565 call.K = K;
566 call.alpha.z.r = alphaX;
567 call.alpha.z.i = alphaY;
568 call.beta.z.r = betaX;
569 call.beta.z.r = betaY;
570 call.incX = incX;
571 call.incY = incY;
572 call.KL = KL;
573 call.KU = KU;
574
575 RsAllocation in_allocs[3];
576 in_allocs[0] = (RsAllocation)A;
577 in_allocs[1] = (RsAllocation)B;
578 in_allocs[2] = (RsAllocation)C;
579
580 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
581 in_allocs, sizeof(in_allocs), nullptr,
582 &call, sizeof(call), nullptr, 0);
583}
584
585
586static void
Tim Murray460a0492013-11-19 12:45:54 -0800587nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700588{
Andreas Gampe67333922014-11-10 20:35:59 -0800589 if (kLogApi) {
590 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
591 }
Jason Sams3eaa338e2009-06-10 15:04:38 -0700592 jint len = _env->GetArrayLength(str);
593 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800594 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700595 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
596}
597
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700598static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800599nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700600{
Andreas Gampe67333922014-11-10 20:35:59 -0800601 if (kLogApi) {
602 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
603 }
Chris Wailes488230c32014-08-14 11:22:40 -0700604 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800605 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700606 if(name == nullptr || strlen(name) == 0) {
607 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700608 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700609 return _env->NewStringUTF(name);
610}
611
Jason Sams7ce033d2009-08-18 14:14:24 -0700612static void
Tim Murray460a0492013-11-19 12:45:54 -0800613nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700614{
Andreas Gampe67333922014-11-10 20:35:59 -0800615 if (kLogApi) {
616 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
617 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800618 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700619}
620
Jason Sams3eaa338e2009-06-10 15:04:38 -0700621// ---------------------------------------------------------------------------
622
Tim Murrayeff663f2013-11-15 13:08:30 -0800623static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700624nDeviceCreate(JNIEnv *_env, jobject _this)
625{
Andreas Gampe67333922014-11-10 20:35:59 -0800626 if (kLogApi) {
627 ALOGD("nDeviceCreate");
628 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700629 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700630}
631
632static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800633nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700634{
Andreas Gampe67333922014-11-10 20:35:59 -0800635 if (kLogApi) {
636 ALOGD("nDeviceDestroy");
637 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700638 return rsDeviceDestroy((RsDevice)dev);
639}
640
Jason Samsebfb4362009-09-23 13:57:02 -0700641static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800642nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700643{
Andreas Gampe67333922014-11-10 20:35:59 -0800644 if (kLogApi) {
645 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
646 }
Jason Samsebfb4362009-09-23 13:57:02 -0700647 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
648}
649
Tim Murrayeff663f2013-11-15 13:08:30 -0800650static jlong
Jason Sams81cd2b12014-12-02 12:36:43 -0800651nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700652{
Andreas Gampe67333922014-11-10 20:35:59 -0800653 if (kLogApi) {
654 ALOGD("nContextCreate");
655 }
Jason Sams81cd2b12014-12-02 12:36:43 -0800656 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags);
Jason Sams704ff642010-02-09 16:05:07 -0800657}
658
Tim Murrayeff663f2013-11-15 13:08:30 -0800659static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800660nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000661 jint colorMin, jint colorPref,
662 jint alphaMin, jint alphaPref,
663 jint depthMin, jint depthPref,
664 jint stencilMin, jint stencilPref,
665 jint samplesMin, jint samplesPref, jfloat samplesQ,
666 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800667{
Jason Sams11c8af92010-10-13 15:31:10 -0700668 RsSurfaceConfig sc;
669 sc.alphaMin = alphaMin;
670 sc.alphaPref = alphaPref;
671 sc.colorMin = colorMin;
672 sc.colorPref = colorPref;
673 sc.depthMin = depthMin;
674 sc.depthPref = depthPref;
675 sc.samplesMin = samplesMin;
676 sc.samplesPref = samplesPref;
677 sc.samplesQ = samplesQ;
678
Andreas Gampe67333922014-11-10 20:35:59 -0800679 if (kLogApi) {
680 ALOGD("nContextCreateGL");
681 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700682 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700683}
684
685static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800686nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800687{
Andreas Gampe67333922014-11-10 20:35:59 -0800688 if (kLogApi) {
689 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
690 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800691 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800692}
693
Tim Murray47f31582015-04-07 15:43:24 -0700694static void
695nContextSetCacheDir(JNIEnv *_env, jobject _this, jlong con, jstring cacheDir)
696{
697 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
698
699 if (kLogApi) {
700 ALOGD("ContextSetCacheDir, con(%p), cacheDir(%s)", (RsContext)con, cacheDirUTF.c_str());
701 }
702 rsContextSetCacheDir((RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length());
703}
704
Jason Sams7d787b42009-11-15 12:14:26 -0800705
706
707static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800708nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800709{
Andreas Gampe67333922014-11-10 20:35:59 -0800710 if (kLogApi) {
711 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
712 width, height, (Surface *)wnd);
713 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800714
Chris Wailes488230c32014-08-14 11:22:40 -0700715 ANativeWindow * window = nullptr;
716 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800717
718 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700719 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800720 }
721
Tim Murrayeff663f2013-11-15 13:08:30 -0800722 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800723}
724
725static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800726nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700727{
Andreas Gampe67333922014-11-10 20:35:59 -0800728 if (kLogApi) {
729 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
730 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800731 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700732}
733
Jason Sams715333b2009-11-17 17:26:46 -0800734static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800735nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800736{
Andreas Gampe67333922014-11-10 20:35:59 -0800737 if (kLogApi) {
738 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
739 }
Jason Sams715333b2009-11-17 17:26:46 -0800740 rsContextDump((RsContext)con, bits);
741}
Jason Samsd19f10d2009-05-22 14:03:28 -0700742
743static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800744nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700745{
Andreas Gampe67333922014-11-10 20:35:59 -0800746 if (kLogApi) {
747 ALOGD("nContextPause, con(%p)", (RsContext)con);
748 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800749 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700750}
751
752static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800753nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700754{
Andreas Gampe67333922014-11-10 20:35:59 -0800755 if (kLogApi) {
756 ALOGD("nContextResume, con(%p)", (RsContext)con);
757 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800758 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700759}
760
Jason Sams1c415172010-11-08 17:06:46 -0800761
762static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800763nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800764{
Andreas Gampe67333922014-11-10 20:35:59 -0800765 if (kLogApi) {
766 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
767 }
Jason Sams1c415172010-11-08 17:06:46 -0800768 char buf[1024];
769
770 size_t receiveLen;
771 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800772 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700773 buf, sizeof(buf),
774 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700775 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800776 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100777 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800778 }
779 return _env->NewStringUTF(buf);
780}
781
Jason Samsedbfabd2011-05-17 15:01:29 -0700782static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800783nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700784{
Jason Sams516c3192009-10-06 13:58:47 -0700785 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800786 if (kLogApi) {
787 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
788 }
Chris Wailes488230c32014-08-14 11:22:40 -0700789 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700790 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800791 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800792 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700793 ptr, len * 4,
794 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700795 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700796 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100797 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700798 }
799 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000800 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800801}
802
803static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800804nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800805{
Andreas Gampe67333922014-11-10 20:35:59 -0800806 if (kLogApi) {
807 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
808 }
Chris Wailes488230c32014-08-14 11:22:40 -0700809 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800810 size_t receiveLen;
811 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800812 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700813 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800814 auxDataPtr[0] = (jint)subID;
815 auxDataPtr[1] = (jint)receiveLen;
816 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000817 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700818}
819
Tim Murrayeff663f2013-11-15 13:08:30 -0800820static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700821{
Andreas Gampe67333922014-11-10 20:35:59 -0800822 if (kLogApi) {
823 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
824 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800825 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700826}
827
Tim Murrayeff663f2013-11-15 13:08:30 -0800828static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700829{
Andreas Gampe67333922014-11-10 20:35:59 -0800830 if (kLogApi) {
831 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
832 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800833 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700834}
835
Jason Sams455d6442013-02-05 19:20:18 -0800836static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800837nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800838{
Chris Wailes488230c32014-08-14 11:22:40 -0700839 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800840 jint len = 0;
841 if (data) {
842 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700843 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800844 }
Andreas Gampe67333922014-11-10 20:35:59 -0800845 if (kLogApi) {
846 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
847 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800848 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800849 if (data) {
850 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
851 }
852}
853
854
Jason Sams516c3192009-10-06 13:58:47 -0700855
Tim Murray460a0492013-11-19 12:45:54 -0800856static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800857nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
858 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700859{
Andreas Gampe67333922014-11-10 20:35:59 -0800860 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100861 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con,
Andreas Gampe67333922014-11-10 20:35:59 -0800862 type, kind, norm, size);
863 }
864 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
865 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700866}
867
Tim Murray460a0492013-11-19 12:45:54 -0800868static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800869nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000870 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700871{
Jason Sams718cd1f2009-12-23 14:35:29 -0800872 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -0800873 if (kLogApi) {
874 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
875 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800876
Chris Wailes488230c32014-08-14 11:22:40 -0700877 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
878 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000879
880 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
881 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
882
883 for(int i = 0; i < fieldCount; i ++) {
884 ids[i] = (RsElement)jIds[i];
885 arraySizes[i] = (uint32_t)jArraySizes[i];
886 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800887
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800888 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
889
890 const char **nameArray = names.c_str();
891 size_t *sizeArray = names.c_str_len();
892
Tim Murray3aa89c12014-08-18 17:51:22 -0700893 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000894 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700895 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700896 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800897
Ashok Bhat98071552014-02-12 09:54:43 +0000898 free(ids);
899 free(arraySizes);
900 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
901 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
902
Tim Murray3aa89c12014-08-18 17:51:22 -0700903 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700904}
905
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700906static void
Tim Murray460a0492013-11-19 12:45:54 -0800907nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700908{
909 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -0800910 if (kLogApi) {
911 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
912 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700913
914 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
915 assert(dataSize == 5);
916
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000917 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800918 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700919
920 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000921 const jint data = (jint)elementData[i];
922 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700923 }
924}
925
926
927static void
Tim Murray460a0492013-11-19 12:45:54 -0800928nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000929 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700930 jobjectArray _names,
931 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700932{
Ashok Bhat98071552014-02-12 09:54:43 +0000933 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -0800934 if (kLogApi) {
935 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
936 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700937
Ashok Bhat98071552014-02-12 09:54:43 +0000938 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
939 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000940 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700941
Andreas Gampe67333922014-11-10 20:35:59 -0800942 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
943 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700944
Ashok Bhat98071552014-02-12 09:54:43 +0000945 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700946 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000947 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700948 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000949 _env->SetLongArrayRegion(_IDs, i, 1, &id);
950 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700951 }
952
953 free(ids);
954 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700955 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700956}
957
Jason Samsd19f10d2009-05-22 14:03:28 -0700958// -----------------------------------
959
Tim Murray460a0492013-11-19 12:45:54 -0800960static jlong
961nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800962 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700963{
Andreas Gampe67333922014-11-10 20:35:59 -0800964 if (kLogApi) {
965 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 +0100966 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv);
Andreas Gampe67333922014-11-10 20:35:59 -0800967 }
Jason Sams3b9c52a2010-10-14 17:48:46 -0700968
Andreas Gampe67333922014-11-10 20:35:59 -0800969 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
970 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700971}
972
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700973static void
Ashok Bhat98071552014-02-12 09:54:43 +0000974nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700975{
976 // We are packing 6 items: mDimX; mDimY; mDimZ;
977 // mDimLOD; mDimFaces; mElement; into typeData
978 int elementCount = _env->GetArrayLength(_typeData);
979
980 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -0800981 if (kLogApi) {
982 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
983 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700984
Ashok Bhat98071552014-02-12 09:54:43 +0000985 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -0800986 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700987
988 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700989 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000990 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700991 }
992}
993
Jason Samsd19f10d2009-05-22 14:03:28 -0700994// -----------------------------------
995
Tim Murray460a0492013-11-19 12:45:54 -0800996static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800997nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
998 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700999{
Andreas Gampe67333922014-11-10 20:35:59 -08001000 if (kLogApi) {
1001 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
1002 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
1003 }
1004 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
1005 (RsAllocationMipmapControl)mips,
1006 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -07001007}
1008
Jason Samsd19f10d2009-05-22 14:03:28 -07001009static void
Tim Murray460a0492013-11-19 12:45:54 -08001010nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -08001011{
Andreas Gampe67333922014-11-10 20:35:59 -08001012 if (kLogApi) {
1013 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
1014 bits);
1015 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001016 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -08001017}
1018
Jason Sams72226e02013-02-22 12:45:54 -08001019static jobject
Tim Murray460a0492013-11-19 12:45:54 -08001020nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -08001021{
Andreas Gampe67333922014-11-10 20:35:59 -08001022 if (kLogApi) {
1023 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1024 }
Jason Sams615e7ce2012-01-13 14:01:20 -08001025
Andreas Gampe67333922014-11-10 20:35:59 -08001026 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
1027 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -08001028 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -07001029 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001030
Jason Sams72226e02013-02-22 12:45:54 -08001031 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
1032 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001033}
1034
1035static void
Tim Murray460a0492013-11-19 12:45:54 -08001036nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -08001037{
Andreas Gampe67333922014-11-10 20:35:59 -08001038 if (kLogApi) {
1039 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
1040 (RsAllocation)alloc, (Surface *)sur);
1041 }
Jason Sams163766c2012-02-15 12:04:24 -08001042
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001043 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -08001044 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -07001045 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -08001046 }
1047
Andreas Gampe67333922014-11-10 20:35:59 -08001048 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
1049 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -08001050}
1051
1052static void
Tim Murray460a0492013-11-19 12:45:54 -08001053nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001054{
Andreas Gampe67333922014-11-10 20:35:59 -08001055 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001056 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001057 }
Tim Murray460a0492013-11-19 12:45:54 -08001058 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001059}
1060
1061static void
Tim Murray460a0492013-11-19 12:45:54 -08001062nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001063{
Andreas Gampe67333922014-11-10 20:35:59 -08001064 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001065 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001066 }
Tim Murray460a0492013-11-19 12:45:54 -08001067 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001068}
1069
1070
1071static void
Tim Murray460a0492013-11-19 12:45:54 -08001072nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -08001073{
Andreas Gampe67333922014-11-10 20:35:59 -08001074 if (kLogApi) {
1075 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
1076 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001077 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -08001078}
1079
Tim Murray460a0492013-11-19 12:45:54 -08001080static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001081nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1082 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -07001083{
Jason Samsffe9f482009-06-01 17:45:53 -07001084 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001085 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -07001086 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -07001087
Jason Sams5476b452010-12-08 16:14:36 -08001088 bitmap.lockPixels();
1089 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001090 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001091 (RsType)type, (RsAllocationMipmapControl)mip,
1092 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001093 bitmap.unlockPixels();
1094 return id;
Jason Samsffe9f482009-06-01 17:45:53 -07001095}
Jason Samsfe08d992009-05-27 14:45:32 -07001096
Tim Murray460a0492013-11-19 12:45:54 -08001097static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001098nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
1099 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -08001100{
1101 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001102 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -08001103 const SkBitmap& bitmap(*nativeBitmap);
1104
1105 bitmap.lockPixels();
1106 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001107 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -08001108 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +00001109 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -08001110 bitmap.unlockPixels();
1111 return id;
1112}
1113
Tim Murray460a0492013-11-19 12:45:54 -08001114static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001115nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1116 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001117{
1118 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001119 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001120 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001121
Jason Sams5476b452010-12-08 16:14:36 -08001122 bitmap.lockPixels();
1123 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001124 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001125 (RsType)type, (RsAllocationMipmapControl)mip,
1126 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001127 bitmap.unlockPixels();
1128 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001129}
1130
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001131static void
Tim Murray460a0492013-11-19 12:45:54 -08001132nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001133{
1134 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001135 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001136 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -08001137 int w = bitmap.width();
1138 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001139
Jason Sams4ef66502010-12-10 16:03:15 -08001140 bitmap.lockPixels();
1141 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001142 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001143 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -08001144 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -08001145 bitmap.unlockPixels();
1146}
1147
1148static void
Tim Murray460a0492013-11-19 12:45:54 -08001149nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -08001150{
1151 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001152 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -08001153 const SkBitmap& bitmap(*nativeBitmap);
1154
1155 bitmap.lockPixels();
1156 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001157 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -08001158 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -07001159 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001160}
1161
Stephen Hines414fa2c2014-04-17 01:02:42 -07001162// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -07001163static void
Tim Murray460a0492013-11-19 12:45:54 -08001164nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001165 jint count, jobject data, jint sizeBytes, jint dataType, jint mSize,
1166 jboolean usePadding)
Jason Samsd19f10d2009-05-22 14:03:28 -07001167{
Jason Samse729a942013-11-06 11:22:02 -08001168 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001169 if (kLogApi) {
1170 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1171 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
1172 dataType);
1173 }
Miao Wang87e908d2015-03-02 15:15:15 -08001174 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true,
1175 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -07001176}
1177
1178static void
Miao Wangc8e237e2015-02-20 18:36:32 -08001179nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1180 jint xoff, jint yoff, jint zoff,
1181 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -07001182{
1183 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -08001184 if (kLogApi) {
Miao Wangc8e237e2015-02-20 18:36:32 -08001185 ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1186 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
Andreas Gampe67333922014-11-10 20:35:59 -08001187 sizeBytes);
1188 }
Chris Wailes488230c32014-08-14 11:22:40 -07001189 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Miao Wangc8e237e2015-02-20 18:36:32 -08001190 rsAllocationElementData((RsContext)con, (RsAllocation)alloc,
1191 xoff, yoff, zoff,
1192 lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -07001193 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1194}
1195
Miao Wangc8e237e2015-02-20 18:36:32 -08001196
Stephen Hines414fa2c2014-04-17 01:02:42 -07001197// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -07001198static void
Tim Murray460a0492013-11-19 12:45:54 -08001199nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001200 jint w, jint h, jobject data, jint sizeBytes, jint dataType, jint mSize,
1201 jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001202{
Jason Samse729a942013-11-06 11:22:02 -08001203 RsAllocation *alloc = (RsAllocation *)_alloc;
1204 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001205 if (kLogApi) {
1206 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1207 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1208 }
Miao Wang87e908d2015-03-02 15:15:15 -08001209 int count = w * h;
1210 PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true,
1211 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -07001212}
1213
Stephen Hines414fa2c2014-04-17 01:02:42 -07001214// Copies from the Allocation pointed to by srcAlloc into the Allocation
1215// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -07001216static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001217nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001218 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001219 jint dstMip, jint dstFace,
1220 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -08001221 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001222 jint srcMip, jint srcFace)
1223{
Andreas Gampe67333922014-11-10 20:35:59 -08001224 if (kLogApi) {
1225 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1226 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
1227 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
1228 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
1229 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
1230 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001231
Tim Murrayeff663f2013-11-15 13:08:30 -08001232 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001233 (RsAllocation)dstAlloc,
1234 dstXoff, dstYoff,
1235 dstMip, dstFace,
1236 width, height,
1237 (RsAllocation)srcAlloc,
1238 srcXoff, srcYoff,
1239 srcMip, srcFace);
1240}
1241
Stephen Hines414fa2c2014-04-17 01:02:42 -07001242// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001243static void
Tim Murray460a0492013-11-19 12:45:54 -08001244nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001245 jint w, jint h, jint d, jobject data, jint sizeBytes, jint dataType,
1246 jint mSize, jboolean usePadding)
Jason Samsb05d6892013-04-09 15:59:24 -07001247{
Jason Samse729a942013-11-06 11:22:02 -08001248 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001249 if (kLogApi) {
1250 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1251 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1252 lod, w, h, d, sizeBytes);
1253 }
Miao Wang87e908d2015-03-02 15:15:15 -08001254 int count = w * h * d;
1255 PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true,
1256 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -07001257}
1258
Stephen Hines414fa2c2014-04-17 01:02:42 -07001259// Copies from the Allocation pointed to by srcAlloc into the Allocation
1260// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -07001261static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001262nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001263 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001264 jint dstMip,
1265 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -08001266 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001267 jint srcMip)
1268{
Andreas Gampe67333922014-11-10 20:35:59 -08001269 if (kLogApi) {
1270 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1271 " dstMip(%i), width(%i), height(%i),"
1272 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
1273 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
1274 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
1275 }
Jason Samsb05d6892013-04-09 15:59:24 -07001276
Tim Murrayeff663f2013-11-15 13:08:30 -08001277 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -07001278 (RsAllocation)dstAlloc,
1279 dstXoff, dstYoff, dstZoff, dstMip,
1280 width, height, depth,
1281 (RsAllocation)srcAlloc,
1282 srcXoff, srcYoff, srcZoff, srcMip);
1283}
1284
Jason Sams21659ac2013-11-06 15:08:07 -08001285
Stephen Hines414fa2c2014-04-17 01:02:42 -07001286// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -07001287static void
Miao Wang87e908d2015-03-02 15:15:15 -08001288nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, jint dataType,
1289 jint mSize, jboolean usePadding)
Jason Sams40a29e82009-08-10 14:55:26 -07001290{
Jason Sams21659ac2013-11-06 15:08:07 -08001291 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001292 if (kLogApi) {
1293 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
1294 }
Miao Wang87e908d2015-03-02 15:15:15 -08001295 int count = 0;
1296 PER_ARRAY_TYPE(0, rsAllocationRead, false,
1297 (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -07001298}
1299
Stephen Hines414fa2c2014-04-17 01:02:42 -07001300// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -07001301static void
Tim Murray460a0492013-11-19 12:45:54 -08001302nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001303 jint count, jobject data, jint sizeBytes, jint dataType,
1304 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001305{
Jason Sams21659ac2013-11-06 15:08:07 -08001306 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001307 if (kLogApi) {
1308 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1309 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
1310 }
Miao Wang87e908d2015-03-02 15:15:15 -08001311 PER_ARRAY_TYPE(0, rsAllocation1DRead, false,
1312 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -08001313}
1314
Miao Wangc8e237e2015-02-20 18:36:32 -08001315// Copies from the Element in the Allocation pointed to by _alloc into the Java array data.
1316static void
Miao Wang45cec0a2015-03-04 16:40:21 -08001317nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
Miao Wangc8e237e2015-02-20 18:36:32 -08001318 jint xoff, jint yoff, jint zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -08001319 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Miao Wangc8e237e2015-02-20 18:36:32 -08001320{
Miao Wang45cec0a2015-03-04 16:40:21 -08001321 jint len = _env->GetArrayLength(data);
Miao Wangc8e237e2015-02-20 18:36:32 -08001322 if (kLogApi) {
Miao Wang45cec0a2015-03-04 16:40:21 -08001323 ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1324 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
1325 sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -08001326 }
Miao Wang45cec0a2015-03-04 16:40:21 -08001327 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
1328 rsAllocationElementRead((RsContext)con, (RsAllocation)alloc,
1329 xoff, yoff, zoff,
Jason Samsa7e25092015-03-11 11:00:00 -07001330 lod, ptr, sizeBytes, compIdx);
Miao Wang45cec0a2015-03-04 16:40:21 -08001331 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
Miao Wangc8e237e2015-02-20 18:36:32 -08001332}
1333
Stephen Hines414fa2c2014-04-17 01:02:42 -07001334// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -08001335static void
Tim Murray460a0492013-11-19 12:45:54 -08001336nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001337 jint w, jint h, jobject data, jint sizeBytes, jint dataType,
1338 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001339{
Jason Sams21659ac2013-11-06 15:08:07 -08001340 RsAllocation *alloc = (RsAllocation *)_alloc;
1341 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001342 if (kLogApi) {
1343 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1344 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1345 }
Miao Wang87e908d2015-03-02 15:15:15 -08001346 int count = w * h;
1347 PER_ARRAY_TYPE(0, rsAllocation2DRead, false,
1348 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -07001349}
Miao Wang87e908d2015-03-02 15:15:15 -08001350
Miao Wangc8e237e2015-02-20 18:36:32 -08001351// Copies from the Allocation pointed to by _alloc into the Java object data.
1352static void
1353nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001354 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType,
1355 jint mSize, jboolean usePadding)
Miao Wangc8e237e2015-02-20 18:36:32 -08001356{
1357 RsAllocation *alloc = (RsAllocation *)_alloc;
1358 if (kLogApi) {
1359 ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1360 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1361 lod, w, h, d, sizeBytes);
1362 }
Miao Wang87e908d2015-03-02 15:15:15 -08001363 int count = w * h * d;
1364 PER_ARRAY_TYPE(nullptr, rsAllocation3DRead, false,
1365 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Miao Wangc8e237e2015-02-20 18:36:32 -08001366}
Jason Samsd19f10d2009-05-22 14:03:28 -07001367
Tim Murray460a0492013-11-19 12:45:54 -08001368static jlong
1369nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001370{
Andreas Gampe67333922014-11-10 20:35:59 -08001371 if (kLogApi) {
1372 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1373 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001374 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001375}
1376
Jason Sams5edc6082010-10-05 13:32:49 -07001377static void
Tim Murray460a0492013-11-19 12:45:54 -08001378nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -07001379{
Andreas Gampe67333922014-11-10 20:35:59 -08001380 if (kLogApi) {
1381 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
1382 (RsAllocation)alloc, dimX);
1383 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001384 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -07001385}
1386
Jason Sams46ba27e32015-02-06 17:45:15 -08001387
1388static jlong
1389nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type)
1390{
1391 if (kLogApi) {
1392 ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)",
1393 (RsContext)con, (RsAllocation)basealloc, (RsElement)type);
1394 }
1395 return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type,
1396 (RsAllocation)basealloc);
1397
1398}
1399
1400static void
1401nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1402 jint x, jint y, jint z, jint face, jint lod,
1403 jint a1, jint a2, jint a3, jint a4)
1404{
1405 uint32_t params[] = {
1406 (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face,
1407 (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4
1408 };
1409 if (kLogApi) {
1410 ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)",
1411 (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4);
1412 }
1413 rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc,
1414 params, sizeof(params));
1415}
1416
1417
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001418// -----------------------------------
1419
Tim Murray460a0492013-11-19 12:45:54 -08001420static jlong
1421nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001422{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001423 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001424 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001425
Tim Murray3aa89c12014-08-18 17:51:22 -07001426 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001427 return id;
1428}
1429
Tim Murray460a0492013-11-19 12:45:54 -08001430static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001431nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001432{
1433 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001434 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001435 return 0;
1436 }
1437
1438 AutoJavaStringToUTF8 str(_env, _path);
1439 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001440 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001441 return 0;
1442 }
1443
Tim Murray3aa89c12014-08-18 17:51:22 -07001444 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001445 return id;
1446}
1447
Tim Murray460a0492013-11-19 12:45:54 -08001448static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001449nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001450{
1451 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001452 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001453
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001454 return id;
1455}
1456
Tim Murray460a0492013-11-19 12:45:54 -08001457static jint
1458nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001459{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001460 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001461 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001462 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001463}
1464
1465static void
Tim Murray460a0492013-11-19 12:45:54 -08001466nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001467{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001468 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001469 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
1470
Tim Murrayeff663f2013-11-15 13:08:30 -08001471 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001472
1473 for(jint i = 0; i < numEntries; i ++) {
1474 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
1475 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
1476 }
1477
1478 free(fileEntries);
1479}
1480
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001481static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001482nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001483{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001484 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001485 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001486 return id;
1487}
Jason Samsd19f10d2009-05-22 14:03:28 -07001488
1489// -----------------------------------
1490
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001491static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001492nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001493 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001494{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001495 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001496 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001497 fileNameUTF.c_str(), fileNameUTF.length(),
1498 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001499
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001500 return id;
1501}
1502
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001503static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001504nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001505 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001506{
1507 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1508 AutoJavaStringToUTF8 nameUTF(_env, name);
1509
Tim Murray3aa89c12014-08-18 17:51:22 -07001510 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001511 nameUTF.c_str(), nameUTF.length(),
1512 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001513 asset->getBuffer(false), asset->getLength());
1514 return id;
1515}
1516
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001517static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001518nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001519 jfloat fontSize, jint dpi)
1520{
1521 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001522 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001523 return 0;
1524 }
1525
1526 AutoJavaStringToUTF8 str(_env, _path);
1527 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001528 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001529 return 0;
1530 }
1531
Tim Murray3aa89c12014-08-18 17:51:22 -07001532 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001533 str.c_str(), str.length(),
1534 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001535 asset->getBuffer(false), asset->getLength());
1536 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001537 return id;
1538}
1539
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001540// -----------------------------------
1541
1542static void
Tim Murray460a0492013-11-19 12:45:54 -08001543nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001544{
Andreas Gampe67333922014-11-10 20:35:59 -08001545 if (kLogApi) {
1546 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1547 (RsScript)script, (RsAllocation)alloc, slot);
1548 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001549 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001550}
1551
1552static void
Tim Murray460a0492013-11-19 12:45:54 -08001553nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001554{
Andreas Gampe67333922014-11-10 20:35:59 -08001555 if (kLogApi) {
1556 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1557 slot, val);
1558 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001559 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001560}
1561
Tim Murray7c4caad2013-04-10 16:21:40 -07001562static jint
Tim Murray460a0492013-11-19 12:45:54 -08001563nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001564{
Andreas Gampe67333922014-11-10 20:35:59 -08001565 if (kLogApi) {
1566 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1567 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001568 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001569 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001570 return value;
1571}
1572
Jason Sams4d339932010-05-11 14:03:58 -07001573static void
Tim Murray460a0492013-11-19 12:45:54 -08001574nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001575{
Andreas Gampe67333922014-11-10 20:35:59 -08001576 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001577 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001578 slot, val);
1579 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001580 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001581}
1582
1583static void
Tim Murray460a0492013-11-19 12:45:54 -08001584nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001585{
Andreas Gampe67333922014-11-10 20:35:59 -08001586 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001587 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001588 slot, val);
1589 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001590 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001591}
1592
Tim Murray7c4caad2013-04-10 16:21:40 -07001593static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001594nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001595{
Andreas Gampe67333922014-11-10 20:35:59 -08001596 if (kLogApi) {
1597 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1598 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001599 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001600 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001601 return value;
1602}
1603
Stephen Hines031ec58c2010-10-11 10:54:21 -07001604static void
Tim Murray460a0492013-11-19 12:45:54 -08001605nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001606{
Andreas Gampe67333922014-11-10 20:35:59 -08001607 if (kLogApi) {
1608 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1609 slot, val);
1610 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001611 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001612}
1613
Tim Murray7c4caad2013-04-10 16:21:40 -07001614static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001615nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001616{
Andreas Gampe67333922014-11-10 20:35:59 -08001617 if (kLogApi) {
1618 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1619 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001620 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001621 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001622 return value;
1623}
1624
Jason Sams4d339932010-05-11 14:03:58 -07001625static void
Tim Murray460a0492013-11-19 12:45:54 -08001626nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001627{
Andreas Gampe67333922014-11-10 20:35:59 -08001628 if (kLogApi) {
1629 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1630 slot, val);
1631 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001632 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001633}
1634
Tim Murray7c4caad2013-04-10 16:21:40 -07001635static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001636nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001637{
Andreas Gampe67333922014-11-10 20:35:59 -08001638 if (kLogApi) {
1639 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1640 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001641 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001642 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001643 return value;
1644}
1645
Stephen Hinesca54ec32010-09-20 17:20:30 -07001646static void
Tim Murray460a0492013-11-19 12:45:54 -08001647nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001648{
Andreas Gampe67333922014-11-10 20:35:59 -08001649 if (kLogApi) {
1650 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1651 }
Jason Sams4d339932010-05-11 14:03:58 -07001652 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001653 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001654 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001655 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1656}
1657
Stephen Hinesadeb8092012-04-20 14:26:06 -07001658static void
Tim Murray460a0492013-11-19 12:45:54 -08001659nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001660{
Andreas Gampe67333922014-11-10 20:35:59 -08001661 if (kLogApi) {
1662 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1663 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001664 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001665 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001666 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001667 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001668}
1669
1670static void
Andreas Gampe67333922014-11-10 20:35:59 -08001671nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1672 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001673{
Andreas Gampe67333922014-11-10 20:35:59 -08001674 if (kLogApi) {
1675 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1676 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001677 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001678 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001679 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001680 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001681 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001682 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001683 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1684 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1685}
1686
Jason Samsd19f10d2009-05-22 14:03:28 -07001687
1688static void
Tim Murray460a0492013-11-19 12:45:54 -08001689nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001690{
Andreas Gampe67333922014-11-10 20:35:59 -08001691 if (kLogApi) {
1692 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1693 }
Romain Guy584a3752009-07-30 18:45:01 -07001694
1695 jint length = _env->GetArrayLength(timeZone);
1696 jbyte* timeZone_ptr;
1697 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1698
Tim Murrayeff663f2013-11-15 13:08:30 -08001699 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001700
1701 if (timeZone_ptr) {
1702 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1703 }
1704}
1705
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001706static void
Tim Murray460a0492013-11-19 12:45:54 -08001707nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001708{
Andreas Gampe67333922014-11-10 20:35:59 -08001709 if (kLogApi) {
1710 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1711 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001712 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001713}
1714
1715static void
Tim Murray460a0492013-11-19 12:45:54 -08001716nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001717{
Andreas Gampe67333922014-11-10 20:35:59 -08001718 if (kLogApi) {
1719 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1720 }
Jason Sams4d339932010-05-11 14:03:58 -07001721 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001722 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001723 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001724 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1725}
1726
Jason Sams6e494d32011-04-27 16:33:11 -07001727static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001728nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1729 jlongArray ains, jlong aout, jbyteArray params,
1730 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001731{
Andreas Gampe67333922014-11-10 20:35:59 -08001732 if (kLogApi) {
1733 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1734 }
Jason Sams6e494d32011-04-27 16:33:11 -07001735
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001736 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001737 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001738
Chris Wailes488230c32014-08-14 11:22:40 -07001739 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001740
Chris Wailes488230c32014-08-14 11:22:40 -07001741 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001742 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001743 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001744
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001745 if (sizeof(RsAllocation) == sizeof(jlong)) {
1746 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001747
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001748 } else {
1749 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001750
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001751 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1752
1753 for (int index = in_len; --index >= 0;) {
1754 in_allocs[index] = (RsAllocation)in_ptr[index];
1755 }
1756 }
Chris Wailes94961062014-06-11 12:01:28 -07001757 }
1758
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001759 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001760 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001761
Chris Wailes488230c32014-08-14 11:22:40 -07001762 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001763 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001764 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001765 }
1766
Chris Wailes488230c32014-08-14 11:22:40 -07001767 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001768 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001769
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001770 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001771 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001772
Chris Wailes488230c32014-08-14 11:22:40 -07001773 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001774 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001775 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001776
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001777 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001778 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001779
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001780 sc.xStart = limit_ptr[0];
1781 sc.xEnd = limit_ptr[1];
1782 sc.yStart = limit_ptr[2];
1783 sc.yEnd = limit_ptr[3];
1784 sc.zStart = limit_ptr[4];
1785 sc.zEnd = limit_ptr[5];
1786 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Jason Sams14331ab2015-01-26 18:14:36 -08001787 sc.arrayStart = 0;
1788 sc.arrayEnd = 0;
1789 sc.array2Start = 0;
1790 sc.array2End = 0;
1791 sc.array3Start = 0;
1792 sc.array3End = 0;
1793 sc.array4Start = 0;
1794 sc.array4End = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001795
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001796 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001797 }
1798
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001799 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1800 in_allocs, in_len, (RsAllocation)aout,
1801 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001802
Chris Wailes488230c32014-08-14 11:22:40 -07001803 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001804 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001805 }
1806
Chris Wailes488230c32014-08-14 11:22:40 -07001807 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001808 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1809 }
1810
Chris Wailes488230c32014-08-14 11:22:40 -07001811 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001812 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1813 }
Chris Wailes94961062014-06-11 12:01:28 -07001814}
1815
Jason Sams22534172009-08-04 16:58:20 -07001816// -----------------------------------
1817
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001818static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001819nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001820 jstring resName, jstring cacheDir,
1821 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001822{
Andreas Gampe67333922014-11-10 20:35:59 -08001823 if (kLogApi) {
1824 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1825 }
Jason Sams22534172009-08-04 16:58:20 -07001826
Jason Samse4a06c52011-03-16 16:29:28 -07001827 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1828 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001829 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001830 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001831 jint _exception = 0;
1832 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001833 if (!scriptRef) {
1834 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001835 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001836 goto exit;
1837 }
Jack Palevich43702d82009-05-28 13:38:16 -07001838 if (length < 0) {
1839 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001840 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001841 goto exit;
1842 }
Jason Samse4a06c52011-03-16 16:29:28 -07001843 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001844 if (remaining < length) {
1845 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001846 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1847 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001848 goto exit;
1849 }
Jason Samse4a06c52011-03-16 16:29:28 -07001850 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001851 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001852
Tim Murrayeff663f2013-11-15 13:08:30 -08001853 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001854
Tim Murray3aa89c12014-08-18 17:51:22 -07001855 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001856 resNameUTF.c_str(), resNameUTF.length(),
1857 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001858 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001859
Jack Palevich43702d82009-05-28 13:38:16 -07001860exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001861 if (script_ptr) {
1862 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001863 _exception ? JNI_ABORT: 0);
1864 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001865
Tim Murray3aa89c12014-08-18 17:51:22 -07001866 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001867}
1868
Tim Murray460a0492013-11-19 12:45:54 -08001869static jlong
1870nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001871{
Andreas Gampe67333922014-11-10 20:35:59 -08001872 if (kLogApi) {
1873 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1874 (void *)eid);
1875 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001876 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001877}
1878
Tim Murray460a0492013-11-19 12:45:54 -08001879static jlong
1880nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001881{
Andreas Gampe67333922014-11-10 20:35:59 -08001882 if (kLogApi) {
1883 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1884 (void *)sid, slot, sig);
1885 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001886 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001887}
1888
Tim Murray460a0492013-11-19 12:45:54 -08001889static jlong
Yang Nibe392ad2015-01-23 17:16:02 -08001890nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
1891{
1892 if (kLogApi) {
Elliott Hughes7ff53fa2015-02-05 21:36:10 -08001893 ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con,
Yang Nibe392ad2015-01-23 17:16:02 -08001894 (void *)sid, slot);
1895 }
1896 return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot);
1897}
1898
1899static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001900nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001901{
Andreas Gampe67333922014-11-10 20:35:59 -08001902 if (kLogApi) {
1903 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1904 slot);
1905 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001906 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001907}
1908
Tim Murray460a0492013-11-19 12:45:54 -08001909static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001910nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1911 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001912{
Andreas Gampe67333922014-11-10 20:35:59 -08001913 if (kLogApi) {
1914 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1915 }
Jason Sams08a81582012-09-18 12:32:10 -07001916
Ashok Bhat98071552014-02-12 09:54:43 +00001917 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001918 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001919 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1920 for(int i = 0; i < kernelsLen; ++i) {
1921 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1922 }
Jason Sams08a81582012-09-18 12:32:10 -07001923
Ashok Bhat98071552014-02-12 09:54:43 +00001924 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001925 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001926 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1927 for(int i = 0; i < srcLen; ++i) {
1928 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1929 }
Jason Sams08a81582012-09-18 12:32:10 -07001930
Ashok Bhat98071552014-02-12 09:54:43 +00001931 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001932 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001933 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1934 for(int i = 0; i < dstkLen; ++i) {
1935 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1936 }
1937
1938 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001939 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001940 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1941 for(int i = 0; i < dstfLen; ++i) {
1942 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1943 }
1944
1945 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001946 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001947 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1948 for(int i = 0; i < typesLen; ++i) {
1949 typesPtr[i] = (RsType)jTypesPtr[i];
1950 }
1951
Tim Murray3aa89c12014-08-18 17:51:22 -07001952 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001953 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1954 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1955 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1956 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1957 (RsType *)typesPtr, typesLen * sizeof(RsType));
1958
1959 free(kernelsPtr);
1960 free(srcPtr);
1961 free(dstkPtr);
1962 free(dstfPtr);
1963 free(typesPtr);
1964 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1965 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1966 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1967 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1968 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001969 return id;
1970}
1971
1972static void
Tim Murray460a0492013-11-19 12:45:54 -08001973nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001974{
Andreas Gampe67333922014-11-10 20:35:59 -08001975 if (kLogApi) {
1976 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1977 (void *)gid, (void *)kid, (void *)alloc);
1978 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001979 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001980}
1981
1982static void
Tim Murray460a0492013-11-19 12:45:54 -08001983nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001984{
Andreas Gampe67333922014-11-10 20:35:59 -08001985 if (kLogApi) {
1986 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1987 (void *)gid, (void *)kid, (void *)alloc);
1988 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001989 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001990}
1991
1992static void
Tim Murray460a0492013-11-19 12:45:54 -08001993nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001994{
Andreas Gampe67333922014-11-10 20:35:59 -08001995 if (kLogApi) {
1996 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
1997 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001998 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001999}
2000
Jason Samsd19f10d2009-05-22 14:03:28 -07002001// ---------------------------------------------------------------------------
2002
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002003static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002004nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07002005 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
2006 jboolean depthMask, jboolean ditherEnable,
2007 jint srcFunc, jint destFunc,
2008 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07002009{
Andreas Gampe67333922014-11-10 20:35:59 -08002010 if (kLogApi) {
2011 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
2012 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002013 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07002014 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
2015 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07002016}
2017
Jason Sams0011bcf2009-12-15 12:58:36 -08002018// ---------------------------------------------------------------------------
2019
2020static void
Tim Murray460a0492013-11-19 12:45:54 -08002021nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08002022{
Andreas Gampe67333922014-11-10 20:35:59 -08002023 if (kLogApi) {
2024 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
2025 (RsProgramVertex)vpv, slot, (RsAllocation)a);
2026 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002027 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08002028}
Jason Sams54c0ec12009-11-30 14:49:55 -08002029
Jason Sams68afd012009-12-17 16:55:08 -08002030static void
Tim Murray460a0492013-11-19 12:45:54 -08002031nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002032{
Andreas Gampe67333922014-11-10 20:35:59 -08002033 if (kLogApi) {
2034 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2035 (RsProgramFragment)vpf, slot, (RsAllocation)a);
2036 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002037 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08002038}
2039
2040static void
Tim Murray460a0492013-11-19 12:45:54 -08002041nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002042{
Andreas Gampe67333922014-11-10 20:35:59 -08002043 if (kLogApi) {
2044 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2045 (RsProgramFragment)vpf, slot, (RsSampler)a);
2046 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002047 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08002048}
2049
Jason Samsd19f10d2009-05-22 14:03:28 -07002050// ---------------------------------------------------------------------------
2051
Tim Murray460a0492013-11-19 12:45:54 -08002052static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002053nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002054 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002055{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002056 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002057 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002058 jint paramLen = _env->GetArrayLength(params);
2059
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002060 int texCount = _env->GetArrayLength(texNames);
2061 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2062 const char ** nameArray = names.c_str();
2063 size_t* sizeArray = names.c_str_len();
2064
Andreas Gampe67333922014-11-10 20:35:59 -08002065 if (kLogApi) {
2066 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2067 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002068
Ashok Bhat98071552014-02-12 09:54:43 +00002069 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2070 for(int i = 0; i < paramLen; ++i) {
2071 paramPtr[i] = (uintptr_t)jParamPtr[i];
2072 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002073 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002074 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002075 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002076
Ashok Bhat98071552014-02-12 09:54:43 +00002077 free(paramPtr);
2078 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002079 return ret;
2080}
2081
2082
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002083// ---------------------------------------------------------------------------
2084
Tim Murray460a0492013-11-19 12:45:54 -08002085static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002086nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002087 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002088{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002089 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002090 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08002091 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002092
Andreas Gampe67333922014-11-10 20:35:59 -08002093 if (kLogApi) {
2094 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2095 }
Jason Sams0011bcf2009-12-15 12:58:36 -08002096
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002097 int texCount = _env->GetArrayLength(texNames);
2098 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2099 const char ** nameArray = names.c_str();
2100 size_t* sizeArray = names.c_str_len();
2101
Ashok Bhat98071552014-02-12 09:54:43 +00002102 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2103 for(int i = 0; i < paramLen; ++i) {
2104 paramPtr[i] = (uintptr_t)jParamPtr[i];
2105 }
2106
Tim Murray3aa89c12014-08-18 17:51:22 -07002107 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002108 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002109 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002110
Ashok Bhat98071552014-02-12 09:54:43 +00002111 free(paramPtr);
2112 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08002113 return ret;
2114}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002115
Jason Samsebfb4362009-09-23 13:57:02 -07002116// ---------------------------------------------------------------------------
2117
Tim Murray460a0492013-11-19 12:45:54 -08002118static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002119nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07002120{
Andreas Gampe67333922014-11-10 20:35:59 -08002121 if (kLogApi) {
2122 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
2123 pointSprite, cull);
2124 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002125 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07002126}
2127
Jason Samsd19f10d2009-05-22 14:03:28 -07002128
2129// ---------------------------------------------------------------------------
2130
2131static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002132nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07002133{
Andreas Gampe67333922014-11-10 20:35:59 -08002134 if (kLogApi) {
2135 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
2136 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002137 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07002138}
2139
2140static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002141nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07002142{
Andreas Gampe67333922014-11-10 20:35:59 -08002143 if (kLogApi) {
2144 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
2145 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002146 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07002147}
2148
2149static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002150nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07002151{
Andreas Gampe67333922014-11-10 20:35:59 -08002152 if (kLogApi) {
2153 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
2154 (RsProgramFragment)pf);
2155 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002156 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07002157}
2158
Jason Sams0826a6f2009-06-15 19:04:56 -07002159static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002160nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07002161{
Andreas Gampe67333922014-11-10 20:35:59 -08002162 if (kLogApi) {
2163 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
2164 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002165 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07002166}
2167
Joe Onoratod7b37742009-08-09 22:57:44 -07002168static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002169nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07002170{
Andreas Gampe67333922014-11-10 20:35:59 -08002171 if (kLogApi) {
2172 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
2173 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002174 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07002175}
2176
Joe Onoratod7b37742009-08-09 22:57:44 -07002177
Jason Sams02fb2cb2009-05-28 15:37:57 -07002178// ---------------------------------------------------------------------------
2179
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002180static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002181nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002182 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07002183{
Andreas Gampe67333922014-11-10 20:35:59 -08002184 if (kLogApi) {
2185 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
2186 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002187 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002188 (RsSamplerValue)magFilter,
2189 (RsSamplerValue)minFilter,
2190 (RsSamplerValue)wrapS,
2191 (RsSamplerValue)wrapT,
2192 (RsSamplerValue)wrapR,
2193 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07002194}
2195
Jason Samsbba134c2009-06-22 15:49:21 -07002196// ---------------------------------------------------------------------------
2197
Tim Murray460a0492013-11-19 12:45:54 -08002198static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00002199nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07002200{
Andreas Gampe67333922014-11-10 20:35:59 -08002201 if (kLogApi) {
2202 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
2203 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002204
2205 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07002206 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002207 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
2208 for(int i = 0; i < vtxLen; ++i) {
2209 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
2210 }
2211
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002212 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07002213 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002214 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
2215 for(int i = 0; i < idxLen; ++i) {
2216 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
2217 }
2218
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002219 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07002220 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002221
Tim Murray3aa89c12014-08-18 17:51:22 -07002222 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002223 (RsAllocation *)vtxPtr, vtxLen,
2224 (RsAllocation *)idxPtr, idxLen,
2225 (uint32_t *)primPtr, primLen);
2226
Ashok Bhat98071552014-02-12 09:54:43 +00002227 free(vtxPtr);
2228 free(idxPtr);
2229 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
2230 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002231 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002232 return id;
2233}
2234
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002235static jint
Tim Murray460a0492013-11-19 12:45:54 -08002236nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002237{
Andreas Gampe67333922014-11-10 20:35:59 -08002238 if (kLogApi) {
2239 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2240 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002241 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002242 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002243 return vtxCount;
2244}
2245
2246static jint
Tim Murray460a0492013-11-19 12:45:54 -08002247nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002248{
Andreas Gampe67333922014-11-10 20:35:59 -08002249 if (kLogApi) {
2250 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2251 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002252 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002253 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002254 return idxCount;
2255}
2256
2257static void
Ashok Bhat98071552014-02-12 09:54:43 +00002258nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002259{
Andreas Gampe67333922014-11-10 20:35:59 -08002260 if (kLogApi) {
2261 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2262 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002263
2264 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08002265 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002266
2267 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002268 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002269 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002270 }
2271
2272 free(allocs);
2273}
2274
2275static void
Ashok Bhat98071552014-02-12 09:54:43 +00002276nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002277{
Andreas Gampe67333922014-11-10 20:35:59 -08002278 if (kLogApi) {
2279 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2280 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002281
2282 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
2283 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
2284
Tim Murrayeff663f2013-11-15 13:08:30 -08002285 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002286
2287 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002288 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002289 const jint prim = (jint)prims[i];
2290 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
2291 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002292 }
2293
2294 free(allocs);
2295 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002296}
2297
Tim Murray56f9e6f2014-05-16 11:47:26 -07002298static jint
2299nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
2300 return (jint)sizeof(void*);
2301}
2302
2303
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002304// ---------------------------------------------------------------------------
2305
Jason Samsd19f10d2009-05-22 14:03:28 -07002306
Jason Sams94d8e90a2009-06-10 16:09:05 -07002307static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07002308
2309static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08002310{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07002311
Tim Murrayeff663f2013-11-15 13:08:30 -08002312{"nDeviceCreate", "()J", (void*)nDeviceCreate },
2313{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
2314{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
2315{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
2316{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
2317{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08002318
Tim Murrayeff663f2013-11-15 13:08:30 -08002319{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
2320{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07002321
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07002322
Jason Sams2e1872f2010-08-17 16:25:41 -07002323// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08002324{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
2325{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
2326{"rsnContextFinish", "(J)V", (void*)nContextFinish },
2327{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
Tim Murray47f31582015-04-07 15:43:24 -07002328{"rsnContextSetCacheDir", "(JLjava/lang/String;)V", (void*)nContextSetCacheDir },
Tim Murrayeff663f2013-11-15 13:08:30 -08002329{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
2330{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
2331{"rsnContextDump", "(JI)V", (void*)nContextDump },
2332{"rsnContextPause", "(J)V", (void*)nContextPause },
2333{"rsnContextResume", "(J)V", (void*)nContextResume },
2334{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07002335{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002336{"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate },
Yang Ni281c3252014-10-24 08:52:24 -07002337{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
2338{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08002339{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
2340{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
2341{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07002342
Tim Murray460a0492013-11-19 12:45:54 -08002343{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002344{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08002345{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
2346{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
2347{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002348{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07002349
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002350{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
2351{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
2352{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07002353
Tim Murray460a0492013-11-19 12:45:54 -08002354{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002355{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08002356{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00002357{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07002358
Tim Murray460a0492013-11-19 12:45:54 -08002359{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002360{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07002361
Ashok Bhat98071552014-02-12 09:54:43 +00002362{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08002363{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
2364{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
2365{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08002366
Tim Murray460a0492013-11-19 12:45:54 -08002367{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
2368{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08002369
Tim Murray460a0492013-11-19 12:45:54 -08002370{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
2371{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
2372{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
2373{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
2374{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
Miao Wang87e908d2015-03-02 15:15:15 -08002375{"rsnAllocationData1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData1D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002376{"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData },
Miao Wang87e908d2015-03-02 15:15:15 -08002377{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData2D },
Tim Murray460a0492013-11-19 12:45:54 -08002378{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002379{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData3D },
Tim Murray460a0492013-11-19 12:45:54 -08002380{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002381{"rsnAllocationRead", "(JJLjava/lang/Object;IIZ)V", (void*)nAllocationRead },
2382{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead1D },
Miao Wang45cec0a2015-03-04 16:40:21 -08002383{"rsnAllocationElementRead", "(JJIIIII[BI)V", (void*)nAllocationElementRead },
Miao Wang87e908d2015-03-02 15:15:15 -08002384{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead2D },
2385{"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead3D },
Tim Murray460a0492013-11-19 12:45:54 -08002386{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
2387{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
2388{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07002389
Jason Sams46ba27e32015-02-06 17:45:15 -08002390{"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate },
2391{"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset },
2392
Tim Murray460a0492013-11-19 12:45:54 -08002393{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
2394{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
2395{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
2396{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07002397
2398{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
2399
Tim Murray460a0492013-11-19 12:45:54 -08002400{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
2401{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
2402{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
2403{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
2404{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
2405{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
2406{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
2407{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
2408{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
2409{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
2410{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
2411{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07002412
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002413{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002414{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2415{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002416{"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002417{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002418{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Ni35be56c2015-04-02 17:47:56 -07002419{"rsnScriptGroup2Create", "(JLjava/lang/String;Ljava/lang/String;[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002420{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2421{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2422{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002423{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002424
Tim Murray25207df2015-01-12 16:47:56 -08002425{"rsnScriptIntrinsicBLAS_Single", "(JJIIIIIIIIIFJJFJIIII)V", (void*)nScriptIntrinsicBLAS_Single },
2426{"rsnScriptIntrinsicBLAS_Double", "(JJIIIIIIIIIDJJDJIIII)V", (void*)nScriptIntrinsicBLAS_Double },
2427{"rsnScriptIntrinsicBLAS_Complex", "(JJIIIIIIIIIFFJJFFJIIII)V", (void*)nScriptIntrinsicBLAS_Complex },
2428{"rsnScriptIntrinsicBLAS_Z", "(JJIIIIIIIIIDDJJDDJIIII)V", (void*)nScriptIntrinsicBLAS_Z },
2429
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002430{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002431
Tim Murray460a0492013-11-19 12:45:54 -08002432{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2433{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2434{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002435
Ashok Bhat98071552014-02-12 09:54:43 +00002436{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002437{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002438{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002439
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002440{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2441{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2442{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2443{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2444{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002445
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002446{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002447
Ashok Bhat98071552014-02-12 09:54:43 +00002448{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002449
Tim Murray460a0492013-11-19 12:45:54 -08002450{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2451{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002452{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2453{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002454
Tim Murray56f9e6f2014-05-16 11:47:26 -07002455{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002456};
2457
2458static int registerFuncs(JNIEnv *_env)
2459{
2460 return android::AndroidRuntime::registerNativeMethods(
2461 _env, classPathName, methods, NELEM(methods));
2462}
2463
2464// ---------------------------------------------------------------------------
2465
2466jint JNI_OnLoad(JavaVM* vm, void* reserved)
2467{
Chris Wailes488230c32014-08-14 11:22:40 -07002468 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002469 jint result = -1;
2470
Jason Samsd19f10d2009-05-22 14:03:28 -07002471 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002472 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002473 goto bail;
2474 }
Chris Wailes488230c32014-08-14 11:22:40 -07002475 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002476
2477 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002478 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002479 goto bail;
2480 }
2481
2482 /* success -- return valid version number */
2483 result = JNI_VERSION_1_4;
2484
2485bail:
2486 return result;
2487}