blob: 3591199acdaf5ffc0463baf89ceb4bdce788c482 [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
426nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con,
Yang Niebf63402015-01-16 11:06:26 -0800427 jstring cacheDir, jlongArray closureArray) {
428 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
429
Yang Ni281c3252014-10-24 08:52:24 -0700430 jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr);
431 jsize numClosures = _env->GetArrayLength(closureArray);
432 RsClosure* closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures);
433 for (int i = 0; i < numClosures; i++) {
434 closures[i] = (RsClosure)jClosures[i];
435 }
436
Yang Niebf63402015-01-16 11:06:26 -0800437 return (jlong)(uintptr_t)rsScriptGroup2Create(
438 (RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length(),
439 closures, numClosures);
Yang Ni281c3252014-10-24 08:52:24 -0700440}
441
442static void
443nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) {
444 rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID);
445}
446
Jason Sams96ed4cf2010-06-15 12:15:57 -0700447static void
Tim Murray25207df2015-01-12 16:47:56 -0800448nScriptIntrinsicBLAS_Single(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
449 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
450 jfloat alpha, jlong A, jlong B, jfloat beta, jlong C, jint incX, jint incY,
451 jint KL, jint KU) {
452 RsBlasCall call;
453 memset(&call, 0, sizeof(call));
454 call.func = (RsBlasFunction)func;
455 call.transA = (RsBlasTranspose)TransA;
456 call.transB = (RsBlasTranspose)TransB;
457 call.side = (RsBlasSide)Side;
458 call.uplo = (RsBlasUplo)Uplo;
459 call.diag = (RsBlasDiag)Diag;
460 call.M = M;
461 call.N = N;
462 call.K = K;
463 call.alpha.f = alpha;
464 call.beta.f = beta;
465 call.incX = incX;
466 call.incY = incY;
467 call.KL = KL;
468 call.KU = KU;
469
470 RsAllocation in_allocs[3];
471 in_allocs[0] = (RsAllocation)A;
472 in_allocs[1] = (RsAllocation)B;
473 in_allocs[2] = (RsAllocation)C;
474
475 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
476 in_allocs, sizeof(in_allocs), nullptr,
477 &call, sizeof(call), nullptr, 0);
478}
479
480static void
481nScriptIntrinsicBLAS_Double(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
482 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
483 jdouble alpha, jlong A, jlong B, jdouble beta, jlong C, jint incX, jint incY,
484 jint KL, jint KU) {
485 RsBlasCall call;
486 memset(&call, 0, sizeof(call));
487 call.func = (RsBlasFunction)func;
488 call.transA = (RsBlasTranspose)TransA;
489 call.transB = (RsBlasTranspose)TransB;
490 call.side = (RsBlasSide)Side;
491 call.uplo = (RsBlasUplo)Uplo;
492 call.diag = (RsBlasDiag)Diag;
493 call.M = M;
494 call.N = N;
495 call.K = K;
496 call.alpha.d = alpha;
497 call.beta.d = beta;
498 call.incX = incX;
499 call.incY = incY;
500 call.KL = KL;
501 call.KU = KU;
502
503 RsAllocation in_allocs[3];
504 in_allocs[0] = (RsAllocation)A;
505 in_allocs[1] = (RsAllocation)B;
506 in_allocs[2] = (RsAllocation)C;
507
508 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
509 in_allocs, sizeof(in_allocs), nullptr,
510 &call, sizeof(call), nullptr, 0);
511}
512
513static void
514nScriptIntrinsicBLAS_Complex(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
515 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
516 jfloat alphaX, jfloat alphaY, jlong A, jlong B, jfloat betaX,
517 jfloat betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
518 RsBlasCall call;
519 memset(&call, 0, sizeof(call));
520 call.func = (RsBlasFunction)func;
521 call.transA = (RsBlasTranspose)TransA;
522 call.transB = (RsBlasTranspose)TransB;
523 call.side = (RsBlasSide)Side;
524 call.uplo = (RsBlasUplo)Uplo;
525 call.diag = (RsBlasDiag)Diag;
526 call.M = M;
527 call.N = N;
528 call.K = K;
529 call.alpha.c.r = alphaX;
530 call.alpha.c.i = alphaY;
531 call.beta.c.r = betaX;
532 call.beta.c.r = betaY;
533 call.incX = incX;
534 call.incY = incY;
535 call.KL = KL;
536 call.KU = KU;
537
538 RsAllocation in_allocs[3];
539 in_allocs[0] = (RsAllocation)A;
540 in_allocs[1] = (RsAllocation)B;
541 in_allocs[2] = (RsAllocation)C;
542
543 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
544 in_allocs, sizeof(in_allocs), nullptr,
545 &call, sizeof(call), nullptr, 0);
546}
547
548static void
549nScriptIntrinsicBLAS_Z(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
550 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
551 jdouble alphaX, jdouble alphaY, jlong A, jlong B, jdouble betaX,
552 jdouble betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
553 RsBlasCall call;
554 memset(&call, 0, sizeof(call));
555 call.func = (RsBlasFunction)func;
556 call.transA = (RsBlasTranspose)TransA;
557 call.transB = (RsBlasTranspose)TransB;
558 call.side = (RsBlasSide)Side;
559 call.uplo = (RsBlasUplo)Uplo;
560 call.diag = (RsBlasDiag)Diag;
561 call.M = M;
562 call.N = N;
563 call.K = K;
564 call.alpha.z.r = alphaX;
565 call.alpha.z.i = alphaY;
566 call.beta.z.r = betaX;
567 call.beta.z.r = betaY;
568 call.incX = incX;
569 call.incY = incY;
570 call.KL = KL;
571 call.KU = KU;
572
573 RsAllocation in_allocs[3];
574 in_allocs[0] = (RsAllocation)A;
575 in_allocs[1] = (RsAllocation)B;
576 in_allocs[2] = (RsAllocation)C;
577
578 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
579 in_allocs, sizeof(in_allocs), nullptr,
580 &call, sizeof(call), nullptr, 0);
581}
582
583
584static void
Tim Murray460a0492013-11-19 12:45:54 -0800585nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700586{
Andreas Gampe67333922014-11-10 20:35:59 -0800587 if (kLogApi) {
588 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
589 }
Jason Sams3eaa338e2009-06-10 15:04:38 -0700590 jint len = _env->GetArrayLength(str);
591 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800592 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700593 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
594}
595
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700596static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800597nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700598{
Andreas Gampe67333922014-11-10 20:35:59 -0800599 if (kLogApi) {
600 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
601 }
Chris Wailes488230c32014-08-14 11:22:40 -0700602 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800603 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700604 if(name == nullptr || strlen(name) == 0) {
605 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700606 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700607 return _env->NewStringUTF(name);
608}
609
Jason Sams7ce033d2009-08-18 14:14:24 -0700610static void
Tim Murray460a0492013-11-19 12:45:54 -0800611nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700612{
Andreas Gampe67333922014-11-10 20:35:59 -0800613 if (kLogApi) {
614 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
615 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800616 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700617}
618
Jason Sams3eaa338e2009-06-10 15:04:38 -0700619// ---------------------------------------------------------------------------
620
Tim Murrayeff663f2013-11-15 13:08:30 -0800621static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700622nDeviceCreate(JNIEnv *_env, jobject _this)
623{
Andreas Gampe67333922014-11-10 20:35:59 -0800624 if (kLogApi) {
625 ALOGD("nDeviceCreate");
626 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700627 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700628}
629
630static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800631nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700632{
Andreas Gampe67333922014-11-10 20:35:59 -0800633 if (kLogApi) {
634 ALOGD("nDeviceDestroy");
635 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700636 return rsDeviceDestroy((RsDevice)dev);
637}
638
Jason Samsebfb4362009-09-23 13:57:02 -0700639static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800640nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700641{
Andreas Gampe67333922014-11-10 20:35:59 -0800642 if (kLogApi) {
643 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
644 }
Jason Samsebfb4362009-09-23 13:57:02 -0700645 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
646}
647
Tim Murrayeff663f2013-11-15 13:08:30 -0800648static jlong
Jason Sams81cd2b12014-12-02 12:36:43 -0800649nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700650{
Andreas Gampe67333922014-11-10 20:35:59 -0800651 if (kLogApi) {
652 ALOGD("nContextCreate");
653 }
Jason Sams81cd2b12014-12-02 12:36:43 -0800654 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags);
Jason Sams704ff642010-02-09 16:05:07 -0800655}
656
Tim Murrayeff663f2013-11-15 13:08:30 -0800657static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800658nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000659 jint colorMin, jint colorPref,
660 jint alphaMin, jint alphaPref,
661 jint depthMin, jint depthPref,
662 jint stencilMin, jint stencilPref,
663 jint samplesMin, jint samplesPref, jfloat samplesQ,
664 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800665{
Jason Sams11c8af92010-10-13 15:31:10 -0700666 RsSurfaceConfig sc;
667 sc.alphaMin = alphaMin;
668 sc.alphaPref = alphaPref;
669 sc.colorMin = colorMin;
670 sc.colorPref = colorPref;
671 sc.depthMin = depthMin;
672 sc.depthPref = depthPref;
673 sc.samplesMin = samplesMin;
674 sc.samplesPref = samplesPref;
675 sc.samplesQ = samplesQ;
676
Andreas Gampe67333922014-11-10 20:35:59 -0800677 if (kLogApi) {
678 ALOGD("nContextCreateGL");
679 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700680 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700681}
682
683static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800684nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800685{
Andreas Gampe67333922014-11-10 20:35:59 -0800686 if (kLogApi) {
687 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
688 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800689 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800690}
691
692
693
694static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800695nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800696{
Andreas Gampe67333922014-11-10 20:35:59 -0800697 if (kLogApi) {
698 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
699 width, height, (Surface *)wnd);
700 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800701
Chris Wailes488230c32014-08-14 11:22:40 -0700702 ANativeWindow * window = nullptr;
703 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800704
705 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700706 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800707 }
708
Tim Murrayeff663f2013-11-15 13:08:30 -0800709 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800710}
711
712static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800713nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700714{
Andreas Gampe67333922014-11-10 20:35:59 -0800715 if (kLogApi) {
716 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
717 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800718 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700719}
720
Jason Sams715333b2009-11-17 17:26:46 -0800721static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800722nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800723{
Andreas Gampe67333922014-11-10 20:35:59 -0800724 if (kLogApi) {
725 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
726 }
Jason Sams715333b2009-11-17 17:26:46 -0800727 rsContextDump((RsContext)con, bits);
728}
Jason Samsd19f10d2009-05-22 14:03:28 -0700729
730static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800731nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700732{
Andreas Gampe67333922014-11-10 20:35:59 -0800733 if (kLogApi) {
734 ALOGD("nContextPause, con(%p)", (RsContext)con);
735 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800736 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700737}
738
739static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800740nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700741{
Andreas Gampe67333922014-11-10 20:35:59 -0800742 if (kLogApi) {
743 ALOGD("nContextResume, con(%p)", (RsContext)con);
744 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800745 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700746}
747
Jason Sams1c415172010-11-08 17:06:46 -0800748
749static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800750nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800751{
Andreas Gampe67333922014-11-10 20:35:59 -0800752 if (kLogApi) {
753 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
754 }
Jason Sams1c415172010-11-08 17:06:46 -0800755 char buf[1024];
756
757 size_t receiveLen;
758 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800759 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700760 buf, sizeof(buf),
761 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700762 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800763 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100764 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800765 }
766 return _env->NewStringUTF(buf);
767}
768
Jason Samsedbfabd2011-05-17 15:01:29 -0700769static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800770nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700771{
Jason Sams516c3192009-10-06 13:58:47 -0700772 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800773 if (kLogApi) {
774 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
775 }
Chris Wailes488230c32014-08-14 11:22:40 -0700776 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700777 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800778 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800779 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700780 ptr, len * 4,
781 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700782 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700783 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100784 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700785 }
786 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000787 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800788}
789
790static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800791nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800792{
Andreas Gampe67333922014-11-10 20:35:59 -0800793 if (kLogApi) {
794 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
795 }
Chris Wailes488230c32014-08-14 11:22:40 -0700796 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800797 size_t receiveLen;
798 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800799 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700800 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800801 auxDataPtr[0] = (jint)subID;
802 auxDataPtr[1] = (jint)receiveLen;
803 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000804 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700805}
806
Tim Murrayeff663f2013-11-15 13:08:30 -0800807static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700808{
Andreas Gampe67333922014-11-10 20:35:59 -0800809 if (kLogApi) {
810 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
811 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800812 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700813}
814
Tim Murrayeff663f2013-11-15 13:08:30 -0800815static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700816{
Andreas Gampe67333922014-11-10 20:35:59 -0800817 if (kLogApi) {
818 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
819 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800820 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700821}
822
Jason Sams455d6442013-02-05 19:20:18 -0800823static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800824nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800825{
Chris Wailes488230c32014-08-14 11:22:40 -0700826 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800827 jint len = 0;
828 if (data) {
829 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700830 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800831 }
Andreas Gampe67333922014-11-10 20:35:59 -0800832 if (kLogApi) {
833 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
834 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800835 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800836 if (data) {
837 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
838 }
839}
840
841
Jason Sams516c3192009-10-06 13:58:47 -0700842
Tim Murray460a0492013-11-19 12:45:54 -0800843static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800844nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
845 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700846{
Andreas Gampe67333922014-11-10 20:35:59 -0800847 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100848 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con,
Andreas Gampe67333922014-11-10 20:35:59 -0800849 type, kind, norm, size);
850 }
851 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
852 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700853}
854
Tim Murray460a0492013-11-19 12:45:54 -0800855static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800856nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000857 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700858{
Jason Sams718cd1f2009-12-23 14:35:29 -0800859 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -0800860 if (kLogApi) {
861 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
862 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800863
Chris Wailes488230c32014-08-14 11:22:40 -0700864 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
865 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000866
867 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
868 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
869
870 for(int i = 0; i < fieldCount; i ++) {
871 ids[i] = (RsElement)jIds[i];
872 arraySizes[i] = (uint32_t)jArraySizes[i];
873 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800874
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800875 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
876
877 const char **nameArray = names.c_str();
878 size_t *sizeArray = names.c_str_len();
879
Tim Murray3aa89c12014-08-18 17:51:22 -0700880 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000881 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700882 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700883 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800884
Ashok Bhat98071552014-02-12 09:54:43 +0000885 free(ids);
886 free(arraySizes);
887 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
888 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
889
Tim Murray3aa89c12014-08-18 17:51:22 -0700890 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700891}
892
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700893static void
Tim Murray460a0492013-11-19 12:45:54 -0800894nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700895{
896 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -0800897 if (kLogApi) {
898 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
899 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700900
901 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
902 assert(dataSize == 5);
903
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000904 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800905 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700906
907 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000908 const jint data = (jint)elementData[i];
909 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700910 }
911}
912
913
914static void
Tim Murray460a0492013-11-19 12:45:54 -0800915nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000916 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700917 jobjectArray _names,
918 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700919{
Ashok Bhat98071552014-02-12 09:54:43 +0000920 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -0800921 if (kLogApi) {
922 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
923 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700924
Ashok Bhat98071552014-02-12 09:54:43 +0000925 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
926 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000927 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700928
Andreas Gampe67333922014-11-10 20:35:59 -0800929 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
930 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700931
Ashok Bhat98071552014-02-12 09:54:43 +0000932 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700933 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000934 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700935 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000936 _env->SetLongArrayRegion(_IDs, i, 1, &id);
937 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700938 }
939
940 free(ids);
941 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700942 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700943}
944
Jason Samsd19f10d2009-05-22 14:03:28 -0700945// -----------------------------------
946
Tim Murray460a0492013-11-19 12:45:54 -0800947static jlong
948nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800949 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700950{
Andreas Gampe67333922014-11-10 20:35:59 -0800951 if (kLogApi) {
952 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 +0100953 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv);
Andreas Gampe67333922014-11-10 20:35:59 -0800954 }
Jason Sams3b9c52a2010-10-14 17:48:46 -0700955
Andreas Gampe67333922014-11-10 20:35:59 -0800956 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
957 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700958}
959
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700960static void
Ashok Bhat98071552014-02-12 09:54:43 +0000961nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700962{
963 // We are packing 6 items: mDimX; mDimY; mDimZ;
964 // mDimLOD; mDimFaces; mElement; into typeData
965 int elementCount = _env->GetArrayLength(_typeData);
966
967 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -0800968 if (kLogApi) {
969 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
970 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700971
Ashok Bhat98071552014-02-12 09:54:43 +0000972 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -0800973 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700974
975 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700976 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000977 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700978 }
979}
980
Jason Samsd19f10d2009-05-22 14:03:28 -0700981// -----------------------------------
982
Tim Murray460a0492013-11-19 12:45:54 -0800983static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800984nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
985 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700986{
Andreas Gampe67333922014-11-10 20:35:59 -0800987 if (kLogApi) {
988 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
989 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
990 }
991 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
992 (RsAllocationMipmapControl)mips,
993 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700994}
995
Jason Samsd19f10d2009-05-22 14:03:28 -0700996static void
Tim Murray460a0492013-11-19 12:45:54 -0800997nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -0800998{
Andreas Gampe67333922014-11-10 20:35:59 -0800999 if (kLogApi) {
1000 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
1001 bits);
1002 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001003 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -08001004}
1005
Jason Sams72226e02013-02-22 12:45:54 -08001006static jobject
Tim Murray460a0492013-11-19 12:45:54 -08001007nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -08001008{
Andreas Gampe67333922014-11-10 20:35:59 -08001009 if (kLogApi) {
1010 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1011 }
Jason Sams615e7ce2012-01-13 14:01:20 -08001012
Andreas Gampe67333922014-11-10 20:35:59 -08001013 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
1014 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -08001015 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -07001016 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001017
Jason Sams72226e02013-02-22 12:45:54 -08001018 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
1019 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001020}
1021
1022static void
Tim Murray460a0492013-11-19 12:45:54 -08001023nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -08001024{
Andreas Gampe67333922014-11-10 20:35:59 -08001025 if (kLogApi) {
1026 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
1027 (RsAllocation)alloc, (Surface *)sur);
1028 }
Jason Sams163766c2012-02-15 12:04:24 -08001029
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001030 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -08001031 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -07001032 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -08001033 }
1034
Andreas Gampe67333922014-11-10 20:35:59 -08001035 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
1036 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -08001037}
1038
1039static void
Tim Murray460a0492013-11-19 12:45:54 -08001040nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001041{
Andreas Gampe67333922014-11-10 20:35:59 -08001042 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001043 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001044 }
Tim Murray460a0492013-11-19 12:45:54 -08001045 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001046}
1047
1048static void
Tim Murray460a0492013-11-19 12:45:54 -08001049nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001050{
Andreas Gampe67333922014-11-10 20:35:59 -08001051 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001052 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001053 }
Tim Murray460a0492013-11-19 12:45:54 -08001054 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001055}
1056
1057
1058static void
Tim Murray460a0492013-11-19 12:45:54 -08001059nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -08001060{
Andreas Gampe67333922014-11-10 20:35:59 -08001061 if (kLogApi) {
1062 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
1063 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001064 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -08001065}
1066
Tim Murray460a0492013-11-19 12:45:54 -08001067static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001068nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1069 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -07001070{
Jason Samsffe9f482009-06-01 17:45:53 -07001071 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001072 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -07001073 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -07001074
Jason Sams5476b452010-12-08 16:14:36 -08001075 bitmap.lockPixels();
1076 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001077 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001078 (RsType)type, (RsAllocationMipmapControl)mip,
1079 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001080 bitmap.unlockPixels();
1081 return id;
Jason Samsffe9f482009-06-01 17:45:53 -07001082}
Jason Samsfe08d992009-05-27 14:45:32 -07001083
Tim Murray460a0492013-11-19 12:45:54 -08001084static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001085nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
1086 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -08001087{
1088 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001089 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -08001090 const SkBitmap& bitmap(*nativeBitmap);
1091
1092 bitmap.lockPixels();
1093 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001094 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -08001095 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +00001096 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -08001097 bitmap.unlockPixels();
1098 return id;
1099}
1100
Tim Murray460a0492013-11-19 12:45:54 -08001101static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001102nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1103 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001104{
1105 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001106 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001107 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001108
Jason Sams5476b452010-12-08 16:14:36 -08001109 bitmap.lockPixels();
1110 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001111 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001112 (RsType)type, (RsAllocationMipmapControl)mip,
1113 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001114 bitmap.unlockPixels();
1115 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001116}
1117
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001118static void
Tim Murray460a0492013-11-19 12:45:54 -08001119nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001120{
1121 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001122 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001123 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -08001124 int w = bitmap.width();
1125 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001126
Jason Sams4ef66502010-12-10 16:03:15 -08001127 bitmap.lockPixels();
1128 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001129 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001130 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -08001131 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -08001132 bitmap.unlockPixels();
1133}
1134
1135static void
Tim Murray460a0492013-11-19 12:45:54 -08001136nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -08001137{
1138 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001139 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -08001140 const SkBitmap& bitmap(*nativeBitmap);
1141
1142 bitmap.lockPixels();
1143 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001144 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -08001145 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -07001146 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001147}
1148
Stephen Hines414fa2c2014-04-17 01:02:42 -07001149// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -07001150static void
Tim Murray460a0492013-11-19 12:45:54 -08001151nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001152 jint count, jobject data, jint sizeBytes, jint dataType, jint mSize,
1153 jboolean usePadding)
Jason Samsd19f10d2009-05-22 14:03:28 -07001154{
Jason Samse729a942013-11-06 11:22:02 -08001155 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001156 if (kLogApi) {
1157 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1158 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
1159 dataType);
1160 }
Miao Wang87e908d2015-03-02 15:15:15 -08001161 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true,
1162 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -07001163}
1164
1165static void
Miao Wangc8e237e2015-02-20 18:36:32 -08001166nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1167 jint xoff, jint yoff, jint zoff,
1168 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -07001169{
1170 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -08001171 if (kLogApi) {
Miao Wangc8e237e2015-02-20 18:36:32 -08001172 ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1173 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
Andreas Gampe67333922014-11-10 20:35:59 -08001174 sizeBytes);
1175 }
Chris Wailes488230c32014-08-14 11:22:40 -07001176 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Miao Wangc8e237e2015-02-20 18:36:32 -08001177 rsAllocationElementData((RsContext)con, (RsAllocation)alloc,
1178 xoff, yoff, zoff,
1179 lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -07001180 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1181}
1182
Miao Wangc8e237e2015-02-20 18:36:32 -08001183
Stephen Hines414fa2c2014-04-17 01:02:42 -07001184// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -07001185static void
Tim Murray460a0492013-11-19 12:45:54 -08001186nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001187 jint w, jint h, jobject data, jint sizeBytes, jint dataType, jint mSize,
1188 jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001189{
Jason Samse729a942013-11-06 11:22:02 -08001190 RsAllocation *alloc = (RsAllocation *)_alloc;
1191 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001192 if (kLogApi) {
1193 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1194 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1195 }
Miao Wang87e908d2015-03-02 15:15:15 -08001196 int count = w * h;
1197 PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true,
1198 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -07001199}
1200
Stephen Hines414fa2c2014-04-17 01:02:42 -07001201// Copies from the Allocation pointed to by srcAlloc into the Allocation
1202// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -07001203static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001204nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001205 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001206 jint dstMip, jint dstFace,
1207 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -08001208 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001209 jint srcMip, jint srcFace)
1210{
Andreas Gampe67333922014-11-10 20:35:59 -08001211 if (kLogApi) {
1212 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1213 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
1214 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
1215 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
1216 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
1217 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001218
Tim Murrayeff663f2013-11-15 13:08:30 -08001219 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001220 (RsAllocation)dstAlloc,
1221 dstXoff, dstYoff,
1222 dstMip, dstFace,
1223 width, height,
1224 (RsAllocation)srcAlloc,
1225 srcXoff, srcYoff,
1226 srcMip, srcFace);
1227}
1228
Stephen Hines414fa2c2014-04-17 01:02:42 -07001229// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001230static void
Tim Murray460a0492013-11-19 12:45:54 -08001231nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001232 jint w, jint h, jint d, jobject data, jint sizeBytes, jint dataType,
1233 jint mSize, jboolean usePadding)
Jason Samsb05d6892013-04-09 15:59:24 -07001234{
Jason Samse729a942013-11-06 11:22:02 -08001235 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001236 if (kLogApi) {
1237 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1238 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1239 lod, w, h, d, sizeBytes);
1240 }
Miao Wang87e908d2015-03-02 15:15:15 -08001241 int count = w * h * d;
1242 PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true,
1243 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -07001244}
1245
Stephen Hines414fa2c2014-04-17 01:02:42 -07001246// Copies from the Allocation pointed to by srcAlloc into the Allocation
1247// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -07001248static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001249nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001250 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001251 jint dstMip,
1252 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -08001253 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001254 jint srcMip)
1255{
Andreas Gampe67333922014-11-10 20:35:59 -08001256 if (kLogApi) {
1257 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1258 " dstMip(%i), width(%i), height(%i),"
1259 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
1260 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
1261 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
1262 }
Jason Samsb05d6892013-04-09 15:59:24 -07001263
Tim Murrayeff663f2013-11-15 13:08:30 -08001264 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -07001265 (RsAllocation)dstAlloc,
1266 dstXoff, dstYoff, dstZoff, dstMip,
1267 width, height, depth,
1268 (RsAllocation)srcAlloc,
1269 srcXoff, srcYoff, srcZoff, srcMip);
1270}
1271
Jason Sams21659ac2013-11-06 15:08:07 -08001272
Stephen Hines414fa2c2014-04-17 01:02:42 -07001273// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -07001274static void
Miao Wang87e908d2015-03-02 15:15:15 -08001275nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, jint dataType,
1276 jint mSize, jboolean usePadding)
Jason Sams40a29e82009-08-10 14:55:26 -07001277{
Jason Sams21659ac2013-11-06 15:08:07 -08001278 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001279 if (kLogApi) {
1280 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
1281 }
Miao Wang87e908d2015-03-02 15:15:15 -08001282 int count = 0;
1283 PER_ARRAY_TYPE(0, rsAllocationRead, false,
1284 (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -07001285}
1286
Stephen Hines414fa2c2014-04-17 01:02:42 -07001287// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -07001288static void
Tim Murray460a0492013-11-19 12:45:54 -08001289nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001290 jint count, jobject data, jint sizeBytes, jint dataType,
1291 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001292{
Jason Sams21659ac2013-11-06 15:08:07 -08001293 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001294 if (kLogApi) {
1295 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1296 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
1297 }
Miao Wang87e908d2015-03-02 15:15:15 -08001298 PER_ARRAY_TYPE(0, rsAllocation1DRead, false,
1299 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -08001300}
1301
Miao Wangc8e237e2015-02-20 18:36:32 -08001302// Copies from the Element in the Allocation pointed to by _alloc into the Java array data.
1303static void
Miao Wang45cec0a2015-03-04 16:40:21 -08001304nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
Miao Wangc8e237e2015-02-20 18:36:32 -08001305 jint xoff, jint yoff, jint zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -08001306 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Miao Wangc8e237e2015-02-20 18:36:32 -08001307{
Miao Wang45cec0a2015-03-04 16:40:21 -08001308 jint len = _env->GetArrayLength(data);
Miao Wangc8e237e2015-02-20 18:36:32 -08001309 if (kLogApi) {
Miao Wang45cec0a2015-03-04 16:40:21 -08001310 ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1311 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
1312 sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -08001313 }
Miao Wang45cec0a2015-03-04 16:40:21 -08001314 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
1315 rsAllocationElementRead((RsContext)con, (RsAllocation)alloc,
1316 xoff, yoff, zoff,
Jason Samsa7e25092015-03-11 11:00:00 -07001317 lod, ptr, sizeBytes, compIdx);
Miao Wang45cec0a2015-03-04 16:40:21 -08001318 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
Miao Wangc8e237e2015-02-20 18:36:32 -08001319}
1320
Stephen Hines414fa2c2014-04-17 01:02:42 -07001321// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -08001322static void
Tim Murray460a0492013-11-19 12:45:54 -08001323nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001324 jint w, jint h, jobject data, jint sizeBytes, jint dataType,
1325 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001326{
Jason Sams21659ac2013-11-06 15:08:07 -08001327 RsAllocation *alloc = (RsAllocation *)_alloc;
1328 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001329 if (kLogApi) {
1330 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1331 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1332 }
Miao Wang87e908d2015-03-02 15:15:15 -08001333 int count = w * h;
1334 PER_ARRAY_TYPE(0, rsAllocation2DRead, false,
1335 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -07001336}
Miao Wang87e908d2015-03-02 15:15:15 -08001337
Miao Wangc8e237e2015-02-20 18:36:32 -08001338// Copies from the Allocation pointed to by _alloc into the Java object data.
1339static void
1340nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001341 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType,
1342 jint mSize, jboolean usePadding)
Miao Wangc8e237e2015-02-20 18:36:32 -08001343{
1344 RsAllocation *alloc = (RsAllocation *)_alloc;
1345 if (kLogApi) {
1346 ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1347 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1348 lod, w, h, d, sizeBytes);
1349 }
Miao Wang87e908d2015-03-02 15:15:15 -08001350 int count = w * h * d;
1351 PER_ARRAY_TYPE(nullptr, rsAllocation3DRead, false,
1352 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Miao Wangc8e237e2015-02-20 18:36:32 -08001353}
Jason Samsd19f10d2009-05-22 14:03:28 -07001354
Tim Murray460a0492013-11-19 12:45:54 -08001355static jlong
1356nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001357{
Andreas Gampe67333922014-11-10 20:35:59 -08001358 if (kLogApi) {
1359 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1360 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001361 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001362}
1363
Jason Sams5edc6082010-10-05 13:32:49 -07001364static void
Tim Murray460a0492013-11-19 12:45:54 -08001365nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -07001366{
Andreas Gampe67333922014-11-10 20:35:59 -08001367 if (kLogApi) {
1368 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
1369 (RsAllocation)alloc, dimX);
1370 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001371 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -07001372}
1373
Jason Sams46ba27e32015-02-06 17:45:15 -08001374
1375static jlong
1376nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type)
1377{
1378 if (kLogApi) {
1379 ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)",
1380 (RsContext)con, (RsAllocation)basealloc, (RsElement)type);
1381 }
1382 return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type,
1383 (RsAllocation)basealloc);
1384
1385}
1386
1387static void
1388nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1389 jint x, jint y, jint z, jint face, jint lod,
1390 jint a1, jint a2, jint a3, jint a4)
1391{
1392 uint32_t params[] = {
1393 (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face,
1394 (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4
1395 };
1396 if (kLogApi) {
1397 ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)",
1398 (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4);
1399 }
1400 rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc,
1401 params, sizeof(params));
1402}
1403
1404
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001405// -----------------------------------
1406
Tim Murray460a0492013-11-19 12:45:54 -08001407static jlong
1408nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001409{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001410 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001411 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001412
Tim Murray3aa89c12014-08-18 17:51:22 -07001413 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001414 return id;
1415}
1416
Tim Murray460a0492013-11-19 12:45:54 -08001417static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001418nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001419{
1420 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001421 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001422 return 0;
1423 }
1424
1425 AutoJavaStringToUTF8 str(_env, _path);
1426 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001427 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001428 return 0;
1429 }
1430
Tim Murray3aa89c12014-08-18 17:51:22 -07001431 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001432 return id;
1433}
1434
Tim Murray460a0492013-11-19 12:45:54 -08001435static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001436nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001437{
1438 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001439 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001440
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001441 return id;
1442}
1443
Tim Murray460a0492013-11-19 12:45:54 -08001444static jint
1445nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001446{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001447 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001448 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001449 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001450}
1451
1452static void
Tim Murray460a0492013-11-19 12:45:54 -08001453nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001454{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001455 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001456 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
1457
Tim Murrayeff663f2013-11-15 13:08:30 -08001458 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001459
1460 for(jint i = 0; i < numEntries; i ++) {
1461 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
1462 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
1463 }
1464
1465 free(fileEntries);
1466}
1467
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001468static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001469nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001470{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001471 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001472 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001473 return id;
1474}
Jason Samsd19f10d2009-05-22 14:03:28 -07001475
1476// -----------------------------------
1477
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001478static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001479nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001480 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001481{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001482 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001483 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001484 fileNameUTF.c_str(), fileNameUTF.length(),
1485 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001486
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001487 return id;
1488}
1489
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001490static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001491nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001492 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001493{
1494 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1495 AutoJavaStringToUTF8 nameUTF(_env, name);
1496
Tim Murray3aa89c12014-08-18 17:51:22 -07001497 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001498 nameUTF.c_str(), nameUTF.length(),
1499 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001500 asset->getBuffer(false), asset->getLength());
1501 return id;
1502}
1503
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001504static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001505nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001506 jfloat fontSize, jint dpi)
1507{
1508 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001509 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001510 return 0;
1511 }
1512
1513 AutoJavaStringToUTF8 str(_env, _path);
1514 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001515 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001516 return 0;
1517 }
1518
Tim Murray3aa89c12014-08-18 17:51:22 -07001519 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001520 str.c_str(), str.length(),
1521 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001522 asset->getBuffer(false), asset->getLength());
1523 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001524 return id;
1525}
1526
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001527// -----------------------------------
1528
1529static void
Tim Murray460a0492013-11-19 12:45:54 -08001530nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001531{
Andreas Gampe67333922014-11-10 20:35:59 -08001532 if (kLogApi) {
1533 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1534 (RsScript)script, (RsAllocation)alloc, slot);
1535 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001536 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001537}
1538
1539static void
Tim Murray460a0492013-11-19 12:45:54 -08001540nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001541{
Andreas Gampe67333922014-11-10 20:35:59 -08001542 if (kLogApi) {
1543 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1544 slot, val);
1545 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001546 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001547}
1548
Tim Murray7c4caad2013-04-10 16:21:40 -07001549static jint
Tim Murray460a0492013-11-19 12:45:54 -08001550nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001551{
Andreas Gampe67333922014-11-10 20:35:59 -08001552 if (kLogApi) {
1553 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1554 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001555 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001556 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001557 return value;
1558}
1559
Jason Sams4d339932010-05-11 14:03:58 -07001560static void
Tim Murray460a0492013-11-19 12:45:54 -08001561nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001562{
Andreas Gampe67333922014-11-10 20:35:59 -08001563 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001564 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001565 slot, val);
1566 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001567 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001568}
1569
1570static void
Tim Murray460a0492013-11-19 12:45:54 -08001571nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001572{
Andreas Gampe67333922014-11-10 20:35:59 -08001573 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001574 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001575 slot, val);
1576 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001577 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001578}
1579
Tim Murray7c4caad2013-04-10 16:21:40 -07001580static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001581nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001582{
Andreas Gampe67333922014-11-10 20:35:59 -08001583 if (kLogApi) {
1584 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1585 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001586 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001587 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001588 return value;
1589}
1590
Stephen Hines031ec58c2010-10-11 10:54:21 -07001591static void
Tim Murray460a0492013-11-19 12:45:54 -08001592nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001593{
Andreas Gampe67333922014-11-10 20:35:59 -08001594 if (kLogApi) {
1595 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1596 slot, val);
1597 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001598 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001599}
1600
Tim Murray7c4caad2013-04-10 16:21:40 -07001601static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001602nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001603{
Andreas Gampe67333922014-11-10 20:35:59 -08001604 if (kLogApi) {
1605 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1606 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001607 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001608 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001609 return value;
1610}
1611
Jason Sams4d339932010-05-11 14:03:58 -07001612static void
Tim Murray460a0492013-11-19 12:45:54 -08001613nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001614{
Andreas Gampe67333922014-11-10 20:35:59 -08001615 if (kLogApi) {
1616 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1617 slot, val);
1618 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001619 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001620}
1621
Tim Murray7c4caad2013-04-10 16:21:40 -07001622static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001623nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001624{
Andreas Gampe67333922014-11-10 20:35:59 -08001625 if (kLogApi) {
1626 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1627 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001628 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001629 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001630 return value;
1631}
1632
Stephen Hinesca54ec32010-09-20 17:20:30 -07001633static void
Tim Murray460a0492013-11-19 12:45:54 -08001634nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001635{
Andreas Gampe67333922014-11-10 20:35:59 -08001636 if (kLogApi) {
1637 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1638 }
Jason Sams4d339932010-05-11 14:03:58 -07001639 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001640 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001641 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001642 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1643}
1644
Stephen Hinesadeb8092012-04-20 14:26:06 -07001645static void
Tim Murray460a0492013-11-19 12:45:54 -08001646nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001647{
Andreas Gampe67333922014-11-10 20:35:59 -08001648 if (kLogApi) {
1649 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1650 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001651 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001652 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001653 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001654 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001655}
1656
1657static void
Andreas Gampe67333922014-11-10 20:35:59 -08001658nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1659 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001660{
Andreas Gampe67333922014-11-10 20:35:59 -08001661 if (kLogApi) {
1662 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1663 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001664 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001665 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001666 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001667 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001668 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001669 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001670 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1671 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1672}
1673
Jason Samsd19f10d2009-05-22 14:03:28 -07001674
1675static void
Tim Murray460a0492013-11-19 12:45:54 -08001676nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001677{
Andreas Gampe67333922014-11-10 20:35:59 -08001678 if (kLogApi) {
1679 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1680 }
Romain Guy584a3752009-07-30 18:45:01 -07001681
1682 jint length = _env->GetArrayLength(timeZone);
1683 jbyte* timeZone_ptr;
1684 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1685
Tim Murrayeff663f2013-11-15 13:08:30 -08001686 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001687
1688 if (timeZone_ptr) {
1689 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1690 }
1691}
1692
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001693static void
Tim Murray460a0492013-11-19 12:45:54 -08001694nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001695{
Andreas Gampe67333922014-11-10 20:35:59 -08001696 if (kLogApi) {
1697 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1698 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001699 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001700}
1701
1702static void
Tim Murray460a0492013-11-19 12:45:54 -08001703nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001704{
Andreas Gampe67333922014-11-10 20:35:59 -08001705 if (kLogApi) {
1706 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1707 }
Jason Sams4d339932010-05-11 14:03:58 -07001708 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001709 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001710 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001711 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1712}
1713
Jason Sams6e494d32011-04-27 16:33:11 -07001714static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001715nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1716 jlongArray ains, jlong aout, jbyteArray params,
1717 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001718{
Andreas Gampe67333922014-11-10 20:35:59 -08001719 if (kLogApi) {
1720 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1721 }
Jason Sams6e494d32011-04-27 16:33:11 -07001722
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001723 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001724 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001725
Chris Wailes488230c32014-08-14 11:22:40 -07001726 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001727
Chris Wailes488230c32014-08-14 11:22:40 -07001728 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001729 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001730 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001731
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001732 if (sizeof(RsAllocation) == sizeof(jlong)) {
1733 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001734
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001735 } else {
1736 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001737
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001738 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1739
1740 for (int index = in_len; --index >= 0;) {
1741 in_allocs[index] = (RsAllocation)in_ptr[index];
1742 }
1743 }
Chris Wailes94961062014-06-11 12:01:28 -07001744 }
1745
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001746 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001747 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001748
Chris Wailes488230c32014-08-14 11:22:40 -07001749 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001750 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001751 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001752 }
1753
Chris Wailes488230c32014-08-14 11:22:40 -07001754 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001755 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001756
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001757 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001758 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001759
Chris Wailes488230c32014-08-14 11:22:40 -07001760 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001761 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001762 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001763
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001764 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001765 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001766
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001767 sc.xStart = limit_ptr[0];
1768 sc.xEnd = limit_ptr[1];
1769 sc.yStart = limit_ptr[2];
1770 sc.yEnd = limit_ptr[3];
1771 sc.zStart = limit_ptr[4];
1772 sc.zEnd = limit_ptr[5];
1773 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Jason Sams14331ab2015-01-26 18:14:36 -08001774 sc.arrayStart = 0;
1775 sc.arrayEnd = 0;
1776 sc.array2Start = 0;
1777 sc.array2End = 0;
1778 sc.array3Start = 0;
1779 sc.array3End = 0;
1780 sc.array4Start = 0;
1781 sc.array4End = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001782
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001783 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001784 }
1785
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001786 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1787 in_allocs, in_len, (RsAllocation)aout,
1788 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001789
Chris Wailes488230c32014-08-14 11:22:40 -07001790 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001791 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001792 }
1793
Chris Wailes488230c32014-08-14 11:22:40 -07001794 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001795 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1796 }
1797
Chris Wailes488230c32014-08-14 11:22:40 -07001798 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001799 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1800 }
Chris Wailes94961062014-06-11 12:01:28 -07001801}
1802
Jason Sams22534172009-08-04 16:58:20 -07001803// -----------------------------------
1804
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001805static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001806nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001807 jstring resName, jstring cacheDir,
1808 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001809{
Andreas Gampe67333922014-11-10 20:35:59 -08001810 if (kLogApi) {
1811 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1812 }
Jason Sams22534172009-08-04 16:58:20 -07001813
Jason Samse4a06c52011-03-16 16:29:28 -07001814 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1815 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001816 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001817 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001818 jint _exception = 0;
1819 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001820 if (!scriptRef) {
1821 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001822 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001823 goto exit;
1824 }
Jack Palevich43702d82009-05-28 13:38:16 -07001825 if (length < 0) {
1826 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001827 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001828 goto exit;
1829 }
Jason Samse4a06c52011-03-16 16:29:28 -07001830 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001831 if (remaining < length) {
1832 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001833 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1834 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001835 goto exit;
1836 }
Jason Samse4a06c52011-03-16 16:29:28 -07001837 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001838 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001839
Tim Murrayeff663f2013-11-15 13:08:30 -08001840 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001841
Tim Murray3aa89c12014-08-18 17:51:22 -07001842 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001843 resNameUTF.c_str(), resNameUTF.length(),
1844 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001845 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001846
Jack Palevich43702d82009-05-28 13:38:16 -07001847exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001848 if (script_ptr) {
1849 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001850 _exception ? JNI_ABORT: 0);
1851 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001852
Tim Murray3aa89c12014-08-18 17:51:22 -07001853 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001854}
1855
Tim Murray460a0492013-11-19 12:45:54 -08001856static jlong
1857nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001858{
Andreas Gampe67333922014-11-10 20:35:59 -08001859 if (kLogApi) {
1860 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1861 (void *)eid);
1862 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001863 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001864}
1865
Tim Murray460a0492013-11-19 12:45:54 -08001866static jlong
1867nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001868{
Andreas Gampe67333922014-11-10 20:35:59 -08001869 if (kLogApi) {
1870 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1871 (void *)sid, slot, sig);
1872 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001873 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001874}
1875
Tim Murray460a0492013-11-19 12:45:54 -08001876static jlong
Yang Nibe392ad2015-01-23 17:16:02 -08001877nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
1878{
1879 if (kLogApi) {
Elliott Hughes7ff53fa2015-02-05 21:36:10 -08001880 ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con,
Yang Nibe392ad2015-01-23 17:16:02 -08001881 (void *)sid, slot);
1882 }
1883 return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot);
1884}
1885
1886static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001887nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001888{
Andreas Gampe67333922014-11-10 20:35:59 -08001889 if (kLogApi) {
1890 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1891 slot);
1892 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001893 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001894}
1895
Tim Murray460a0492013-11-19 12:45:54 -08001896static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001897nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1898 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001899{
Andreas Gampe67333922014-11-10 20:35:59 -08001900 if (kLogApi) {
1901 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1902 }
Jason Sams08a81582012-09-18 12:32:10 -07001903
Ashok Bhat98071552014-02-12 09:54:43 +00001904 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001905 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001906 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1907 for(int i = 0; i < kernelsLen; ++i) {
1908 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1909 }
Jason Sams08a81582012-09-18 12:32:10 -07001910
Ashok Bhat98071552014-02-12 09:54:43 +00001911 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001912 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001913 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1914 for(int i = 0; i < srcLen; ++i) {
1915 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1916 }
Jason Sams08a81582012-09-18 12:32:10 -07001917
Ashok Bhat98071552014-02-12 09:54:43 +00001918 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001919 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001920 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1921 for(int i = 0; i < dstkLen; ++i) {
1922 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1923 }
1924
1925 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001926 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001927 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1928 for(int i = 0; i < dstfLen; ++i) {
1929 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1930 }
1931
1932 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001933 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001934 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1935 for(int i = 0; i < typesLen; ++i) {
1936 typesPtr[i] = (RsType)jTypesPtr[i];
1937 }
1938
Tim Murray3aa89c12014-08-18 17:51:22 -07001939 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001940 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1941 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1942 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1943 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1944 (RsType *)typesPtr, typesLen * sizeof(RsType));
1945
1946 free(kernelsPtr);
1947 free(srcPtr);
1948 free(dstkPtr);
1949 free(dstfPtr);
1950 free(typesPtr);
1951 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1952 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1953 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1954 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1955 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001956 return id;
1957}
1958
1959static void
Tim Murray460a0492013-11-19 12:45:54 -08001960nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001961{
Andreas Gampe67333922014-11-10 20:35:59 -08001962 if (kLogApi) {
1963 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1964 (void *)gid, (void *)kid, (void *)alloc);
1965 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001966 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001967}
1968
1969static void
Tim Murray460a0492013-11-19 12:45:54 -08001970nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001971{
Andreas Gampe67333922014-11-10 20:35:59 -08001972 if (kLogApi) {
1973 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1974 (void *)gid, (void *)kid, (void *)alloc);
1975 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001976 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001977}
1978
1979static void
Tim Murray460a0492013-11-19 12:45:54 -08001980nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001981{
Andreas Gampe67333922014-11-10 20:35:59 -08001982 if (kLogApi) {
1983 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
1984 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001985 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001986}
1987
Jason Samsd19f10d2009-05-22 14:03:28 -07001988// ---------------------------------------------------------------------------
1989
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001990static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001991nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001992 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1993 jboolean depthMask, jboolean ditherEnable,
1994 jint srcFunc, jint destFunc,
1995 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001996{
Andreas Gampe67333922014-11-10 20:35:59 -08001997 if (kLogApi) {
1998 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
1999 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002000 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07002001 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
2002 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07002003}
2004
Jason Sams0011bcf2009-12-15 12:58:36 -08002005// ---------------------------------------------------------------------------
2006
2007static void
Tim Murray460a0492013-11-19 12:45:54 -08002008nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08002009{
Andreas Gampe67333922014-11-10 20:35:59 -08002010 if (kLogApi) {
2011 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
2012 (RsProgramVertex)vpv, slot, (RsAllocation)a);
2013 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002014 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08002015}
Jason Sams54c0ec12009-11-30 14:49:55 -08002016
Jason Sams68afd012009-12-17 16:55:08 -08002017static void
Tim Murray460a0492013-11-19 12:45:54 -08002018nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002019{
Andreas Gampe67333922014-11-10 20:35:59 -08002020 if (kLogApi) {
2021 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2022 (RsProgramFragment)vpf, slot, (RsAllocation)a);
2023 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002024 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08002025}
2026
2027static void
Tim Murray460a0492013-11-19 12:45:54 -08002028nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002029{
Andreas Gampe67333922014-11-10 20:35:59 -08002030 if (kLogApi) {
2031 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2032 (RsProgramFragment)vpf, slot, (RsSampler)a);
2033 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002034 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08002035}
2036
Jason Samsd19f10d2009-05-22 14:03:28 -07002037// ---------------------------------------------------------------------------
2038
Tim Murray460a0492013-11-19 12:45:54 -08002039static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002040nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002041 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002042{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002043 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002044 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002045 jint paramLen = _env->GetArrayLength(params);
2046
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002047 int texCount = _env->GetArrayLength(texNames);
2048 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2049 const char ** nameArray = names.c_str();
2050 size_t* sizeArray = names.c_str_len();
2051
Andreas Gampe67333922014-11-10 20:35:59 -08002052 if (kLogApi) {
2053 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2054 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002055
Ashok Bhat98071552014-02-12 09:54:43 +00002056 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2057 for(int i = 0; i < paramLen; ++i) {
2058 paramPtr[i] = (uintptr_t)jParamPtr[i];
2059 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002060 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002061 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002062 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002063
Ashok Bhat98071552014-02-12 09:54:43 +00002064 free(paramPtr);
2065 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002066 return ret;
2067}
2068
2069
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002070// ---------------------------------------------------------------------------
2071
Tim Murray460a0492013-11-19 12:45:54 -08002072static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002073nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002074 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002075{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002076 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002077 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08002078 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002079
Andreas Gampe67333922014-11-10 20:35:59 -08002080 if (kLogApi) {
2081 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2082 }
Jason Sams0011bcf2009-12-15 12:58:36 -08002083
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002084 int texCount = _env->GetArrayLength(texNames);
2085 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2086 const char ** nameArray = names.c_str();
2087 size_t* sizeArray = names.c_str_len();
2088
Ashok Bhat98071552014-02-12 09:54:43 +00002089 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2090 for(int i = 0; i < paramLen; ++i) {
2091 paramPtr[i] = (uintptr_t)jParamPtr[i];
2092 }
2093
Tim Murray3aa89c12014-08-18 17:51:22 -07002094 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002095 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002096 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002097
Ashok Bhat98071552014-02-12 09:54:43 +00002098 free(paramPtr);
2099 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08002100 return ret;
2101}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002102
Jason Samsebfb4362009-09-23 13:57:02 -07002103// ---------------------------------------------------------------------------
2104
Tim Murray460a0492013-11-19 12:45:54 -08002105static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002106nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07002107{
Andreas Gampe67333922014-11-10 20:35:59 -08002108 if (kLogApi) {
2109 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
2110 pointSprite, cull);
2111 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002112 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07002113}
2114
Jason Samsd19f10d2009-05-22 14:03:28 -07002115
2116// ---------------------------------------------------------------------------
2117
2118static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002119nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07002120{
Andreas Gampe67333922014-11-10 20:35:59 -08002121 if (kLogApi) {
2122 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
2123 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002124 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07002125}
2126
2127static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002128nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07002129{
Andreas Gampe67333922014-11-10 20:35:59 -08002130 if (kLogApi) {
2131 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
2132 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002133 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07002134}
2135
2136static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002137nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07002138{
Andreas Gampe67333922014-11-10 20:35:59 -08002139 if (kLogApi) {
2140 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
2141 (RsProgramFragment)pf);
2142 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002143 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07002144}
2145
Jason Sams0826a6f2009-06-15 19:04:56 -07002146static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002147nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07002148{
Andreas Gampe67333922014-11-10 20:35:59 -08002149 if (kLogApi) {
2150 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
2151 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002152 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07002153}
2154
Joe Onoratod7b37742009-08-09 22:57:44 -07002155static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002156nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07002157{
Andreas Gampe67333922014-11-10 20:35:59 -08002158 if (kLogApi) {
2159 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
2160 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002161 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07002162}
2163
Joe Onoratod7b37742009-08-09 22:57:44 -07002164
Jason Sams02fb2cb2009-05-28 15:37:57 -07002165// ---------------------------------------------------------------------------
2166
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002167static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002168nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002169 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07002170{
Andreas Gampe67333922014-11-10 20:35:59 -08002171 if (kLogApi) {
2172 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
2173 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002174 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002175 (RsSamplerValue)magFilter,
2176 (RsSamplerValue)minFilter,
2177 (RsSamplerValue)wrapS,
2178 (RsSamplerValue)wrapT,
2179 (RsSamplerValue)wrapR,
2180 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07002181}
2182
Jason Samsbba134c2009-06-22 15:49:21 -07002183// ---------------------------------------------------------------------------
2184
Tim Murray460a0492013-11-19 12:45:54 -08002185static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00002186nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07002187{
Andreas Gampe67333922014-11-10 20:35:59 -08002188 if (kLogApi) {
2189 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
2190 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002191
2192 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07002193 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002194 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
2195 for(int i = 0; i < vtxLen; ++i) {
2196 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
2197 }
2198
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002199 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07002200 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002201 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
2202 for(int i = 0; i < idxLen; ++i) {
2203 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
2204 }
2205
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002206 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07002207 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002208
Tim Murray3aa89c12014-08-18 17:51:22 -07002209 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002210 (RsAllocation *)vtxPtr, vtxLen,
2211 (RsAllocation *)idxPtr, idxLen,
2212 (uint32_t *)primPtr, primLen);
2213
Ashok Bhat98071552014-02-12 09:54:43 +00002214 free(vtxPtr);
2215 free(idxPtr);
2216 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
2217 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002218 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002219 return id;
2220}
2221
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002222static jint
Tim Murray460a0492013-11-19 12:45:54 -08002223nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002224{
Andreas Gampe67333922014-11-10 20:35:59 -08002225 if (kLogApi) {
2226 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2227 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002228 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002229 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002230 return vtxCount;
2231}
2232
2233static jint
Tim Murray460a0492013-11-19 12:45:54 -08002234nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002235{
Andreas Gampe67333922014-11-10 20:35:59 -08002236 if (kLogApi) {
2237 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2238 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002239 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002240 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002241 return idxCount;
2242}
2243
2244static void
Ashok Bhat98071552014-02-12 09:54:43 +00002245nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002246{
Andreas Gampe67333922014-11-10 20:35:59 -08002247 if (kLogApi) {
2248 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2249 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002250
2251 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08002252 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002253
2254 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002255 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002256 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002257 }
2258
2259 free(allocs);
2260}
2261
2262static void
Ashok Bhat98071552014-02-12 09:54:43 +00002263nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002264{
Andreas Gampe67333922014-11-10 20:35:59 -08002265 if (kLogApi) {
2266 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2267 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002268
2269 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
2270 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
2271
Tim Murrayeff663f2013-11-15 13:08:30 -08002272 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002273
2274 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002275 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002276 const jint prim = (jint)prims[i];
2277 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
2278 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002279 }
2280
2281 free(allocs);
2282 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002283}
2284
Tim Murray56f9e6f2014-05-16 11:47:26 -07002285static jint
2286nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
2287 return (jint)sizeof(void*);
2288}
2289
2290
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002291// ---------------------------------------------------------------------------
2292
Jason Samsd19f10d2009-05-22 14:03:28 -07002293
Jason Sams94d8e90a2009-06-10 16:09:05 -07002294static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07002295
2296static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08002297{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07002298
Tim Murrayeff663f2013-11-15 13:08:30 -08002299{"nDeviceCreate", "()J", (void*)nDeviceCreate },
2300{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
2301{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
2302{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
2303{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
2304{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08002305
Tim Murrayeff663f2013-11-15 13:08:30 -08002306{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
2307{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07002308
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07002309
Jason Sams2e1872f2010-08-17 16:25:41 -07002310// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08002311{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
2312{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
2313{"rsnContextFinish", "(J)V", (void*)nContextFinish },
2314{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
2315{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
2316{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
2317{"rsnContextDump", "(JI)V", (void*)nContextDump },
2318{"rsnContextPause", "(J)V", (void*)nContextPause },
2319{"rsnContextResume", "(J)V", (void*)nContextResume },
2320{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07002321{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002322{"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate },
Yang Ni281c3252014-10-24 08:52:24 -07002323{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
2324{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08002325{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
2326{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
2327{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07002328
Tim Murray460a0492013-11-19 12:45:54 -08002329{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002330{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08002331{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
2332{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
2333{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002334{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07002335
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002336{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
2337{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
2338{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07002339
Tim Murray460a0492013-11-19 12:45:54 -08002340{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002341{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08002342{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00002343{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07002344
Tim Murray460a0492013-11-19 12:45:54 -08002345{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002346{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07002347
Ashok Bhat98071552014-02-12 09:54:43 +00002348{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08002349{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
2350{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
2351{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08002352
Tim Murray460a0492013-11-19 12:45:54 -08002353{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
2354{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08002355
Tim Murray460a0492013-11-19 12:45:54 -08002356{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
2357{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
2358{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
2359{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
2360{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
Miao Wang87e908d2015-03-02 15:15:15 -08002361{"rsnAllocationData1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData1D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002362{"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData },
Miao Wang87e908d2015-03-02 15:15:15 -08002363{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData2D },
Tim Murray460a0492013-11-19 12:45:54 -08002364{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002365{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData3D },
Tim Murray460a0492013-11-19 12:45:54 -08002366{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002367{"rsnAllocationRead", "(JJLjava/lang/Object;IIZ)V", (void*)nAllocationRead },
2368{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead1D },
Miao Wang45cec0a2015-03-04 16:40:21 -08002369{"rsnAllocationElementRead", "(JJIIIII[BI)V", (void*)nAllocationElementRead },
Miao Wang87e908d2015-03-02 15:15:15 -08002370{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead2D },
2371{"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead3D },
Tim Murray460a0492013-11-19 12:45:54 -08002372{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
2373{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
2374{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07002375
Jason Sams46ba27e32015-02-06 17:45:15 -08002376{"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate },
2377{"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset },
2378
Tim Murray460a0492013-11-19 12:45:54 -08002379{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
2380{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
2381{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
2382{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07002383
2384{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
2385
Tim Murray460a0492013-11-19 12:45:54 -08002386{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
2387{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
2388{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
2389{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
2390{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
2391{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
2392{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
2393{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
2394{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
2395{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
2396{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
2397{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07002398
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002399{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002400{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2401{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002402{"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002403{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002404{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Niebf63402015-01-16 11:06:26 -08002405{"rsnScriptGroup2Create", "(JLjava/lang/String;[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002406{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2407{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2408{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002409{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002410
Tim Murray25207df2015-01-12 16:47:56 -08002411{"rsnScriptIntrinsicBLAS_Single", "(JJIIIIIIIIIFJJFJIIII)V", (void*)nScriptIntrinsicBLAS_Single },
2412{"rsnScriptIntrinsicBLAS_Double", "(JJIIIIIIIIIDJJDJIIII)V", (void*)nScriptIntrinsicBLAS_Double },
2413{"rsnScriptIntrinsicBLAS_Complex", "(JJIIIIIIIIIFFJJFFJIIII)V", (void*)nScriptIntrinsicBLAS_Complex },
2414{"rsnScriptIntrinsicBLAS_Z", "(JJIIIIIIIIIDDJJDDJIIII)V", (void*)nScriptIntrinsicBLAS_Z },
2415
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002416{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002417
Tim Murray460a0492013-11-19 12:45:54 -08002418{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2419{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2420{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002421
Ashok Bhat98071552014-02-12 09:54:43 +00002422{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002423{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002424{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002425
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002426{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2427{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2428{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2429{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2430{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002431
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002432{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002433
Ashok Bhat98071552014-02-12 09:54:43 +00002434{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002435
Tim Murray460a0492013-11-19 12:45:54 -08002436{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2437{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002438{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2439{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002440
Tim Murray56f9e6f2014-05-16 11:47:26 -07002441{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002442};
2443
2444static int registerFuncs(JNIEnv *_env)
2445{
2446 return android::AndroidRuntime::registerNativeMethods(
2447 _env, classPathName, methods, NELEM(methods));
2448}
2449
2450// ---------------------------------------------------------------------------
2451
2452jint JNI_OnLoad(JavaVM* vm, void* reserved)
2453{
Chris Wailes488230c32014-08-14 11:22:40 -07002454 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002455 jint result = -1;
2456
Jason Samsd19f10d2009-05-22 14:03:28 -07002457 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002458 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002459 goto bail;
2460 }
Chris Wailes488230c32014-08-14 11:22:40 -07002461 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002462
2463 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002464 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002465 goto bail;
2466 }
2467
2468 /* success -- return valid version number */
2469 result = JNI_VERSION_1_4;
2470
2471bail:
2472 return result;
2473}