blob: ae48a5f76cec03c0edda6c01755d6d34fead9d73 [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 Recka771b982015-04-10 13:52:57 -07001105 SkBitmap bitmap;
1106 GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap);
Jason Samsffe9f482009-06-01 17:45:53 -07001107
Jason Sams5476b452010-12-08 16:14:36 -08001108 bitmap.lockPixels();
1109 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001110 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001111 (RsType)type, (RsAllocationMipmapControl)mip,
1112 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001113 bitmap.unlockPixels();
1114 return id;
Jason Samsffe9f482009-06-01 17:45:53 -07001115}
Jason Samsfe08d992009-05-27 14:45:32 -07001116
Tim Murray460a0492013-11-19 12:45:54 -08001117static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001118nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
1119 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -08001120{
John Recka771b982015-04-10 13:52:57 -07001121 SkBitmap bitmap;
1122 GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap);
Tim Murraya3145512012-12-04 17:59:29 -08001123
1124 bitmap.lockPixels();
1125 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001126 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -08001127 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +00001128 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -08001129 bitmap.unlockPixels();
1130 return id;
1131}
1132
Tim Murray460a0492013-11-19 12:45:54 -08001133static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001134nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1135 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001136{
John Recka771b982015-04-10 13:52:57 -07001137 SkBitmap bitmap;
1138 GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001139
Jason Sams5476b452010-12-08 16:14:36 -08001140 bitmap.lockPixels();
1141 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001142 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001143 (RsType)type, (RsAllocationMipmapControl)mip,
1144 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001145 bitmap.unlockPixels();
1146 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001147}
1148
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001149static void
Tim Murray460a0492013-11-19 12:45:54 -08001150nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001151{
John Recka771b982015-04-10 13:52:57 -07001152 SkBitmap bitmap;
1153 GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap);
Jason Samsf7086092011-01-12 13:28:37 -08001154 int w = bitmap.width();
1155 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001156
Jason Sams4ef66502010-12-10 16:03:15 -08001157 bitmap.lockPixels();
1158 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001159 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001160 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea32012-11-27 14:55:08 -08001161 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -08001162 bitmap.unlockPixels();
1163}
1164
1165static void
Tim Murray460a0492013-11-19 12:45:54 -08001166nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -08001167{
John Recka771b982015-04-10 13:52:57 -07001168 SkBitmap bitmap;
1169 GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap);
Jason Sams4ef66502010-12-10 16:03:15 -08001170
1171 bitmap.lockPixels();
1172 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001173 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -08001174 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -07001175 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001176}
1177
Stephen Hines414fa2c2014-04-17 01:02:42 -07001178// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -07001179static void
Tim Murray460a0492013-11-19 12:45:54 -08001180nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001181 jint count, jobject data, jint sizeBytes, jint dataType, jint mSize,
1182 jboolean usePadding)
Jason Samsd19f10d2009-05-22 14:03:28 -07001183{
Jason Samse729a942013-11-06 11:22:02 -08001184 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001185 if (kLogApi) {
1186 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1187 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
1188 dataType);
1189 }
Miao Wang87e908d2015-03-02 15:15:15 -08001190 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true,
1191 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -07001192}
1193
1194static void
Miao Wangc8e237e2015-02-20 18:36:32 -08001195nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1196 jint xoff, jint yoff, jint zoff,
1197 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -07001198{
1199 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -08001200 if (kLogApi) {
Miao Wangc8e237e2015-02-20 18:36:32 -08001201 ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1202 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
Andreas Gampe67333922014-11-10 20:35:59 -08001203 sizeBytes);
1204 }
Chris Wailes488230c32014-08-14 11:22:40 -07001205 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Miao Wangc8e237e2015-02-20 18:36:32 -08001206 rsAllocationElementData((RsContext)con, (RsAllocation)alloc,
1207 xoff, yoff, zoff,
1208 lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -07001209 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1210}
1211
Miao Wangc8e237e2015-02-20 18:36:32 -08001212
Stephen Hines414fa2c2014-04-17 01:02:42 -07001213// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -07001214static void
Tim Murray460a0492013-11-19 12:45:54 -08001215nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001216 jint w, jint h, jobject data, jint sizeBytes, jint dataType, jint mSize,
1217 jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001218{
Jason Samse729a942013-11-06 11:22:02 -08001219 RsAllocation *alloc = (RsAllocation *)_alloc;
1220 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001221 if (kLogApi) {
1222 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1223 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1224 }
Miao Wang87e908d2015-03-02 15:15:15 -08001225 int count = w * h;
1226 PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true,
1227 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -07001228}
1229
Stephen Hines414fa2c2014-04-17 01:02:42 -07001230// Copies from the Allocation pointed to by srcAlloc into the Allocation
1231// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -07001232static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001233nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001234 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001235 jint dstMip, jint dstFace,
1236 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -08001237 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001238 jint srcMip, jint srcFace)
1239{
Andreas Gampe67333922014-11-10 20:35:59 -08001240 if (kLogApi) {
1241 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1242 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
1243 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
1244 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
1245 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
1246 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001247
Tim Murrayeff663f2013-11-15 13:08:30 -08001248 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001249 (RsAllocation)dstAlloc,
1250 dstXoff, dstYoff,
1251 dstMip, dstFace,
1252 width, height,
1253 (RsAllocation)srcAlloc,
1254 srcXoff, srcYoff,
1255 srcMip, srcFace);
1256}
1257
Stephen Hines414fa2c2014-04-17 01:02:42 -07001258// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001259static void
Tim Murray460a0492013-11-19 12:45:54 -08001260nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001261 jint w, jint h, jint d, jobject data, jint sizeBytes, jint dataType,
1262 jint mSize, jboolean usePadding)
Jason Samsb05d6892013-04-09 15:59:24 -07001263{
Jason Samse729a942013-11-06 11:22:02 -08001264 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001265 if (kLogApi) {
1266 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1267 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1268 lod, w, h, d, sizeBytes);
1269 }
Miao Wang87e908d2015-03-02 15:15:15 -08001270 int count = w * h * d;
1271 PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true,
1272 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -07001273}
1274
Stephen Hines414fa2c2014-04-17 01:02:42 -07001275// Copies from the Allocation pointed to by srcAlloc into the Allocation
1276// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -07001277static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001278nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001279 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001280 jint dstMip,
1281 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -08001282 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001283 jint srcMip)
1284{
Andreas Gampe67333922014-11-10 20:35:59 -08001285 if (kLogApi) {
1286 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1287 " dstMip(%i), width(%i), height(%i),"
1288 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
1289 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
1290 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
1291 }
Jason Samsb05d6892013-04-09 15:59:24 -07001292
Tim Murrayeff663f2013-11-15 13:08:30 -08001293 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -07001294 (RsAllocation)dstAlloc,
1295 dstXoff, dstYoff, dstZoff, dstMip,
1296 width, height, depth,
1297 (RsAllocation)srcAlloc,
1298 srcXoff, srcYoff, srcZoff, srcMip);
1299}
1300
Jason Sams21659ac2013-11-06 15:08:07 -08001301
Stephen Hines414fa2c2014-04-17 01:02:42 -07001302// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -07001303static void
Miao Wang87e908d2015-03-02 15:15:15 -08001304nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, jint dataType,
1305 jint mSize, jboolean usePadding)
Jason Sams40a29e82009-08-10 14:55:26 -07001306{
Jason Sams21659ac2013-11-06 15:08:07 -08001307 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001308 if (kLogApi) {
1309 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
1310 }
Miao Wang87e908d2015-03-02 15:15:15 -08001311 int count = 0;
1312 PER_ARRAY_TYPE(0, rsAllocationRead, false,
1313 (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -07001314}
1315
Stephen Hines414fa2c2014-04-17 01:02:42 -07001316// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -07001317static void
Tim Murray460a0492013-11-19 12:45:54 -08001318nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001319 jint count, jobject data, jint sizeBytes, jint dataType,
1320 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001321{
Jason Sams21659ac2013-11-06 15:08:07 -08001322 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001323 if (kLogApi) {
1324 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1325 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
1326 }
Miao Wang87e908d2015-03-02 15:15:15 -08001327 PER_ARRAY_TYPE(0, rsAllocation1DRead, false,
1328 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -08001329}
1330
Miao Wangc8e237e2015-02-20 18:36:32 -08001331// Copies from the Element in the Allocation pointed to by _alloc into the Java array data.
1332static void
Miao Wang45cec0a2015-03-04 16:40:21 -08001333nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
Miao Wangc8e237e2015-02-20 18:36:32 -08001334 jint xoff, jint yoff, jint zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -08001335 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Miao Wangc8e237e2015-02-20 18:36:32 -08001336{
Miao Wang45cec0a2015-03-04 16:40:21 -08001337 jint len = _env->GetArrayLength(data);
Miao Wangc8e237e2015-02-20 18:36:32 -08001338 if (kLogApi) {
Miao Wang45cec0a2015-03-04 16:40:21 -08001339 ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1340 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
1341 sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -08001342 }
Miao Wang45cec0a2015-03-04 16:40:21 -08001343 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
1344 rsAllocationElementRead((RsContext)con, (RsAllocation)alloc,
1345 xoff, yoff, zoff,
Jason Samsa7e25092015-03-11 11:00:00 -07001346 lod, ptr, sizeBytes, compIdx);
Miao Wang45cec0a2015-03-04 16:40:21 -08001347 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
Miao Wangc8e237e2015-02-20 18:36:32 -08001348}
1349
Stephen Hines414fa2c2014-04-17 01:02:42 -07001350// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -08001351static void
Tim Murray460a0492013-11-19 12:45:54 -08001352nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001353 jint w, jint h, jobject data, jint sizeBytes, jint dataType,
1354 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001355{
Jason Sams21659ac2013-11-06 15:08:07 -08001356 RsAllocation *alloc = (RsAllocation *)_alloc;
1357 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001358 if (kLogApi) {
1359 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1360 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1361 }
Miao Wang87e908d2015-03-02 15:15:15 -08001362 int count = w * h;
1363 PER_ARRAY_TYPE(0, rsAllocation2DRead, false,
1364 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -07001365}
Miao Wang87e908d2015-03-02 15:15:15 -08001366
Miao Wangc8e237e2015-02-20 18:36:32 -08001367// Copies from the Allocation pointed to by _alloc into the Java object data.
1368static void
1369nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001370 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType,
1371 jint mSize, jboolean usePadding)
Miao Wangc8e237e2015-02-20 18:36:32 -08001372{
1373 RsAllocation *alloc = (RsAllocation *)_alloc;
1374 if (kLogApi) {
1375 ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1376 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1377 lod, w, h, d, sizeBytes);
1378 }
Miao Wang87e908d2015-03-02 15:15:15 -08001379 int count = w * h * d;
1380 PER_ARRAY_TYPE(nullptr, rsAllocation3DRead, false,
1381 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Miao Wangc8e237e2015-02-20 18:36:32 -08001382}
Jason Samsd19f10d2009-05-22 14:03:28 -07001383
Tim Murray460a0492013-11-19 12:45:54 -08001384static jlong
1385nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001386{
Andreas Gampe67333922014-11-10 20:35:59 -08001387 if (kLogApi) {
1388 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1389 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001390 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001391}
1392
Jason Sams5edc6082010-10-05 13:32:49 -07001393static void
Tim Murray460a0492013-11-19 12:45:54 -08001394nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -07001395{
Andreas Gampe67333922014-11-10 20:35:59 -08001396 if (kLogApi) {
1397 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
1398 (RsAllocation)alloc, dimX);
1399 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001400 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -07001401}
1402
Jason Sams46ba27e32015-02-06 17:45:15 -08001403
1404static jlong
1405nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type)
1406{
1407 if (kLogApi) {
1408 ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)",
1409 (RsContext)con, (RsAllocation)basealloc, (RsElement)type);
1410 }
1411 return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type,
1412 (RsAllocation)basealloc);
1413
1414}
1415
1416static void
1417nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1418 jint x, jint y, jint z, jint face, jint lod,
1419 jint a1, jint a2, jint a3, jint a4)
1420{
1421 uint32_t params[] = {
1422 (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face,
1423 (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4
1424 };
1425 if (kLogApi) {
1426 ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)",
1427 (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4);
1428 }
1429 rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc,
1430 params, sizeof(params));
1431}
1432
1433
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001434// -----------------------------------
1435
Tim Murray460a0492013-11-19 12:45:54 -08001436static jlong
1437nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001438{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001439 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001440 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001441
Tim Murray3aa89c12014-08-18 17:51:22 -07001442 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001443 return id;
1444}
1445
Tim Murray460a0492013-11-19 12:45:54 -08001446static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001447nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001448{
1449 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001450 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001451 return 0;
1452 }
1453
1454 AutoJavaStringToUTF8 str(_env, _path);
1455 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001456 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001457 return 0;
1458 }
1459
Tim Murray3aa89c12014-08-18 17:51:22 -07001460 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001461 return id;
1462}
1463
Tim Murray460a0492013-11-19 12:45:54 -08001464static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001465nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001466{
1467 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001468 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001469
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001470 return id;
1471}
1472
Tim Murray460a0492013-11-19 12:45:54 -08001473static jint
1474nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001475{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001476 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001477 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001478 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001479}
1480
1481static void
Tim Murray460a0492013-11-19 12:45:54 -08001482nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001483{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001484 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001485 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
1486
Tim Murrayeff663f2013-11-15 13:08:30 -08001487 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001488
1489 for(jint i = 0; i < numEntries; i ++) {
1490 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
1491 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
1492 }
1493
1494 free(fileEntries);
1495}
1496
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001497static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001498nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001499{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001500 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001501 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001502 return id;
1503}
Jason Samsd19f10d2009-05-22 14:03:28 -07001504
1505// -----------------------------------
1506
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001507static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001508nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001509 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001510{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001511 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001512 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001513 fileNameUTF.c_str(), fileNameUTF.length(),
1514 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001515
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001516 return id;
1517}
1518
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001519static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001520nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001521 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001522{
1523 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1524 AutoJavaStringToUTF8 nameUTF(_env, name);
1525
Tim Murray3aa89c12014-08-18 17:51:22 -07001526 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001527 nameUTF.c_str(), nameUTF.length(),
1528 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001529 asset->getBuffer(false), asset->getLength());
1530 return id;
1531}
1532
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001533static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001534nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001535 jfloat fontSize, jint dpi)
1536{
1537 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001538 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001539 return 0;
1540 }
1541
1542 AutoJavaStringToUTF8 str(_env, _path);
1543 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001544 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001545 return 0;
1546 }
1547
Tim Murray3aa89c12014-08-18 17:51:22 -07001548 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001549 str.c_str(), str.length(),
1550 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001551 asset->getBuffer(false), asset->getLength());
1552 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001553 return id;
1554}
1555
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001556// -----------------------------------
1557
1558static void
Tim Murray460a0492013-11-19 12:45:54 -08001559nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001560{
Andreas Gampe67333922014-11-10 20:35:59 -08001561 if (kLogApi) {
1562 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1563 (RsScript)script, (RsAllocation)alloc, slot);
1564 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001565 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001566}
1567
1568static void
Tim Murray460a0492013-11-19 12:45:54 -08001569nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001570{
Andreas Gampe67333922014-11-10 20:35:59 -08001571 if (kLogApi) {
1572 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1573 slot, val);
1574 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001575 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001576}
1577
Tim Murray7c4caad2013-04-10 16:21:40 -07001578static jint
Tim Murray460a0492013-11-19 12:45:54 -08001579nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001580{
Andreas Gampe67333922014-11-10 20:35:59 -08001581 if (kLogApi) {
1582 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1583 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001584 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001585 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001586 return value;
1587}
1588
Jason Sams4d339932010-05-11 14:03:58 -07001589static void
Tim Murray460a0492013-11-19 12:45:54 -08001590nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001591{
Andreas Gampe67333922014-11-10 20:35:59 -08001592 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001593 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001594 slot, val);
1595 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001596 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001597}
1598
1599static void
Tim Murray460a0492013-11-19 12:45:54 -08001600nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001601{
Andreas Gampe67333922014-11-10 20:35:59 -08001602 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001603 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001604 slot, val);
1605 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001606 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001607}
1608
Tim Murray7c4caad2013-04-10 16:21:40 -07001609static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001610nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001611{
Andreas Gampe67333922014-11-10 20:35:59 -08001612 if (kLogApi) {
1613 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1614 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001615 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001616 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001617 return value;
1618}
1619
Stephen Hines031ec58c2010-10-11 10:54:21 -07001620static void
Tim Murray460a0492013-11-19 12:45:54 -08001621nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001622{
Andreas Gampe67333922014-11-10 20:35:59 -08001623 if (kLogApi) {
1624 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1625 slot, val);
1626 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001627 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001628}
1629
Tim Murray7c4caad2013-04-10 16:21:40 -07001630static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001631nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001632{
Andreas Gampe67333922014-11-10 20:35:59 -08001633 if (kLogApi) {
1634 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1635 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001636 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001637 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001638 return value;
1639}
1640
Jason Sams4d339932010-05-11 14:03:58 -07001641static void
Tim Murray460a0492013-11-19 12:45:54 -08001642nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001643{
Andreas Gampe67333922014-11-10 20:35:59 -08001644 if (kLogApi) {
1645 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1646 slot, val);
1647 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001648 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001649}
1650
Tim Murray7c4caad2013-04-10 16:21:40 -07001651static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001652nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001653{
Andreas Gampe67333922014-11-10 20:35:59 -08001654 if (kLogApi) {
1655 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1656 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001657 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001658 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001659 return value;
1660}
1661
Stephen Hinesca54ec32010-09-20 17:20:30 -07001662static void
Tim Murray460a0492013-11-19 12:45:54 -08001663nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001664{
Andreas Gampe67333922014-11-10 20:35:59 -08001665 if (kLogApi) {
1666 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1667 }
Jason Sams4d339932010-05-11 14:03:58 -07001668 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001669 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001670 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001671 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1672}
1673
Stephen Hinesadeb8092012-04-20 14:26:06 -07001674static void
Tim Murray460a0492013-11-19 12:45:54 -08001675nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001676{
Andreas Gampe67333922014-11-10 20:35:59 -08001677 if (kLogApi) {
1678 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1679 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001680 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001681 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001682 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001683 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001684}
1685
1686static void
Andreas Gampe67333922014-11-10 20:35:59 -08001687nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1688 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001689{
Andreas Gampe67333922014-11-10 20:35:59 -08001690 if (kLogApi) {
1691 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1692 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001693 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001694 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001695 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001696 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001697 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001698 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001699 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1700 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1701}
1702
Jason Samsd19f10d2009-05-22 14:03:28 -07001703
1704static void
Tim Murray460a0492013-11-19 12:45:54 -08001705nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001706{
Andreas Gampe67333922014-11-10 20:35:59 -08001707 if (kLogApi) {
1708 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1709 }
Romain Guy584a3752009-07-30 18:45:01 -07001710
1711 jint length = _env->GetArrayLength(timeZone);
1712 jbyte* timeZone_ptr;
1713 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1714
Tim Murrayeff663f2013-11-15 13:08:30 -08001715 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001716
1717 if (timeZone_ptr) {
1718 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1719 }
1720}
1721
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001722static void
Tim Murray460a0492013-11-19 12:45:54 -08001723nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001724{
Andreas Gampe67333922014-11-10 20:35:59 -08001725 if (kLogApi) {
1726 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1727 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001728 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001729}
1730
1731static void
Tim Murray460a0492013-11-19 12:45:54 -08001732nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001733{
Andreas Gampe67333922014-11-10 20:35:59 -08001734 if (kLogApi) {
1735 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1736 }
Jason Sams4d339932010-05-11 14:03:58 -07001737 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001738 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001739 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001740 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1741}
1742
Jason Sams6e494d32011-04-27 16:33:11 -07001743static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001744nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1745 jlongArray ains, jlong aout, jbyteArray params,
1746 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001747{
Andreas Gampe67333922014-11-10 20:35:59 -08001748 if (kLogApi) {
1749 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1750 }
Jason Sams6e494d32011-04-27 16:33:11 -07001751
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001752 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001753 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001754
Chris Wailes488230c32014-08-14 11:22:40 -07001755 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001756
Chris Wailes488230c32014-08-14 11:22:40 -07001757 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001758 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001759 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001760
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001761 if (sizeof(RsAllocation) == sizeof(jlong)) {
1762 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001763
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001764 } else {
1765 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001766
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001767 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1768
1769 for (int index = in_len; --index >= 0;) {
1770 in_allocs[index] = (RsAllocation)in_ptr[index];
1771 }
1772 }
Chris Wailes94961062014-06-11 12:01:28 -07001773 }
1774
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001775 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001776 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001777
Chris Wailes488230c32014-08-14 11:22:40 -07001778 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001779 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001780 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001781 }
1782
Chris Wailes488230c32014-08-14 11:22:40 -07001783 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001784 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001785
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001786 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001787 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001788
Chris Wailes488230c32014-08-14 11:22:40 -07001789 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001790 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001791 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001792
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001793 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001794 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001795
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001796 sc.xStart = limit_ptr[0];
1797 sc.xEnd = limit_ptr[1];
1798 sc.yStart = limit_ptr[2];
1799 sc.yEnd = limit_ptr[3];
1800 sc.zStart = limit_ptr[4];
1801 sc.zEnd = limit_ptr[5];
1802 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Jason Sams14331ab2015-01-26 18:14:36 -08001803 sc.arrayStart = 0;
1804 sc.arrayEnd = 0;
1805 sc.array2Start = 0;
1806 sc.array2End = 0;
1807 sc.array3Start = 0;
1808 sc.array3End = 0;
1809 sc.array4Start = 0;
1810 sc.array4End = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001811
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001812 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001813 }
1814
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001815 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1816 in_allocs, in_len, (RsAllocation)aout,
1817 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001818
Chris Wailes488230c32014-08-14 11:22:40 -07001819 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001820 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001821 }
1822
Chris Wailes488230c32014-08-14 11:22:40 -07001823 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001824 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1825 }
1826
Chris Wailes488230c32014-08-14 11:22:40 -07001827 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001828 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1829 }
Chris Wailes94961062014-06-11 12:01:28 -07001830}
1831
Jason Sams22534172009-08-04 16:58:20 -07001832// -----------------------------------
1833
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001834static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001835nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001836 jstring resName, jstring cacheDir,
1837 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001838{
Andreas Gampe67333922014-11-10 20:35:59 -08001839 if (kLogApi) {
1840 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1841 }
Jason Sams22534172009-08-04 16:58:20 -07001842
Jason Samse4a06c52011-03-16 16:29:28 -07001843 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1844 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001845 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001846 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001847 jint _exception = 0;
1848 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001849 if (!scriptRef) {
1850 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001851 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001852 goto exit;
1853 }
Jack Palevich43702d82009-05-28 13:38:16 -07001854 if (length < 0) {
1855 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001856 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001857 goto exit;
1858 }
Jason Samse4a06c52011-03-16 16:29:28 -07001859 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001860 if (remaining < length) {
1861 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001862 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1863 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001864 goto exit;
1865 }
Jason Samse4a06c52011-03-16 16:29:28 -07001866 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001867 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001868
Tim Murrayeff663f2013-11-15 13:08:30 -08001869 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001870
Tim Murray3aa89c12014-08-18 17:51:22 -07001871 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001872 resNameUTF.c_str(), resNameUTF.length(),
1873 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001874 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001875
Jack Palevich43702d82009-05-28 13:38:16 -07001876exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001877 if (script_ptr) {
1878 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001879 _exception ? JNI_ABORT: 0);
1880 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001881
Tim Murray3aa89c12014-08-18 17:51:22 -07001882 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001883}
1884
Tim Murray460a0492013-11-19 12:45:54 -08001885static jlong
1886nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001887{
Andreas Gampe67333922014-11-10 20:35:59 -08001888 if (kLogApi) {
1889 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1890 (void *)eid);
1891 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001892 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001893}
1894
Tim Murray460a0492013-11-19 12:45:54 -08001895static jlong
1896nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001897{
Andreas Gampe67333922014-11-10 20:35:59 -08001898 if (kLogApi) {
1899 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1900 (void *)sid, slot, sig);
1901 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001902 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001903}
1904
Tim Murray460a0492013-11-19 12:45:54 -08001905static jlong
Yang Nibe392ad2015-01-23 17:16:02 -08001906nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
1907{
1908 if (kLogApi) {
Elliott Hughes7ff53fa2015-02-05 21:36:10 -08001909 ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con,
Yang Nibe392ad2015-01-23 17:16:02 -08001910 (void *)sid, slot);
1911 }
1912 return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot);
1913}
1914
1915static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001916nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001917{
Andreas Gampe67333922014-11-10 20:35:59 -08001918 if (kLogApi) {
1919 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1920 slot);
1921 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001922 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001923}
1924
Tim Murray460a0492013-11-19 12:45:54 -08001925static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001926nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1927 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001928{
Andreas Gampe67333922014-11-10 20:35:59 -08001929 if (kLogApi) {
1930 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1931 }
Jason Sams08a81582012-09-18 12:32:10 -07001932
Ashok Bhat98071552014-02-12 09:54:43 +00001933 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001934 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001935 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1936 for(int i = 0; i < kernelsLen; ++i) {
1937 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1938 }
Jason Sams08a81582012-09-18 12:32:10 -07001939
Ashok Bhat98071552014-02-12 09:54:43 +00001940 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001941 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001942 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1943 for(int i = 0; i < srcLen; ++i) {
1944 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1945 }
Jason Sams08a81582012-09-18 12:32:10 -07001946
Ashok Bhat98071552014-02-12 09:54:43 +00001947 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001948 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001949 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1950 for(int i = 0; i < dstkLen; ++i) {
1951 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1952 }
1953
1954 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001955 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001956 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1957 for(int i = 0; i < dstfLen; ++i) {
1958 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1959 }
1960
1961 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001962 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001963 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1964 for(int i = 0; i < typesLen; ++i) {
1965 typesPtr[i] = (RsType)jTypesPtr[i];
1966 }
1967
Tim Murray3aa89c12014-08-18 17:51:22 -07001968 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001969 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1970 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1971 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1972 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1973 (RsType *)typesPtr, typesLen * sizeof(RsType));
1974
1975 free(kernelsPtr);
1976 free(srcPtr);
1977 free(dstkPtr);
1978 free(dstfPtr);
1979 free(typesPtr);
1980 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1981 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1982 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1983 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1984 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001985 return id;
1986}
1987
1988static void
Tim Murray460a0492013-11-19 12:45:54 -08001989nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001990{
Andreas Gampe67333922014-11-10 20:35:59 -08001991 if (kLogApi) {
1992 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1993 (void *)gid, (void *)kid, (void *)alloc);
1994 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001995 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001996}
1997
1998static void
Tim Murray460a0492013-11-19 12:45:54 -08001999nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07002000{
Andreas Gampe67333922014-11-10 20:35:59 -08002001 if (kLogApi) {
2002 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
2003 (void *)gid, (void *)kid, (void *)alloc);
2004 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002005 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07002006}
2007
2008static void
Tim Murray460a0492013-11-19 12:45:54 -08002009nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07002010{
Andreas Gampe67333922014-11-10 20:35:59 -08002011 if (kLogApi) {
2012 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
2013 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002014 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07002015}
2016
Jason Samsd19f10d2009-05-22 14:03:28 -07002017// ---------------------------------------------------------------------------
2018
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002019static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002020nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07002021 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
2022 jboolean depthMask, jboolean ditherEnable,
2023 jint srcFunc, jint destFunc,
2024 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07002025{
Andreas Gampe67333922014-11-10 20:35:59 -08002026 if (kLogApi) {
2027 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
2028 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002029 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07002030 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
2031 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07002032}
2033
Jason Sams0011bcf2009-12-15 12:58:36 -08002034// ---------------------------------------------------------------------------
2035
2036static void
Tim Murray460a0492013-11-19 12:45:54 -08002037nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08002038{
Andreas Gampe67333922014-11-10 20:35:59 -08002039 if (kLogApi) {
2040 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
2041 (RsProgramVertex)vpv, slot, (RsAllocation)a);
2042 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002043 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08002044}
Jason Sams54c0ec12009-11-30 14:49:55 -08002045
Jason Sams68afd012009-12-17 16:55:08 -08002046static void
Tim Murray460a0492013-11-19 12:45:54 -08002047nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002048{
Andreas Gampe67333922014-11-10 20:35:59 -08002049 if (kLogApi) {
2050 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2051 (RsProgramFragment)vpf, slot, (RsAllocation)a);
2052 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002053 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08002054}
2055
2056static void
Tim Murray460a0492013-11-19 12:45:54 -08002057nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002058{
Andreas Gampe67333922014-11-10 20:35:59 -08002059 if (kLogApi) {
2060 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2061 (RsProgramFragment)vpf, slot, (RsSampler)a);
2062 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002063 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08002064}
2065
Jason Samsd19f10d2009-05-22 14:03:28 -07002066// ---------------------------------------------------------------------------
2067
Tim Murray460a0492013-11-19 12:45:54 -08002068static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002069nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002070 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002071{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002072 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002073 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002074 jint paramLen = _env->GetArrayLength(params);
2075
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002076 int texCount = _env->GetArrayLength(texNames);
2077 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2078 const char ** nameArray = names.c_str();
2079 size_t* sizeArray = names.c_str_len();
2080
Andreas Gampe67333922014-11-10 20:35:59 -08002081 if (kLogApi) {
2082 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2083 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002084
Ashok Bhat98071552014-02-12 09:54:43 +00002085 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2086 for(int i = 0; i < paramLen; ++i) {
2087 paramPtr[i] = (uintptr_t)jParamPtr[i];
2088 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002089 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002090 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002091 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002092
Ashok Bhat98071552014-02-12 09:54:43 +00002093 free(paramPtr);
2094 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002095 return ret;
2096}
2097
2098
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002099// ---------------------------------------------------------------------------
2100
Tim Murray460a0492013-11-19 12:45:54 -08002101static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002102nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002103 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002104{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002105 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002106 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08002107 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002108
Andreas Gampe67333922014-11-10 20:35:59 -08002109 if (kLogApi) {
2110 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2111 }
Jason Sams0011bcf2009-12-15 12:58:36 -08002112
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002113 int texCount = _env->GetArrayLength(texNames);
2114 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2115 const char ** nameArray = names.c_str();
2116 size_t* sizeArray = names.c_str_len();
2117
Ashok Bhat98071552014-02-12 09:54:43 +00002118 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2119 for(int i = 0; i < paramLen; ++i) {
2120 paramPtr[i] = (uintptr_t)jParamPtr[i];
2121 }
2122
Tim Murray3aa89c12014-08-18 17:51:22 -07002123 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002124 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002125 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002126
Ashok Bhat98071552014-02-12 09:54:43 +00002127 free(paramPtr);
2128 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08002129 return ret;
2130}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002131
Jason Samsebfb4362009-09-23 13:57:02 -07002132// ---------------------------------------------------------------------------
2133
Tim Murray460a0492013-11-19 12:45:54 -08002134static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002135nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07002136{
Andreas Gampe67333922014-11-10 20:35:59 -08002137 if (kLogApi) {
2138 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
2139 pointSprite, cull);
2140 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002141 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07002142}
2143
Jason Samsd19f10d2009-05-22 14:03:28 -07002144
2145// ---------------------------------------------------------------------------
2146
2147static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002148nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07002149{
Andreas Gampe67333922014-11-10 20:35:59 -08002150 if (kLogApi) {
2151 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
2152 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002153 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07002154}
2155
2156static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002157nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07002158{
Andreas Gampe67333922014-11-10 20:35:59 -08002159 if (kLogApi) {
2160 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
2161 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002162 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07002163}
2164
2165static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002166nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07002167{
Andreas Gampe67333922014-11-10 20:35:59 -08002168 if (kLogApi) {
2169 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
2170 (RsProgramFragment)pf);
2171 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002172 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07002173}
2174
Jason Sams0826a6f2009-06-15 19:04:56 -07002175static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002176nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07002177{
Andreas Gampe67333922014-11-10 20:35:59 -08002178 if (kLogApi) {
2179 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
2180 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002181 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07002182}
2183
Joe Onoratod7b37742009-08-09 22:57:44 -07002184static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002185nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07002186{
Andreas Gampe67333922014-11-10 20:35:59 -08002187 if (kLogApi) {
2188 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
2189 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002190 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07002191}
2192
Joe Onoratod7b37742009-08-09 22:57:44 -07002193
Jason Sams02fb2cb2009-05-28 15:37:57 -07002194// ---------------------------------------------------------------------------
2195
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002196static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002197nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002198 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07002199{
Andreas Gampe67333922014-11-10 20:35:59 -08002200 if (kLogApi) {
2201 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
2202 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002203 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002204 (RsSamplerValue)magFilter,
2205 (RsSamplerValue)minFilter,
2206 (RsSamplerValue)wrapS,
2207 (RsSamplerValue)wrapT,
2208 (RsSamplerValue)wrapR,
2209 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07002210}
2211
Jason Samsbba134c2009-06-22 15:49:21 -07002212// ---------------------------------------------------------------------------
2213
Tim Murray460a0492013-11-19 12:45:54 -08002214static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00002215nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07002216{
Andreas Gampe67333922014-11-10 20:35:59 -08002217 if (kLogApi) {
2218 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
2219 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002220
2221 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07002222 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002223 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
2224 for(int i = 0; i < vtxLen; ++i) {
2225 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
2226 }
2227
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002228 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07002229 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002230 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
2231 for(int i = 0; i < idxLen; ++i) {
2232 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
2233 }
2234
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002235 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07002236 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002237
Tim Murray3aa89c12014-08-18 17:51:22 -07002238 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002239 (RsAllocation *)vtxPtr, vtxLen,
2240 (RsAllocation *)idxPtr, idxLen,
2241 (uint32_t *)primPtr, primLen);
2242
Ashok Bhat98071552014-02-12 09:54:43 +00002243 free(vtxPtr);
2244 free(idxPtr);
2245 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
2246 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002247 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002248 return id;
2249}
2250
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002251static jint
Tim Murray460a0492013-11-19 12:45:54 -08002252nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002253{
Andreas Gampe67333922014-11-10 20:35:59 -08002254 if (kLogApi) {
2255 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2256 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002257 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002258 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002259 return vtxCount;
2260}
2261
2262static jint
Tim Murray460a0492013-11-19 12:45:54 -08002263nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002264{
Andreas Gampe67333922014-11-10 20:35:59 -08002265 if (kLogApi) {
2266 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2267 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002268 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002269 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002270 return idxCount;
2271}
2272
2273static void
Ashok Bhat98071552014-02-12 09:54:43 +00002274nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002275{
Andreas Gampe67333922014-11-10 20:35:59 -08002276 if (kLogApi) {
2277 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2278 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002279
2280 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08002281 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002282
2283 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002284 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002285 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002286 }
2287
2288 free(allocs);
2289}
2290
2291static void
Ashok Bhat98071552014-02-12 09:54:43 +00002292nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002293{
Andreas Gampe67333922014-11-10 20:35:59 -08002294 if (kLogApi) {
2295 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2296 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002297
2298 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
2299 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
2300
Tim Murrayeff663f2013-11-15 13:08:30 -08002301 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002302
2303 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002304 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002305 const jint prim = (jint)prims[i];
2306 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
2307 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002308 }
2309
2310 free(allocs);
2311 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002312}
2313
Tim Murray56f9e6f2014-05-16 11:47:26 -07002314static jint
2315nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
2316 return (jint)sizeof(void*);
2317}
2318
2319
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002320// ---------------------------------------------------------------------------
2321
Jason Samsd19f10d2009-05-22 14:03:28 -07002322
Jason Sams94d8e90a2009-06-10 16:09:05 -07002323static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07002324
2325static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08002326{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07002327
Tim Murrayeff663f2013-11-15 13:08:30 -08002328{"nDeviceCreate", "()J", (void*)nDeviceCreate },
2329{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
2330{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
2331{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
2332{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
2333{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08002334
Tim Murrayeff663f2013-11-15 13:08:30 -08002335{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
2336{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07002337
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07002338
Jason Sams2e1872f2010-08-17 16:25:41 -07002339// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08002340{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
2341{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
2342{"rsnContextFinish", "(J)V", (void*)nContextFinish },
2343{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
Tim Murray47f31582015-04-07 15:43:24 -07002344{"rsnContextSetCacheDir", "(JLjava/lang/String;)V", (void*)nContextSetCacheDir },
Tim Murrayeff663f2013-11-15 13:08:30 -08002345{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
2346{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
2347{"rsnContextDump", "(JI)V", (void*)nContextDump },
2348{"rsnContextPause", "(J)V", (void*)nContextPause },
2349{"rsnContextResume", "(J)V", (void*)nContextResume },
2350{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07002351{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002352{"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate },
Yang Ni281c3252014-10-24 08:52:24 -07002353{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
2354{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08002355{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
2356{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
2357{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07002358
Tim Murray460a0492013-11-19 12:45:54 -08002359{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002360{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08002361{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
2362{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
2363{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002364{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07002365
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002366{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
2367{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
2368{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07002369
Tim Murray460a0492013-11-19 12:45:54 -08002370{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002371{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08002372{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00002373{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07002374
Tim Murray460a0492013-11-19 12:45:54 -08002375{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002376{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07002377
Ashok Bhat98071552014-02-12 09:54:43 +00002378{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08002379{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
2380{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
2381{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08002382
Tim Murray460a0492013-11-19 12:45:54 -08002383{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
2384{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08002385
Tim Murray460a0492013-11-19 12:45:54 -08002386{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
2387{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
2388{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
2389{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
2390{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
Miao Wang87e908d2015-03-02 15:15:15 -08002391{"rsnAllocationData1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData1D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002392{"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData },
Miao Wang87e908d2015-03-02 15:15:15 -08002393{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData2D },
Tim Murray460a0492013-11-19 12:45:54 -08002394{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002395{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData3D },
Tim Murray460a0492013-11-19 12:45:54 -08002396{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002397{"rsnAllocationRead", "(JJLjava/lang/Object;IIZ)V", (void*)nAllocationRead },
2398{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead1D },
Miao Wang45cec0a2015-03-04 16:40:21 -08002399{"rsnAllocationElementRead", "(JJIIIII[BI)V", (void*)nAllocationElementRead },
Miao Wang87e908d2015-03-02 15:15:15 -08002400{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead2D },
2401{"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead3D },
Tim Murray460a0492013-11-19 12:45:54 -08002402{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
2403{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
2404{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07002405
Jason Sams46ba27e32015-02-06 17:45:15 -08002406{"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate },
2407{"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset },
2408
Tim Murray460a0492013-11-19 12:45:54 -08002409{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
2410{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
2411{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
2412{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07002413
2414{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
2415
Tim Murray460a0492013-11-19 12:45:54 -08002416{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
2417{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
2418{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
2419{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
2420{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
2421{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
2422{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
2423{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
2424{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
2425{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
2426{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
2427{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07002428
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002429{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002430{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2431{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002432{"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002433{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002434{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Ni35be56c2015-04-02 17:47:56 -07002435{"rsnScriptGroup2Create", "(JLjava/lang/String;Ljava/lang/String;[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002436{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2437{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2438{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002439{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002440
Tim Murray25207df2015-01-12 16:47:56 -08002441{"rsnScriptIntrinsicBLAS_Single", "(JJIIIIIIIIIFJJFJIIII)V", (void*)nScriptIntrinsicBLAS_Single },
2442{"rsnScriptIntrinsicBLAS_Double", "(JJIIIIIIIIIDJJDJIIII)V", (void*)nScriptIntrinsicBLAS_Double },
2443{"rsnScriptIntrinsicBLAS_Complex", "(JJIIIIIIIIIFFJJFFJIIII)V", (void*)nScriptIntrinsicBLAS_Complex },
2444{"rsnScriptIntrinsicBLAS_Z", "(JJIIIIIIIIIDDJJDDJIIII)V", (void*)nScriptIntrinsicBLAS_Z },
2445
Tim Murray9cb16a22015-04-01 11:07:16 -07002446{"rsnScriptIntrinsicBLAS_BNNM", "(JJIIIJIJIJII)V", (void*)nScriptIntrinsicBLAS_BNNM },
2447
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002448{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002449
Tim Murray460a0492013-11-19 12:45:54 -08002450{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2451{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2452{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002453
Ashok Bhat98071552014-02-12 09:54:43 +00002454{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002455{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002456{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002457
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002458{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2459{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2460{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2461{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2462{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002463
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002464{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002465
Ashok Bhat98071552014-02-12 09:54:43 +00002466{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002467
Tim Murray460a0492013-11-19 12:45:54 -08002468{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2469{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002470{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2471{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002472
Tim Murray56f9e6f2014-05-16 11:47:26 -07002473{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002474};
2475
2476static int registerFuncs(JNIEnv *_env)
2477{
2478 return android::AndroidRuntime::registerNativeMethods(
2479 _env, classPathName, methods, NELEM(methods));
2480}
2481
2482// ---------------------------------------------------------------------------
2483
2484jint JNI_OnLoad(JavaVM* vm, void* reserved)
2485{
Chris Wailes488230c32014-08-14 11:22:40 -07002486 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002487 jint result = -1;
2488
Jason Samsd19f10d2009-05-22 14:03:28 -07002489 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002490 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002491 goto bail;
2492 }
Chris Wailes488230c32014-08-14 11:22:40 -07002493 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002494
2495 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002496 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002497 goto bail;
2498 }
2499
2500 /* success -- return valid version number */
2501 result = JNI_VERSION_1_4;
2502
2503bail:
2504 return result;
2505}