blob: 676d94fd9e17d0af531227892b90d3121f24edf0 [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
Tim Murray47f31582015-04-07 15:43:24 -0700692static void
693nContextSetCacheDir(JNIEnv *_env, jobject _this, jlong con, jstring cacheDir)
694{
695 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
696
697 if (kLogApi) {
698 ALOGD("ContextSetCacheDir, con(%p), cacheDir(%s)", (RsContext)con, cacheDirUTF.c_str());
699 }
700 rsContextSetCacheDir((RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length());
701}
702
Jason Sams7d787b42009-11-15 12:14:26 -0800703
704
705static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800706nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800707{
Andreas Gampe67333922014-11-10 20:35:59 -0800708 if (kLogApi) {
709 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
710 width, height, (Surface *)wnd);
711 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800712
Chris Wailes488230c32014-08-14 11:22:40 -0700713 ANativeWindow * window = nullptr;
714 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800715
716 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700717 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800718 }
719
Tim Murrayeff663f2013-11-15 13:08:30 -0800720 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800721}
722
723static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800724nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700725{
Andreas Gampe67333922014-11-10 20:35:59 -0800726 if (kLogApi) {
727 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
728 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800729 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700730}
731
Jason Sams715333b2009-11-17 17:26:46 -0800732static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800733nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800734{
Andreas Gampe67333922014-11-10 20:35:59 -0800735 if (kLogApi) {
736 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
737 }
Jason Sams715333b2009-11-17 17:26:46 -0800738 rsContextDump((RsContext)con, bits);
739}
Jason Samsd19f10d2009-05-22 14:03:28 -0700740
741static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800742nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700743{
Andreas Gampe67333922014-11-10 20:35:59 -0800744 if (kLogApi) {
745 ALOGD("nContextPause, con(%p)", (RsContext)con);
746 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800747 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700748}
749
750static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800751nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700752{
Andreas Gampe67333922014-11-10 20:35:59 -0800753 if (kLogApi) {
754 ALOGD("nContextResume, con(%p)", (RsContext)con);
755 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800756 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700757}
758
Jason Sams1c415172010-11-08 17:06:46 -0800759
760static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800761nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800762{
Andreas Gampe67333922014-11-10 20:35:59 -0800763 if (kLogApi) {
764 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
765 }
Jason Sams1c415172010-11-08 17:06:46 -0800766 char buf[1024];
767
768 size_t receiveLen;
769 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800770 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700771 buf, sizeof(buf),
772 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700773 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800774 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100775 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800776 }
777 return _env->NewStringUTF(buf);
778}
779
Jason Samsedbfabd2011-05-17 15:01:29 -0700780static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800781nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700782{
Jason Sams516c3192009-10-06 13:58:47 -0700783 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800784 if (kLogApi) {
785 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
786 }
Chris Wailes488230c32014-08-14 11:22:40 -0700787 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700788 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800789 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800790 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700791 ptr, len * 4,
792 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700793 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700794 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100795 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700796 }
797 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000798 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800799}
800
801static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800802nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800803{
Andreas Gampe67333922014-11-10 20:35:59 -0800804 if (kLogApi) {
805 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
806 }
Chris Wailes488230c32014-08-14 11:22:40 -0700807 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800808 size_t receiveLen;
809 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800810 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700811 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800812 auxDataPtr[0] = (jint)subID;
813 auxDataPtr[1] = (jint)receiveLen;
814 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000815 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700816}
817
Tim Murrayeff663f2013-11-15 13:08:30 -0800818static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700819{
Andreas Gampe67333922014-11-10 20:35:59 -0800820 if (kLogApi) {
821 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
822 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800823 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700824}
825
Tim Murrayeff663f2013-11-15 13:08:30 -0800826static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700827{
Andreas Gampe67333922014-11-10 20:35:59 -0800828 if (kLogApi) {
829 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
830 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800831 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700832}
833
Jason Sams455d6442013-02-05 19:20:18 -0800834static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800835nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800836{
Chris Wailes488230c32014-08-14 11:22:40 -0700837 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800838 jint len = 0;
839 if (data) {
840 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700841 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800842 }
Andreas Gampe67333922014-11-10 20:35:59 -0800843 if (kLogApi) {
844 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
845 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800846 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800847 if (data) {
848 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
849 }
850}
851
852
Jason Sams516c3192009-10-06 13:58:47 -0700853
Tim Murray460a0492013-11-19 12:45:54 -0800854static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800855nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
856 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700857{
Andreas Gampe67333922014-11-10 20:35:59 -0800858 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100859 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con,
Andreas Gampe67333922014-11-10 20:35:59 -0800860 type, kind, norm, size);
861 }
862 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
863 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700864}
865
Tim Murray460a0492013-11-19 12:45:54 -0800866static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800867nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000868 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700869{
Jason Sams718cd1f2009-12-23 14:35:29 -0800870 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -0800871 if (kLogApi) {
872 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
873 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800874
Chris Wailes488230c32014-08-14 11:22:40 -0700875 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
876 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000877
878 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
879 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
880
881 for(int i = 0; i < fieldCount; i ++) {
882 ids[i] = (RsElement)jIds[i];
883 arraySizes[i] = (uint32_t)jArraySizes[i];
884 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800885
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800886 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
887
888 const char **nameArray = names.c_str();
889 size_t *sizeArray = names.c_str_len();
890
Tim Murray3aa89c12014-08-18 17:51:22 -0700891 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000892 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700893 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700894 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800895
Ashok Bhat98071552014-02-12 09:54:43 +0000896 free(ids);
897 free(arraySizes);
898 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
899 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
900
Tim Murray3aa89c12014-08-18 17:51:22 -0700901 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700902}
903
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700904static void
Tim Murray460a0492013-11-19 12:45:54 -0800905nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700906{
907 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -0800908 if (kLogApi) {
909 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
910 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700911
912 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
913 assert(dataSize == 5);
914
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000915 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800916 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700917
918 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000919 const jint data = (jint)elementData[i];
920 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700921 }
922}
923
924
925static void
Tim Murray460a0492013-11-19 12:45:54 -0800926nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000927 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700928 jobjectArray _names,
929 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700930{
Ashok Bhat98071552014-02-12 09:54:43 +0000931 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -0800932 if (kLogApi) {
933 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
934 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700935
Ashok Bhat98071552014-02-12 09:54:43 +0000936 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
937 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000938 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700939
Andreas Gampe67333922014-11-10 20:35:59 -0800940 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
941 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700942
Ashok Bhat98071552014-02-12 09:54:43 +0000943 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700944 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000945 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700946 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000947 _env->SetLongArrayRegion(_IDs, i, 1, &id);
948 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700949 }
950
951 free(ids);
952 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700953 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700954}
955
Jason Samsd19f10d2009-05-22 14:03:28 -0700956// -----------------------------------
957
Tim Murray460a0492013-11-19 12:45:54 -0800958static jlong
959nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800960 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700961{
Andreas Gampe67333922014-11-10 20:35:59 -0800962 if (kLogApi) {
963 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 +0100964 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv);
Andreas Gampe67333922014-11-10 20:35:59 -0800965 }
Jason Sams3b9c52a2010-10-14 17:48:46 -0700966
Andreas Gampe67333922014-11-10 20:35:59 -0800967 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
968 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700969}
970
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700971static void
Ashok Bhat98071552014-02-12 09:54:43 +0000972nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700973{
974 // We are packing 6 items: mDimX; mDimY; mDimZ;
975 // mDimLOD; mDimFaces; mElement; into typeData
976 int elementCount = _env->GetArrayLength(_typeData);
977
978 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -0800979 if (kLogApi) {
980 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
981 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700982
Ashok Bhat98071552014-02-12 09:54:43 +0000983 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -0800984 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700985
986 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700987 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000988 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700989 }
990}
991
Jason Samsd19f10d2009-05-22 14:03:28 -0700992// -----------------------------------
993
Tim Murray460a0492013-11-19 12:45:54 -0800994static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800995nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
996 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700997{
Andreas Gampe67333922014-11-10 20:35:59 -0800998 if (kLogApi) {
999 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
1000 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
1001 }
1002 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
1003 (RsAllocationMipmapControl)mips,
1004 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -07001005}
1006
Jason Samsd19f10d2009-05-22 14:03:28 -07001007static void
Tim Murray460a0492013-11-19 12:45:54 -08001008nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -08001009{
Andreas Gampe67333922014-11-10 20:35:59 -08001010 if (kLogApi) {
1011 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
1012 bits);
1013 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001014 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -08001015}
1016
Jason Sams72226e02013-02-22 12:45:54 -08001017static jobject
Tim Murray460a0492013-11-19 12:45:54 -08001018nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -08001019{
Andreas Gampe67333922014-11-10 20:35:59 -08001020 if (kLogApi) {
1021 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1022 }
Jason Sams615e7ce2012-01-13 14:01:20 -08001023
Andreas Gampe67333922014-11-10 20:35:59 -08001024 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
1025 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -08001026 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -07001027 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001028
Jason Sams72226e02013-02-22 12:45:54 -08001029 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
1030 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001031}
1032
1033static void
Tim Murray460a0492013-11-19 12:45:54 -08001034nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -08001035{
Andreas Gampe67333922014-11-10 20:35:59 -08001036 if (kLogApi) {
1037 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
1038 (RsAllocation)alloc, (Surface *)sur);
1039 }
Jason Sams163766c2012-02-15 12:04:24 -08001040
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001041 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -08001042 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -07001043 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -08001044 }
1045
Andreas Gampe67333922014-11-10 20:35:59 -08001046 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
1047 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -08001048}
1049
1050static void
Tim Murray460a0492013-11-19 12:45:54 -08001051nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001052{
Andreas Gampe67333922014-11-10 20:35:59 -08001053 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001054 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001055 }
Tim Murray460a0492013-11-19 12:45:54 -08001056 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001057}
1058
1059static void
Tim Murray460a0492013-11-19 12:45:54 -08001060nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001061{
Andreas Gampe67333922014-11-10 20:35:59 -08001062 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001063 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001064 }
Tim Murray460a0492013-11-19 12:45:54 -08001065 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001066}
1067
1068
1069static void
Tim Murray460a0492013-11-19 12:45:54 -08001070nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -08001071{
Andreas Gampe67333922014-11-10 20:35:59 -08001072 if (kLogApi) {
1073 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
1074 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001075 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -08001076}
1077
Tim Murray460a0492013-11-19 12:45:54 -08001078static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001079nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1080 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -07001081{
Jason Samsffe9f482009-06-01 17:45:53 -07001082 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001083 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -07001084 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -07001085
Jason Sams5476b452010-12-08 16:14:36 -08001086 bitmap.lockPixels();
1087 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001088 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001089 (RsType)type, (RsAllocationMipmapControl)mip,
1090 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001091 bitmap.unlockPixels();
1092 return id;
Jason Samsffe9f482009-06-01 17:45:53 -07001093}
Jason Samsfe08d992009-05-27 14:45:32 -07001094
Tim Murray460a0492013-11-19 12:45:54 -08001095static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001096nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
1097 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -08001098{
1099 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001100 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -08001101 const SkBitmap& bitmap(*nativeBitmap);
1102
1103 bitmap.lockPixels();
1104 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001105 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -08001106 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +00001107 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -08001108 bitmap.unlockPixels();
1109 return id;
1110}
1111
Tim Murray460a0492013-11-19 12:45:54 -08001112static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001113nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1114 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001115{
1116 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001117 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001118 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001119
Jason Sams5476b452010-12-08 16:14:36 -08001120 bitmap.lockPixels();
1121 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001122 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001123 (RsType)type, (RsAllocationMipmapControl)mip,
1124 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001125 bitmap.unlockPixels();
1126 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001127}
1128
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001129static void
Tim Murray460a0492013-11-19 12:45:54 -08001130nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001131{
1132 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001133 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001134 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -08001135 int w = bitmap.width();
1136 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001137
Jason Sams4ef66502010-12-10 16:03:15 -08001138 bitmap.lockPixels();
1139 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001140 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001141 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -08001142 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -08001143 bitmap.unlockPixels();
1144}
1145
1146static void
Tim Murray460a0492013-11-19 12:45:54 -08001147nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -08001148{
1149 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001150 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -08001151 const SkBitmap& bitmap(*nativeBitmap);
1152
1153 bitmap.lockPixels();
1154 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001155 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -08001156 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -07001157 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001158}
1159
Stephen Hines414fa2c2014-04-17 01:02:42 -07001160// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -07001161static void
Tim Murray460a0492013-11-19 12:45:54 -08001162nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001163 jint count, jobject data, jint sizeBytes, jint dataType, jint mSize,
1164 jboolean usePadding)
Jason Samsd19f10d2009-05-22 14:03:28 -07001165{
Jason Samse729a942013-11-06 11:22:02 -08001166 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001167 if (kLogApi) {
1168 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1169 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
1170 dataType);
1171 }
Miao Wang87e908d2015-03-02 15:15:15 -08001172 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true,
1173 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -07001174}
1175
1176static void
Miao Wangc8e237e2015-02-20 18:36:32 -08001177nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1178 jint xoff, jint yoff, jint zoff,
1179 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -07001180{
1181 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -08001182 if (kLogApi) {
Miao Wangc8e237e2015-02-20 18:36:32 -08001183 ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1184 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
Andreas Gampe67333922014-11-10 20:35:59 -08001185 sizeBytes);
1186 }
Chris Wailes488230c32014-08-14 11:22:40 -07001187 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Miao Wangc8e237e2015-02-20 18:36:32 -08001188 rsAllocationElementData((RsContext)con, (RsAllocation)alloc,
1189 xoff, yoff, zoff,
1190 lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -07001191 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1192}
1193
Miao Wangc8e237e2015-02-20 18:36:32 -08001194
Stephen Hines414fa2c2014-04-17 01:02:42 -07001195// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -07001196static void
Tim Murray460a0492013-11-19 12:45:54 -08001197nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001198 jint w, jint h, jobject data, jint sizeBytes, jint dataType, jint mSize,
1199 jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001200{
Jason Samse729a942013-11-06 11:22:02 -08001201 RsAllocation *alloc = (RsAllocation *)_alloc;
1202 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001203 if (kLogApi) {
1204 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1205 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1206 }
Miao Wang87e908d2015-03-02 15:15:15 -08001207 int count = w * h;
1208 PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true,
1209 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -07001210}
1211
Stephen Hines414fa2c2014-04-17 01:02:42 -07001212// Copies from the Allocation pointed to by srcAlloc into the Allocation
1213// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -07001214static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001215nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001216 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001217 jint dstMip, jint dstFace,
1218 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -08001219 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001220 jint srcMip, jint srcFace)
1221{
Andreas Gampe67333922014-11-10 20:35:59 -08001222 if (kLogApi) {
1223 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1224 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
1225 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
1226 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
1227 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
1228 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001229
Tim Murrayeff663f2013-11-15 13:08:30 -08001230 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001231 (RsAllocation)dstAlloc,
1232 dstXoff, dstYoff,
1233 dstMip, dstFace,
1234 width, height,
1235 (RsAllocation)srcAlloc,
1236 srcXoff, srcYoff,
1237 srcMip, srcFace);
1238}
1239
Stephen Hines414fa2c2014-04-17 01:02:42 -07001240// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001241static void
Tim Murray460a0492013-11-19 12:45:54 -08001242nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001243 jint w, jint h, jint d, jobject data, jint sizeBytes, jint dataType,
1244 jint mSize, jboolean usePadding)
Jason Samsb05d6892013-04-09 15:59:24 -07001245{
Jason Samse729a942013-11-06 11:22:02 -08001246 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001247 if (kLogApi) {
1248 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1249 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1250 lod, w, h, d, sizeBytes);
1251 }
Miao Wang87e908d2015-03-02 15:15:15 -08001252 int count = w * h * d;
1253 PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true,
1254 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -07001255}
1256
Stephen Hines414fa2c2014-04-17 01:02:42 -07001257// Copies from the Allocation pointed to by srcAlloc into the Allocation
1258// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -07001259static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001260nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001261 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001262 jint dstMip,
1263 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -08001264 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001265 jint srcMip)
1266{
Andreas Gampe67333922014-11-10 20:35:59 -08001267 if (kLogApi) {
1268 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1269 " dstMip(%i), width(%i), height(%i),"
1270 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
1271 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
1272 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
1273 }
Jason Samsb05d6892013-04-09 15:59:24 -07001274
Tim Murrayeff663f2013-11-15 13:08:30 -08001275 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -07001276 (RsAllocation)dstAlloc,
1277 dstXoff, dstYoff, dstZoff, dstMip,
1278 width, height, depth,
1279 (RsAllocation)srcAlloc,
1280 srcXoff, srcYoff, srcZoff, srcMip);
1281}
1282
Jason Sams21659ac2013-11-06 15:08:07 -08001283
Stephen Hines414fa2c2014-04-17 01:02:42 -07001284// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -07001285static void
Miao Wang87e908d2015-03-02 15:15:15 -08001286nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, jint dataType,
1287 jint mSize, jboolean usePadding)
Jason Sams40a29e82009-08-10 14:55:26 -07001288{
Jason Sams21659ac2013-11-06 15:08:07 -08001289 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001290 if (kLogApi) {
1291 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
1292 }
Miao Wang87e908d2015-03-02 15:15:15 -08001293 int count = 0;
1294 PER_ARRAY_TYPE(0, rsAllocationRead, false,
1295 (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -07001296}
1297
Stephen Hines414fa2c2014-04-17 01:02:42 -07001298// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -07001299static void
Tim Murray460a0492013-11-19 12:45:54 -08001300nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001301 jint count, jobject data, jint sizeBytes, jint dataType,
1302 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001303{
Jason Sams21659ac2013-11-06 15:08:07 -08001304 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001305 if (kLogApi) {
1306 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1307 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
1308 }
Miao Wang87e908d2015-03-02 15:15:15 -08001309 PER_ARRAY_TYPE(0, rsAllocation1DRead, false,
1310 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -08001311}
1312
Miao Wangc8e237e2015-02-20 18:36:32 -08001313// Copies from the Element in the Allocation pointed to by _alloc into the Java array data.
1314static void
Miao Wang45cec0a2015-03-04 16:40:21 -08001315nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
Miao Wangc8e237e2015-02-20 18:36:32 -08001316 jint xoff, jint yoff, jint zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -08001317 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Miao Wangc8e237e2015-02-20 18:36:32 -08001318{
Miao Wang45cec0a2015-03-04 16:40:21 -08001319 jint len = _env->GetArrayLength(data);
Miao Wangc8e237e2015-02-20 18:36:32 -08001320 if (kLogApi) {
Miao Wang45cec0a2015-03-04 16:40:21 -08001321 ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1322 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
1323 sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -08001324 }
Miao Wang45cec0a2015-03-04 16:40:21 -08001325 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
1326 rsAllocationElementRead((RsContext)con, (RsAllocation)alloc,
1327 xoff, yoff, zoff,
Jason Samsa7e25092015-03-11 11:00:00 -07001328 lod, ptr, sizeBytes, compIdx);
Miao Wang45cec0a2015-03-04 16:40:21 -08001329 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
Miao Wangc8e237e2015-02-20 18:36:32 -08001330}
1331
Stephen Hines414fa2c2014-04-17 01:02:42 -07001332// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -08001333static void
Tim Murray460a0492013-11-19 12:45:54 -08001334nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001335 jint w, jint h, jobject data, jint sizeBytes, jint dataType,
1336 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001337{
Jason Sams21659ac2013-11-06 15:08:07 -08001338 RsAllocation *alloc = (RsAllocation *)_alloc;
1339 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001340 if (kLogApi) {
1341 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1342 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1343 }
Miao Wang87e908d2015-03-02 15:15:15 -08001344 int count = w * h;
1345 PER_ARRAY_TYPE(0, rsAllocation2DRead, false,
1346 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -07001347}
Miao Wang87e908d2015-03-02 15:15:15 -08001348
Miao Wangc8e237e2015-02-20 18:36:32 -08001349// Copies from the Allocation pointed to by _alloc into the Java object data.
1350static void
1351nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001352 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType,
1353 jint mSize, jboolean usePadding)
Miao Wangc8e237e2015-02-20 18:36:32 -08001354{
1355 RsAllocation *alloc = (RsAllocation *)_alloc;
1356 if (kLogApi) {
1357 ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1358 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1359 lod, w, h, d, sizeBytes);
1360 }
Miao Wang87e908d2015-03-02 15:15:15 -08001361 int count = w * h * d;
1362 PER_ARRAY_TYPE(nullptr, rsAllocation3DRead, false,
1363 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Miao Wangc8e237e2015-02-20 18:36:32 -08001364}
Jason Samsd19f10d2009-05-22 14:03:28 -07001365
Tim Murray460a0492013-11-19 12:45:54 -08001366static jlong
1367nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001368{
Andreas Gampe67333922014-11-10 20:35:59 -08001369 if (kLogApi) {
1370 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1371 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001372 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001373}
1374
Jason Sams5edc6082010-10-05 13:32:49 -07001375static void
Tim Murray460a0492013-11-19 12:45:54 -08001376nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -07001377{
Andreas Gampe67333922014-11-10 20:35:59 -08001378 if (kLogApi) {
1379 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
1380 (RsAllocation)alloc, dimX);
1381 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001382 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -07001383}
1384
Jason Sams46ba27e32015-02-06 17:45:15 -08001385
1386static jlong
1387nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type)
1388{
1389 if (kLogApi) {
1390 ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)",
1391 (RsContext)con, (RsAllocation)basealloc, (RsElement)type);
1392 }
1393 return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type,
1394 (RsAllocation)basealloc);
1395
1396}
1397
1398static void
1399nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1400 jint x, jint y, jint z, jint face, jint lod,
1401 jint a1, jint a2, jint a3, jint a4)
1402{
1403 uint32_t params[] = {
1404 (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face,
1405 (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4
1406 };
1407 if (kLogApi) {
1408 ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)",
1409 (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4);
1410 }
1411 rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc,
1412 params, sizeof(params));
1413}
1414
1415
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001416// -----------------------------------
1417
Tim Murray460a0492013-11-19 12:45:54 -08001418static jlong
1419nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001420{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001421 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001422 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001423
Tim Murray3aa89c12014-08-18 17:51:22 -07001424 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001425 return id;
1426}
1427
Tim Murray460a0492013-11-19 12:45:54 -08001428static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001429nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001430{
1431 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001432 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001433 return 0;
1434 }
1435
1436 AutoJavaStringToUTF8 str(_env, _path);
1437 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001438 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001439 return 0;
1440 }
1441
Tim Murray3aa89c12014-08-18 17:51:22 -07001442 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001443 return id;
1444}
1445
Tim Murray460a0492013-11-19 12:45:54 -08001446static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001447nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001448{
1449 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001450 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001451
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001452 return id;
1453}
1454
Tim Murray460a0492013-11-19 12:45:54 -08001455static jint
1456nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001457{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001458 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001459 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001460 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001461}
1462
1463static void
Tim Murray460a0492013-11-19 12:45:54 -08001464nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001465{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001466 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001467 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
1468
Tim Murrayeff663f2013-11-15 13:08:30 -08001469 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001470
1471 for(jint i = 0; i < numEntries; i ++) {
1472 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
1473 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
1474 }
1475
1476 free(fileEntries);
1477}
1478
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001479static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001480nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001481{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001482 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001483 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001484 return id;
1485}
Jason Samsd19f10d2009-05-22 14:03:28 -07001486
1487// -----------------------------------
1488
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001489static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001490nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001491 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001492{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001493 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001494 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001495 fileNameUTF.c_str(), fileNameUTF.length(),
1496 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001497
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001498 return id;
1499}
1500
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001501static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001502nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001503 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001504{
1505 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1506 AutoJavaStringToUTF8 nameUTF(_env, name);
1507
Tim Murray3aa89c12014-08-18 17:51:22 -07001508 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001509 nameUTF.c_str(), nameUTF.length(),
1510 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001511 asset->getBuffer(false), asset->getLength());
1512 return id;
1513}
1514
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001515static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001516nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001517 jfloat fontSize, jint dpi)
1518{
1519 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001520 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001521 return 0;
1522 }
1523
1524 AutoJavaStringToUTF8 str(_env, _path);
1525 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001526 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001527 return 0;
1528 }
1529
Tim Murray3aa89c12014-08-18 17:51:22 -07001530 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001531 str.c_str(), str.length(),
1532 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001533 asset->getBuffer(false), asset->getLength());
1534 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001535 return id;
1536}
1537
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001538// -----------------------------------
1539
1540static void
Tim Murray460a0492013-11-19 12:45:54 -08001541nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001542{
Andreas Gampe67333922014-11-10 20:35:59 -08001543 if (kLogApi) {
1544 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1545 (RsScript)script, (RsAllocation)alloc, slot);
1546 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001547 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001548}
1549
1550static void
Tim Murray460a0492013-11-19 12:45:54 -08001551nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001552{
Andreas Gampe67333922014-11-10 20:35:59 -08001553 if (kLogApi) {
1554 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1555 slot, val);
1556 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001557 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001558}
1559
Tim Murray7c4caad2013-04-10 16:21:40 -07001560static jint
Tim Murray460a0492013-11-19 12:45:54 -08001561nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001562{
Andreas Gampe67333922014-11-10 20:35:59 -08001563 if (kLogApi) {
1564 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1565 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001566 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001567 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001568 return value;
1569}
1570
Jason Sams4d339932010-05-11 14:03:58 -07001571static void
Tim Murray460a0492013-11-19 12:45:54 -08001572nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001573{
Andreas Gampe67333922014-11-10 20:35:59 -08001574 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001575 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001576 slot, val);
1577 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001578 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001579}
1580
1581static void
Tim Murray460a0492013-11-19 12:45:54 -08001582nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001583{
Andreas Gampe67333922014-11-10 20:35:59 -08001584 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001585 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001586 slot, val);
1587 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001588 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001589}
1590
Tim Murray7c4caad2013-04-10 16:21:40 -07001591static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001592nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001593{
Andreas Gampe67333922014-11-10 20:35:59 -08001594 if (kLogApi) {
1595 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1596 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001597 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001598 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001599 return value;
1600}
1601
Stephen Hines031ec58c2010-10-11 10:54:21 -07001602static void
Tim Murray460a0492013-11-19 12:45:54 -08001603nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001604{
Andreas Gampe67333922014-11-10 20:35:59 -08001605 if (kLogApi) {
1606 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1607 slot, val);
1608 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001609 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001610}
1611
Tim Murray7c4caad2013-04-10 16:21:40 -07001612static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001613nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001614{
Andreas Gampe67333922014-11-10 20:35:59 -08001615 if (kLogApi) {
1616 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1617 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001618 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001619 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001620 return value;
1621}
1622
Jason Sams4d339932010-05-11 14:03:58 -07001623static void
Tim Murray460a0492013-11-19 12:45:54 -08001624nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001625{
Andreas Gampe67333922014-11-10 20:35:59 -08001626 if (kLogApi) {
1627 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1628 slot, val);
1629 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001630 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001631}
1632
Tim Murray7c4caad2013-04-10 16:21:40 -07001633static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001634nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001635{
Andreas Gampe67333922014-11-10 20:35:59 -08001636 if (kLogApi) {
1637 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1638 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001639 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001640 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001641 return value;
1642}
1643
Stephen Hinesca54ec32010-09-20 17:20:30 -07001644static void
Tim Murray460a0492013-11-19 12:45:54 -08001645nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001646{
Andreas Gampe67333922014-11-10 20:35:59 -08001647 if (kLogApi) {
1648 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1649 }
Jason Sams4d339932010-05-11 14:03:58 -07001650 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001651 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001652 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001653 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1654}
1655
Stephen Hinesadeb8092012-04-20 14:26:06 -07001656static void
Tim Murray460a0492013-11-19 12:45:54 -08001657nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001658{
Andreas Gampe67333922014-11-10 20:35:59 -08001659 if (kLogApi) {
1660 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1661 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001662 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001663 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001664 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001665 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001666}
1667
1668static void
Andreas Gampe67333922014-11-10 20:35:59 -08001669nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1670 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001671{
Andreas Gampe67333922014-11-10 20:35:59 -08001672 if (kLogApi) {
1673 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1674 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001675 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001676 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001677 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001678 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001679 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001680 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001681 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1682 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1683}
1684
Jason Samsd19f10d2009-05-22 14:03:28 -07001685
1686static void
Tim Murray460a0492013-11-19 12:45:54 -08001687nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001688{
Andreas Gampe67333922014-11-10 20:35:59 -08001689 if (kLogApi) {
1690 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1691 }
Romain Guy584a3752009-07-30 18:45:01 -07001692
1693 jint length = _env->GetArrayLength(timeZone);
1694 jbyte* timeZone_ptr;
1695 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1696
Tim Murrayeff663f2013-11-15 13:08:30 -08001697 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001698
1699 if (timeZone_ptr) {
1700 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1701 }
1702}
1703
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001704static void
Tim Murray460a0492013-11-19 12:45:54 -08001705nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001706{
Andreas Gampe67333922014-11-10 20:35:59 -08001707 if (kLogApi) {
1708 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1709 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001710 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001711}
1712
1713static void
Tim Murray460a0492013-11-19 12:45:54 -08001714nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001715{
Andreas Gampe67333922014-11-10 20:35:59 -08001716 if (kLogApi) {
1717 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1718 }
Jason Sams4d339932010-05-11 14:03:58 -07001719 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001720 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001721 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001722 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1723}
1724
Jason Sams6e494d32011-04-27 16:33:11 -07001725static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001726nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1727 jlongArray ains, jlong aout, jbyteArray params,
1728 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001729{
Andreas Gampe67333922014-11-10 20:35:59 -08001730 if (kLogApi) {
1731 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1732 }
Jason Sams6e494d32011-04-27 16:33:11 -07001733
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001734 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001735 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001736
Chris Wailes488230c32014-08-14 11:22:40 -07001737 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001738
Chris Wailes488230c32014-08-14 11:22:40 -07001739 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001740 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001741 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001742
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001743 if (sizeof(RsAllocation) == sizeof(jlong)) {
1744 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001745
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001746 } else {
1747 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001748
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001749 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1750
1751 for (int index = in_len; --index >= 0;) {
1752 in_allocs[index] = (RsAllocation)in_ptr[index];
1753 }
1754 }
Chris Wailes94961062014-06-11 12:01:28 -07001755 }
1756
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001757 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001758 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001759
Chris Wailes488230c32014-08-14 11:22:40 -07001760 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001761 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001762 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001763 }
1764
Chris Wailes488230c32014-08-14 11:22:40 -07001765 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001766 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001767
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001768 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001769 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001770
Chris Wailes488230c32014-08-14 11:22:40 -07001771 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001772 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001773 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001774
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001775 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001776 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001777
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001778 sc.xStart = limit_ptr[0];
1779 sc.xEnd = limit_ptr[1];
1780 sc.yStart = limit_ptr[2];
1781 sc.yEnd = limit_ptr[3];
1782 sc.zStart = limit_ptr[4];
1783 sc.zEnd = limit_ptr[5];
1784 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Jason Sams14331ab2015-01-26 18:14:36 -08001785 sc.arrayStart = 0;
1786 sc.arrayEnd = 0;
1787 sc.array2Start = 0;
1788 sc.array2End = 0;
1789 sc.array3Start = 0;
1790 sc.array3End = 0;
1791 sc.array4Start = 0;
1792 sc.array4End = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001793
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001794 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001795 }
1796
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001797 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1798 in_allocs, in_len, (RsAllocation)aout,
1799 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001800
Chris Wailes488230c32014-08-14 11:22:40 -07001801 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001802 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001803 }
1804
Chris Wailes488230c32014-08-14 11:22:40 -07001805 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001806 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1807 }
1808
Chris Wailes488230c32014-08-14 11:22:40 -07001809 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001810 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1811 }
Chris Wailes94961062014-06-11 12:01:28 -07001812}
1813
Jason Sams22534172009-08-04 16:58:20 -07001814// -----------------------------------
1815
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001816static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001817nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001818 jstring resName, jstring cacheDir,
1819 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001820{
Andreas Gampe67333922014-11-10 20:35:59 -08001821 if (kLogApi) {
1822 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1823 }
Jason Sams22534172009-08-04 16:58:20 -07001824
Jason Samse4a06c52011-03-16 16:29:28 -07001825 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1826 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001827 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001828 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001829 jint _exception = 0;
1830 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001831 if (!scriptRef) {
1832 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001833 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001834 goto exit;
1835 }
Jack Palevich43702d82009-05-28 13:38:16 -07001836 if (length < 0) {
1837 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001838 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001839 goto exit;
1840 }
Jason Samse4a06c52011-03-16 16:29:28 -07001841 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001842 if (remaining < length) {
1843 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001844 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1845 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001846 goto exit;
1847 }
Jason Samse4a06c52011-03-16 16:29:28 -07001848 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001849 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001850
Tim Murrayeff663f2013-11-15 13:08:30 -08001851 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001852
Tim Murray3aa89c12014-08-18 17:51:22 -07001853 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001854 resNameUTF.c_str(), resNameUTF.length(),
1855 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001856 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001857
Jack Palevich43702d82009-05-28 13:38:16 -07001858exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001859 if (script_ptr) {
1860 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001861 _exception ? JNI_ABORT: 0);
1862 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001863
Tim Murray3aa89c12014-08-18 17:51:22 -07001864 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001865}
1866
Tim Murray460a0492013-11-19 12:45:54 -08001867static jlong
1868nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001869{
Andreas Gampe67333922014-11-10 20:35:59 -08001870 if (kLogApi) {
1871 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1872 (void *)eid);
1873 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001874 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001875}
1876
Tim Murray460a0492013-11-19 12:45:54 -08001877static jlong
1878nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001879{
Andreas Gampe67333922014-11-10 20:35:59 -08001880 if (kLogApi) {
1881 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1882 (void *)sid, slot, sig);
1883 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001884 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001885}
1886
Tim Murray460a0492013-11-19 12:45:54 -08001887static jlong
Yang Nibe392ad2015-01-23 17:16:02 -08001888nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
1889{
1890 if (kLogApi) {
Elliott Hughes7ff53fa2015-02-05 21:36:10 -08001891 ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con,
Yang Nibe392ad2015-01-23 17:16:02 -08001892 (void *)sid, slot);
1893 }
1894 return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot);
1895}
1896
1897static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001898nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001899{
Andreas Gampe67333922014-11-10 20:35:59 -08001900 if (kLogApi) {
1901 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1902 slot);
1903 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001904 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001905}
1906
Tim Murray460a0492013-11-19 12:45:54 -08001907static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001908nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1909 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001910{
Andreas Gampe67333922014-11-10 20:35:59 -08001911 if (kLogApi) {
1912 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1913 }
Jason Sams08a81582012-09-18 12:32:10 -07001914
Ashok Bhat98071552014-02-12 09:54:43 +00001915 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001916 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001917 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1918 for(int i = 0; i < kernelsLen; ++i) {
1919 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1920 }
Jason Sams08a81582012-09-18 12:32:10 -07001921
Ashok Bhat98071552014-02-12 09:54:43 +00001922 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001923 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001924 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1925 for(int i = 0; i < srcLen; ++i) {
1926 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1927 }
Jason Sams08a81582012-09-18 12:32:10 -07001928
Ashok Bhat98071552014-02-12 09:54:43 +00001929 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001930 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001931 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1932 for(int i = 0; i < dstkLen; ++i) {
1933 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1934 }
1935
1936 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001937 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001938 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1939 for(int i = 0; i < dstfLen; ++i) {
1940 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1941 }
1942
1943 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001944 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001945 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1946 for(int i = 0; i < typesLen; ++i) {
1947 typesPtr[i] = (RsType)jTypesPtr[i];
1948 }
1949
Tim Murray3aa89c12014-08-18 17:51:22 -07001950 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001951 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1952 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1953 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1954 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1955 (RsType *)typesPtr, typesLen * sizeof(RsType));
1956
1957 free(kernelsPtr);
1958 free(srcPtr);
1959 free(dstkPtr);
1960 free(dstfPtr);
1961 free(typesPtr);
1962 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1963 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1964 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1965 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1966 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001967 return id;
1968}
1969
1970static void
Tim Murray460a0492013-11-19 12:45:54 -08001971nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001972{
Andreas Gampe67333922014-11-10 20:35:59 -08001973 if (kLogApi) {
1974 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1975 (void *)gid, (void *)kid, (void *)alloc);
1976 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001977 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001978}
1979
1980static void
Tim Murray460a0492013-11-19 12:45:54 -08001981nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001982{
Andreas Gampe67333922014-11-10 20:35:59 -08001983 if (kLogApi) {
1984 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1985 (void *)gid, (void *)kid, (void *)alloc);
1986 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001987 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001988}
1989
1990static void
Tim Murray460a0492013-11-19 12:45:54 -08001991nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001992{
Andreas Gampe67333922014-11-10 20:35:59 -08001993 if (kLogApi) {
1994 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
1995 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001996 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001997}
1998
Jason Samsd19f10d2009-05-22 14:03:28 -07001999// ---------------------------------------------------------------------------
2000
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002001static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002002nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07002003 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
2004 jboolean depthMask, jboolean ditherEnable,
2005 jint srcFunc, jint destFunc,
2006 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07002007{
Andreas Gampe67333922014-11-10 20:35:59 -08002008 if (kLogApi) {
2009 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
2010 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002011 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07002012 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
2013 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07002014}
2015
Jason Sams0011bcf2009-12-15 12:58:36 -08002016// ---------------------------------------------------------------------------
2017
2018static void
Tim Murray460a0492013-11-19 12:45:54 -08002019nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08002020{
Andreas Gampe67333922014-11-10 20:35:59 -08002021 if (kLogApi) {
2022 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
2023 (RsProgramVertex)vpv, slot, (RsAllocation)a);
2024 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002025 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08002026}
Jason Sams54c0ec12009-11-30 14:49:55 -08002027
Jason Sams68afd012009-12-17 16:55:08 -08002028static void
Tim Murray460a0492013-11-19 12:45:54 -08002029nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002030{
Andreas Gampe67333922014-11-10 20:35:59 -08002031 if (kLogApi) {
2032 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2033 (RsProgramFragment)vpf, slot, (RsAllocation)a);
2034 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002035 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08002036}
2037
2038static void
Tim Murray460a0492013-11-19 12:45:54 -08002039nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002040{
Andreas Gampe67333922014-11-10 20:35:59 -08002041 if (kLogApi) {
2042 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2043 (RsProgramFragment)vpf, slot, (RsSampler)a);
2044 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002045 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08002046}
2047
Jason Samsd19f10d2009-05-22 14:03:28 -07002048// ---------------------------------------------------------------------------
2049
Tim Murray460a0492013-11-19 12:45:54 -08002050static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002051nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002052 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002053{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002054 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002055 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002056 jint paramLen = _env->GetArrayLength(params);
2057
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002058 int texCount = _env->GetArrayLength(texNames);
2059 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2060 const char ** nameArray = names.c_str();
2061 size_t* sizeArray = names.c_str_len();
2062
Andreas Gampe67333922014-11-10 20:35:59 -08002063 if (kLogApi) {
2064 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2065 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002066
Ashok Bhat98071552014-02-12 09:54:43 +00002067 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2068 for(int i = 0; i < paramLen; ++i) {
2069 paramPtr[i] = (uintptr_t)jParamPtr[i];
2070 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002071 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002072 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002073 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002074
Ashok Bhat98071552014-02-12 09:54:43 +00002075 free(paramPtr);
2076 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002077 return ret;
2078}
2079
2080
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002081// ---------------------------------------------------------------------------
2082
Tim Murray460a0492013-11-19 12:45:54 -08002083static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002084nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002085 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002086{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002087 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002088 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08002089 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002090
Andreas Gampe67333922014-11-10 20:35:59 -08002091 if (kLogApi) {
2092 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2093 }
Jason Sams0011bcf2009-12-15 12:58:36 -08002094
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002095 int texCount = _env->GetArrayLength(texNames);
2096 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2097 const char ** nameArray = names.c_str();
2098 size_t* sizeArray = names.c_str_len();
2099
Ashok Bhat98071552014-02-12 09:54:43 +00002100 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2101 for(int i = 0; i < paramLen; ++i) {
2102 paramPtr[i] = (uintptr_t)jParamPtr[i];
2103 }
2104
Tim Murray3aa89c12014-08-18 17:51:22 -07002105 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002106 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002107 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002108
Ashok Bhat98071552014-02-12 09:54:43 +00002109 free(paramPtr);
2110 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08002111 return ret;
2112}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002113
Jason Samsebfb4362009-09-23 13:57:02 -07002114// ---------------------------------------------------------------------------
2115
Tim Murray460a0492013-11-19 12:45:54 -08002116static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002117nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07002118{
Andreas Gampe67333922014-11-10 20:35:59 -08002119 if (kLogApi) {
2120 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
2121 pointSprite, cull);
2122 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002123 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07002124}
2125
Jason Samsd19f10d2009-05-22 14:03:28 -07002126
2127// ---------------------------------------------------------------------------
2128
2129static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002130nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07002131{
Andreas Gampe67333922014-11-10 20:35:59 -08002132 if (kLogApi) {
2133 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
2134 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002135 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07002136}
2137
2138static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002139nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07002140{
Andreas Gampe67333922014-11-10 20:35:59 -08002141 if (kLogApi) {
2142 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
2143 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002144 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07002145}
2146
2147static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002148nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07002149{
Andreas Gampe67333922014-11-10 20:35:59 -08002150 if (kLogApi) {
2151 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
2152 (RsProgramFragment)pf);
2153 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002154 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07002155}
2156
Jason Sams0826a6f2009-06-15 19:04:56 -07002157static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002158nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07002159{
Andreas Gampe67333922014-11-10 20:35:59 -08002160 if (kLogApi) {
2161 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
2162 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002163 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07002164}
2165
Joe Onoratod7b37742009-08-09 22:57:44 -07002166static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002167nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07002168{
Andreas Gampe67333922014-11-10 20:35:59 -08002169 if (kLogApi) {
2170 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
2171 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002172 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07002173}
2174
Joe Onoratod7b37742009-08-09 22:57:44 -07002175
Jason Sams02fb2cb2009-05-28 15:37:57 -07002176// ---------------------------------------------------------------------------
2177
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002178static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002179nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002180 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07002181{
Andreas Gampe67333922014-11-10 20:35:59 -08002182 if (kLogApi) {
2183 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
2184 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002185 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002186 (RsSamplerValue)magFilter,
2187 (RsSamplerValue)minFilter,
2188 (RsSamplerValue)wrapS,
2189 (RsSamplerValue)wrapT,
2190 (RsSamplerValue)wrapR,
2191 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07002192}
2193
Jason Samsbba134c2009-06-22 15:49:21 -07002194// ---------------------------------------------------------------------------
2195
Tim Murray460a0492013-11-19 12:45:54 -08002196static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00002197nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07002198{
Andreas Gampe67333922014-11-10 20:35:59 -08002199 if (kLogApi) {
2200 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
2201 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002202
2203 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07002204 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002205 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
2206 for(int i = 0; i < vtxLen; ++i) {
2207 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
2208 }
2209
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002210 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07002211 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002212 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
2213 for(int i = 0; i < idxLen; ++i) {
2214 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
2215 }
2216
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002217 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07002218 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002219
Tim Murray3aa89c12014-08-18 17:51:22 -07002220 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002221 (RsAllocation *)vtxPtr, vtxLen,
2222 (RsAllocation *)idxPtr, idxLen,
2223 (uint32_t *)primPtr, primLen);
2224
Ashok Bhat98071552014-02-12 09:54:43 +00002225 free(vtxPtr);
2226 free(idxPtr);
2227 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
2228 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002229 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002230 return id;
2231}
2232
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002233static jint
Tim Murray460a0492013-11-19 12:45:54 -08002234nMeshGetVertexBufferCount(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("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2238 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002239 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002240 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002241 return vtxCount;
2242}
2243
2244static jint
Tim Murray460a0492013-11-19 12:45:54 -08002245nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002246{
Andreas Gampe67333922014-11-10 20:35:59 -08002247 if (kLogApi) {
2248 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2249 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002250 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002251 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002252 return idxCount;
2253}
2254
2255static void
Ashok Bhat98071552014-02-12 09:54:43 +00002256nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002257{
Andreas Gampe67333922014-11-10 20:35:59 -08002258 if (kLogApi) {
2259 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2260 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002261
2262 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08002263 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002264
2265 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002266 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002267 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002268 }
2269
2270 free(allocs);
2271}
2272
2273static void
Ashok Bhat98071552014-02-12 09:54:43 +00002274nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002275{
Andreas Gampe67333922014-11-10 20:35:59 -08002276 if (kLogApi) {
2277 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2278 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002279
2280 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
2281 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
2282
Tim Murrayeff663f2013-11-15 13:08:30 -08002283 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002284
2285 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002286 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002287 const jint prim = (jint)prims[i];
2288 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
2289 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002290 }
2291
2292 free(allocs);
2293 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002294}
2295
Tim Murray56f9e6f2014-05-16 11:47:26 -07002296static jint
2297nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
2298 return (jint)sizeof(void*);
2299}
2300
2301
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002302// ---------------------------------------------------------------------------
2303
Jason Samsd19f10d2009-05-22 14:03:28 -07002304
Jason Sams94d8e90a2009-06-10 16:09:05 -07002305static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07002306
2307static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08002308{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07002309
Tim Murrayeff663f2013-11-15 13:08:30 -08002310{"nDeviceCreate", "()J", (void*)nDeviceCreate },
2311{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
2312{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
2313{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
2314{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
2315{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08002316
Tim Murrayeff663f2013-11-15 13:08:30 -08002317{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
2318{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07002319
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07002320
Jason Sams2e1872f2010-08-17 16:25:41 -07002321// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08002322{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
2323{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
2324{"rsnContextFinish", "(J)V", (void*)nContextFinish },
2325{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
Tim Murray47f31582015-04-07 15:43:24 -07002326{"rsnContextSetCacheDir", "(JLjava/lang/String;)V", (void*)nContextSetCacheDir },
Tim Murrayeff663f2013-11-15 13:08:30 -08002327{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
2328{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
2329{"rsnContextDump", "(JI)V", (void*)nContextDump },
2330{"rsnContextPause", "(J)V", (void*)nContextPause },
2331{"rsnContextResume", "(J)V", (void*)nContextResume },
2332{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07002333{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002334{"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate },
Yang Ni281c3252014-10-24 08:52:24 -07002335{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
2336{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08002337{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
2338{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
2339{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07002340
Tim Murray460a0492013-11-19 12:45:54 -08002341{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002342{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08002343{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
2344{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
2345{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002346{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07002347
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002348{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
2349{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
2350{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07002351
Tim Murray460a0492013-11-19 12:45:54 -08002352{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002353{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08002354{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00002355{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07002356
Tim Murray460a0492013-11-19 12:45:54 -08002357{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002358{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07002359
Ashok Bhat98071552014-02-12 09:54:43 +00002360{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08002361{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
2362{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
2363{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08002364
Tim Murray460a0492013-11-19 12:45:54 -08002365{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
2366{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08002367
Tim Murray460a0492013-11-19 12:45:54 -08002368{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
2369{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
2370{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
2371{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
2372{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
Miao Wang87e908d2015-03-02 15:15:15 -08002373{"rsnAllocationData1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData1D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002374{"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData },
Miao Wang87e908d2015-03-02 15:15:15 -08002375{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData2D },
Tim Murray460a0492013-11-19 12:45:54 -08002376{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002377{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData3D },
Tim Murray460a0492013-11-19 12:45:54 -08002378{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002379{"rsnAllocationRead", "(JJLjava/lang/Object;IIZ)V", (void*)nAllocationRead },
2380{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead1D },
Miao Wang45cec0a2015-03-04 16:40:21 -08002381{"rsnAllocationElementRead", "(JJIIIII[BI)V", (void*)nAllocationElementRead },
Miao Wang87e908d2015-03-02 15:15:15 -08002382{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead2D },
2383{"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead3D },
Tim Murray460a0492013-11-19 12:45:54 -08002384{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
2385{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
2386{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07002387
Jason Sams46ba27e32015-02-06 17:45:15 -08002388{"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate },
2389{"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset },
2390
Tim Murray460a0492013-11-19 12:45:54 -08002391{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
2392{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
2393{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
2394{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07002395
2396{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
2397
Tim Murray460a0492013-11-19 12:45:54 -08002398{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
2399{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
2400{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
2401{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
2402{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
2403{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
2404{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
2405{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
2406{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
2407{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
2408{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
2409{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07002410
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002411{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002412{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2413{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002414{"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002415{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002416{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Niebf63402015-01-16 11:06:26 -08002417{"rsnScriptGroup2Create", "(JLjava/lang/String;[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002418{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2419{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2420{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002421{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002422
Tim Murray25207df2015-01-12 16:47:56 -08002423{"rsnScriptIntrinsicBLAS_Single", "(JJIIIIIIIIIFJJFJIIII)V", (void*)nScriptIntrinsicBLAS_Single },
2424{"rsnScriptIntrinsicBLAS_Double", "(JJIIIIIIIIIDJJDJIIII)V", (void*)nScriptIntrinsicBLAS_Double },
2425{"rsnScriptIntrinsicBLAS_Complex", "(JJIIIIIIIIIFFJJFFJIIII)V", (void*)nScriptIntrinsicBLAS_Complex },
2426{"rsnScriptIntrinsicBLAS_Z", "(JJIIIIIIIIIDDJJDDJIIII)V", (void*)nScriptIntrinsicBLAS_Z },
2427
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002428{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002429
Tim Murray460a0492013-11-19 12:45:54 -08002430{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2431{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2432{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002433
Ashok Bhat98071552014-02-12 09:54:43 +00002434{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002435{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002436{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002437
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002438{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2439{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2440{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2441{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2442{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002443
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002444{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002445
Ashok Bhat98071552014-02-12 09:54:43 +00002446{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002447
Tim Murray460a0492013-11-19 12:45:54 -08002448{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2449{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002450{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2451{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002452
Tim Murray56f9e6f2014-05-16 11:47:26 -07002453{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002454};
2455
2456static int registerFuncs(JNIEnv *_env)
2457{
2458 return android::AndroidRuntime::registerNativeMethods(
2459 _env, classPathName, methods, NELEM(methods));
2460}
2461
2462// ---------------------------------------------------------------------------
2463
2464jint JNI_OnLoad(JavaVM* vm, void* reserved)
2465{
Chris Wailes488230c32014-08-14 11:22:40 -07002466 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002467 jint result = -1;
2468
Jason Samsd19f10d2009-05-22 14:03:28 -07002469 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002470 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002471 goto bail;
2472 }
Chris Wailes488230c32014-08-14 11:22:40 -07002473 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002474
2475 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002476 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002477 goto bail;
2478 }
2479
2480 /* success -- return valid version number */
2481 result = JNI_VERSION_1_4;
2482
2483bail:
2484 return result;
2485}