blob: cbe87fc73f25799e80b85abb545ad89410ffcb5f [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
Stephen Hines4cbe25a2012-01-18 18:46:27 -08002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Samsd19f10d2009-05-22 14:03:28 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jason Samsf29ca502009-06-23 12:22:47 -070017#define LOG_TAG "libRS_jni"
18
Jason Samsd19f10d2009-05-22 14:03:28 -070019#include <stdlib.h>
20#include <stdio.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <math.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070024#include <utils/misc.h>
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +010025#include <inttypes.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070026
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080027#include <androidfw/Asset.h>
28#include <androidfw/AssetManager.h>
29#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070030
Jason Samsd19f10d2009-05-22 14:03:28 -070031#include "jni.h"
32#include "JNIHelp.h"
33#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070034#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080035#include "android_runtime/android_util_AssetManager.h"
John Reckf4faeac2015-03-05 13:50:31 -080036#include "android/graphics/GraphicsJNI.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070037
Jason Sams1d6983a2012-02-16 16:07:49 -080038#include <rs.h>
39#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070040#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080041#include <gui/GLConsumer.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070042#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070043
Steve Block3762c312012-01-06 19:20:56 +000044//#define LOG_API ALOGE
Andreas Gampe67333922014-11-10 20:35:59 -080045static constexpr bool kLogApi = false;
Jason Samsd19f10d2009-05-22 14:03:28 -070046
47using namespace android;
48
Andreas Gampe67333922014-11-10 20:35:59 -080049template <typename... T>
50void UNUSED(T... t) {}
51
Stephen Hines414fa2c2014-04-17 01:02:42 -070052#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \
Jason Samse729a942013-11-06 11:22:02 -080053 jint len = 0; \
Chris Wailes488230c32014-08-14 11:22:40 -070054 void *ptr = nullptr; \
Miao Wang87e908d2015-03-02 15:15:15 -080055 void *srcPtr = nullptr; \
Jason Sams21659ac2013-11-06 15:08:07 -080056 size_t typeBytes = 0; \
Stephen Hines414fa2c2014-04-17 01:02:42 -070057 jint relFlag = 0; \
58 if (readonly) { \
59 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
Miao Wang87e908d2015-03-02 15:15:15 -080060 /* readonly = true, also indicates we are copying to the allocation . */ \
Stephen Hines414fa2c2014-04-17 01:02:42 -070061 relFlag = JNI_ABORT; \
62 } \
Jason Samse729a942013-11-06 11:22:02 -080063 switch(dataType) { \
64 case RS_TYPE_FLOAT_32: \
65 len = _env->GetArrayLength((jfloatArray)data); \
66 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080067 typeBytes = 4; \
Miao Wang87e908d2015-03-02 15:15:15 -080068 if (usePadding) { \
69 srcPtr = ptr; \
70 len = len / 3 * 4; \
71 if (count == 0) { \
72 count = len / 4; \
73 } \
74 ptr = malloc (len * typeBytes); \
75 if (readonly) { \
76 copyWithPadding(ptr, srcPtr, mSize, count); \
77 fnc(__VA_ARGS__); \
78 } else { \
79 fnc(__VA_ARGS__); \
80 copyWithUnPadding(srcPtr, ptr, mSize, count); \
81 } \
82 free(ptr); \
83 ptr = srcPtr; \
84 } else { \
85 fnc(__VA_ARGS__); \
86 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -070087 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080088 return; \
89 case RS_TYPE_FLOAT_64: \
90 len = _env->GetArrayLength((jdoubleArray)data); \
91 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080092 typeBytes = 8; \
Miao Wang87e908d2015-03-02 15:15:15 -080093 if (usePadding) { \
94 srcPtr = ptr; \
95 len = len / 3 * 4; \
96 if (count == 0) { \
97 count = len / 4; \
98 } \
99 ptr = malloc (len * typeBytes); \
100 if (readonly) { \
101 copyWithPadding(ptr, srcPtr, mSize, count); \
102 fnc(__VA_ARGS__); \
103 } else { \
104 fnc(__VA_ARGS__); \
105 copyWithUnPadding(srcPtr, ptr, mSize, count); \
106 } \
107 free(ptr); \
108 ptr = srcPtr; \
109 } else { \
110 fnc(__VA_ARGS__); \
111 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700112 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800113 return; \
114 case RS_TYPE_SIGNED_8: \
115 case RS_TYPE_UNSIGNED_8: \
116 len = _env->GetArrayLength((jbyteArray)data); \
117 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800118 typeBytes = 1; \
Miao Wang87e908d2015-03-02 15:15:15 -0800119 if (usePadding) { \
120 srcPtr = ptr; \
121 len = len / 3 * 4; \
122 if (count == 0) { \
123 count = len / 4; \
124 } \
125 ptr = malloc (len * typeBytes); \
126 if (readonly) { \
127 copyWithPadding(ptr, srcPtr, mSize, count); \
128 fnc(__VA_ARGS__); \
129 } else { \
130 fnc(__VA_ARGS__); \
131 copyWithUnPadding(srcPtr, ptr, mSize, count); \
132 } \
133 free(ptr); \
134 ptr = srcPtr; \
135 } else { \
136 fnc(__VA_ARGS__); \
137 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700138 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800139 return; \
140 case RS_TYPE_SIGNED_16: \
141 case RS_TYPE_UNSIGNED_16: \
142 len = _env->GetArrayLength((jshortArray)data); \
143 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800144 typeBytes = 2; \
Miao Wang87e908d2015-03-02 15:15:15 -0800145 if (usePadding) { \
146 srcPtr = ptr; \
147 len = len / 3 * 4; \
148 if (count == 0) { \
149 count = len / 4; \
150 } \
151 ptr = malloc (len * typeBytes); \
152 if (readonly) { \
153 copyWithPadding(ptr, srcPtr, mSize, count); \
154 fnc(__VA_ARGS__); \
155 } else { \
156 fnc(__VA_ARGS__); \
157 copyWithUnPadding(srcPtr, ptr, mSize, count); \
158 } \
159 free(ptr); \
160 ptr = srcPtr; \
161 } else { \
162 fnc(__VA_ARGS__); \
163 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700164 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800165 return; \
166 case RS_TYPE_SIGNED_32: \
167 case RS_TYPE_UNSIGNED_32: \
168 len = _env->GetArrayLength((jintArray)data); \
169 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800170 typeBytes = 4; \
Miao Wang87e908d2015-03-02 15:15:15 -0800171 if (usePadding) { \
172 srcPtr = ptr; \
173 len = len / 3 * 4; \
174 if (count == 0) { \
175 count = len / 4; \
176 } \
177 ptr = malloc (len * typeBytes); \
178 if (readonly) { \
179 copyWithPadding(ptr, srcPtr, mSize, count); \
180 fnc(__VA_ARGS__); \
181 } else { \
182 fnc(__VA_ARGS__); \
183 copyWithUnPadding(srcPtr, ptr, mSize, count); \
184 } \
185 free(ptr); \
186 ptr = srcPtr; \
187 } else { \
188 fnc(__VA_ARGS__); \
189 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700190 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800191 return; \
192 case RS_TYPE_SIGNED_64: \
193 case RS_TYPE_UNSIGNED_64: \
194 len = _env->GetArrayLength((jlongArray)data); \
195 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800196 typeBytes = 8; \
Miao Wang87e908d2015-03-02 15:15:15 -0800197 if (usePadding) { \
198 srcPtr = ptr; \
199 len = len / 3 * 4; \
200 if (count == 0) { \
201 count = len / 4; \
202 } \
203 ptr = malloc (len * typeBytes); \
204 if (readonly) { \
205 copyWithPadding(ptr, srcPtr, mSize, count); \
206 fnc(__VA_ARGS__); \
207 } else { \
208 fnc(__VA_ARGS__); \
209 copyWithUnPadding(srcPtr, ptr, mSize, count); \
210 } \
211 free(ptr); \
212 ptr = srcPtr; \
213 } else { \
214 fnc(__VA_ARGS__); \
215 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700216 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800217 return; \
218 default: \
219 break; \
220 } \
Miao Wang87e908d2015-03-02 15:15:15 -0800221 UNUSED(len, ptr, srcPtr, typeBytes, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800222}
223
224
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800225class AutoJavaStringToUTF8 {
226public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800227 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Chris Wailes488230c32014-08-14 11:22:40 -0700228 fCStr = env->GetStringUTFChars(str, nullptr);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800229 fLength = env->GetStringUTFLength(str);
230 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800231 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800232 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
233 }
234 const char* c_str() const { return fCStr; }
235 jsize length() const { return fLength; }
236
237private:
238 JNIEnv* fEnv;
239 jstring fJStr;
240 const char* fCStr;
241 jsize fLength;
242};
243
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800244class AutoJavaStringArrayToUTF8 {
245public:
246 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
247 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
Chris Wailes488230c32014-08-14 11:22:40 -0700248 mCStrings = nullptr;
249 mSizeArray = nullptr;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800250 if (stringsLength > 0) {
251 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
252 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
253 for (jsize ct = 0; ct < stringsLength; ct ++) {
254 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
Chris Wailes488230c32014-08-14 11:22:40 -0700255 mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800256 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
257 }
258 }
259 }
260 ~AutoJavaStringArrayToUTF8() {
261 for (jsize ct=0; ct < mStringsLength; ct++) {
262 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
263 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
264 }
265 free(mCStrings);
266 free(mSizeArray);
267 }
268 const char **c_str() const { return mCStrings; }
269 size_t *c_str_len() const { return mSizeArray; }
270 jsize length() const { return mStringsLength; }
271
272private:
273 JNIEnv *mEnv;
274 jobjectArray mStrings;
275 const char **mCStrings;
276 size_t *mSizeArray;
277 jsize mStringsLength;
278};
279
Jason Samsd19f10d2009-05-22 14:03:28 -0700280// ---------------------------------------------------------------------------
281
Jason Samsffe9f482009-06-01 17:45:53 -0700282static jfieldID gContextId = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700283
284static void _nInit(JNIEnv *_env, jclass _this)
285{
Tim Murrayeff663f2013-11-15 13:08:30 -0800286 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700287}
288
Jason Samsd19f10d2009-05-22 14:03:28 -0700289// ---------------------------------------------------------------------------
290
Miao Wang87e908d2015-03-02 15:15:15 -0800291static void copyWithPadding(void* ptr, void* srcPtr, int mSize, int count) {
292 int sizeBytesPad = mSize * 4;
293 int sizeBytes = mSize * 3;
294 uint8_t *dst = static_cast<uint8_t *>(ptr);
295 uint8_t *src = static_cast<uint8_t *>(srcPtr);
296 for (int i = 0; i < count; i++) {
297 memcpy(dst, src, sizeBytes);
298 dst += sizeBytesPad;
299 src += sizeBytes;
300 }
301}
302
303static void copyWithUnPadding(void* ptr, void* srcPtr, int mSize, int count) {
304 int sizeBytesPad = mSize * 4;
305 int sizeBytes = mSize * 3;
306 uint8_t *dst = static_cast<uint8_t *>(ptr);
307 uint8_t *src = static_cast<uint8_t *>(srcPtr);
308 for (int i = 0; i < count; i++) {
309 memcpy(dst, src, sizeBytes);
310 dst += sizeBytes;
311 src += sizeBytesPad;
312 }
313}
314
315
316// ---------------------------------------------------------------------------
Jason Sams3eaa3382009-06-10 15:04:38 -0700317static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800318nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700319{
Andreas Gampe67333922014-11-10 20:35:59 -0800320 if (kLogApi) {
321 ALOGD("nContextFinish, con(%p)", (RsContext)con);
322 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800323 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700324}
325
Yang Ni281c3252014-10-24 08:52:24 -0700326static jlong
327nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID,
328 jlong returnValue, jlongArray fieldIDArray,
329 jlongArray valueArray, jintArray sizeArray,
330 jlongArray depClosureArray, jlongArray depFieldIDArray) {
331 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
332 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
333 RsScriptFieldID* fieldIDs =
334 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
335 for (int i = 0; i< fieldIDs_length; i++) {
336 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
337 }
338
339 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
340 jsize values_length = _env->GetArrayLength(valueArray);
341 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
342 for (int i = 0; i < values_length; i++) {
343 values[i] = (uintptr_t)jValues[i];
344 }
345
346 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
347 jsize sizes_length = _env->GetArrayLength(sizeArray);
348
349 jlong* jDepClosures =
350 _env->GetLongArrayElements(depClosureArray, nullptr);
351 jsize depClosures_length = _env->GetArrayLength(depClosureArray);
352 RsClosure* depClosures =
353 (RsClosure*)alloca(sizeof(RsClosure) * depClosures_length);
354 for (int i = 0; i < depClosures_length; i++) {
355 depClosures[i] = (RsClosure)jDepClosures[i];
356 }
357
358 jlong* jDepFieldIDs =
359 _env->GetLongArrayElements(depFieldIDArray, nullptr);
360 jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray);
361 RsScriptFieldID* depFieldIDs =
362 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * depFieldIDs_length);
363 for (int i = 0; i < depClosures_length; i++) {
364 depFieldIDs[i] = (RsClosure)jDepFieldIDs[i];
365 }
366
367 return (jlong)(uintptr_t)rsClosureCreate(
368 (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue,
369 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
Yang Ni4c93c8c2015-03-26 14:35:22 -0700370 (int*)sizes, (size_t)sizes_length,
Yang Ni281c3252014-10-24 08:52:24 -0700371 depClosures, (size_t)depClosures_length,
372 depFieldIDs, (size_t)depFieldIDs_length);
373}
374
Yang Nibe392ad2015-01-23 17:16:02 -0800375static jlong
376nInvokeClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong invokeID,
377 jbyteArray paramArray, jlongArray fieldIDArray, jlongArray valueArray,
378 jintArray sizeArray) {
379 jbyte* jParams = _env->GetByteArrayElements(paramArray, nullptr);
380 jsize jParamLength = _env->GetArrayLength(paramArray);
381
382 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
383 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
384 RsScriptFieldID* fieldIDs =
385 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
386 for (int i = 0; i< fieldIDs_length; i++) {
387 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
388 }
389
390 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
391 jsize values_length = _env->GetArrayLength(valueArray);
392 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
393 for (int i = 0; i < values_length; i++) {
394 values[i] = (uintptr_t)jValues[i];
395 }
396
397 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
398 jsize sizes_length = _env->GetArrayLength(sizeArray);
399
400 return (jlong)(uintptr_t)rsInvokeClosureCreate(
401 (RsContext)con, (RsScriptInvokeID)invokeID, jParams, jParamLength,
402 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
Yang Ni4c93c8c2015-03-26 14:35:22 -0700403 (int*)sizes, (size_t)sizes_length);
Yang Nibe392ad2015-01-23 17:16:02 -0800404}
405
Yang Ni281c3252014-10-24 08:52:24 -0700406static void
407nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
408 jint index, jlong value, jint size) {
409 rsClosureSetArg((RsContext)con, (RsClosure)closureID, (uint32_t)index,
410 (uintptr_t)value, (size_t)size);
411}
412
413static void
414nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
415 jlong fieldID, jlong value, jint size) {
416 rsClosureSetGlobal((RsContext)con, (RsClosure)closureID,
417 (RsScriptFieldID)fieldID, (uintptr_t)value, (size_t)size);
418}
419
420static long
Yang Ni35be56c2015-04-02 17:47:56 -0700421nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con, jstring name,
Yang Niebf63402015-01-16 11:06:26 -0800422 jstring cacheDir, jlongArray closureArray) {
Yang Ni35be56c2015-04-02 17:47:56 -0700423 AutoJavaStringToUTF8 nameUTF(_env, name);
Yang Niebf63402015-01-16 11:06:26 -0800424 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
425
Yang Ni281c3252014-10-24 08:52:24 -0700426 jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr);
427 jsize numClosures = _env->GetArrayLength(closureArray);
428 RsClosure* closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures);
429 for (int i = 0; i < numClosures; i++) {
430 closures[i] = (RsClosure)jClosures[i];
431 }
432
Yang Niebf63402015-01-16 11:06:26 -0800433 return (jlong)(uintptr_t)rsScriptGroup2Create(
Yang Ni35be56c2015-04-02 17:47:56 -0700434 (RsContext)con, nameUTF.c_str(), nameUTF.length(),
435 cacheDirUTF.c_str(), cacheDirUTF.length(),
Yang Niebf63402015-01-16 11:06:26 -0800436 closures, numClosures);
Yang Ni281c3252014-10-24 08:52:24 -0700437}
438
439static void
440nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) {
441 rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID);
442}
443
Jason Sams96ed4cf2010-06-15 12:15:57 -0700444static void
Tim Murray25207df2015-01-12 16:47:56 -0800445nScriptIntrinsicBLAS_Single(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
446 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
447 jfloat alpha, jlong A, jlong B, jfloat beta, jlong C, jint incX, jint incY,
448 jint KL, jint KU) {
449 RsBlasCall call;
450 memset(&call, 0, sizeof(call));
451 call.func = (RsBlasFunction)func;
452 call.transA = (RsBlasTranspose)TransA;
453 call.transB = (RsBlasTranspose)TransB;
454 call.side = (RsBlasSide)Side;
455 call.uplo = (RsBlasUplo)Uplo;
456 call.diag = (RsBlasDiag)Diag;
457 call.M = M;
458 call.N = N;
459 call.K = K;
460 call.alpha.f = alpha;
461 call.beta.f = beta;
462 call.incX = incX;
463 call.incY = incY;
464 call.KL = KL;
465 call.KU = KU;
466
467 RsAllocation in_allocs[3];
468 in_allocs[0] = (RsAllocation)A;
469 in_allocs[1] = (RsAllocation)B;
470 in_allocs[2] = (RsAllocation)C;
471
472 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
473 in_allocs, sizeof(in_allocs), nullptr,
474 &call, sizeof(call), nullptr, 0);
475}
476
477static void
478nScriptIntrinsicBLAS_Double(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
479 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
480 jdouble alpha, jlong A, jlong B, jdouble beta, jlong C, jint incX, jint incY,
481 jint KL, jint KU) {
482 RsBlasCall call;
483 memset(&call, 0, sizeof(call));
484 call.func = (RsBlasFunction)func;
485 call.transA = (RsBlasTranspose)TransA;
486 call.transB = (RsBlasTranspose)TransB;
487 call.side = (RsBlasSide)Side;
488 call.uplo = (RsBlasUplo)Uplo;
489 call.diag = (RsBlasDiag)Diag;
490 call.M = M;
491 call.N = N;
492 call.K = K;
493 call.alpha.d = alpha;
494 call.beta.d = beta;
495 call.incX = incX;
496 call.incY = incY;
497 call.KL = KL;
498 call.KU = KU;
499
500 RsAllocation in_allocs[3];
501 in_allocs[0] = (RsAllocation)A;
502 in_allocs[1] = (RsAllocation)B;
503 in_allocs[2] = (RsAllocation)C;
504
505 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
506 in_allocs, sizeof(in_allocs), nullptr,
507 &call, sizeof(call), nullptr, 0);
508}
509
510static void
511nScriptIntrinsicBLAS_Complex(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
512 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
513 jfloat alphaX, jfloat alphaY, jlong A, jlong B, jfloat betaX,
514 jfloat betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
515 RsBlasCall call;
516 memset(&call, 0, sizeof(call));
517 call.func = (RsBlasFunction)func;
518 call.transA = (RsBlasTranspose)TransA;
519 call.transB = (RsBlasTranspose)TransB;
520 call.side = (RsBlasSide)Side;
521 call.uplo = (RsBlasUplo)Uplo;
522 call.diag = (RsBlasDiag)Diag;
523 call.M = M;
524 call.N = N;
525 call.K = K;
526 call.alpha.c.r = alphaX;
527 call.alpha.c.i = alphaY;
528 call.beta.c.r = betaX;
529 call.beta.c.r = betaY;
530 call.incX = incX;
531 call.incY = incY;
532 call.KL = KL;
533 call.KU = KU;
534
535 RsAllocation in_allocs[3];
536 in_allocs[0] = (RsAllocation)A;
537 in_allocs[1] = (RsAllocation)B;
538 in_allocs[2] = (RsAllocation)C;
539
540 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
541 in_allocs, sizeof(in_allocs), nullptr,
542 &call, sizeof(call), nullptr, 0);
543}
544
545static void
546nScriptIntrinsicBLAS_Z(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
547 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
548 jdouble alphaX, jdouble alphaY, jlong A, jlong B, jdouble betaX,
549 jdouble betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
550 RsBlasCall call;
551 memset(&call, 0, sizeof(call));
552 call.func = (RsBlasFunction)func;
553 call.transA = (RsBlasTranspose)TransA;
554 call.transB = (RsBlasTranspose)TransB;
555 call.side = (RsBlasSide)Side;
556 call.uplo = (RsBlasUplo)Uplo;
557 call.diag = (RsBlasDiag)Diag;
558 call.M = M;
559 call.N = N;
560 call.K = K;
561 call.alpha.z.r = alphaX;
562 call.alpha.z.i = alphaY;
563 call.beta.z.r = betaX;
564 call.beta.z.r = betaY;
565 call.incX = incX;
566 call.incY = incY;
567 call.KL = KL;
568 call.KU = KU;
569
570 RsAllocation in_allocs[3];
571 in_allocs[0] = (RsAllocation)A;
572 in_allocs[1] = (RsAllocation)B;
573 in_allocs[2] = (RsAllocation)C;
574
575 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
576 in_allocs, sizeof(in_allocs), nullptr,
577 &call, sizeof(call), nullptr, 0);
578}
579
580
581static void
Tim Murray9cb16a22015-04-01 11:07:16 -0700582nScriptIntrinsicBLAS_BNNM(JNIEnv *_env, jobject _this, jlong con, jlong id, jint M, jint N, jint K,
583 jlong A, jint a_offset, jlong B, jint b_offset, jlong C, jint c_offset,
584 jint c_mult_int) {
585 RsBlasCall call;
586 memset(&call, 0, sizeof(call));
587 call.func = RsBlas_bnnm;
588 call.M = M;
589 call.N = N;
590 call.K = K;
591 call.a_offset = a_offset;
592 call.b_offset = b_offset;
593 call.c_offset = c_offset;
594 call.c_mult_int = c_mult_int;
595
596 RsAllocation in_allocs[3];
597 in_allocs[0] = (RsAllocation)A;
598 in_allocs[1] = (RsAllocation)B;
599 in_allocs[2] = (RsAllocation)C;
600
601 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
602 in_allocs, sizeof(in_allocs), nullptr,
603 &call, sizeof(call), nullptr, 0);
604}
605
606
607static void
Tim Murray460a0492013-11-19 12:45:54 -0800608nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa3382009-06-10 15:04:38 -0700609{
Andreas Gampe67333922014-11-10 20:35:59 -0800610 if (kLogApi) {
611 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
612 }
Jason Sams3eaa3382009-06-10 15:04:38 -0700613 jint len = _env->GetArrayLength(str);
614 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800615 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa3382009-06-10 15:04:38 -0700616 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
617}
618
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700619static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800620nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700621{
Andreas Gampe67333922014-11-10 20:35:59 -0800622 if (kLogApi) {
623 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
624 }
Chris Wailes488230c32014-08-14 11:22:40 -0700625 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800626 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700627 if(name == nullptr || strlen(name) == 0) {
628 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700629 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700630 return _env->NewStringUTF(name);
631}
632
Jason Sams7ce033d2009-08-18 14:14:24 -0700633static void
Tim Murray460a0492013-11-19 12:45:54 -0800634nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700635{
Andreas Gampe67333922014-11-10 20:35:59 -0800636 if (kLogApi) {
637 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
638 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800639 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700640}
641
Jason Sams3eaa3382009-06-10 15:04:38 -0700642// ---------------------------------------------------------------------------
643
Tim Murrayeff663f2013-11-15 13:08:30 -0800644static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700645nDeviceCreate(JNIEnv *_env, jobject _this)
646{
Andreas Gampe67333922014-11-10 20:35:59 -0800647 if (kLogApi) {
648 ALOGD("nDeviceCreate");
649 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700650 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700651}
652
653static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800654nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700655{
Andreas Gampe67333922014-11-10 20:35:59 -0800656 if (kLogApi) {
657 ALOGD("nDeviceDestroy");
658 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700659 return rsDeviceDestroy((RsDevice)dev);
660}
661
Jason Samsebfb4362009-09-23 13:57:02 -0700662static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800663nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700664{
Andreas Gampe67333922014-11-10 20:35:59 -0800665 if (kLogApi) {
666 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
667 }
Jason Samsebfb4362009-09-23 13:57:02 -0700668 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
669}
670
Tim Murrayeff663f2013-11-15 13:08:30 -0800671static jlong
Jason Sams81cd2b12014-12-02 12:36:43 -0800672nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700673{
Andreas Gampe67333922014-11-10 20:35:59 -0800674 if (kLogApi) {
675 ALOGD("nContextCreate");
676 }
Jason Sams81cd2b12014-12-02 12:36:43 -0800677 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags);
Jason Sams704ff642010-02-09 16:05:07 -0800678}
679
Tim Murrayeff663f2013-11-15 13:08:30 -0800680static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800681nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000682 jint colorMin, jint colorPref,
683 jint alphaMin, jint alphaPref,
684 jint depthMin, jint depthPref,
685 jint stencilMin, jint stencilPref,
686 jint samplesMin, jint samplesPref, jfloat samplesQ,
687 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800688{
Jason Sams11c8af92010-10-13 15:31:10 -0700689 RsSurfaceConfig sc;
690 sc.alphaMin = alphaMin;
691 sc.alphaPref = alphaPref;
692 sc.colorMin = colorMin;
693 sc.colorPref = colorPref;
694 sc.depthMin = depthMin;
695 sc.depthPref = depthPref;
696 sc.samplesMin = samplesMin;
697 sc.samplesPref = samplesPref;
698 sc.samplesQ = samplesQ;
699
Andreas Gampe67333922014-11-10 20:35:59 -0800700 if (kLogApi) {
701 ALOGD("nContextCreateGL");
702 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700703 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700704}
705
706static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800707nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800708{
Andreas Gampe67333922014-11-10 20:35:59 -0800709 if (kLogApi) {
710 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
711 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800712 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800713}
714
Tim Murray47f31582015-04-07 15:43:24 -0700715static void
716nContextSetCacheDir(JNIEnv *_env, jobject _this, jlong con, jstring cacheDir)
717{
718 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
719
720 if (kLogApi) {
721 ALOGD("ContextSetCacheDir, con(%p), cacheDir(%s)", (RsContext)con, cacheDirUTF.c_str());
722 }
723 rsContextSetCacheDir((RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length());
724}
725
Jason Sams7d787b42009-11-15 12:14:26 -0800726
727
728static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800729nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800730{
Andreas Gampe67333922014-11-10 20:35:59 -0800731 if (kLogApi) {
732 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
733 width, height, (Surface *)wnd);
734 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800735
Chris Wailes488230c32014-08-14 11:22:40 -0700736 ANativeWindow * window = nullptr;
737 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800738
739 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700740 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800741 }
742
Tim Murrayeff663f2013-11-15 13:08:30 -0800743 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800744}
745
746static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800747nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700748{
Andreas Gampe67333922014-11-10 20:35:59 -0800749 if (kLogApi) {
750 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
751 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800752 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700753}
754
Jason Sams715333b2009-11-17 17:26:46 -0800755static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800756nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800757{
Andreas Gampe67333922014-11-10 20:35:59 -0800758 if (kLogApi) {
759 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
760 }
Jason Sams715333b2009-11-17 17:26:46 -0800761 rsContextDump((RsContext)con, bits);
762}
Jason Samsd19f10d2009-05-22 14:03:28 -0700763
764static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800765nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700766{
Andreas Gampe67333922014-11-10 20:35:59 -0800767 if (kLogApi) {
768 ALOGD("nContextPause, con(%p)", (RsContext)con);
769 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800770 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700771}
772
773static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800774nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700775{
Andreas Gampe67333922014-11-10 20:35:59 -0800776 if (kLogApi) {
777 ALOGD("nContextResume, con(%p)", (RsContext)con);
778 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800779 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700780}
781
Jason Sams1c415172010-11-08 17:06:46 -0800782
783static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800784nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800785{
Andreas Gampe67333922014-11-10 20:35:59 -0800786 if (kLogApi) {
787 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
788 }
Jason Sams1c415172010-11-08 17:06:46 -0800789 char buf[1024];
790
791 size_t receiveLen;
792 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800793 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700794 buf, sizeof(buf),
795 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700796 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800797 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100798 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800799 }
800 return _env->NewStringUTF(buf);
801}
802
Jason Samsedbfabd2011-05-17 15:01:29 -0700803static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800804nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700805{
Jason Sams516c3192009-10-06 13:58:47 -0700806 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800807 if (kLogApi) {
808 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
809 }
Chris Wailes488230c32014-08-14 11:22:40 -0700810 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700811 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800812 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800813 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700814 ptr, len * 4,
815 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700816 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700817 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100818 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700819 }
820 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000821 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800822}
823
824static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800825nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800826{
Andreas Gampe67333922014-11-10 20:35:59 -0800827 if (kLogApi) {
828 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
829 }
Chris Wailes488230c32014-08-14 11:22:40 -0700830 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800831 size_t receiveLen;
832 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800833 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700834 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800835 auxDataPtr[0] = (jint)subID;
836 auxDataPtr[1] = (jint)receiveLen;
837 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000838 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700839}
840
Tim Murrayeff663f2013-11-15 13:08:30 -0800841static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700842{
Andreas Gampe67333922014-11-10 20:35:59 -0800843 if (kLogApi) {
844 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
845 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800846 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700847}
848
Tim Murrayeff663f2013-11-15 13:08:30 -0800849static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700850{
Andreas Gampe67333922014-11-10 20:35:59 -0800851 if (kLogApi) {
852 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
853 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800854 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700855}
856
Jason Sams455d6442013-02-05 19:20:18 -0800857static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800858nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800859{
Chris Wailes488230c32014-08-14 11:22:40 -0700860 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800861 jint len = 0;
862 if (data) {
863 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700864 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800865 }
Andreas Gampe67333922014-11-10 20:35:59 -0800866 if (kLogApi) {
867 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
868 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800869 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800870 if (data) {
871 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
872 }
873}
874
875
Jason Sams516c3192009-10-06 13:58:47 -0700876
Tim Murray460a0492013-11-19 12:45:54 -0800877static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800878nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
879 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700880{
Andreas Gampe67333922014-11-10 20:35:59 -0800881 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100882 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con,
Andreas Gampe67333922014-11-10 20:35:59 -0800883 type, kind, norm, size);
884 }
885 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
886 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700887}
888
Tim Murray460a0492013-11-19 12:45:54 -0800889static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800890nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000891 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700892{
Jason Sams718cd1f2009-12-23 14:35:29 -0800893 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -0800894 if (kLogApi) {
895 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
896 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800897
Chris Wailes488230c32014-08-14 11:22:40 -0700898 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
899 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000900
901 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
902 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
903
904 for(int i = 0; i < fieldCount; i ++) {
905 ids[i] = (RsElement)jIds[i];
906 arraySizes[i] = (uint32_t)jArraySizes[i];
907 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800908
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800909 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
910
911 const char **nameArray = names.c_str();
912 size_t *sizeArray = names.c_str_len();
913
Tim Murray3aa89c12014-08-18 17:51:22 -0700914 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000915 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700916 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700917 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800918
Ashok Bhat98071552014-02-12 09:54:43 +0000919 free(ids);
920 free(arraySizes);
921 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
922 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
923
Tim Murray3aa89c12014-08-18 17:51:22 -0700924 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700925}
926
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700927static void
Tim Murray460a0492013-11-19 12:45:54 -0800928nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700929{
930 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -0800931 if (kLogApi) {
932 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
933 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700934
935 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
936 assert(dataSize == 5);
937
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000938 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800939 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700940
941 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000942 const jint data = (jint)elementData[i];
943 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700944 }
945}
946
947
948static void
Tim Murray460a0492013-11-19 12:45:54 -0800949nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000950 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700951 jobjectArray _names,
952 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700953{
Ashok Bhat98071552014-02-12 09:54:43 +0000954 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -0800955 if (kLogApi) {
956 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
957 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700958
Ashok Bhat98071552014-02-12 09:54:43 +0000959 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
960 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000961 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700962
Andreas Gampe67333922014-11-10 20:35:59 -0800963 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
964 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700965
Ashok Bhat98071552014-02-12 09:54:43 +0000966 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700967 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000968 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700969 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000970 _env->SetLongArrayRegion(_IDs, i, 1, &id);
971 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700972 }
973
974 free(ids);
975 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700976 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700977}
978
Jason Samsd19f10d2009-05-22 14:03:28 -0700979// -----------------------------------
980
Tim Murray460a0492013-11-19 12:45:54 -0800981static jlong
982nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800983 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700984{
Andreas Gampe67333922014-11-10 20:35:59 -0800985 if (kLogApi) {
986 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 +0100987 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv);
Andreas Gampe67333922014-11-10 20:35:59 -0800988 }
Jason Sams3b9c52a2010-10-14 17:48:46 -0700989
Andreas Gampe67333922014-11-10 20:35:59 -0800990 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
991 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700992}
993
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700994static void
Ashok Bhat98071552014-02-12 09:54:43 +0000995nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700996{
997 // We are packing 6 items: mDimX; mDimY; mDimZ;
998 // mDimLOD; mDimFaces; mElement; into typeData
999 int elementCount = _env->GetArrayLength(_typeData);
1000
1001 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001002 if (kLogApi) {
1003 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
1004 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001005
Ashok Bhat98071552014-02-12 09:54:43 +00001006 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -08001007 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001008
1009 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001010 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001011 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001012 }
1013}
1014
Jason Samsd19f10d2009-05-22 14:03:28 -07001015// -----------------------------------
1016
Tim Murray460a0492013-11-19 12:45:54 -08001017static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001018nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
1019 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -07001020{
Andreas Gampe67333922014-11-10 20:35:59 -08001021 if (kLogApi) {
1022 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
1023 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
1024 }
1025 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
1026 (RsAllocationMipmapControl)mips,
1027 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -07001028}
1029
Jason Samsd19f10d2009-05-22 14:03:28 -07001030static void
Tim Murray460a0492013-11-19 12:45:54 -08001031nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -08001032{
Andreas Gampe67333922014-11-10 20:35:59 -08001033 if (kLogApi) {
1034 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
1035 bits);
1036 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001037 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -08001038}
1039
Jason Sams72226e02013-02-22 12:45:54 -08001040static jobject
Tim Murray460a0492013-11-19 12:45:54 -08001041nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -08001042{
Andreas Gampe67333922014-11-10 20:35:59 -08001043 if (kLogApi) {
1044 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1045 }
Jason Sams615e7ce2012-01-13 14:01:20 -08001046
Andreas Gampe67333922014-11-10 20:35:59 -08001047 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
1048 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -08001049 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -07001050 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001051
Jason Sams72226e02013-02-22 12:45:54 -08001052 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
1053 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001054}
1055
1056static void
Tim Murray460a0492013-11-19 12:45:54 -08001057nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -08001058{
Andreas Gampe67333922014-11-10 20:35:59 -08001059 if (kLogApi) {
1060 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
1061 (RsAllocation)alloc, (Surface *)sur);
1062 }
Jason Sams163766c2012-02-15 12:04:24 -08001063
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001064 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -08001065 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -07001066 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -08001067 }
1068
Andreas Gampe67333922014-11-10 20:35:59 -08001069 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
1070 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -08001071}
1072
1073static void
Tim Murray460a0492013-11-19 12:45:54 -08001074nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001075{
Andreas Gampe67333922014-11-10 20:35:59 -08001076 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001077 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001078 }
Tim Murray460a0492013-11-19 12:45:54 -08001079 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001080}
1081
1082static void
Tim Murray460a0492013-11-19 12:45:54 -08001083nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001084{
Andreas Gampe67333922014-11-10 20:35:59 -08001085 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001086 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001087 }
Tim Murray460a0492013-11-19 12:45:54 -08001088 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001089}
1090
1091
1092static void
Tim Murray460a0492013-11-19 12:45:54 -08001093nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -08001094{
Andreas Gampe67333922014-11-10 20:35:59 -08001095 if (kLogApi) {
1096 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
1097 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001098 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -08001099}
1100
Tim Murray460a0492013-11-19 12:45:54 -08001101static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001102nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1103 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -07001104{
John Reckedc22fb2015-04-20 22:06:31 +00001105 SkBitmap const * nativeBitmap =
1106 GraphicsJNI::getSkBitmap(_env, jbitmap);
1107 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -07001108
Jason Sams5476b452010-12-08 16:14:36 -08001109 bitmap.lockPixels();
1110 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001111 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001112 (RsType)type, (RsAllocationMipmapControl)mip,
1113 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001114 bitmap.unlockPixels();
1115 return id;
Jason Samsffe9f482009-06-01 17:45:53 -07001116}
Jason Samsfe08d992009-05-27 14:45:32 -07001117
Tim Murray460a0492013-11-19 12:45:54 -08001118static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001119nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
1120 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -08001121{
John Reckedc22fb2015-04-20 22:06:31 +00001122 SkBitmap const * nativeBitmap =
1123 GraphicsJNI::getSkBitmap(_env, jbitmap);
1124 const SkBitmap& bitmap(*nativeBitmap);
Tim Murraya3145512012-12-04 17:59:29 -08001125
1126 bitmap.lockPixels();
1127 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001128 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -08001129 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +00001130 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -08001131 bitmap.unlockPixels();
1132 return id;
1133}
1134
Tim Murray460a0492013-11-19 12:45:54 -08001135static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001136nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1137 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001138{
John Reckedc22fb2015-04-20 22:06:31 +00001139 SkBitmap const * nativeBitmap =
1140 GraphicsJNI::getSkBitmap(_env, jbitmap);
1141 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001142
Jason Sams5476b452010-12-08 16:14:36 -08001143 bitmap.lockPixels();
1144 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001145 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001146 (RsType)type, (RsAllocationMipmapControl)mip,
1147 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001148 bitmap.unlockPixels();
1149 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001150}
1151
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001152static void
Tim Murray460a0492013-11-19 12:45:54 -08001153nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001154{
John Reckedc22fb2015-04-20 22:06:31 +00001155 SkBitmap const * nativeBitmap =
1156 GraphicsJNI::getSkBitmap(_env, jbitmap);
1157 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -08001158 int w = bitmap.width();
1159 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001160
Jason Sams4ef66502010-12-10 16:03:15 -08001161 bitmap.lockPixels();
1162 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001163 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001164 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea32012-11-27 14:55:08 -08001165 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -08001166 bitmap.unlockPixels();
1167}
1168
1169static void
Tim Murray460a0492013-11-19 12:45:54 -08001170nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -08001171{
John Reckedc22fb2015-04-20 22:06:31 +00001172 SkBitmap const * nativeBitmap =
1173 GraphicsJNI::getSkBitmap(_env, jbitmap);
1174 const SkBitmap& bitmap(*nativeBitmap);
Jason Sams4ef66502010-12-10 16:03:15 -08001175
1176 bitmap.lockPixels();
1177 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001178 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -08001179 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -07001180 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001181}
1182
Stephen Hines414fa2c2014-04-17 01:02:42 -07001183// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -07001184static void
Tim Murray460a0492013-11-19 12:45:54 -08001185nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001186 jint count, jobject data, jint sizeBytes, jint dataType, jint mSize,
1187 jboolean usePadding)
Jason Samsd19f10d2009-05-22 14:03:28 -07001188{
Jason Samse729a942013-11-06 11:22:02 -08001189 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001190 if (kLogApi) {
1191 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1192 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
1193 dataType);
1194 }
Miao Wang87e908d2015-03-02 15:15:15 -08001195 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true,
1196 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -07001197}
1198
1199static void
Miao Wangc8e237e2015-02-20 18:36:32 -08001200nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1201 jint xoff, jint yoff, jint zoff,
1202 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -07001203{
1204 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -08001205 if (kLogApi) {
Miao Wangc8e237e2015-02-20 18:36:32 -08001206 ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1207 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
Andreas Gampe67333922014-11-10 20:35:59 -08001208 sizeBytes);
1209 }
Chris Wailes488230c32014-08-14 11:22:40 -07001210 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Miao Wangc8e237e2015-02-20 18:36:32 -08001211 rsAllocationElementData((RsContext)con, (RsAllocation)alloc,
1212 xoff, yoff, zoff,
1213 lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -07001214 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1215}
1216
Miao Wangc8e237e2015-02-20 18:36:32 -08001217
Stephen Hines414fa2c2014-04-17 01:02:42 -07001218// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -07001219static void
Tim Murray460a0492013-11-19 12:45:54 -08001220nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001221 jint w, jint h, jobject data, jint sizeBytes, jint dataType, jint mSize,
1222 jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001223{
Jason Samse729a942013-11-06 11:22:02 -08001224 RsAllocation *alloc = (RsAllocation *)_alloc;
1225 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001226 if (kLogApi) {
1227 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1228 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1229 }
Miao Wang87e908d2015-03-02 15:15:15 -08001230 int count = w * h;
1231 PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true,
1232 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -07001233}
1234
Stephen Hines414fa2c2014-04-17 01:02:42 -07001235// Copies from the Allocation pointed to by srcAlloc into the Allocation
1236// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -07001237static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001238nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001239 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001240 jint dstMip, jint dstFace,
1241 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -08001242 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001243 jint srcMip, jint srcFace)
1244{
Andreas Gampe67333922014-11-10 20:35:59 -08001245 if (kLogApi) {
1246 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1247 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
1248 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
1249 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
1250 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
1251 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001252
Tim Murrayeff663f2013-11-15 13:08:30 -08001253 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001254 (RsAllocation)dstAlloc,
1255 dstXoff, dstYoff,
1256 dstMip, dstFace,
1257 width, height,
1258 (RsAllocation)srcAlloc,
1259 srcXoff, srcYoff,
1260 srcMip, srcFace);
1261}
1262
Stephen Hines414fa2c2014-04-17 01:02:42 -07001263// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001264static void
Tim Murray460a0492013-11-19 12:45:54 -08001265nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001266 jint w, jint h, jint d, jobject data, jint sizeBytes, jint dataType,
1267 jint mSize, jboolean usePadding)
Jason Samsb05d6892013-04-09 15:59:24 -07001268{
Jason Samse729a942013-11-06 11:22:02 -08001269 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001270 if (kLogApi) {
1271 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1272 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1273 lod, w, h, d, sizeBytes);
1274 }
Miao Wang87e908d2015-03-02 15:15:15 -08001275 int count = w * h * d;
1276 PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true,
1277 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -07001278}
1279
Stephen Hines414fa2c2014-04-17 01:02:42 -07001280// Copies from the Allocation pointed to by srcAlloc into the Allocation
1281// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -07001282static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001283nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001284 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001285 jint dstMip,
1286 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -08001287 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001288 jint srcMip)
1289{
Andreas Gampe67333922014-11-10 20:35:59 -08001290 if (kLogApi) {
1291 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1292 " dstMip(%i), width(%i), height(%i),"
1293 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
1294 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
1295 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
1296 }
Jason Samsb05d6892013-04-09 15:59:24 -07001297
Tim Murrayeff663f2013-11-15 13:08:30 -08001298 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -07001299 (RsAllocation)dstAlloc,
1300 dstXoff, dstYoff, dstZoff, dstMip,
1301 width, height, depth,
1302 (RsAllocation)srcAlloc,
1303 srcXoff, srcYoff, srcZoff, srcMip);
1304}
1305
Jason Sams21659ac2013-11-06 15:08:07 -08001306
Stephen Hines414fa2c2014-04-17 01:02:42 -07001307// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -07001308static void
Miao Wang87e908d2015-03-02 15:15:15 -08001309nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, jint dataType,
1310 jint mSize, jboolean usePadding)
Jason Sams40a29e82009-08-10 14:55:26 -07001311{
Jason Sams21659ac2013-11-06 15:08:07 -08001312 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001313 if (kLogApi) {
1314 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
1315 }
Miao Wang87e908d2015-03-02 15:15:15 -08001316 int count = 0;
1317 PER_ARRAY_TYPE(0, rsAllocationRead, false,
1318 (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -07001319}
1320
Stephen Hines414fa2c2014-04-17 01:02:42 -07001321// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -07001322static void
Tim Murray460a0492013-11-19 12:45:54 -08001323nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001324 jint count, jobject data, jint sizeBytes, jint dataType,
1325 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001326{
Jason Sams21659ac2013-11-06 15:08:07 -08001327 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001328 if (kLogApi) {
1329 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1330 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
1331 }
Miao Wang87e908d2015-03-02 15:15:15 -08001332 PER_ARRAY_TYPE(0, rsAllocation1DRead, false,
1333 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -08001334}
1335
Miao Wangc8e237e2015-02-20 18:36:32 -08001336// Copies from the Element in the Allocation pointed to by _alloc into the Java array data.
1337static void
Miao Wang45cec0a2015-03-04 16:40:21 -08001338nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
Miao Wangc8e237e2015-02-20 18:36:32 -08001339 jint xoff, jint yoff, jint zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -08001340 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Miao Wangc8e237e2015-02-20 18:36:32 -08001341{
Miao Wang45cec0a2015-03-04 16:40:21 -08001342 jint len = _env->GetArrayLength(data);
Miao Wangc8e237e2015-02-20 18:36:32 -08001343 if (kLogApi) {
Miao Wang45cec0a2015-03-04 16:40:21 -08001344 ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1345 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
1346 sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -08001347 }
Miao Wang45cec0a2015-03-04 16:40:21 -08001348 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
1349 rsAllocationElementRead((RsContext)con, (RsAllocation)alloc,
1350 xoff, yoff, zoff,
Jason Samsa7e25092015-03-11 11:00:00 -07001351 lod, ptr, sizeBytes, compIdx);
Miao Wang45cec0a2015-03-04 16:40:21 -08001352 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
Miao Wangc8e237e2015-02-20 18:36:32 -08001353}
1354
Stephen Hines414fa2c2014-04-17 01:02:42 -07001355// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -08001356static void
Tim Murray460a0492013-11-19 12:45:54 -08001357nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001358 jint w, jint h, jobject data, jint sizeBytes, jint dataType,
1359 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001360{
Jason Sams21659ac2013-11-06 15:08:07 -08001361 RsAllocation *alloc = (RsAllocation *)_alloc;
1362 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001363 if (kLogApi) {
1364 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1365 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1366 }
Miao Wang87e908d2015-03-02 15:15:15 -08001367 int count = w * h;
1368 PER_ARRAY_TYPE(0, rsAllocation2DRead, false,
1369 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -07001370}
Miao Wang87e908d2015-03-02 15:15:15 -08001371
Miao Wangc8e237e2015-02-20 18:36:32 -08001372// Copies from the Allocation pointed to by _alloc into the Java object data.
1373static void
1374nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001375 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType,
1376 jint mSize, jboolean usePadding)
Miao Wangc8e237e2015-02-20 18:36:32 -08001377{
1378 RsAllocation *alloc = (RsAllocation *)_alloc;
1379 if (kLogApi) {
1380 ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1381 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1382 lod, w, h, d, sizeBytes);
1383 }
Miao Wang87e908d2015-03-02 15:15:15 -08001384 int count = w * h * d;
1385 PER_ARRAY_TYPE(nullptr, rsAllocation3DRead, false,
1386 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Miao Wangc8e237e2015-02-20 18:36:32 -08001387}
Jason Samsd19f10d2009-05-22 14:03:28 -07001388
Tim Murray460a0492013-11-19 12:45:54 -08001389static jlong
1390nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001391{
Andreas Gampe67333922014-11-10 20:35:59 -08001392 if (kLogApi) {
1393 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1394 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001395 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001396}
1397
Jason Sams5edc6082010-10-05 13:32:49 -07001398static void
Tim Murray460a0492013-11-19 12:45:54 -08001399nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -07001400{
Andreas Gampe67333922014-11-10 20:35:59 -08001401 if (kLogApi) {
1402 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
1403 (RsAllocation)alloc, dimX);
1404 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001405 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -07001406}
1407
Jason Sams46ba27e32015-02-06 17:45:15 -08001408
1409static jlong
1410nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type)
1411{
1412 if (kLogApi) {
1413 ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)",
1414 (RsContext)con, (RsAllocation)basealloc, (RsElement)type);
1415 }
1416 return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type,
1417 (RsAllocation)basealloc);
1418
1419}
1420
1421static void
1422nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1423 jint x, jint y, jint z, jint face, jint lod,
1424 jint a1, jint a2, jint a3, jint a4)
1425{
1426 uint32_t params[] = {
1427 (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face,
1428 (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4
1429 };
1430 if (kLogApi) {
1431 ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)",
1432 (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4);
1433 }
1434 rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc,
1435 params, sizeof(params));
1436}
1437
1438
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001439// -----------------------------------
1440
Tim Murray460a0492013-11-19 12:45:54 -08001441static jlong
1442nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001443{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001444 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001445 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001446
Tim Murray3aa89c12014-08-18 17:51:22 -07001447 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001448 return id;
1449}
1450
Tim Murray460a0492013-11-19 12:45:54 -08001451static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001452nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001453{
1454 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001455 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001456 return 0;
1457 }
1458
1459 AutoJavaStringToUTF8 str(_env, _path);
1460 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001461 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001462 return 0;
1463 }
1464
Tim Murray3aa89c12014-08-18 17:51:22 -07001465 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001466 return id;
1467}
1468
Tim Murray460a0492013-11-19 12:45:54 -08001469static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001470nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001471{
1472 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001473 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001474
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001475 return id;
1476}
1477
Tim Murray460a0492013-11-19 12:45:54 -08001478static jint
1479nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001480{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001481 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001482 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001483 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001484}
1485
1486static void
Tim Murray460a0492013-11-19 12:45:54 -08001487nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001488{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001489 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001490 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
1491
Tim Murrayeff663f2013-11-15 13:08:30 -08001492 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001493
1494 for(jint i = 0; i < numEntries; i ++) {
1495 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
1496 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
1497 }
1498
1499 free(fileEntries);
1500}
1501
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001502static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001503nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001504{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001505 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001506 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001507 return id;
1508}
Jason Samsd19f10d2009-05-22 14:03:28 -07001509
1510// -----------------------------------
1511
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001512static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001513nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001514 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001515{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001516 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001517 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001518 fileNameUTF.c_str(), fileNameUTF.length(),
1519 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001520
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001521 return id;
1522}
1523
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001524static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001525nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001526 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001527{
1528 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1529 AutoJavaStringToUTF8 nameUTF(_env, name);
1530
Tim Murray3aa89c12014-08-18 17:51:22 -07001531 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001532 nameUTF.c_str(), nameUTF.length(),
1533 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001534 asset->getBuffer(false), asset->getLength());
1535 return id;
1536}
1537
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001538static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001539nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001540 jfloat fontSize, jint dpi)
1541{
1542 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001543 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001544 return 0;
1545 }
1546
1547 AutoJavaStringToUTF8 str(_env, _path);
1548 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001549 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001550 return 0;
1551 }
1552
Tim Murray3aa89c12014-08-18 17:51:22 -07001553 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001554 str.c_str(), str.length(),
1555 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001556 asset->getBuffer(false), asset->getLength());
1557 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001558 return id;
1559}
1560
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001561// -----------------------------------
1562
1563static void
Tim Murray460a0492013-11-19 12:45:54 -08001564nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001565{
Andreas Gampe67333922014-11-10 20:35:59 -08001566 if (kLogApi) {
1567 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1568 (RsScript)script, (RsAllocation)alloc, slot);
1569 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001570 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001571}
1572
1573static void
Tim Murray460a0492013-11-19 12:45:54 -08001574nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001575{
Andreas Gampe67333922014-11-10 20:35:59 -08001576 if (kLogApi) {
1577 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1578 slot, val);
1579 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001580 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001581}
1582
Tim Murray7c4caad2013-04-10 16:21:40 -07001583static jint
Tim Murray460a0492013-11-19 12:45:54 -08001584nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001585{
Andreas Gampe67333922014-11-10 20:35:59 -08001586 if (kLogApi) {
1587 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1588 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001589 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001590 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001591 return value;
1592}
1593
Jason Sams4d339932010-05-11 14:03:58 -07001594static void
Tim Murray460a0492013-11-19 12:45:54 -08001595nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001596{
Andreas Gampe67333922014-11-10 20:35:59 -08001597 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001598 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001599 slot, val);
1600 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001601 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001602}
1603
1604static void
Tim Murray460a0492013-11-19 12:45:54 -08001605nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001606{
Andreas Gampe67333922014-11-10 20:35:59 -08001607 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001608 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001609 slot, val);
1610 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001611 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001612}
1613
Tim Murray7c4caad2013-04-10 16:21:40 -07001614static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001615nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001616{
Andreas Gampe67333922014-11-10 20:35:59 -08001617 if (kLogApi) {
1618 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1619 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001620 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001621 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001622 return value;
1623}
1624
Stephen Hines031ec58c2010-10-11 10:54:21 -07001625static void
Tim Murray460a0492013-11-19 12:45:54 -08001626nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001627{
Andreas Gampe67333922014-11-10 20:35:59 -08001628 if (kLogApi) {
1629 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1630 slot, val);
1631 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001632 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001633}
1634
Tim Murray7c4caad2013-04-10 16:21:40 -07001635static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001636nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001637{
Andreas Gampe67333922014-11-10 20:35:59 -08001638 if (kLogApi) {
1639 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1640 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001641 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001642 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001643 return value;
1644}
1645
Jason Sams4d339932010-05-11 14:03:58 -07001646static void
Tim Murray460a0492013-11-19 12:45:54 -08001647nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001648{
Andreas Gampe67333922014-11-10 20:35:59 -08001649 if (kLogApi) {
1650 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1651 slot, val);
1652 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001653 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001654}
1655
Tim Murray7c4caad2013-04-10 16:21:40 -07001656static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001657nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001658{
Andreas Gampe67333922014-11-10 20:35:59 -08001659 if (kLogApi) {
1660 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1661 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001662 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001663 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001664 return value;
1665}
1666
Stephen Hinesca54ec32010-09-20 17:20:30 -07001667static void
Tim Murray460a0492013-11-19 12:45:54 -08001668nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001669{
Andreas Gampe67333922014-11-10 20:35:59 -08001670 if (kLogApi) {
1671 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1672 }
Jason Sams4d339932010-05-11 14:03:58 -07001673 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001674 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001675 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001676 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1677}
1678
Stephen Hinesadeb8092012-04-20 14:26:06 -07001679static void
Tim Murray460a0492013-11-19 12:45:54 -08001680nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001681{
Andreas Gampe67333922014-11-10 20:35:59 -08001682 if (kLogApi) {
1683 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1684 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001685 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001686 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001687 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001688 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001689}
1690
1691static void
Andreas Gampe67333922014-11-10 20:35:59 -08001692nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1693 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001694{
Andreas Gampe67333922014-11-10 20:35:59 -08001695 if (kLogApi) {
1696 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1697 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001698 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001699 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001700 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001701 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001702 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001703 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001704 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1705 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1706}
1707
Jason Samsd19f10d2009-05-22 14:03:28 -07001708
1709static void
Tim Murray460a0492013-11-19 12:45:54 -08001710nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001711{
Andreas Gampe67333922014-11-10 20:35:59 -08001712 if (kLogApi) {
1713 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1714 }
Romain Guy584a3752009-07-30 18:45:01 -07001715
1716 jint length = _env->GetArrayLength(timeZone);
1717 jbyte* timeZone_ptr;
1718 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1719
Tim Murrayeff663f2013-11-15 13:08:30 -08001720 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001721
1722 if (timeZone_ptr) {
1723 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1724 }
1725}
1726
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001727static void
Tim Murray460a0492013-11-19 12:45:54 -08001728nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001729{
Andreas Gampe67333922014-11-10 20:35:59 -08001730 if (kLogApi) {
1731 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1732 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001733 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001734}
1735
1736static void
Tim Murray460a0492013-11-19 12:45:54 -08001737nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001738{
Andreas Gampe67333922014-11-10 20:35:59 -08001739 if (kLogApi) {
1740 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1741 }
Jason Sams4d339932010-05-11 14:03:58 -07001742 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001743 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001744 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001745 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1746}
1747
Jason Sams6e494d32011-04-27 16:33:11 -07001748static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001749nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1750 jlongArray ains, jlong aout, jbyteArray params,
1751 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001752{
Andreas Gampe67333922014-11-10 20:35:59 -08001753 if (kLogApi) {
1754 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1755 }
Jason Sams6e494d32011-04-27 16:33:11 -07001756
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001757 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001758 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001759
Chris Wailes488230c32014-08-14 11:22:40 -07001760 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001761
Chris Wailes488230c32014-08-14 11:22:40 -07001762 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001763 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001764 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001765
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001766 if (sizeof(RsAllocation) == sizeof(jlong)) {
1767 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001768
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001769 } else {
1770 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001771
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001772 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1773
1774 for (int index = in_len; --index >= 0;) {
1775 in_allocs[index] = (RsAllocation)in_ptr[index];
1776 }
1777 }
Chris Wailes94961062014-06-11 12:01:28 -07001778 }
1779
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001780 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001781 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001782
Chris Wailes488230c32014-08-14 11:22:40 -07001783 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001784 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001785 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001786 }
1787
Chris Wailes488230c32014-08-14 11:22:40 -07001788 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001789 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001790
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001791 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001792 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001793
Chris Wailes488230c32014-08-14 11:22:40 -07001794 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001795 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001796 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001797
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001798 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001799 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001800
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001801 sc.xStart = limit_ptr[0];
1802 sc.xEnd = limit_ptr[1];
1803 sc.yStart = limit_ptr[2];
1804 sc.yEnd = limit_ptr[3];
1805 sc.zStart = limit_ptr[4];
1806 sc.zEnd = limit_ptr[5];
1807 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Jason Sams14331ab2015-01-26 18:14:36 -08001808 sc.arrayStart = 0;
1809 sc.arrayEnd = 0;
1810 sc.array2Start = 0;
1811 sc.array2End = 0;
1812 sc.array3Start = 0;
1813 sc.array3End = 0;
1814 sc.array4Start = 0;
1815 sc.array4End = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001816
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001817 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001818 }
1819
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001820 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1821 in_allocs, in_len, (RsAllocation)aout,
1822 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001823
Chris Wailes488230c32014-08-14 11:22:40 -07001824 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001825 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001826 }
1827
Chris Wailes488230c32014-08-14 11:22:40 -07001828 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001829 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1830 }
1831
Chris Wailes488230c32014-08-14 11:22:40 -07001832 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001833 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1834 }
Chris Wailes94961062014-06-11 12:01:28 -07001835}
1836
Jason Sams22534172009-08-04 16:58:20 -07001837// -----------------------------------
1838
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001839static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001840nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001841 jstring resName, jstring cacheDir,
1842 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001843{
Andreas Gampe67333922014-11-10 20:35:59 -08001844 if (kLogApi) {
1845 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1846 }
Jason Sams22534172009-08-04 16:58:20 -07001847
Jason Samse4a06c52011-03-16 16:29:28 -07001848 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1849 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001850 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001851 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001852 jint _exception = 0;
1853 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001854 if (!scriptRef) {
1855 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001856 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001857 goto exit;
1858 }
Jack Palevich43702d82009-05-28 13:38:16 -07001859 if (length < 0) {
1860 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001861 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001862 goto exit;
1863 }
Jason Samse4a06c52011-03-16 16:29:28 -07001864 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001865 if (remaining < length) {
1866 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001867 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1868 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001869 goto exit;
1870 }
Jason Samse4a06c52011-03-16 16:29:28 -07001871 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001872 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001873
Tim Murrayeff663f2013-11-15 13:08:30 -08001874 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001875
Tim Murray3aa89c12014-08-18 17:51:22 -07001876 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001877 resNameUTF.c_str(), resNameUTF.length(),
1878 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001879 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001880
Jack Palevich43702d82009-05-28 13:38:16 -07001881exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001882 if (script_ptr) {
1883 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001884 _exception ? JNI_ABORT: 0);
1885 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001886
Tim Murray3aa89c12014-08-18 17:51:22 -07001887 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001888}
1889
Tim Murray460a0492013-11-19 12:45:54 -08001890static jlong
1891nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001892{
Andreas Gampe67333922014-11-10 20:35:59 -08001893 if (kLogApi) {
1894 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1895 (void *)eid);
1896 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001897 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001898}
1899
Tim Murray460a0492013-11-19 12:45:54 -08001900static jlong
1901nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001902{
Andreas Gampe67333922014-11-10 20:35:59 -08001903 if (kLogApi) {
1904 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1905 (void *)sid, slot, sig);
1906 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001907 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001908}
1909
Tim Murray460a0492013-11-19 12:45:54 -08001910static jlong
Yang Nibe392ad2015-01-23 17:16:02 -08001911nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
1912{
1913 if (kLogApi) {
Elliott Hughes7ff53fa2015-02-05 21:36:10 -08001914 ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con,
Yang Nibe392ad2015-01-23 17:16:02 -08001915 (void *)sid, slot);
1916 }
1917 return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot);
1918}
1919
1920static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001921nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001922{
Andreas Gampe67333922014-11-10 20:35:59 -08001923 if (kLogApi) {
1924 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1925 slot);
1926 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001927 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001928}
1929
Tim Murray460a0492013-11-19 12:45:54 -08001930static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001931nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1932 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001933{
Andreas Gampe67333922014-11-10 20:35:59 -08001934 if (kLogApi) {
1935 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1936 }
Jason Sams08a81582012-09-18 12:32:10 -07001937
Ashok Bhat98071552014-02-12 09:54:43 +00001938 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001939 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001940 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1941 for(int i = 0; i < kernelsLen; ++i) {
1942 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1943 }
Jason Sams08a81582012-09-18 12:32:10 -07001944
Ashok Bhat98071552014-02-12 09:54:43 +00001945 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001946 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001947 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1948 for(int i = 0; i < srcLen; ++i) {
1949 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1950 }
Jason Sams08a81582012-09-18 12:32:10 -07001951
Ashok Bhat98071552014-02-12 09:54:43 +00001952 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001953 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001954 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1955 for(int i = 0; i < dstkLen; ++i) {
1956 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1957 }
1958
1959 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001960 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001961 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1962 for(int i = 0; i < dstfLen; ++i) {
1963 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1964 }
1965
1966 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001967 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001968 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1969 for(int i = 0; i < typesLen; ++i) {
1970 typesPtr[i] = (RsType)jTypesPtr[i];
1971 }
1972
Tim Murray3aa89c12014-08-18 17:51:22 -07001973 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001974 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1975 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1976 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1977 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1978 (RsType *)typesPtr, typesLen * sizeof(RsType));
1979
1980 free(kernelsPtr);
1981 free(srcPtr);
1982 free(dstkPtr);
1983 free(dstfPtr);
1984 free(typesPtr);
1985 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1986 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1987 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1988 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1989 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001990 return id;
1991}
1992
1993static void
Tim Murray460a0492013-11-19 12:45:54 -08001994nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001995{
Andreas Gampe67333922014-11-10 20:35:59 -08001996 if (kLogApi) {
1997 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1998 (void *)gid, (void *)kid, (void *)alloc);
1999 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002000 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07002001}
2002
2003static void
Tim Murray460a0492013-11-19 12:45:54 -08002004nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07002005{
Andreas Gampe67333922014-11-10 20:35:59 -08002006 if (kLogApi) {
2007 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
2008 (void *)gid, (void *)kid, (void *)alloc);
2009 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002010 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07002011}
2012
2013static void
Tim Murray460a0492013-11-19 12:45:54 -08002014nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07002015{
Andreas Gampe67333922014-11-10 20:35:59 -08002016 if (kLogApi) {
2017 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
2018 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002019 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07002020}
2021
Jason Samsd19f10d2009-05-22 14:03:28 -07002022// ---------------------------------------------------------------------------
2023
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002024static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002025nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07002026 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
2027 jboolean depthMask, jboolean ditherEnable,
2028 jint srcFunc, jint destFunc,
2029 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07002030{
Andreas Gampe67333922014-11-10 20:35:59 -08002031 if (kLogApi) {
2032 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
2033 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002034 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07002035 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
2036 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07002037}
2038
Jason Sams0011bcf2009-12-15 12:58:36 -08002039// ---------------------------------------------------------------------------
2040
2041static void
Tim Murray460a0492013-11-19 12:45:54 -08002042nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08002043{
Andreas Gampe67333922014-11-10 20:35:59 -08002044 if (kLogApi) {
2045 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
2046 (RsProgramVertex)vpv, slot, (RsAllocation)a);
2047 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002048 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08002049}
Jason Sams54c0ec12009-11-30 14:49:55 -08002050
Jason Sams68afd012009-12-17 16:55:08 -08002051static void
Tim Murray460a0492013-11-19 12:45:54 -08002052nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002053{
Andreas Gampe67333922014-11-10 20:35:59 -08002054 if (kLogApi) {
2055 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2056 (RsProgramFragment)vpf, slot, (RsAllocation)a);
2057 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002058 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08002059}
2060
2061static void
Tim Murray460a0492013-11-19 12:45:54 -08002062nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002063{
Andreas Gampe67333922014-11-10 20:35:59 -08002064 if (kLogApi) {
2065 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2066 (RsProgramFragment)vpf, slot, (RsSampler)a);
2067 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002068 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08002069}
2070
Jason Samsd19f10d2009-05-22 14:03:28 -07002071// ---------------------------------------------------------------------------
2072
Tim Murray460a0492013-11-19 12:45:54 -08002073static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002074nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002075 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002076{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002077 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002078 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002079 jint paramLen = _env->GetArrayLength(params);
2080
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002081 int texCount = _env->GetArrayLength(texNames);
2082 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2083 const char ** nameArray = names.c_str();
2084 size_t* sizeArray = names.c_str_len();
2085
Andreas Gampe67333922014-11-10 20:35:59 -08002086 if (kLogApi) {
2087 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2088 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002089
Ashok Bhat98071552014-02-12 09:54:43 +00002090 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2091 for(int i = 0; i < paramLen; ++i) {
2092 paramPtr[i] = (uintptr_t)jParamPtr[i];
2093 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002094 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002095 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002096 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002097
Ashok Bhat98071552014-02-12 09:54:43 +00002098 free(paramPtr);
2099 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002100 return ret;
2101}
2102
2103
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002104// ---------------------------------------------------------------------------
2105
Tim Murray460a0492013-11-19 12:45:54 -08002106static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002107nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002108 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002109{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002110 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002111 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08002112 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002113
Andreas Gampe67333922014-11-10 20:35:59 -08002114 if (kLogApi) {
2115 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2116 }
Jason Sams0011bcf2009-12-15 12:58:36 -08002117
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002118 int texCount = _env->GetArrayLength(texNames);
2119 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2120 const char ** nameArray = names.c_str();
2121 size_t* sizeArray = names.c_str_len();
2122
Ashok Bhat98071552014-02-12 09:54:43 +00002123 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2124 for(int i = 0; i < paramLen; ++i) {
2125 paramPtr[i] = (uintptr_t)jParamPtr[i];
2126 }
2127
Tim Murray3aa89c12014-08-18 17:51:22 -07002128 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002129 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002130 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002131
Ashok Bhat98071552014-02-12 09:54:43 +00002132 free(paramPtr);
2133 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08002134 return ret;
2135}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002136
Jason Samsebfb4362009-09-23 13:57:02 -07002137// ---------------------------------------------------------------------------
2138
Tim Murray460a0492013-11-19 12:45:54 -08002139static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002140nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07002141{
Andreas Gampe67333922014-11-10 20:35:59 -08002142 if (kLogApi) {
2143 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
2144 pointSprite, cull);
2145 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002146 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07002147}
2148
Jason Samsd19f10d2009-05-22 14:03:28 -07002149
2150// ---------------------------------------------------------------------------
2151
2152static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002153nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07002154{
Andreas Gampe67333922014-11-10 20:35:59 -08002155 if (kLogApi) {
2156 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
2157 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002158 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07002159}
2160
2161static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002162nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07002163{
Andreas Gampe67333922014-11-10 20:35:59 -08002164 if (kLogApi) {
2165 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
2166 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002167 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07002168}
2169
2170static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002171nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07002172{
Andreas Gampe67333922014-11-10 20:35:59 -08002173 if (kLogApi) {
2174 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
2175 (RsProgramFragment)pf);
2176 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002177 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07002178}
2179
Jason Sams0826a6f2009-06-15 19:04:56 -07002180static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002181nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07002182{
Andreas Gampe67333922014-11-10 20:35:59 -08002183 if (kLogApi) {
2184 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
2185 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002186 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07002187}
2188
Joe Onoratod7b37742009-08-09 22:57:44 -07002189static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002190nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07002191{
Andreas Gampe67333922014-11-10 20:35:59 -08002192 if (kLogApi) {
2193 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
2194 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002195 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07002196}
2197
Joe Onoratod7b37742009-08-09 22:57:44 -07002198
Jason Sams02fb2cb2009-05-28 15:37:57 -07002199// ---------------------------------------------------------------------------
2200
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002201static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002202nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002203 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07002204{
Andreas Gampe67333922014-11-10 20:35:59 -08002205 if (kLogApi) {
2206 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
2207 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002208 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002209 (RsSamplerValue)magFilter,
2210 (RsSamplerValue)minFilter,
2211 (RsSamplerValue)wrapS,
2212 (RsSamplerValue)wrapT,
2213 (RsSamplerValue)wrapR,
2214 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07002215}
2216
Jason Samsbba134c2009-06-22 15:49:21 -07002217// ---------------------------------------------------------------------------
2218
Tim Murray460a0492013-11-19 12:45:54 -08002219static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00002220nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07002221{
Andreas Gampe67333922014-11-10 20:35:59 -08002222 if (kLogApi) {
2223 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
2224 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002225
2226 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07002227 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002228 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
2229 for(int i = 0; i < vtxLen; ++i) {
2230 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
2231 }
2232
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002233 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07002234 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002235 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
2236 for(int i = 0; i < idxLen; ++i) {
2237 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
2238 }
2239
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002240 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07002241 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002242
Tim Murray3aa89c12014-08-18 17:51:22 -07002243 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002244 (RsAllocation *)vtxPtr, vtxLen,
2245 (RsAllocation *)idxPtr, idxLen,
2246 (uint32_t *)primPtr, primLen);
2247
Ashok Bhat98071552014-02-12 09:54:43 +00002248 free(vtxPtr);
2249 free(idxPtr);
2250 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
2251 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002252 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002253 return id;
2254}
2255
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002256static jint
Tim Murray460a0492013-11-19 12:45:54 -08002257nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002258{
Andreas Gampe67333922014-11-10 20:35:59 -08002259 if (kLogApi) {
2260 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2261 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002262 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002263 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002264 return vtxCount;
2265}
2266
2267static jint
Tim Murray460a0492013-11-19 12:45:54 -08002268nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002269{
Andreas Gampe67333922014-11-10 20:35:59 -08002270 if (kLogApi) {
2271 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2272 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002273 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002274 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002275 return idxCount;
2276}
2277
2278static void
Ashok Bhat98071552014-02-12 09:54:43 +00002279nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002280{
Andreas Gampe67333922014-11-10 20:35:59 -08002281 if (kLogApi) {
2282 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2283 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002284
2285 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08002286 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002287
2288 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002289 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002290 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002291 }
2292
2293 free(allocs);
2294}
2295
2296static void
Ashok Bhat98071552014-02-12 09:54:43 +00002297nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002298{
Andreas Gampe67333922014-11-10 20:35:59 -08002299 if (kLogApi) {
2300 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2301 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002302
2303 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
2304 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
2305
Tim Murrayeff663f2013-11-15 13:08:30 -08002306 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002307
2308 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002309 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002310 const jint prim = (jint)prims[i];
2311 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
2312 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002313 }
2314
2315 free(allocs);
2316 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002317}
2318
Tim Murray56f9e6f2014-05-16 11:47:26 -07002319static jint
2320nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
2321 return (jint)sizeof(void*);
2322}
2323
2324
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002325// ---------------------------------------------------------------------------
2326
Jason Samsd19f10d2009-05-22 14:03:28 -07002327
Jason Sams94d8e90a2009-06-10 16:09:05 -07002328static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07002329
2330static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08002331{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07002332
Tim Murrayeff663f2013-11-15 13:08:30 -08002333{"nDeviceCreate", "()J", (void*)nDeviceCreate },
2334{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
2335{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
2336{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
2337{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
2338{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08002339
Tim Murrayeff663f2013-11-15 13:08:30 -08002340{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
2341{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07002342
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07002343
Jason Sams2e1872f2010-08-17 16:25:41 -07002344// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08002345{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
2346{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
2347{"rsnContextFinish", "(J)V", (void*)nContextFinish },
2348{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
Tim Murray47f31582015-04-07 15:43:24 -07002349{"rsnContextSetCacheDir", "(JLjava/lang/String;)V", (void*)nContextSetCacheDir },
Tim Murrayeff663f2013-11-15 13:08:30 -08002350{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
2351{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
2352{"rsnContextDump", "(JI)V", (void*)nContextDump },
2353{"rsnContextPause", "(J)V", (void*)nContextPause },
2354{"rsnContextResume", "(J)V", (void*)nContextResume },
2355{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07002356{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002357{"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate },
Yang Ni281c3252014-10-24 08:52:24 -07002358{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
2359{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08002360{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
2361{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
2362{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07002363
Tim Murray460a0492013-11-19 12:45:54 -08002364{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002365{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08002366{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
2367{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
2368{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002369{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07002370
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002371{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
2372{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
2373{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07002374
Tim Murray460a0492013-11-19 12:45:54 -08002375{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002376{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08002377{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00002378{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07002379
Tim Murray460a0492013-11-19 12:45:54 -08002380{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002381{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07002382
Ashok Bhat98071552014-02-12 09:54:43 +00002383{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08002384{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
2385{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
2386{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08002387
Tim Murray460a0492013-11-19 12:45:54 -08002388{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
2389{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08002390
Tim Murray460a0492013-11-19 12:45:54 -08002391{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
2392{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
2393{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
2394{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
2395{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
Miao Wang87e908d2015-03-02 15:15:15 -08002396{"rsnAllocationData1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData1D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002397{"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData },
Miao Wang87e908d2015-03-02 15:15:15 -08002398{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData2D },
Tim Murray460a0492013-11-19 12:45:54 -08002399{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002400{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData3D },
Tim Murray460a0492013-11-19 12:45:54 -08002401{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002402{"rsnAllocationRead", "(JJLjava/lang/Object;IIZ)V", (void*)nAllocationRead },
2403{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead1D },
Miao Wang45cec0a2015-03-04 16:40:21 -08002404{"rsnAllocationElementRead", "(JJIIIII[BI)V", (void*)nAllocationElementRead },
Miao Wang87e908d2015-03-02 15:15:15 -08002405{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead2D },
2406{"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead3D },
Tim Murray460a0492013-11-19 12:45:54 -08002407{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
2408{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
2409{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07002410
Jason Sams46ba27e32015-02-06 17:45:15 -08002411{"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate },
2412{"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset },
2413
Tim Murray460a0492013-11-19 12:45:54 -08002414{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
2415{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
2416{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
2417{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07002418
2419{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
2420
Tim Murray460a0492013-11-19 12:45:54 -08002421{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
2422{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
2423{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
2424{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
2425{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
2426{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
2427{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
2428{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
2429{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
2430{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
2431{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
2432{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07002433
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002434{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002435{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2436{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002437{"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002438{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002439{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Ni35be56c2015-04-02 17:47:56 -07002440{"rsnScriptGroup2Create", "(JLjava/lang/String;Ljava/lang/String;[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002441{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2442{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2443{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002444{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002445
Tim Murray25207df2015-01-12 16:47:56 -08002446{"rsnScriptIntrinsicBLAS_Single", "(JJIIIIIIIIIFJJFJIIII)V", (void*)nScriptIntrinsicBLAS_Single },
2447{"rsnScriptIntrinsicBLAS_Double", "(JJIIIIIIIIIDJJDJIIII)V", (void*)nScriptIntrinsicBLAS_Double },
2448{"rsnScriptIntrinsicBLAS_Complex", "(JJIIIIIIIIIFFJJFFJIIII)V", (void*)nScriptIntrinsicBLAS_Complex },
2449{"rsnScriptIntrinsicBLAS_Z", "(JJIIIIIIIIIDDJJDDJIIII)V", (void*)nScriptIntrinsicBLAS_Z },
2450
Tim Murray9cb16a22015-04-01 11:07:16 -07002451{"rsnScriptIntrinsicBLAS_BNNM", "(JJIIIJIJIJII)V", (void*)nScriptIntrinsicBLAS_BNNM },
2452
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002453{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002454
Tim Murray460a0492013-11-19 12:45:54 -08002455{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2456{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2457{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002458
Ashok Bhat98071552014-02-12 09:54:43 +00002459{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002460{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002461{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002462
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002463{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2464{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2465{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2466{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2467{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002468
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002469{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002470
Ashok Bhat98071552014-02-12 09:54:43 +00002471{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002472
Tim Murray460a0492013-11-19 12:45:54 -08002473{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2474{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002475{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2476{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002477
Tim Murray56f9e6f2014-05-16 11:47:26 -07002478{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002479};
2480
2481static int registerFuncs(JNIEnv *_env)
2482{
2483 return android::AndroidRuntime::registerNativeMethods(
2484 _env, classPathName, methods, NELEM(methods));
2485}
2486
2487// ---------------------------------------------------------------------------
2488
2489jint JNI_OnLoad(JavaVM* vm, void* reserved)
2490{
Chris Wailes488230c32014-08-14 11:22:40 -07002491 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002492 jint result = -1;
2493
Jason Samsd19f10d2009-05-22 14:03:28 -07002494 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002495 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002496 goto bail;
2497 }
Chris Wailes488230c32014-08-14 11:22:40 -07002498 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002499
2500 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002501 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002502 goto bail;
2503 }
2504
2505 /* success -- return valid version number */
2506 result = JNI_VERSION_1_4;
2507
2508bail:
2509 return result;
2510}