blob: 6f6729bbaae0e0368c6e4481cd1176854327d0f9 [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
Stephen Hines4cbe25a2012-01-18 18:46:27 -08002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Samsd19f10d2009-05-22 14:03:28 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jason Samsf29ca502009-06-23 12:22:47 -070017#define LOG_TAG "libRS_jni"
18
Jason Samsd19f10d2009-05-22 14:03:28 -070019#include <stdlib.h>
20#include <stdio.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <math.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070024#include <utils/misc.h>
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +010025#include <inttypes.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070026
Derek Sollenbergereece0dd2014-02-27 14:31:29 -050027#include <SkBitmap.h>
Jason Samsffe9f482009-06-01 17:45:53 -070028
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080029#include <androidfw/Asset.h>
30#include <androidfw/AssetManager.h>
31#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070032
Jason Samsd19f10d2009-05-22 14:03:28 -070033#include "jni.h"
34#include "JNIHelp.h"
35#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070036#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080037#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070038
Jason Sams1d6983a2012-02-16 16:07:49 -080039#include <rs.h>
40#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070041#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080042#include <gui/GLConsumer.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070043#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070044
Steve Block3762c312012-01-06 19:20:56 +000045//#define LOG_API ALOGE
Andreas Gampe67333922014-11-10 20:35:59 -080046static constexpr bool kLogApi = false;
Jason Samsd19f10d2009-05-22 14:03:28 -070047
48using namespace android;
49
Andreas Gampe67333922014-11-10 20:35:59 -080050template <typename... T>
51void UNUSED(T... t) {}
52
Stephen Hines414fa2c2014-04-17 01:02:42 -070053#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \
Jason Samse729a942013-11-06 11:22:02 -080054 jint len = 0; \
Chris Wailes488230c32014-08-14 11:22:40 -070055 void *ptr = nullptr; \
Miao Wang87e908d2015-03-02 15:15:15 -080056 void *srcPtr = nullptr; \
Jason Sams21659ac2013-11-06 15:08:07 -080057 size_t typeBytes = 0; \
Stephen Hines414fa2c2014-04-17 01:02:42 -070058 jint relFlag = 0; \
59 if (readonly) { \
60 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
Miao Wang87e908d2015-03-02 15:15:15 -080061 /* readonly = true, also indicates we are copying to the allocation . */ \
Stephen Hines414fa2c2014-04-17 01:02:42 -070062 relFlag = JNI_ABORT; \
63 } \
Jason Samse729a942013-11-06 11:22:02 -080064 switch(dataType) { \
65 case RS_TYPE_FLOAT_32: \
66 len = _env->GetArrayLength((jfloatArray)data); \
67 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080068 typeBytes = 4; \
Miao Wang87e908d2015-03-02 15:15:15 -080069 if (usePadding) { \
70 srcPtr = ptr; \
71 len = len / 3 * 4; \
72 if (count == 0) { \
73 count = len / 4; \
74 } \
75 ptr = malloc (len * typeBytes); \
76 if (readonly) { \
77 copyWithPadding(ptr, srcPtr, mSize, count); \
78 fnc(__VA_ARGS__); \
79 } else { \
80 fnc(__VA_ARGS__); \
81 copyWithUnPadding(srcPtr, ptr, mSize, count); \
82 } \
83 free(ptr); \
84 ptr = srcPtr; \
85 } else { \
86 fnc(__VA_ARGS__); \
87 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -070088 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080089 return; \
90 case RS_TYPE_FLOAT_64: \
91 len = _env->GetArrayLength((jdoubleArray)data); \
92 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080093 typeBytes = 8; \
Miao Wang87e908d2015-03-02 15:15:15 -080094 if (usePadding) { \
95 srcPtr = ptr; \
96 len = len / 3 * 4; \
97 if (count == 0) { \
98 count = len / 4; \
99 } \
100 ptr = malloc (len * typeBytes); \
101 if (readonly) { \
102 copyWithPadding(ptr, srcPtr, mSize, count); \
103 fnc(__VA_ARGS__); \
104 } else { \
105 fnc(__VA_ARGS__); \
106 copyWithUnPadding(srcPtr, ptr, mSize, count); \
107 } \
108 free(ptr); \
109 ptr = srcPtr; \
110 } else { \
111 fnc(__VA_ARGS__); \
112 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700113 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800114 return; \
115 case RS_TYPE_SIGNED_8: \
116 case RS_TYPE_UNSIGNED_8: \
117 len = _env->GetArrayLength((jbyteArray)data); \
118 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800119 typeBytes = 1; \
Miao Wang87e908d2015-03-02 15:15:15 -0800120 if (usePadding) { \
121 srcPtr = ptr; \
122 len = len / 3 * 4; \
123 if (count == 0) { \
124 count = len / 4; \
125 } \
126 ptr = malloc (len * typeBytes); \
127 if (readonly) { \
128 copyWithPadding(ptr, srcPtr, mSize, count); \
129 fnc(__VA_ARGS__); \
130 } else { \
131 fnc(__VA_ARGS__); \
132 copyWithUnPadding(srcPtr, ptr, mSize, count); \
133 } \
134 free(ptr); \
135 ptr = srcPtr; \
136 } else { \
137 fnc(__VA_ARGS__); \
138 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700139 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800140 return; \
141 case RS_TYPE_SIGNED_16: \
142 case RS_TYPE_UNSIGNED_16: \
143 len = _env->GetArrayLength((jshortArray)data); \
144 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800145 typeBytes = 2; \
Miao Wang87e908d2015-03-02 15:15:15 -0800146 if (usePadding) { \
147 srcPtr = ptr; \
148 len = len / 3 * 4; \
149 if (count == 0) { \
150 count = len / 4; \
151 } \
152 ptr = malloc (len * typeBytes); \
153 if (readonly) { \
154 copyWithPadding(ptr, srcPtr, mSize, count); \
155 fnc(__VA_ARGS__); \
156 } else { \
157 fnc(__VA_ARGS__); \
158 copyWithUnPadding(srcPtr, ptr, mSize, count); \
159 } \
160 free(ptr); \
161 ptr = srcPtr; \
162 } else { \
163 fnc(__VA_ARGS__); \
164 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700165 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800166 return; \
167 case RS_TYPE_SIGNED_32: \
168 case RS_TYPE_UNSIGNED_32: \
169 len = _env->GetArrayLength((jintArray)data); \
170 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800171 typeBytes = 4; \
Miao Wang87e908d2015-03-02 15:15:15 -0800172 if (usePadding) { \
173 srcPtr = ptr; \
174 len = len / 3 * 4; \
175 if (count == 0) { \
176 count = len / 4; \
177 } \
178 ptr = malloc (len * typeBytes); \
179 if (readonly) { \
180 copyWithPadding(ptr, srcPtr, mSize, count); \
181 fnc(__VA_ARGS__); \
182 } else { \
183 fnc(__VA_ARGS__); \
184 copyWithUnPadding(srcPtr, ptr, mSize, count); \
185 } \
186 free(ptr); \
187 ptr = srcPtr; \
188 } else { \
189 fnc(__VA_ARGS__); \
190 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700191 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800192 return; \
193 case RS_TYPE_SIGNED_64: \
194 case RS_TYPE_UNSIGNED_64: \
195 len = _env->GetArrayLength((jlongArray)data); \
196 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800197 typeBytes = 8; \
Miao Wang87e908d2015-03-02 15:15:15 -0800198 if (usePadding) { \
199 srcPtr = ptr; \
200 len = len / 3 * 4; \
201 if (count == 0) { \
202 count = len / 4; \
203 } \
204 ptr = malloc (len * typeBytes); \
205 if (readonly) { \
206 copyWithPadding(ptr, srcPtr, mSize, count); \
207 fnc(__VA_ARGS__); \
208 } else { \
209 fnc(__VA_ARGS__); \
210 copyWithUnPadding(srcPtr, ptr, mSize, count); \
211 } \
212 free(ptr); \
213 ptr = srcPtr; \
214 } else { \
215 fnc(__VA_ARGS__); \
216 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700217 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800218 return; \
219 default: \
220 break; \
221 } \
Miao Wang87e908d2015-03-02 15:15:15 -0800222 UNUSED(len, ptr, srcPtr, typeBytes, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800223}
224
225
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800226class AutoJavaStringToUTF8 {
227public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800228 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Chris Wailes488230c32014-08-14 11:22:40 -0700229 fCStr = env->GetStringUTFChars(str, nullptr);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800230 fLength = env->GetStringUTFLength(str);
231 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800232 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800233 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
234 }
235 const char* c_str() const { return fCStr; }
236 jsize length() const { return fLength; }
237
238private:
239 JNIEnv* fEnv;
240 jstring fJStr;
241 const char* fCStr;
242 jsize fLength;
243};
244
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800245class AutoJavaStringArrayToUTF8 {
246public:
247 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
248 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
Chris Wailes488230c32014-08-14 11:22:40 -0700249 mCStrings = nullptr;
250 mSizeArray = nullptr;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800251 if (stringsLength > 0) {
252 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
253 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
254 for (jsize ct = 0; ct < stringsLength; ct ++) {
255 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
Chris Wailes488230c32014-08-14 11:22:40 -0700256 mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800257 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
258 }
259 }
260 }
261 ~AutoJavaStringArrayToUTF8() {
262 for (jsize ct=0; ct < mStringsLength; ct++) {
263 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
264 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
265 }
266 free(mCStrings);
267 free(mSizeArray);
268 }
269 const char **c_str() const { return mCStrings; }
270 size_t *c_str_len() const { return mSizeArray; }
271 jsize length() const { return mStringsLength; }
272
273private:
274 JNIEnv *mEnv;
275 jobjectArray mStrings;
276 const char **mCStrings;
277 size_t *mSizeArray;
278 jsize mStringsLength;
279};
280
Jason Samsd19f10d2009-05-22 14:03:28 -0700281// ---------------------------------------------------------------------------
282
Jason Samsffe9f482009-06-01 17:45:53 -0700283static jfieldID gContextId = 0;
284static jfieldID gNativeBitmapID = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700285
286static void _nInit(JNIEnv *_env, jclass _this)
287{
Tim Murrayeff663f2013-11-15 13:08:30 -0800288 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsffe9f482009-06-01 17:45:53 -0700289
290 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000291 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700292}
293
Jason Samsd19f10d2009-05-22 14:03:28 -0700294// ---------------------------------------------------------------------------
295
Miao Wang87e908d2015-03-02 15:15:15 -0800296static void copyWithPadding(void* ptr, void* srcPtr, int mSize, int count) {
297 int sizeBytesPad = mSize * 4;
298 int sizeBytes = mSize * 3;
299 uint8_t *dst = static_cast<uint8_t *>(ptr);
300 uint8_t *src = static_cast<uint8_t *>(srcPtr);
301 for (int i = 0; i < count; i++) {
302 memcpy(dst, src, sizeBytes);
303 dst += sizeBytesPad;
304 src += sizeBytes;
305 }
306}
307
308static void copyWithUnPadding(void* ptr, void* srcPtr, int mSize, int count) {
309 int sizeBytesPad = mSize * 4;
310 int sizeBytes = mSize * 3;
311 uint8_t *dst = static_cast<uint8_t *>(ptr);
312 uint8_t *src = static_cast<uint8_t *>(srcPtr);
313 for (int i = 0; i < count; i++) {
314 memcpy(dst, src, sizeBytes);
315 dst += sizeBytes;
316 src += sizeBytesPad;
317 }
318}
319
320
321// ---------------------------------------------------------------------------
Jason Sams3eaa338e2009-06-10 15:04:38 -0700322static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800323nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700324{
Andreas Gampe67333922014-11-10 20:35:59 -0800325 if (kLogApi) {
326 ALOGD("nContextFinish, con(%p)", (RsContext)con);
327 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800328 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700329}
330
Yang Ni281c3252014-10-24 08:52:24 -0700331static jlong
332nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID,
333 jlong returnValue, jlongArray fieldIDArray,
334 jlongArray valueArray, jintArray sizeArray,
335 jlongArray depClosureArray, jlongArray depFieldIDArray) {
336 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
337 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
338 RsScriptFieldID* fieldIDs =
339 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
340 for (int i = 0; i< fieldIDs_length; i++) {
341 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
342 }
343
344 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
345 jsize values_length = _env->GetArrayLength(valueArray);
346 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
347 for (int i = 0; i < values_length; i++) {
348 values[i] = (uintptr_t)jValues[i];
349 }
350
351 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
352 jsize sizes_length = _env->GetArrayLength(sizeArray);
353
354 jlong* jDepClosures =
355 _env->GetLongArrayElements(depClosureArray, nullptr);
356 jsize depClosures_length = _env->GetArrayLength(depClosureArray);
357 RsClosure* depClosures =
358 (RsClosure*)alloca(sizeof(RsClosure) * depClosures_length);
359 for (int i = 0; i < depClosures_length; i++) {
360 depClosures[i] = (RsClosure)jDepClosures[i];
361 }
362
363 jlong* jDepFieldIDs =
364 _env->GetLongArrayElements(depFieldIDArray, nullptr);
365 jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray);
366 RsScriptFieldID* depFieldIDs =
367 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * depFieldIDs_length);
368 for (int i = 0; i < depClosures_length; i++) {
369 depFieldIDs[i] = (RsClosure)jDepFieldIDs[i];
370 }
371
372 return (jlong)(uintptr_t)rsClosureCreate(
373 (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue,
374 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
Yang Ni4c93c8c2015-03-26 14:35:22 -0700375 (int*)sizes, (size_t)sizes_length,
Yang Ni281c3252014-10-24 08:52:24 -0700376 depClosures, (size_t)depClosures_length,
377 depFieldIDs, (size_t)depFieldIDs_length);
378}
379
Yang Nibe392ad2015-01-23 17:16:02 -0800380static jlong
381nInvokeClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong invokeID,
382 jbyteArray paramArray, jlongArray fieldIDArray, jlongArray valueArray,
383 jintArray sizeArray) {
384 jbyte* jParams = _env->GetByteArrayElements(paramArray, nullptr);
385 jsize jParamLength = _env->GetArrayLength(paramArray);
386
387 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
388 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
389 RsScriptFieldID* fieldIDs =
390 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
391 for (int i = 0; i< fieldIDs_length; i++) {
392 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
393 }
394
395 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
396 jsize values_length = _env->GetArrayLength(valueArray);
397 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
398 for (int i = 0; i < values_length; i++) {
399 values[i] = (uintptr_t)jValues[i];
400 }
401
402 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
403 jsize sizes_length = _env->GetArrayLength(sizeArray);
404
405 return (jlong)(uintptr_t)rsInvokeClosureCreate(
406 (RsContext)con, (RsScriptInvokeID)invokeID, jParams, jParamLength,
407 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
Yang Ni4c93c8c2015-03-26 14:35:22 -0700408 (int*)sizes, (size_t)sizes_length);
Yang Nibe392ad2015-01-23 17:16:02 -0800409}
410
Yang Ni281c3252014-10-24 08:52:24 -0700411static void
412nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
413 jint index, jlong value, jint size) {
414 rsClosureSetArg((RsContext)con, (RsClosure)closureID, (uint32_t)index,
415 (uintptr_t)value, (size_t)size);
416}
417
418static void
419nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
420 jlong fieldID, jlong value, jint size) {
421 rsClosureSetGlobal((RsContext)con, (RsClosure)closureID,
422 (RsScriptFieldID)fieldID, (uintptr_t)value, (size_t)size);
423}
424
425static long
Yang Ni35be56c2015-04-02 17:47:56 -0700426nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con, jstring name,
Yang Niebf63402015-01-16 11:06:26 -0800427 jstring cacheDir, jlongArray closureArray) {
Yang Ni35be56c2015-04-02 17:47:56 -0700428 AutoJavaStringToUTF8 nameUTF(_env, name);
Yang Niebf63402015-01-16 11:06:26 -0800429 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
430
Yang Ni281c3252014-10-24 08:52:24 -0700431 jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr);
432 jsize numClosures = _env->GetArrayLength(closureArray);
433 RsClosure* closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures);
434 for (int i = 0; i < numClosures; i++) {
435 closures[i] = (RsClosure)jClosures[i];
436 }
437
Yang Niebf63402015-01-16 11:06:26 -0800438 return (jlong)(uintptr_t)rsScriptGroup2Create(
Yang Ni35be56c2015-04-02 17:47:56 -0700439 (RsContext)con, nameUTF.c_str(), nameUTF.length(),
440 cacheDirUTF.c_str(), cacheDirUTF.length(),
Yang Niebf63402015-01-16 11:06:26 -0800441 closures, numClosures);
Yang Ni281c3252014-10-24 08:52:24 -0700442}
443
444static void
445nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) {
446 rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID);
447}
448
Jason Sams96ed4cf2010-06-15 12:15:57 -0700449static void
Tim Murray25207df2015-01-12 16:47:56 -0800450nScriptIntrinsicBLAS_Single(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
451 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
452 jfloat alpha, jlong A, jlong B, jfloat beta, jlong C, jint incX, jint incY,
453 jint KL, jint KU) {
454 RsBlasCall call;
455 memset(&call, 0, sizeof(call));
456 call.func = (RsBlasFunction)func;
457 call.transA = (RsBlasTranspose)TransA;
458 call.transB = (RsBlasTranspose)TransB;
459 call.side = (RsBlasSide)Side;
460 call.uplo = (RsBlasUplo)Uplo;
461 call.diag = (RsBlasDiag)Diag;
462 call.M = M;
463 call.N = N;
464 call.K = K;
465 call.alpha.f = alpha;
466 call.beta.f = beta;
467 call.incX = incX;
468 call.incY = incY;
469 call.KL = KL;
470 call.KU = KU;
471
472 RsAllocation in_allocs[3];
473 in_allocs[0] = (RsAllocation)A;
474 in_allocs[1] = (RsAllocation)B;
475 in_allocs[2] = (RsAllocation)C;
476
477 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
478 in_allocs, sizeof(in_allocs), nullptr,
479 &call, sizeof(call), nullptr, 0);
480}
481
482static void
483nScriptIntrinsicBLAS_Double(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
484 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
485 jdouble alpha, jlong A, jlong B, jdouble beta, jlong C, jint incX, jint incY,
486 jint KL, jint KU) {
487 RsBlasCall call;
488 memset(&call, 0, sizeof(call));
489 call.func = (RsBlasFunction)func;
490 call.transA = (RsBlasTranspose)TransA;
491 call.transB = (RsBlasTranspose)TransB;
492 call.side = (RsBlasSide)Side;
493 call.uplo = (RsBlasUplo)Uplo;
494 call.diag = (RsBlasDiag)Diag;
495 call.M = M;
496 call.N = N;
497 call.K = K;
498 call.alpha.d = alpha;
499 call.beta.d = beta;
500 call.incX = incX;
501 call.incY = incY;
502 call.KL = KL;
503 call.KU = KU;
504
505 RsAllocation in_allocs[3];
506 in_allocs[0] = (RsAllocation)A;
507 in_allocs[1] = (RsAllocation)B;
508 in_allocs[2] = (RsAllocation)C;
509
510 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
511 in_allocs, sizeof(in_allocs), nullptr,
512 &call, sizeof(call), nullptr, 0);
513}
514
515static void
516nScriptIntrinsicBLAS_Complex(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
517 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
518 jfloat alphaX, jfloat alphaY, jlong A, jlong B, jfloat betaX,
519 jfloat betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
520 RsBlasCall call;
521 memset(&call, 0, sizeof(call));
522 call.func = (RsBlasFunction)func;
523 call.transA = (RsBlasTranspose)TransA;
524 call.transB = (RsBlasTranspose)TransB;
525 call.side = (RsBlasSide)Side;
526 call.uplo = (RsBlasUplo)Uplo;
527 call.diag = (RsBlasDiag)Diag;
528 call.M = M;
529 call.N = N;
530 call.K = K;
531 call.alpha.c.r = alphaX;
532 call.alpha.c.i = alphaY;
533 call.beta.c.r = betaX;
534 call.beta.c.r = betaY;
535 call.incX = incX;
536 call.incY = incY;
537 call.KL = KL;
538 call.KU = KU;
539
540 RsAllocation in_allocs[3];
541 in_allocs[0] = (RsAllocation)A;
542 in_allocs[1] = (RsAllocation)B;
543 in_allocs[2] = (RsAllocation)C;
544
545 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
546 in_allocs, sizeof(in_allocs), nullptr,
547 &call, sizeof(call), nullptr, 0);
548}
549
550static void
551nScriptIntrinsicBLAS_Z(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
552 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
553 jdouble alphaX, jdouble alphaY, jlong A, jlong B, jdouble betaX,
554 jdouble betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
555 RsBlasCall call;
556 memset(&call, 0, sizeof(call));
557 call.func = (RsBlasFunction)func;
558 call.transA = (RsBlasTranspose)TransA;
559 call.transB = (RsBlasTranspose)TransB;
560 call.side = (RsBlasSide)Side;
561 call.uplo = (RsBlasUplo)Uplo;
562 call.diag = (RsBlasDiag)Diag;
563 call.M = M;
564 call.N = N;
565 call.K = K;
566 call.alpha.z.r = alphaX;
567 call.alpha.z.i = alphaY;
568 call.beta.z.r = betaX;
569 call.beta.z.r = betaY;
570 call.incX = incX;
571 call.incY = incY;
572 call.KL = KL;
573 call.KU = KU;
574
575 RsAllocation in_allocs[3];
576 in_allocs[0] = (RsAllocation)A;
577 in_allocs[1] = (RsAllocation)B;
578 in_allocs[2] = (RsAllocation)C;
579
580 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
581 in_allocs, sizeof(in_allocs), nullptr,
582 &call, sizeof(call), nullptr, 0);
583}
584
585
586static void
Tim Murray9cb16a22015-04-01 11:07:16 -0700587nScriptIntrinsicBLAS_BNNM(JNIEnv *_env, jobject _this, jlong con, jlong id, jint M, jint N, jint K,
588 jlong A, jint a_offset, jlong B, jint b_offset, jlong C, jint c_offset,
589 jint c_mult_int) {
590 RsBlasCall call;
591 memset(&call, 0, sizeof(call));
592 call.func = RsBlas_bnnm;
593 call.M = M;
594 call.N = N;
595 call.K = K;
596 call.a_offset = a_offset;
597 call.b_offset = b_offset;
598 call.c_offset = c_offset;
599 call.c_mult_int = c_mult_int;
600
601 RsAllocation in_allocs[3];
602 in_allocs[0] = (RsAllocation)A;
603 in_allocs[1] = (RsAllocation)B;
604 in_allocs[2] = (RsAllocation)C;
605
606 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
607 in_allocs, sizeof(in_allocs), nullptr,
608 &call, sizeof(call), nullptr, 0);
609}
610
611
612static void
Tim Murray460a0492013-11-19 12:45:54 -0800613nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700614{
Andreas Gampe67333922014-11-10 20:35:59 -0800615 if (kLogApi) {
616 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
617 }
Jason Sams3eaa338e2009-06-10 15:04:38 -0700618 jint len = _env->GetArrayLength(str);
619 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800620 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700621 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
622}
623
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700624static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800625nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700626{
Andreas Gampe67333922014-11-10 20:35:59 -0800627 if (kLogApi) {
628 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
629 }
Chris Wailes488230c32014-08-14 11:22:40 -0700630 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800631 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700632 if(name == nullptr || strlen(name) == 0) {
633 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700634 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700635 return _env->NewStringUTF(name);
636}
637
Jason Sams7ce033d2009-08-18 14:14:24 -0700638static void
Tim Murray460a0492013-11-19 12:45:54 -0800639nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700640{
Andreas Gampe67333922014-11-10 20:35:59 -0800641 if (kLogApi) {
642 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
643 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800644 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700645}
646
Jason Sams3eaa338e2009-06-10 15:04:38 -0700647// ---------------------------------------------------------------------------
648
Tim Murrayeff663f2013-11-15 13:08:30 -0800649static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700650nDeviceCreate(JNIEnv *_env, jobject _this)
651{
Andreas Gampe67333922014-11-10 20:35:59 -0800652 if (kLogApi) {
653 ALOGD("nDeviceCreate");
654 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700655 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700656}
657
658static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800659nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700660{
Andreas Gampe67333922014-11-10 20:35:59 -0800661 if (kLogApi) {
662 ALOGD("nDeviceDestroy");
663 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700664 return rsDeviceDestroy((RsDevice)dev);
665}
666
Jason Samsebfb4362009-09-23 13:57:02 -0700667static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800668nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700669{
Andreas Gampe67333922014-11-10 20:35:59 -0800670 if (kLogApi) {
671 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
672 }
Jason Samsebfb4362009-09-23 13:57:02 -0700673 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
674}
675
Tim Murrayeff663f2013-11-15 13:08:30 -0800676static jlong
Jason Sams81cd2b12014-12-02 12:36:43 -0800677nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700678{
Andreas Gampe67333922014-11-10 20:35:59 -0800679 if (kLogApi) {
680 ALOGD("nContextCreate");
681 }
Jason Sams81cd2b12014-12-02 12:36:43 -0800682 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags);
Jason Sams704ff642010-02-09 16:05:07 -0800683}
684
Tim Murrayeff663f2013-11-15 13:08:30 -0800685static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800686nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000687 jint colorMin, jint colorPref,
688 jint alphaMin, jint alphaPref,
689 jint depthMin, jint depthPref,
690 jint stencilMin, jint stencilPref,
691 jint samplesMin, jint samplesPref, jfloat samplesQ,
692 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800693{
Jason Sams11c8af92010-10-13 15:31:10 -0700694 RsSurfaceConfig sc;
695 sc.alphaMin = alphaMin;
696 sc.alphaPref = alphaPref;
697 sc.colorMin = colorMin;
698 sc.colorPref = colorPref;
699 sc.depthMin = depthMin;
700 sc.depthPref = depthPref;
701 sc.samplesMin = samplesMin;
702 sc.samplesPref = samplesPref;
703 sc.samplesQ = samplesQ;
704
Andreas Gampe67333922014-11-10 20:35:59 -0800705 if (kLogApi) {
706 ALOGD("nContextCreateGL");
707 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700708 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700709}
710
711static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800712nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800713{
Andreas Gampe67333922014-11-10 20:35:59 -0800714 if (kLogApi) {
715 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
716 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800717 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800718}
719
Tim Murray47f31582015-04-07 15:43:24 -0700720static void
721nContextSetCacheDir(JNIEnv *_env, jobject _this, jlong con, jstring cacheDir)
722{
723 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
724
725 if (kLogApi) {
726 ALOGD("ContextSetCacheDir, con(%p), cacheDir(%s)", (RsContext)con, cacheDirUTF.c_str());
727 }
728 rsContextSetCacheDir((RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length());
729}
730
Jason Sams7d787b42009-11-15 12:14:26 -0800731
732
733static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800734nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800735{
Andreas Gampe67333922014-11-10 20:35:59 -0800736 if (kLogApi) {
737 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
738 width, height, (Surface *)wnd);
739 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800740
Chris Wailes488230c32014-08-14 11:22:40 -0700741 ANativeWindow * window = nullptr;
742 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800743
744 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700745 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800746 }
747
Tim Murrayeff663f2013-11-15 13:08:30 -0800748 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800749}
750
751static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800752nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700753{
Andreas Gampe67333922014-11-10 20:35:59 -0800754 if (kLogApi) {
755 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
756 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800757 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700758}
759
Jason Sams715333b2009-11-17 17:26:46 -0800760static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800761nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800762{
Andreas Gampe67333922014-11-10 20:35:59 -0800763 if (kLogApi) {
764 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
765 }
Jason Sams715333b2009-11-17 17:26:46 -0800766 rsContextDump((RsContext)con, bits);
767}
Jason Samsd19f10d2009-05-22 14:03:28 -0700768
769static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800770nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700771{
Andreas Gampe67333922014-11-10 20:35:59 -0800772 if (kLogApi) {
773 ALOGD("nContextPause, con(%p)", (RsContext)con);
774 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800775 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700776}
777
778static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800779nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700780{
Andreas Gampe67333922014-11-10 20:35:59 -0800781 if (kLogApi) {
782 ALOGD("nContextResume, con(%p)", (RsContext)con);
783 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800784 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700785}
786
Jason Sams1c415172010-11-08 17:06:46 -0800787
788static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800789nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800790{
Andreas Gampe67333922014-11-10 20:35:59 -0800791 if (kLogApi) {
792 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
793 }
Jason Sams1c415172010-11-08 17:06:46 -0800794 char buf[1024];
795
796 size_t receiveLen;
797 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800798 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700799 buf, sizeof(buf),
800 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700801 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800802 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100803 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800804 }
805 return _env->NewStringUTF(buf);
806}
807
Jason Samsedbfabd2011-05-17 15:01:29 -0700808static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800809nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700810{
Jason Sams516c3192009-10-06 13:58:47 -0700811 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800812 if (kLogApi) {
813 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
814 }
Chris Wailes488230c32014-08-14 11:22:40 -0700815 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700816 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800817 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800818 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700819 ptr, len * 4,
820 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700821 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700822 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100823 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700824 }
825 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000826 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800827}
828
829static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800830nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800831{
Andreas Gampe67333922014-11-10 20:35:59 -0800832 if (kLogApi) {
833 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
834 }
Chris Wailes488230c32014-08-14 11:22:40 -0700835 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800836 size_t receiveLen;
837 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800838 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700839 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800840 auxDataPtr[0] = (jint)subID;
841 auxDataPtr[1] = (jint)receiveLen;
842 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000843 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700844}
845
Tim Murrayeff663f2013-11-15 13:08:30 -0800846static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700847{
Andreas Gampe67333922014-11-10 20:35:59 -0800848 if (kLogApi) {
849 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
850 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800851 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700852}
853
Tim Murrayeff663f2013-11-15 13:08:30 -0800854static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700855{
Andreas Gampe67333922014-11-10 20:35:59 -0800856 if (kLogApi) {
857 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
858 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800859 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700860}
861
Jason Sams455d6442013-02-05 19:20:18 -0800862static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800863nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800864{
Chris Wailes488230c32014-08-14 11:22:40 -0700865 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800866 jint len = 0;
867 if (data) {
868 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700869 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800870 }
Andreas Gampe67333922014-11-10 20:35:59 -0800871 if (kLogApi) {
872 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
873 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800874 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800875 if (data) {
876 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
877 }
878}
879
880
Jason Sams516c3192009-10-06 13:58:47 -0700881
Tim Murray460a0492013-11-19 12:45:54 -0800882static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800883nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
884 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700885{
Andreas Gampe67333922014-11-10 20:35:59 -0800886 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100887 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con,
Andreas Gampe67333922014-11-10 20:35:59 -0800888 type, kind, norm, size);
889 }
890 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
891 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700892}
893
Tim Murray460a0492013-11-19 12:45:54 -0800894static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800895nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000896 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700897{
Jason Sams718cd1f2009-12-23 14:35:29 -0800898 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -0800899 if (kLogApi) {
900 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
901 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800902
Chris Wailes488230c32014-08-14 11:22:40 -0700903 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
904 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000905
906 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
907 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
908
909 for(int i = 0; i < fieldCount; i ++) {
910 ids[i] = (RsElement)jIds[i];
911 arraySizes[i] = (uint32_t)jArraySizes[i];
912 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800913
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800914 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
915
916 const char **nameArray = names.c_str();
917 size_t *sizeArray = names.c_str_len();
918
Tim Murray3aa89c12014-08-18 17:51:22 -0700919 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000920 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700921 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700922 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800923
Ashok Bhat98071552014-02-12 09:54:43 +0000924 free(ids);
925 free(arraySizes);
926 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
927 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
928
Tim Murray3aa89c12014-08-18 17:51:22 -0700929 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700930}
931
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700932static void
Tim Murray460a0492013-11-19 12:45:54 -0800933nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700934{
935 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -0800936 if (kLogApi) {
937 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
938 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700939
940 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
941 assert(dataSize == 5);
942
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000943 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800944 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700945
946 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000947 const jint data = (jint)elementData[i];
948 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700949 }
950}
951
952
953static void
Tim Murray460a0492013-11-19 12:45:54 -0800954nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000955 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700956 jobjectArray _names,
957 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700958{
Ashok Bhat98071552014-02-12 09:54:43 +0000959 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -0800960 if (kLogApi) {
961 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
962 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700963
Ashok Bhat98071552014-02-12 09:54:43 +0000964 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
965 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000966 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700967
Andreas Gampe67333922014-11-10 20:35:59 -0800968 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
969 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700970
Ashok Bhat98071552014-02-12 09:54:43 +0000971 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700972 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000973 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700974 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000975 _env->SetLongArrayRegion(_IDs, i, 1, &id);
976 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700977 }
978
979 free(ids);
980 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700981 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700982}
983
Jason Samsd19f10d2009-05-22 14:03:28 -0700984// -----------------------------------
985
Tim Murray460a0492013-11-19 12:45:54 -0800986static jlong
987nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800988 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700989{
Andreas Gampe67333922014-11-10 20:35:59 -0800990 if (kLogApi) {
991 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 +0100992 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv);
Andreas Gampe67333922014-11-10 20:35:59 -0800993 }
Jason Sams3b9c52a2010-10-14 17:48:46 -0700994
Andreas Gampe67333922014-11-10 20:35:59 -0800995 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
996 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700997}
998
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700999static void
Ashok Bhat98071552014-02-12 09:54:43 +00001000nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001001{
1002 // We are packing 6 items: mDimX; mDimY; mDimZ;
1003 // mDimLOD; mDimFaces; mElement; into typeData
1004 int elementCount = _env->GetArrayLength(_typeData);
1005
1006 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001007 if (kLogApi) {
1008 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
1009 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001010
Ashok Bhat98071552014-02-12 09:54:43 +00001011 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -08001012 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001013
1014 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001015 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001016 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001017 }
1018}
1019
Jason Samsd19f10d2009-05-22 14:03:28 -07001020// -----------------------------------
1021
Tim Murray460a0492013-11-19 12:45:54 -08001022static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001023nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
1024 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -07001025{
Andreas Gampe67333922014-11-10 20:35:59 -08001026 if (kLogApi) {
1027 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
1028 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
1029 }
1030 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
1031 (RsAllocationMipmapControl)mips,
1032 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -07001033}
1034
Jason Samsd19f10d2009-05-22 14:03:28 -07001035static void
Tim Murray460a0492013-11-19 12:45:54 -08001036nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -08001037{
Andreas Gampe67333922014-11-10 20:35:59 -08001038 if (kLogApi) {
1039 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
1040 bits);
1041 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001042 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -08001043}
1044
Jason Sams72226e02013-02-22 12:45:54 -08001045static jobject
Tim Murray460a0492013-11-19 12:45:54 -08001046nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -08001047{
Andreas Gampe67333922014-11-10 20:35:59 -08001048 if (kLogApi) {
1049 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1050 }
Jason Sams615e7ce2012-01-13 14:01:20 -08001051
Andreas Gampe67333922014-11-10 20:35:59 -08001052 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
1053 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -08001054 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -07001055 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001056
Jason Sams72226e02013-02-22 12:45:54 -08001057 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
1058 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001059}
1060
1061static void
Tim Murray460a0492013-11-19 12:45:54 -08001062nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -08001063{
Andreas Gampe67333922014-11-10 20:35:59 -08001064 if (kLogApi) {
1065 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
1066 (RsAllocation)alloc, (Surface *)sur);
1067 }
Jason Sams163766c2012-02-15 12:04:24 -08001068
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001069 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -08001070 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -07001071 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -08001072 }
1073
Andreas Gampe67333922014-11-10 20:35:59 -08001074 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
1075 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -08001076}
1077
1078static void
Tim Murray460a0492013-11-19 12:45:54 -08001079nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001080{
Andreas Gampe67333922014-11-10 20:35:59 -08001081 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001082 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001083 }
Tim Murray460a0492013-11-19 12:45:54 -08001084 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001085}
1086
1087static void
Tim Murray460a0492013-11-19 12:45:54 -08001088nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001089{
Andreas Gampe67333922014-11-10 20:35:59 -08001090 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001091 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001092 }
Tim Murray460a0492013-11-19 12:45:54 -08001093 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001094}
1095
1096
1097static void
Tim Murray460a0492013-11-19 12:45:54 -08001098nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -08001099{
Andreas Gampe67333922014-11-10 20:35:59 -08001100 if (kLogApi) {
1101 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
1102 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001103 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -08001104}
1105
Tim Murray460a0492013-11-19 12:45:54 -08001106static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001107nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1108 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -07001109{
Jason Samsffe9f482009-06-01 17:45:53 -07001110 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001111 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -07001112 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -07001113
Jason Sams5476b452010-12-08 16:14:36 -08001114 bitmap.lockPixels();
1115 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001116 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001117 (RsType)type, (RsAllocationMipmapControl)mip,
1118 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001119 bitmap.unlockPixels();
1120 return id;
Jason Samsffe9f482009-06-01 17:45:53 -07001121}
Jason Samsfe08d992009-05-27 14:45:32 -07001122
Tim Murray460a0492013-11-19 12:45:54 -08001123static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001124nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
1125 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -08001126{
1127 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001128 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -08001129 const SkBitmap& bitmap(*nativeBitmap);
1130
1131 bitmap.lockPixels();
1132 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001133 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -08001134 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +00001135 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -08001136 bitmap.unlockPixels();
1137 return id;
1138}
1139
Tim Murray460a0492013-11-19 12:45:54 -08001140static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001141nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1142 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001143{
1144 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001145 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001146 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001147
Jason Sams5476b452010-12-08 16:14:36 -08001148 bitmap.lockPixels();
1149 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001150 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001151 (RsType)type, (RsAllocationMipmapControl)mip,
1152 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001153 bitmap.unlockPixels();
1154 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001155}
1156
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001157static void
Tim Murray460a0492013-11-19 12:45:54 -08001158nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001159{
1160 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001161 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001162 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -08001163 int w = bitmap.width();
1164 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001165
Jason Sams4ef66502010-12-10 16:03:15 -08001166 bitmap.lockPixels();
1167 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001168 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001169 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -08001170 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -08001171 bitmap.unlockPixels();
1172}
1173
1174static void
Tim Murray460a0492013-11-19 12:45:54 -08001175nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -08001176{
1177 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001178 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -08001179 const SkBitmap& bitmap(*nativeBitmap);
1180
1181 bitmap.lockPixels();
1182 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001183 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -08001184 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -07001185 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001186}
1187
Stephen Hines414fa2c2014-04-17 01:02:42 -07001188// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -07001189static void
Tim Murray460a0492013-11-19 12:45:54 -08001190nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001191 jint count, jobject data, jint sizeBytes, jint dataType, jint mSize,
1192 jboolean usePadding)
Jason Samsd19f10d2009-05-22 14:03:28 -07001193{
Jason Samse729a942013-11-06 11:22:02 -08001194 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001195 if (kLogApi) {
1196 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1197 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
1198 dataType);
1199 }
Miao Wang87e908d2015-03-02 15:15:15 -08001200 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true,
1201 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -07001202}
1203
1204static void
Miao Wangc8e237e2015-02-20 18:36:32 -08001205nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1206 jint xoff, jint yoff, jint zoff,
1207 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -07001208{
1209 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -08001210 if (kLogApi) {
Miao Wangc8e237e2015-02-20 18:36:32 -08001211 ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1212 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
Andreas Gampe67333922014-11-10 20:35:59 -08001213 sizeBytes);
1214 }
Chris Wailes488230c32014-08-14 11:22:40 -07001215 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Miao Wangc8e237e2015-02-20 18:36:32 -08001216 rsAllocationElementData((RsContext)con, (RsAllocation)alloc,
1217 xoff, yoff, zoff,
1218 lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -07001219 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1220}
1221
Miao Wangc8e237e2015-02-20 18:36:32 -08001222
Stephen Hines414fa2c2014-04-17 01:02:42 -07001223// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -07001224static void
Tim Murray460a0492013-11-19 12:45:54 -08001225nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001226 jint w, jint h, jobject data, jint sizeBytes, jint dataType, jint mSize,
1227 jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001228{
Jason Samse729a942013-11-06 11:22:02 -08001229 RsAllocation *alloc = (RsAllocation *)_alloc;
1230 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001231 if (kLogApi) {
1232 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1233 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1234 }
Miao Wang87e908d2015-03-02 15:15:15 -08001235 int count = w * h;
1236 PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true,
1237 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -07001238}
1239
Stephen Hines414fa2c2014-04-17 01:02:42 -07001240// Copies from the Allocation pointed to by srcAlloc into the Allocation
1241// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -07001242static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001243nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001244 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001245 jint dstMip, jint dstFace,
1246 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -08001247 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001248 jint srcMip, jint srcFace)
1249{
Andreas Gampe67333922014-11-10 20:35:59 -08001250 if (kLogApi) {
1251 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1252 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
1253 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
1254 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
1255 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
1256 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001257
Tim Murrayeff663f2013-11-15 13:08:30 -08001258 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001259 (RsAllocation)dstAlloc,
1260 dstXoff, dstYoff,
1261 dstMip, dstFace,
1262 width, height,
1263 (RsAllocation)srcAlloc,
1264 srcXoff, srcYoff,
1265 srcMip, srcFace);
1266}
1267
Stephen Hines414fa2c2014-04-17 01:02:42 -07001268// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001269static void
Tim Murray460a0492013-11-19 12:45:54 -08001270nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001271 jint w, jint h, jint d, jobject data, jint sizeBytes, jint dataType,
1272 jint mSize, jboolean usePadding)
Jason Samsb05d6892013-04-09 15:59:24 -07001273{
Jason Samse729a942013-11-06 11:22:02 -08001274 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001275 if (kLogApi) {
1276 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1277 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1278 lod, w, h, d, sizeBytes);
1279 }
Miao Wang87e908d2015-03-02 15:15:15 -08001280 int count = w * h * d;
1281 PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true,
1282 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -07001283}
1284
Stephen Hines414fa2c2014-04-17 01:02:42 -07001285// Copies from the Allocation pointed to by srcAlloc into the Allocation
1286// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -07001287static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001288nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001289 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001290 jint dstMip,
1291 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -08001292 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001293 jint srcMip)
1294{
Andreas Gampe67333922014-11-10 20:35:59 -08001295 if (kLogApi) {
1296 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1297 " dstMip(%i), width(%i), height(%i),"
1298 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
1299 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
1300 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
1301 }
Jason Samsb05d6892013-04-09 15:59:24 -07001302
Tim Murrayeff663f2013-11-15 13:08:30 -08001303 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -07001304 (RsAllocation)dstAlloc,
1305 dstXoff, dstYoff, dstZoff, dstMip,
1306 width, height, depth,
1307 (RsAllocation)srcAlloc,
1308 srcXoff, srcYoff, srcZoff, srcMip);
1309}
1310
Jason Sams21659ac2013-11-06 15:08:07 -08001311
Stephen Hines414fa2c2014-04-17 01:02:42 -07001312// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -07001313static void
Miao Wang87e908d2015-03-02 15:15:15 -08001314nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, jint dataType,
1315 jint mSize, jboolean usePadding)
Jason Sams40a29e82009-08-10 14:55:26 -07001316{
Jason Sams21659ac2013-11-06 15:08:07 -08001317 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001318 if (kLogApi) {
1319 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
1320 }
Miao Wang87e908d2015-03-02 15:15:15 -08001321 int count = 0;
1322 PER_ARRAY_TYPE(0, rsAllocationRead, false,
1323 (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -07001324}
1325
Stephen Hines414fa2c2014-04-17 01:02:42 -07001326// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -07001327static void
Tim Murray460a0492013-11-19 12:45:54 -08001328nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001329 jint count, jobject data, jint sizeBytes, jint dataType,
1330 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001331{
Jason Sams21659ac2013-11-06 15:08:07 -08001332 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001333 if (kLogApi) {
1334 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1335 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
1336 }
Miao Wang87e908d2015-03-02 15:15:15 -08001337 PER_ARRAY_TYPE(0, rsAllocation1DRead, false,
1338 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -08001339}
1340
Miao Wangc8e237e2015-02-20 18:36:32 -08001341// Copies from the Element in the Allocation pointed to by _alloc into the Java array data.
1342static void
Miao Wang45cec0a2015-03-04 16:40:21 -08001343nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
Miao Wangc8e237e2015-02-20 18:36:32 -08001344 jint xoff, jint yoff, jint zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -08001345 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Miao Wangc8e237e2015-02-20 18:36:32 -08001346{
Miao Wang45cec0a2015-03-04 16:40:21 -08001347 jint len = _env->GetArrayLength(data);
Miao Wangc8e237e2015-02-20 18:36:32 -08001348 if (kLogApi) {
Miao Wang45cec0a2015-03-04 16:40:21 -08001349 ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1350 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
1351 sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -08001352 }
Miao Wang45cec0a2015-03-04 16:40:21 -08001353 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
1354 rsAllocationElementRead((RsContext)con, (RsAllocation)alloc,
1355 xoff, yoff, zoff,
Jason Samsa7e25092015-03-11 11:00:00 -07001356 lod, ptr, sizeBytes, compIdx);
Miao Wang45cec0a2015-03-04 16:40:21 -08001357 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
Miao Wangc8e237e2015-02-20 18:36:32 -08001358}
1359
Stephen Hines414fa2c2014-04-17 01:02:42 -07001360// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -08001361static void
Tim Murray460a0492013-11-19 12:45:54 -08001362nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001363 jint w, jint h, jobject data, jint sizeBytes, jint dataType,
1364 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001365{
Jason Sams21659ac2013-11-06 15:08:07 -08001366 RsAllocation *alloc = (RsAllocation *)_alloc;
1367 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001368 if (kLogApi) {
1369 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1370 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1371 }
Miao Wang87e908d2015-03-02 15:15:15 -08001372 int count = w * h;
1373 PER_ARRAY_TYPE(0, rsAllocation2DRead, false,
1374 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -07001375}
Miao Wang87e908d2015-03-02 15:15:15 -08001376
Miao Wangc8e237e2015-02-20 18:36:32 -08001377// Copies from the Allocation pointed to by _alloc into the Java object data.
1378static void
1379nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001380 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType,
1381 jint mSize, jboolean usePadding)
Miao Wangc8e237e2015-02-20 18:36:32 -08001382{
1383 RsAllocation *alloc = (RsAllocation *)_alloc;
1384 if (kLogApi) {
1385 ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1386 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1387 lod, w, h, d, sizeBytes);
1388 }
Miao Wang87e908d2015-03-02 15:15:15 -08001389 int count = w * h * d;
1390 PER_ARRAY_TYPE(nullptr, rsAllocation3DRead, false,
1391 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Miao Wangc8e237e2015-02-20 18:36:32 -08001392}
Jason Samsd19f10d2009-05-22 14:03:28 -07001393
Tim Murray460a0492013-11-19 12:45:54 -08001394static jlong
1395nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001396{
Andreas Gampe67333922014-11-10 20:35:59 -08001397 if (kLogApi) {
1398 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1399 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001400 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001401}
1402
Jason Sams5edc6082010-10-05 13:32:49 -07001403static void
Tim Murray460a0492013-11-19 12:45:54 -08001404nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -07001405{
Andreas Gampe67333922014-11-10 20:35:59 -08001406 if (kLogApi) {
1407 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
1408 (RsAllocation)alloc, dimX);
1409 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001410 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -07001411}
1412
Jason Sams46ba27e32015-02-06 17:45:15 -08001413
1414static jlong
1415nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type)
1416{
1417 if (kLogApi) {
1418 ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)",
1419 (RsContext)con, (RsAllocation)basealloc, (RsElement)type);
1420 }
1421 return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type,
1422 (RsAllocation)basealloc);
1423
1424}
1425
1426static void
1427nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1428 jint x, jint y, jint z, jint face, jint lod,
1429 jint a1, jint a2, jint a3, jint a4)
1430{
1431 uint32_t params[] = {
1432 (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face,
1433 (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4
1434 };
1435 if (kLogApi) {
1436 ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)",
1437 (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4);
1438 }
1439 rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc,
1440 params, sizeof(params));
1441}
1442
1443
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001444// -----------------------------------
1445
Tim Murray460a0492013-11-19 12:45:54 -08001446static jlong
1447nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001448{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001449 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001450 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001451
Tim Murray3aa89c12014-08-18 17:51:22 -07001452 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001453 return id;
1454}
1455
Tim Murray460a0492013-11-19 12:45:54 -08001456static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001457nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001458{
1459 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001460 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001461 return 0;
1462 }
1463
1464 AutoJavaStringToUTF8 str(_env, _path);
1465 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001466 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001467 return 0;
1468 }
1469
Tim Murray3aa89c12014-08-18 17:51:22 -07001470 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001471 return id;
1472}
1473
Tim Murray460a0492013-11-19 12:45:54 -08001474static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001475nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001476{
1477 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001478 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001479
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001480 return id;
1481}
1482
Tim Murray460a0492013-11-19 12:45:54 -08001483static jint
1484nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001485{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001486 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001487 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001488 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001489}
1490
1491static void
Tim Murray460a0492013-11-19 12:45:54 -08001492nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001493{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001494 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001495 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
1496
Tim Murrayeff663f2013-11-15 13:08:30 -08001497 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001498
1499 for(jint i = 0; i < numEntries; i ++) {
1500 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
1501 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
1502 }
1503
1504 free(fileEntries);
1505}
1506
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001507static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001508nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001509{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001510 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001511 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001512 return id;
1513}
Jason Samsd19f10d2009-05-22 14:03:28 -07001514
1515// -----------------------------------
1516
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001517static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001518nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001519 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001520{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001521 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001522 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001523 fileNameUTF.c_str(), fileNameUTF.length(),
1524 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001525
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001526 return id;
1527}
1528
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001529static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001530nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001531 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001532{
1533 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1534 AutoJavaStringToUTF8 nameUTF(_env, name);
1535
Tim Murray3aa89c12014-08-18 17:51:22 -07001536 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001537 nameUTF.c_str(), nameUTF.length(),
1538 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001539 asset->getBuffer(false), asset->getLength());
1540 return id;
1541}
1542
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001543static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001544nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001545 jfloat fontSize, jint dpi)
1546{
1547 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001548 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001549 return 0;
1550 }
1551
1552 AutoJavaStringToUTF8 str(_env, _path);
1553 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001554 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001555 return 0;
1556 }
1557
Tim Murray3aa89c12014-08-18 17:51:22 -07001558 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001559 str.c_str(), str.length(),
1560 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001561 asset->getBuffer(false), asset->getLength());
1562 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001563 return id;
1564}
1565
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001566// -----------------------------------
1567
1568static void
Tim Murray460a0492013-11-19 12:45:54 -08001569nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001570{
Andreas Gampe67333922014-11-10 20:35:59 -08001571 if (kLogApi) {
1572 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1573 (RsScript)script, (RsAllocation)alloc, slot);
1574 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001575 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001576}
1577
1578static void
Tim Murray460a0492013-11-19 12:45:54 -08001579nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001580{
Andreas Gampe67333922014-11-10 20:35:59 -08001581 if (kLogApi) {
1582 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1583 slot, val);
1584 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001585 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001586}
1587
Tim Murray7c4caad2013-04-10 16:21:40 -07001588static jint
Tim Murray460a0492013-11-19 12:45:54 -08001589nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001590{
Andreas Gampe67333922014-11-10 20:35:59 -08001591 if (kLogApi) {
1592 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1593 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001594 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001595 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001596 return value;
1597}
1598
Jason Sams4d339932010-05-11 14:03:58 -07001599static void
Tim Murray460a0492013-11-19 12:45:54 -08001600nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001601{
Andreas Gampe67333922014-11-10 20:35:59 -08001602 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001603 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001604 slot, val);
1605 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001606 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001607}
1608
1609static void
Tim Murray460a0492013-11-19 12:45:54 -08001610nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001611{
Andreas Gampe67333922014-11-10 20:35:59 -08001612 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001613 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001614 slot, val);
1615 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001616 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001617}
1618
Tim Murray7c4caad2013-04-10 16:21:40 -07001619static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001620nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001621{
Andreas Gampe67333922014-11-10 20:35:59 -08001622 if (kLogApi) {
1623 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1624 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001625 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001626 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001627 return value;
1628}
1629
Stephen Hines031ec58c2010-10-11 10:54:21 -07001630static void
Tim Murray460a0492013-11-19 12:45:54 -08001631nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001632{
Andreas Gampe67333922014-11-10 20:35:59 -08001633 if (kLogApi) {
1634 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1635 slot, val);
1636 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001637 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001638}
1639
Tim Murray7c4caad2013-04-10 16:21:40 -07001640static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001641nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001642{
Andreas Gampe67333922014-11-10 20:35:59 -08001643 if (kLogApi) {
1644 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1645 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001646 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001647 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001648 return value;
1649}
1650
Jason Sams4d339932010-05-11 14:03:58 -07001651static void
Tim Murray460a0492013-11-19 12:45:54 -08001652nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001653{
Andreas Gampe67333922014-11-10 20:35:59 -08001654 if (kLogApi) {
1655 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1656 slot, val);
1657 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001658 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001659}
1660
Tim Murray7c4caad2013-04-10 16:21:40 -07001661static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001662nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001663{
Andreas Gampe67333922014-11-10 20:35:59 -08001664 if (kLogApi) {
1665 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1666 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001667 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001668 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001669 return value;
1670}
1671
Stephen Hinesca54ec32010-09-20 17:20:30 -07001672static void
Tim Murray460a0492013-11-19 12:45:54 -08001673nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001674{
Andreas Gampe67333922014-11-10 20:35:59 -08001675 if (kLogApi) {
1676 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1677 }
Jason Sams4d339932010-05-11 14:03:58 -07001678 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001679 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001680 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001681 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1682}
1683
Stephen Hinesadeb8092012-04-20 14:26:06 -07001684static void
Tim Murray460a0492013-11-19 12:45:54 -08001685nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001686{
Andreas Gampe67333922014-11-10 20:35:59 -08001687 if (kLogApi) {
1688 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1689 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001690 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001691 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001692 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001693 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001694}
1695
1696static void
Andreas Gampe67333922014-11-10 20:35:59 -08001697nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1698 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001699{
Andreas Gampe67333922014-11-10 20:35:59 -08001700 if (kLogApi) {
1701 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1702 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001703 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001704 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001705 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001706 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001707 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001708 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001709 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1710 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1711}
1712
Jason Samsd19f10d2009-05-22 14:03:28 -07001713
1714static void
Tim Murray460a0492013-11-19 12:45:54 -08001715nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001716{
Andreas Gampe67333922014-11-10 20:35:59 -08001717 if (kLogApi) {
1718 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1719 }
Romain Guy584a3752009-07-30 18:45:01 -07001720
1721 jint length = _env->GetArrayLength(timeZone);
1722 jbyte* timeZone_ptr;
1723 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1724
Tim Murrayeff663f2013-11-15 13:08:30 -08001725 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001726
1727 if (timeZone_ptr) {
1728 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1729 }
1730}
1731
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001732static void
Tim Murray460a0492013-11-19 12:45:54 -08001733nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001734{
Andreas Gampe67333922014-11-10 20:35:59 -08001735 if (kLogApi) {
1736 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1737 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001738 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001739}
1740
1741static void
Tim Murray460a0492013-11-19 12:45:54 -08001742nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001743{
Andreas Gampe67333922014-11-10 20:35:59 -08001744 if (kLogApi) {
1745 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1746 }
Jason Sams4d339932010-05-11 14:03:58 -07001747 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001748 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001749 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001750 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1751}
1752
Jason Sams6e494d32011-04-27 16:33:11 -07001753static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001754nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1755 jlongArray ains, jlong aout, jbyteArray params,
1756 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001757{
Andreas Gampe67333922014-11-10 20:35:59 -08001758 if (kLogApi) {
1759 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1760 }
Jason Sams6e494d32011-04-27 16:33:11 -07001761
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001762 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001763 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001764
Chris Wailes488230c32014-08-14 11:22:40 -07001765 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001766
Chris Wailes488230c32014-08-14 11:22:40 -07001767 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001768 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001769 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001770
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001771 if (sizeof(RsAllocation) == sizeof(jlong)) {
1772 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001773
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001774 } else {
1775 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001776
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001777 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1778
1779 for (int index = in_len; --index >= 0;) {
1780 in_allocs[index] = (RsAllocation)in_ptr[index];
1781 }
1782 }
Chris Wailes94961062014-06-11 12:01:28 -07001783 }
1784
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001785 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001786 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001787
Chris Wailes488230c32014-08-14 11:22:40 -07001788 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001789 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001790 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001791 }
1792
Chris Wailes488230c32014-08-14 11:22:40 -07001793 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001794 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001795
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001796 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001797 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001798
Chris Wailes488230c32014-08-14 11:22:40 -07001799 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001800 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001801 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001802
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001803 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001804 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001805
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001806 sc.xStart = limit_ptr[0];
1807 sc.xEnd = limit_ptr[1];
1808 sc.yStart = limit_ptr[2];
1809 sc.yEnd = limit_ptr[3];
1810 sc.zStart = limit_ptr[4];
1811 sc.zEnd = limit_ptr[5];
1812 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Jason Sams14331ab2015-01-26 18:14:36 -08001813 sc.arrayStart = 0;
1814 sc.arrayEnd = 0;
1815 sc.array2Start = 0;
1816 sc.array2End = 0;
1817 sc.array3Start = 0;
1818 sc.array3End = 0;
1819 sc.array4Start = 0;
1820 sc.array4End = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001821
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001822 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001823 }
1824
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001825 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1826 in_allocs, in_len, (RsAllocation)aout,
1827 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001828
Chris Wailes488230c32014-08-14 11:22:40 -07001829 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001830 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001831 }
1832
Chris Wailes488230c32014-08-14 11:22:40 -07001833 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001834 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1835 }
1836
Chris Wailes488230c32014-08-14 11:22:40 -07001837 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001838 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1839 }
Chris Wailes94961062014-06-11 12:01:28 -07001840}
1841
Jason Sams22534172009-08-04 16:58:20 -07001842// -----------------------------------
1843
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001844static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001845nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001846 jstring resName, jstring cacheDir,
1847 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001848{
Andreas Gampe67333922014-11-10 20:35:59 -08001849 if (kLogApi) {
1850 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1851 }
Jason Sams22534172009-08-04 16:58:20 -07001852
Jason Samse4a06c52011-03-16 16:29:28 -07001853 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1854 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001855 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001856 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001857 jint _exception = 0;
1858 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001859 if (!scriptRef) {
1860 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001861 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001862 goto exit;
1863 }
Jack Palevich43702d82009-05-28 13:38:16 -07001864 if (length < 0) {
1865 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001866 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001867 goto exit;
1868 }
Jason Samse4a06c52011-03-16 16:29:28 -07001869 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001870 if (remaining < length) {
1871 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001872 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1873 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001874 goto exit;
1875 }
Jason Samse4a06c52011-03-16 16:29:28 -07001876 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001877 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001878
Tim Murrayeff663f2013-11-15 13:08:30 -08001879 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001880
Tim Murray3aa89c12014-08-18 17:51:22 -07001881 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001882 resNameUTF.c_str(), resNameUTF.length(),
1883 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001884 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001885
Jack Palevich43702d82009-05-28 13:38:16 -07001886exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001887 if (script_ptr) {
1888 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001889 _exception ? JNI_ABORT: 0);
1890 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001891
Tim Murray3aa89c12014-08-18 17:51:22 -07001892 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001893}
1894
Tim Murray460a0492013-11-19 12:45:54 -08001895static jlong
1896nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001897{
Andreas Gampe67333922014-11-10 20:35:59 -08001898 if (kLogApi) {
1899 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1900 (void *)eid);
1901 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001902 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001903}
1904
Tim Murray460a0492013-11-19 12:45:54 -08001905static jlong
1906nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001907{
Andreas Gampe67333922014-11-10 20:35:59 -08001908 if (kLogApi) {
1909 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1910 (void *)sid, slot, sig);
1911 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001912 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001913}
1914
Tim Murray460a0492013-11-19 12:45:54 -08001915static jlong
Yang Nibe392ad2015-01-23 17:16:02 -08001916nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
1917{
1918 if (kLogApi) {
Elliott Hughes7ff53fa2015-02-05 21:36:10 -08001919 ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con,
Yang Nibe392ad2015-01-23 17:16:02 -08001920 (void *)sid, slot);
1921 }
1922 return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot);
1923}
1924
1925static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001926nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001927{
Andreas Gampe67333922014-11-10 20:35:59 -08001928 if (kLogApi) {
1929 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1930 slot);
1931 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001932 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001933}
1934
Tim Murray460a0492013-11-19 12:45:54 -08001935static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001936nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1937 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001938{
Andreas Gampe67333922014-11-10 20:35:59 -08001939 if (kLogApi) {
1940 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1941 }
Jason Sams08a81582012-09-18 12:32:10 -07001942
Ashok Bhat98071552014-02-12 09:54:43 +00001943 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001944 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001945 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1946 for(int i = 0; i < kernelsLen; ++i) {
1947 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1948 }
Jason Sams08a81582012-09-18 12:32:10 -07001949
Ashok Bhat98071552014-02-12 09:54:43 +00001950 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001951 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001952 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1953 for(int i = 0; i < srcLen; ++i) {
1954 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1955 }
Jason Sams08a81582012-09-18 12:32:10 -07001956
Ashok Bhat98071552014-02-12 09:54:43 +00001957 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001958 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001959 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1960 for(int i = 0; i < dstkLen; ++i) {
1961 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1962 }
1963
1964 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001965 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001966 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1967 for(int i = 0; i < dstfLen; ++i) {
1968 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1969 }
1970
1971 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001972 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001973 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1974 for(int i = 0; i < typesLen; ++i) {
1975 typesPtr[i] = (RsType)jTypesPtr[i];
1976 }
1977
Tim Murray3aa89c12014-08-18 17:51:22 -07001978 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001979 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1980 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1981 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1982 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1983 (RsType *)typesPtr, typesLen * sizeof(RsType));
1984
1985 free(kernelsPtr);
1986 free(srcPtr);
1987 free(dstkPtr);
1988 free(dstfPtr);
1989 free(typesPtr);
1990 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1991 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1992 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1993 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1994 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001995 return id;
1996}
1997
1998static void
Tim Murray460a0492013-11-19 12:45:54 -08001999nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07002000{
Andreas Gampe67333922014-11-10 20:35:59 -08002001 if (kLogApi) {
2002 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
2003 (void *)gid, (void *)kid, (void *)alloc);
2004 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002005 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07002006}
2007
2008static void
Tim Murray460a0492013-11-19 12:45:54 -08002009nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07002010{
Andreas Gampe67333922014-11-10 20:35:59 -08002011 if (kLogApi) {
2012 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
2013 (void *)gid, (void *)kid, (void *)alloc);
2014 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002015 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07002016}
2017
2018static void
Tim Murray460a0492013-11-19 12:45:54 -08002019nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07002020{
Andreas Gampe67333922014-11-10 20:35:59 -08002021 if (kLogApi) {
2022 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
2023 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002024 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07002025}
2026
Jason Samsd19f10d2009-05-22 14:03:28 -07002027// ---------------------------------------------------------------------------
2028
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002029static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002030nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07002031 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
2032 jboolean depthMask, jboolean ditherEnable,
2033 jint srcFunc, jint destFunc,
2034 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07002035{
Andreas Gampe67333922014-11-10 20:35:59 -08002036 if (kLogApi) {
2037 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
2038 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002039 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07002040 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
2041 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07002042}
2043
Jason Sams0011bcf2009-12-15 12:58:36 -08002044// ---------------------------------------------------------------------------
2045
2046static void
Tim Murray460a0492013-11-19 12:45:54 -08002047nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08002048{
Andreas Gampe67333922014-11-10 20:35:59 -08002049 if (kLogApi) {
2050 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
2051 (RsProgramVertex)vpv, slot, (RsAllocation)a);
2052 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002053 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08002054}
Jason Sams54c0ec12009-11-30 14:49:55 -08002055
Jason Sams68afd012009-12-17 16:55:08 -08002056static void
Tim Murray460a0492013-11-19 12:45:54 -08002057nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002058{
Andreas Gampe67333922014-11-10 20:35:59 -08002059 if (kLogApi) {
2060 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2061 (RsProgramFragment)vpf, slot, (RsAllocation)a);
2062 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002063 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08002064}
2065
2066static void
Tim Murray460a0492013-11-19 12:45:54 -08002067nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002068{
Andreas Gampe67333922014-11-10 20:35:59 -08002069 if (kLogApi) {
2070 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2071 (RsProgramFragment)vpf, slot, (RsSampler)a);
2072 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002073 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08002074}
2075
Jason Samsd19f10d2009-05-22 14:03:28 -07002076// ---------------------------------------------------------------------------
2077
Tim Murray460a0492013-11-19 12:45:54 -08002078static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002079nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002080 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002081{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002082 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002083 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002084 jint paramLen = _env->GetArrayLength(params);
2085
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002086 int texCount = _env->GetArrayLength(texNames);
2087 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2088 const char ** nameArray = names.c_str();
2089 size_t* sizeArray = names.c_str_len();
2090
Andreas Gampe67333922014-11-10 20:35:59 -08002091 if (kLogApi) {
2092 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2093 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002094
Ashok Bhat98071552014-02-12 09:54:43 +00002095 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2096 for(int i = 0; i < paramLen; ++i) {
2097 paramPtr[i] = (uintptr_t)jParamPtr[i];
2098 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002099 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002100 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002101 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002102
Ashok Bhat98071552014-02-12 09:54:43 +00002103 free(paramPtr);
2104 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002105 return ret;
2106}
2107
2108
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002109// ---------------------------------------------------------------------------
2110
Tim Murray460a0492013-11-19 12:45:54 -08002111static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002112nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002113 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002114{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002115 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002116 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08002117 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002118
Andreas Gampe67333922014-11-10 20:35:59 -08002119 if (kLogApi) {
2120 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2121 }
Jason Sams0011bcf2009-12-15 12:58:36 -08002122
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002123 int texCount = _env->GetArrayLength(texNames);
2124 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2125 const char ** nameArray = names.c_str();
2126 size_t* sizeArray = names.c_str_len();
2127
Ashok Bhat98071552014-02-12 09:54:43 +00002128 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2129 for(int i = 0; i < paramLen; ++i) {
2130 paramPtr[i] = (uintptr_t)jParamPtr[i];
2131 }
2132
Tim Murray3aa89c12014-08-18 17:51:22 -07002133 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002134 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002135 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002136
Ashok Bhat98071552014-02-12 09:54:43 +00002137 free(paramPtr);
2138 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08002139 return ret;
2140}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002141
Jason Samsebfb4362009-09-23 13:57:02 -07002142// ---------------------------------------------------------------------------
2143
Tim Murray460a0492013-11-19 12:45:54 -08002144static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002145nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07002146{
Andreas Gampe67333922014-11-10 20:35:59 -08002147 if (kLogApi) {
2148 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
2149 pointSprite, cull);
2150 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002151 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07002152}
2153
Jason Samsd19f10d2009-05-22 14:03:28 -07002154
2155// ---------------------------------------------------------------------------
2156
2157static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002158nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07002159{
Andreas Gampe67333922014-11-10 20:35:59 -08002160 if (kLogApi) {
2161 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
2162 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002163 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07002164}
2165
2166static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002167nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07002168{
Andreas Gampe67333922014-11-10 20:35:59 -08002169 if (kLogApi) {
2170 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
2171 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002172 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07002173}
2174
2175static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002176nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07002177{
Andreas Gampe67333922014-11-10 20:35:59 -08002178 if (kLogApi) {
2179 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
2180 (RsProgramFragment)pf);
2181 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002182 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07002183}
2184
Jason Sams0826a6f2009-06-15 19:04:56 -07002185static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002186nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07002187{
Andreas Gampe67333922014-11-10 20:35:59 -08002188 if (kLogApi) {
2189 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
2190 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002191 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07002192}
2193
Joe Onoratod7b37742009-08-09 22:57:44 -07002194static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002195nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07002196{
Andreas Gampe67333922014-11-10 20:35:59 -08002197 if (kLogApi) {
2198 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
2199 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002200 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07002201}
2202
Joe Onoratod7b37742009-08-09 22:57:44 -07002203
Jason Sams02fb2cb2009-05-28 15:37:57 -07002204// ---------------------------------------------------------------------------
2205
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002206static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002207nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002208 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07002209{
Andreas Gampe67333922014-11-10 20:35:59 -08002210 if (kLogApi) {
2211 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
2212 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002213 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002214 (RsSamplerValue)magFilter,
2215 (RsSamplerValue)minFilter,
2216 (RsSamplerValue)wrapS,
2217 (RsSamplerValue)wrapT,
2218 (RsSamplerValue)wrapR,
2219 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07002220}
2221
Jason Samsbba134c2009-06-22 15:49:21 -07002222// ---------------------------------------------------------------------------
2223
Tim Murray460a0492013-11-19 12:45:54 -08002224static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00002225nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07002226{
Andreas Gampe67333922014-11-10 20:35:59 -08002227 if (kLogApi) {
2228 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
2229 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002230
2231 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07002232 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002233 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
2234 for(int i = 0; i < vtxLen; ++i) {
2235 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
2236 }
2237
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002238 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07002239 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002240 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
2241 for(int i = 0; i < idxLen; ++i) {
2242 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
2243 }
2244
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002245 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07002246 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002247
Tim Murray3aa89c12014-08-18 17:51:22 -07002248 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002249 (RsAllocation *)vtxPtr, vtxLen,
2250 (RsAllocation *)idxPtr, idxLen,
2251 (uint32_t *)primPtr, primLen);
2252
Ashok Bhat98071552014-02-12 09:54:43 +00002253 free(vtxPtr);
2254 free(idxPtr);
2255 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
2256 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002257 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002258 return id;
2259}
2260
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002261static jint
Tim Murray460a0492013-11-19 12:45:54 -08002262nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002263{
Andreas Gampe67333922014-11-10 20:35:59 -08002264 if (kLogApi) {
2265 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2266 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002267 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002268 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002269 return vtxCount;
2270}
2271
2272static jint
Tim Murray460a0492013-11-19 12:45:54 -08002273nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002274{
Andreas Gampe67333922014-11-10 20:35:59 -08002275 if (kLogApi) {
2276 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2277 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002278 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002279 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002280 return idxCount;
2281}
2282
2283static void
Ashok Bhat98071552014-02-12 09:54:43 +00002284nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002285{
Andreas Gampe67333922014-11-10 20:35:59 -08002286 if (kLogApi) {
2287 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2288 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002289
2290 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08002291 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002292
2293 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002294 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002295 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002296 }
2297
2298 free(allocs);
2299}
2300
2301static void
Ashok Bhat98071552014-02-12 09:54:43 +00002302nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002303{
Andreas Gampe67333922014-11-10 20:35:59 -08002304 if (kLogApi) {
2305 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2306 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002307
2308 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
2309 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
2310
Tim Murrayeff663f2013-11-15 13:08:30 -08002311 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002312
2313 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002314 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002315 const jint prim = (jint)prims[i];
2316 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
2317 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002318 }
2319
2320 free(allocs);
2321 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002322}
2323
Tim Murray56f9e6f2014-05-16 11:47:26 -07002324static jint
2325nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
2326 return (jint)sizeof(void*);
2327}
2328
2329
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002330// ---------------------------------------------------------------------------
2331
Jason Samsd19f10d2009-05-22 14:03:28 -07002332
Jason Sams94d8e90a2009-06-10 16:09:05 -07002333static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07002334
2335static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08002336{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07002337
Tim Murrayeff663f2013-11-15 13:08:30 -08002338{"nDeviceCreate", "()J", (void*)nDeviceCreate },
2339{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
2340{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
2341{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
2342{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
2343{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08002344
Tim Murrayeff663f2013-11-15 13:08:30 -08002345{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
2346{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07002347
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07002348
Jason Sams2e1872f2010-08-17 16:25:41 -07002349// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08002350{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
2351{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
2352{"rsnContextFinish", "(J)V", (void*)nContextFinish },
2353{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
Tim Murray47f31582015-04-07 15:43:24 -07002354{"rsnContextSetCacheDir", "(JLjava/lang/String;)V", (void*)nContextSetCacheDir },
Tim Murrayeff663f2013-11-15 13:08:30 -08002355{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
2356{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
2357{"rsnContextDump", "(JI)V", (void*)nContextDump },
2358{"rsnContextPause", "(J)V", (void*)nContextPause },
2359{"rsnContextResume", "(J)V", (void*)nContextResume },
2360{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07002361{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002362{"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate },
Yang Ni281c3252014-10-24 08:52:24 -07002363{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
2364{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08002365{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
2366{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
2367{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07002368
Tim Murray460a0492013-11-19 12:45:54 -08002369{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002370{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08002371{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
2372{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
2373{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002374{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07002375
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002376{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
2377{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
2378{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07002379
Tim Murray460a0492013-11-19 12:45:54 -08002380{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002381{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08002382{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00002383{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07002384
Tim Murray460a0492013-11-19 12:45:54 -08002385{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002386{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07002387
Ashok Bhat98071552014-02-12 09:54:43 +00002388{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08002389{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
2390{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
2391{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08002392
Tim Murray460a0492013-11-19 12:45:54 -08002393{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
2394{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08002395
Tim Murray460a0492013-11-19 12:45:54 -08002396{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
2397{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
2398{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
2399{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
2400{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
Miao Wang87e908d2015-03-02 15:15:15 -08002401{"rsnAllocationData1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData1D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002402{"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData },
Miao Wang87e908d2015-03-02 15:15:15 -08002403{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData2D },
Tim Murray460a0492013-11-19 12:45:54 -08002404{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002405{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData3D },
Tim Murray460a0492013-11-19 12:45:54 -08002406{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002407{"rsnAllocationRead", "(JJLjava/lang/Object;IIZ)V", (void*)nAllocationRead },
2408{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead1D },
Miao Wang45cec0a2015-03-04 16:40:21 -08002409{"rsnAllocationElementRead", "(JJIIIII[BI)V", (void*)nAllocationElementRead },
Miao Wang87e908d2015-03-02 15:15:15 -08002410{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead2D },
2411{"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead3D },
Tim Murray460a0492013-11-19 12:45:54 -08002412{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
2413{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
2414{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07002415
Jason Sams46ba27e32015-02-06 17:45:15 -08002416{"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate },
2417{"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset },
2418
Tim Murray460a0492013-11-19 12:45:54 -08002419{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
2420{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
2421{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
2422{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07002423
2424{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
2425
Tim Murray460a0492013-11-19 12:45:54 -08002426{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
2427{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
2428{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
2429{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
2430{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
2431{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
2432{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
2433{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
2434{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
2435{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
2436{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
2437{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07002438
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002439{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002440{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2441{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002442{"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002443{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002444{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Ni35be56c2015-04-02 17:47:56 -07002445{"rsnScriptGroup2Create", "(JLjava/lang/String;Ljava/lang/String;[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002446{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2447{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2448{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002449{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002450
Tim Murray25207df2015-01-12 16:47:56 -08002451{"rsnScriptIntrinsicBLAS_Single", "(JJIIIIIIIIIFJJFJIIII)V", (void*)nScriptIntrinsicBLAS_Single },
2452{"rsnScriptIntrinsicBLAS_Double", "(JJIIIIIIIIIDJJDJIIII)V", (void*)nScriptIntrinsicBLAS_Double },
2453{"rsnScriptIntrinsicBLAS_Complex", "(JJIIIIIIIIIFFJJFFJIIII)V", (void*)nScriptIntrinsicBLAS_Complex },
2454{"rsnScriptIntrinsicBLAS_Z", "(JJIIIIIIIIIDDJJDDJIIII)V", (void*)nScriptIntrinsicBLAS_Z },
2455
Tim Murray9cb16a22015-04-01 11:07:16 -07002456{"rsnScriptIntrinsicBLAS_BNNM", "(JJIIIJIJIJII)V", (void*)nScriptIntrinsicBLAS_BNNM },
2457
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002458{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002459
Tim Murray460a0492013-11-19 12:45:54 -08002460{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2461{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2462{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002463
Ashok Bhat98071552014-02-12 09:54:43 +00002464{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002465{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002466{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002467
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002468{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2469{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2470{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2471{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2472{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002473
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002474{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002475
Ashok Bhat98071552014-02-12 09:54:43 +00002476{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002477
Tim Murray460a0492013-11-19 12:45:54 -08002478{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2479{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002480{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2481{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002482
Tim Murray56f9e6f2014-05-16 11:47:26 -07002483{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002484};
2485
2486static int registerFuncs(JNIEnv *_env)
2487{
2488 return android::AndroidRuntime::registerNativeMethods(
2489 _env, classPathName, methods, NELEM(methods));
2490}
2491
2492// ---------------------------------------------------------------------------
2493
2494jint JNI_OnLoad(JavaVM* vm, void* reserved)
2495{
Chris Wailes488230c32014-08-14 11:22:40 -07002496 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002497 jint result = -1;
2498
Jason Samsd19f10d2009-05-22 14:03:28 -07002499 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002500 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002501 goto bail;
2502 }
Chris Wailes488230c32014-08-14 11:22:40 -07002503 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002504
2505 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002506 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002507 goto bail;
2508 }
2509
2510 /* success -- return valid version number */
2511 result = JNI_VERSION_1_4;
2512
2513bail:
2514 return result;
2515}