blob: 57ca8878481908da779a0f9cee92042a675e7013 [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 Samsbc5c64b2015-04-16 15:13:52 -070017#define LOG_TAG "RenderScript_jni"
Jason Samsf29ca502009-06-23 12:22:47 -070018
Jason Samsd19f10d2009-05-22 14:03:28 -070019#include <stdlib.h>
20#include <stdio.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <math.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070024#include <utils/misc.h>
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +010025#include <inttypes.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070026
Derek Sollenbergereece0dd2014-02-27 14:31:29 -050027#include <SkBitmap.h>
Jason Samsffe9f482009-06-01 17:45:53 -070028
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080029#include <androidfw/Asset.h>
30#include <androidfw/AssetManager.h>
31#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070032
Jason Samsd19f10d2009-05-22 14:03:28 -070033#include "jni.h"
34#include "JNIHelp.h"
35#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070036#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080037#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070038
Jason Sams1d6983a2012-02-16 16:07:49 -080039#include <rs.h>
40#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070041#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080042#include <gui/GLConsumer.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070043#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070044
Steve Block3762c312012-01-06 19:20:56 +000045//#define LOG_API ALOGE
Andreas Gampe67333922014-11-10 20:35:59 -080046static constexpr bool kLogApi = false;
Jason Samsd19f10d2009-05-22 14:03:28 -070047
48using namespace android;
49
Andreas Gampe67333922014-11-10 20:35:59 -080050template <typename... T>
51void UNUSED(T... t) {}
52
Stephen Hines414fa2c2014-04-17 01:02:42 -070053#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \
Jason Samse729a942013-11-06 11:22:02 -080054 jint len = 0; \
Chris Wailes488230c32014-08-14 11:22:40 -070055 void *ptr = nullptr; \
Miao Wang87e908d2015-03-02 15:15:15 -080056 void *srcPtr = nullptr; \
Jason Sams21659ac2013-11-06 15:08:07 -080057 size_t typeBytes = 0; \
Stephen Hines414fa2c2014-04-17 01:02:42 -070058 jint relFlag = 0; \
59 if (readonly) { \
60 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
Miao Wang87e908d2015-03-02 15:15:15 -080061 /* readonly = true, also indicates we are copying to the allocation . */ \
Stephen Hines414fa2c2014-04-17 01:02:42 -070062 relFlag = JNI_ABORT; \
63 } \
Jason Samse729a942013-11-06 11:22:02 -080064 switch(dataType) { \
65 case RS_TYPE_FLOAT_32: \
66 len = _env->GetArrayLength((jfloatArray)data); \
67 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080068 typeBytes = 4; \
Miao Wang87e908d2015-03-02 15:15:15 -080069 if (usePadding) { \
70 srcPtr = ptr; \
71 len = len / 3 * 4; \
72 if (count == 0) { \
73 count = len / 4; \
74 } \
75 ptr = malloc (len * typeBytes); \
76 if (readonly) { \
77 copyWithPadding(ptr, srcPtr, mSize, count); \
78 fnc(__VA_ARGS__); \
79 } else { \
80 fnc(__VA_ARGS__); \
81 copyWithUnPadding(srcPtr, ptr, mSize, count); \
82 } \
83 free(ptr); \
84 ptr = srcPtr; \
85 } else { \
86 fnc(__VA_ARGS__); \
87 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -070088 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080089 return; \
90 case RS_TYPE_FLOAT_64: \
91 len = _env->GetArrayLength((jdoubleArray)data); \
92 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080093 typeBytes = 8; \
Miao Wang87e908d2015-03-02 15:15:15 -080094 if (usePadding) { \
95 srcPtr = ptr; \
96 len = len / 3 * 4; \
97 if (count == 0) { \
98 count = len / 4; \
99 } \
100 ptr = malloc (len * typeBytes); \
101 if (readonly) { \
102 copyWithPadding(ptr, srcPtr, mSize, count); \
103 fnc(__VA_ARGS__); \
104 } else { \
105 fnc(__VA_ARGS__); \
106 copyWithUnPadding(srcPtr, ptr, mSize, count); \
107 } \
108 free(ptr); \
109 ptr = srcPtr; \
110 } else { \
111 fnc(__VA_ARGS__); \
112 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700113 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800114 return; \
115 case RS_TYPE_SIGNED_8: \
116 case RS_TYPE_UNSIGNED_8: \
117 len = _env->GetArrayLength((jbyteArray)data); \
118 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800119 typeBytes = 1; \
Miao Wang87e908d2015-03-02 15:15:15 -0800120 if (usePadding) { \
121 srcPtr = ptr; \
122 len = len / 3 * 4; \
123 if (count == 0) { \
124 count = len / 4; \
125 } \
126 ptr = malloc (len * typeBytes); \
127 if (readonly) { \
128 copyWithPadding(ptr, srcPtr, mSize, count); \
129 fnc(__VA_ARGS__); \
130 } else { \
131 fnc(__VA_ARGS__); \
132 copyWithUnPadding(srcPtr, ptr, mSize, count); \
133 } \
134 free(ptr); \
135 ptr = srcPtr; \
136 } else { \
137 fnc(__VA_ARGS__); \
138 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700139 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800140 return; \
141 case RS_TYPE_SIGNED_16: \
142 case RS_TYPE_UNSIGNED_16: \
143 len = _env->GetArrayLength((jshortArray)data); \
144 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800145 typeBytes = 2; \
Miao Wang87e908d2015-03-02 15:15:15 -0800146 if (usePadding) { \
147 srcPtr = ptr; \
148 len = len / 3 * 4; \
149 if (count == 0) { \
150 count = len / 4; \
151 } \
152 ptr = malloc (len * typeBytes); \
153 if (readonly) { \
154 copyWithPadding(ptr, srcPtr, mSize, count); \
155 fnc(__VA_ARGS__); \
156 } else { \
157 fnc(__VA_ARGS__); \
158 copyWithUnPadding(srcPtr, ptr, mSize, count); \
159 } \
160 free(ptr); \
161 ptr = srcPtr; \
162 } else { \
163 fnc(__VA_ARGS__); \
164 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700165 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800166 return; \
167 case RS_TYPE_SIGNED_32: \
168 case RS_TYPE_UNSIGNED_32: \
169 len = _env->GetArrayLength((jintArray)data); \
170 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800171 typeBytes = 4; \
Miao Wang87e908d2015-03-02 15:15:15 -0800172 if (usePadding) { \
173 srcPtr = ptr; \
174 len = len / 3 * 4; \
175 if (count == 0) { \
176 count = len / 4; \
177 } \
178 ptr = malloc (len * typeBytes); \
179 if (readonly) { \
180 copyWithPadding(ptr, srcPtr, mSize, count); \
181 fnc(__VA_ARGS__); \
182 } else { \
183 fnc(__VA_ARGS__); \
184 copyWithUnPadding(srcPtr, ptr, mSize, count); \
185 } \
186 free(ptr); \
187 ptr = srcPtr; \
188 } else { \
189 fnc(__VA_ARGS__); \
190 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700191 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800192 return; \
193 case RS_TYPE_SIGNED_64: \
194 case RS_TYPE_UNSIGNED_64: \
195 len = _env->GetArrayLength((jlongArray)data); \
196 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800197 typeBytes = 8; \
Miao Wang87e908d2015-03-02 15:15:15 -0800198 if (usePadding) { \
199 srcPtr = ptr; \
200 len = len / 3 * 4; \
201 if (count == 0) { \
202 count = len / 4; \
203 } \
204 ptr = malloc (len * typeBytes); \
205 if (readonly) { \
206 copyWithPadding(ptr, srcPtr, mSize, count); \
207 fnc(__VA_ARGS__); \
208 } else { \
209 fnc(__VA_ARGS__); \
210 copyWithUnPadding(srcPtr, ptr, mSize, count); \
211 } \
212 free(ptr); \
213 ptr = srcPtr; \
214 } else { \
215 fnc(__VA_ARGS__); \
216 } \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700217 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800218 return; \
219 default: \
220 break; \
221 } \
Miao Wang87e908d2015-03-02 15:15:15 -0800222 UNUSED(len, ptr, srcPtr, typeBytes, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800223}
224
225
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800226class AutoJavaStringToUTF8 {
227public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800228 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Chris Wailes488230c32014-08-14 11:22:40 -0700229 fCStr = env->GetStringUTFChars(str, nullptr);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800230 fLength = env->GetStringUTFLength(str);
231 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800232 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800233 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
234 }
235 const char* c_str() const { return fCStr; }
236 jsize length() const { return fLength; }
237
238private:
239 JNIEnv* fEnv;
240 jstring fJStr;
241 const char* fCStr;
242 jsize fLength;
243};
244
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800245class AutoJavaStringArrayToUTF8 {
246public:
247 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
248 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
Chris Wailes488230c32014-08-14 11:22:40 -0700249 mCStrings = nullptr;
250 mSizeArray = nullptr;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800251 if (stringsLength > 0) {
252 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
253 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
254 for (jsize ct = 0; ct < stringsLength; ct ++) {
255 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
Chris Wailes488230c32014-08-14 11:22:40 -0700256 mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800257 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
258 }
259 }
260 }
261 ~AutoJavaStringArrayToUTF8() {
262 for (jsize ct=0; ct < mStringsLength; ct++) {
263 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
264 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
265 }
266 free(mCStrings);
267 free(mSizeArray);
268 }
269 const char **c_str() const { return mCStrings; }
270 size_t *c_str_len() const { return mSizeArray; }
271 jsize length() const { return mStringsLength; }
272
273private:
274 JNIEnv *mEnv;
275 jobjectArray mStrings;
276 const char **mCStrings;
277 size_t *mSizeArray;
278 jsize mStringsLength;
279};
280
Jason Samsd19f10d2009-05-22 14:03:28 -0700281// ---------------------------------------------------------------------------
282
Jason Samsffe9f482009-06-01 17:45:53 -0700283static jfieldID gContextId = 0;
284static jfieldID gNativeBitmapID = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700285
286static void _nInit(JNIEnv *_env, jclass _this)
287{
Tim Murrayeff663f2013-11-15 13:08:30 -0800288 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsffe9f482009-06-01 17:45:53 -0700289
290 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000291 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700292}
293
Jason Samsd19f10d2009-05-22 14:03:28 -0700294// ---------------------------------------------------------------------------
295
Miao Wang87e908d2015-03-02 15:15:15 -0800296static void copyWithPadding(void* ptr, void* srcPtr, int mSize, int count) {
297 int sizeBytesPad = mSize * 4;
298 int sizeBytes = mSize * 3;
299 uint8_t *dst = static_cast<uint8_t *>(ptr);
300 uint8_t *src = static_cast<uint8_t *>(srcPtr);
301 for (int i = 0; i < count; i++) {
302 memcpy(dst, src, sizeBytes);
303 dst += sizeBytesPad;
304 src += sizeBytes;
305 }
306}
307
308static void copyWithUnPadding(void* ptr, void* srcPtr, int mSize, int count) {
309 int sizeBytesPad = mSize * 4;
310 int sizeBytes = mSize * 3;
311 uint8_t *dst = static_cast<uint8_t *>(ptr);
312 uint8_t *src = static_cast<uint8_t *>(srcPtr);
313 for (int i = 0; i < count; i++) {
314 memcpy(dst, src, sizeBytes);
315 dst += sizeBytes;
316 src += sizeBytesPad;
317 }
318}
319
320
321// ---------------------------------------------------------------------------
Jason Sams3eaa338e2009-06-10 15:04:38 -0700322static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800323nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700324{
Andreas Gampe67333922014-11-10 20:35:59 -0800325 if (kLogApi) {
326 ALOGD("nContextFinish, con(%p)", (RsContext)con);
327 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800328 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700329}
330
Yang Ni281c3252014-10-24 08:52:24 -0700331static jlong
332nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID,
333 jlong returnValue, jlongArray fieldIDArray,
334 jlongArray valueArray, jintArray sizeArray,
335 jlongArray depClosureArray, jlongArray depFieldIDArray) {
Yang Ni4e90b9b2015-04-30 16:13:54 -0700336 jlong ret = 0;
337
Yang Ni281c3252014-10-24 08:52:24 -0700338 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
339 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
Yang Ni281c3252014-10-24 08:52:24 -0700340 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
341 jsize values_length = _env->GetArrayLength(valueArray);
Yang Ni4e90b9b2015-04-30 16:13:54 -0700342 jint* jSizes = _env->GetIntArrayElements(sizeArray, nullptr);
Yang Ni281c3252014-10-24 08:52:24 -0700343 jsize sizes_length = _env->GetArrayLength(sizeArray);
Yang Ni281c3252014-10-24 08:52:24 -0700344 jlong* jDepClosures =
345 _env->GetLongArrayElements(depClosureArray, nullptr);
346 jsize depClosures_length = _env->GetArrayLength(depClosureArray);
Yang Ni281c3252014-10-24 08:52:24 -0700347 jlong* jDepFieldIDs =
348 _env->GetLongArrayElements(depFieldIDArray, nullptr);
349 jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray);
Yang Ni4e90b9b2015-04-30 16:13:54 -0700350
351 size_t numValues, numDependencies;
352 RsScriptFieldID* fieldIDs;
353 uintptr_t* values;
354 RsClosure* depClosures;
355 RsScriptFieldID* depFieldIDs;
356
357 if (fieldIDs_length != values_length || values_length != sizes_length) {
358 ALOGE("Unmatched field IDs, values, and sizes in closure creation.");
359 goto exit;
360 }
361
362 numValues = (size_t)fieldIDs_length;
363
364 if (depClosures_length != depFieldIDs_length) {
365 ALOGE("Unmatched closures and field IDs for dependencies in closure creation.");
366 goto exit;
367 }
368
369 numDependencies = (size_t)depClosures_length;
370
371 if (numDependencies > numValues) {
372 ALOGE("Unexpected number of dependencies in closure creation");
373 goto exit;
374 }
375
Yang Ni7b2a46f2015-05-05 12:41:19 -0700376 if (numValues > RS_CLOSURE_MAX_NUMBER_ARGS_AND_BINDINGS) {
Yang Ni4e90b9b2015-04-30 16:13:54 -0700377 ALOGE("Too many arguments or globals in closure creation");
378 goto exit;
379 }
380
381 fieldIDs = (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * numValues);
382 if (fieldIDs == nullptr) {
383 goto exit;
384 }
385
386 for (size_t i = 0; i < numValues; i++) {
387 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
388 }
389
390 values = (uintptr_t*)alloca(sizeof(uintptr_t) * numValues);
391 if (values == nullptr) {
392 goto exit;
393 }
394
395 for (size_t i = 0; i < numValues; i++) {
396 values[i] = (uintptr_t)jValues[i];
397 }
398
399 depClosures = (RsClosure*)alloca(sizeof(RsClosure) * numDependencies);
400 if (depClosures == nullptr) {
401 goto exit;
402 }
403
404 for (size_t i = 0; i < numDependencies; i++) {
405 depClosures[i] = (RsClosure)jDepClosures[i];
406 }
407
408 depFieldIDs = (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * numDependencies);
409 if (depFieldIDs == nullptr) {
410 goto exit;
411 }
412
413 for (size_t i = 0; i < numDependencies; i++) {
Yang Ni281c3252014-10-24 08:52:24 -0700414 depFieldIDs[i] = (RsClosure)jDepFieldIDs[i];
415 }
416
Yang Ni4e90b9b2015-04-30 16:13:54 -0700417 ret = (jlong)(uintptr_t)rsClosureCreate(
Yang Ni281c3252014-10-24 08:52:24 -0700418 (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue,
Yang Ni4e90b9b2015-04-30 16:13:54 -0700419 fieldIDs, numValues, values, numValues,
420 (int*)jSizes, numValues,
421 depClosures, numDependencies,
422 depFieldIDs, numDependencies);
423
424exit:
425
426 _env->ReleaseLongArrayElements(depFieldIDArray, jDepFieldIDs, JNI_ABORT);
427 _env->ReleaseLongArrayElements(depClosureArray, jDepClosures, JNI_ABORT);
428 _env->ReleaseIntArrayElements (sizeArray, jSizes, JNI_ABORT);
429 _env->ReleaseLongArrayElements(valueArray, jValues, JNI_ABORT);
430 _env->ReleaseLongArrayElements(fieldIDArray, jFieldIDs, JNI_ABORT);
431
432 return ret;
Yang Ni281c3252014-10-24 08:52:24 -0700433}
434
Yang Nibe392ad2015-01-23 17:16:02 -0800435static jlong
436nInvokeClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong invokeID,
437 jbyteArray paramArray, jlongArray fieldIDArray, jlongArray valueArray,
438 jintArray sizeArray) {
Yang Ni4e90b9b2015-04-30 16:13:54 -0700439 jlong ret = 0;
440
Yang Nibe392ad2015-01-23 17:16:02 -0800441 jbyte* jParams = _env->GetByteArrayElements(paramArray, nullptr);
442 jsize jParamLength = _env->GetArrayLength(paramArray);
Yang Nibe392ad2015-01-23 17:16:02 -0800443 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
444 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
Yang Ni4e90b9b2015-04-30 16:13:54 -0700445 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
446 jsize values_length = _env->GetArrayLength(valueArray);
447 jint* jSizes = _env->GetIntArrayElements(sizeArray, nullptr);
448 jsize sizes_length = _env->GetArrayLength(sizeArray);
449
450 size_t numValues;
451 RsScriptFieldID* fieldIDs;
452 uintptr_t* values;
453
454 if (fieldIDs_length != values_length || values_length != sizes_length) {
455 ALOGE("Unmatched field IDs, values, and sizes in closure creation.");
456 goto exit;
457 }
458
459 numValues = (size_t) fieldIDs_length;
460
Yang Ni7b2a46f2015-05-05 12:41:19 -0700461 if (numValues > RS_CLOSURE_MAX_NUMBER_ARGS_AND_BINDINGS) {
Yang Ni4e90b9b2015-04-30 16:13:54 -0700462 ALOGE("Too many arguments or globals in closure creation");
463 goto exit;
464 }
465
466 fieldIDs = (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * numValues);
467 if (fieldIDs == nullptr) {
468 goto exit;
469 }
470
471 for (size_t i = 0; i< numValues; i++) {
Yang Nibe392ad2015-01-23 17:16:02 -0800472 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
473 }
474
Yang Ni4e90b9b2015-04-30 16:13:54 -0700475 values = (uintptr_t*)alloca(sizeof(uintptr_t) * numValues);
476 if (values == nullptr) {
477 goto exit;
478 }
479
480 for (size_t i = 0; i < numValues; i++) {
Yang Nibe392ad2015-01-23 17:16:02 -0800481 values[i] = (uintptr_t)jValues[i];
482 }
483
Yang Ni4e90b9b2015-04-30 16:13:54 -0700484 ret = (jlong)(uintptr_t)rsInvokeClosureCreate(
Yang Nibe392ad2015-01-23 17:16:02 -0800485 (RsContext)con, (RsScriptInvokeID)invokeID, jParams, jParamLength,
Yang Ni4e90b9b2015-04-30 16:13:54 -0700486 fieldIDs, numValues, values, numValues,
487 (int*)jSizes, numValues);
488
489exit:
490
491 _env->ReleaseIntArrayElements (sizeArray, jSizes, JNI_ABORT);
492 _env->ReleaseLongArrayElements(valueArray, jValues, JNI_ABORT);
493 _env->ReleaseLongArrayElements(fieldIDArray, jFieldIDs, JNI_ABORT);
494 _env->ReleaseByteArrayElements(paramArray, jParams, JNI_ABORT);
495
496 return ret;
Yang Nibe392ad2015-01-23 17:16:02 -0800497}
498
Yang Ni281c3252014-10-24 08:52:24 -0700499static void
500nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
501 jint index, jlong value, jint size) {
502 rsClosureSetArg((RsContext)con, (RsClosure)closureID, (uint32_t)index,
503 (uintptr_t)value, (size_t)size);
504}
505
506static void
507nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
508 jlong fieldID, jlong value, jint size) {
509 rsClosureSetGlobal((RsContext)con, (RsClosure)closureID,
510 (RsScriptFieldID)fieldID, (uintptr_t)value, (size_t)size);
511}
512
513static long
Yang Ni35be56c2015-04-02 17:47:56 -0700514nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con, jstring name,
Yang Niebf63402015-01-16 11:06:26 -0800515 jstring cacheDir, jlongArray closureArray) {
Yang Ni4e90b9b2015-04-30 16:13:54 -0700516 jlong ret = 0;
517
Yang Ni35be56c2015-04-02 17:47:56 -0700518 AutoJavaStringToUTF8 nameUTF(_env, name);
Yang Niebf63402015-01-16 11:06:26 -0800519 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
520
Yang Ni281c3252014-10-24 08:52:24 -0700521 jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr);
522 jsize numClosures = _env->GetArrayLength(closureArray);
Yang Ni4e90b9b2015-04-30 16:13:54 -0700523
524 RsClosure* closures;
525
Yang Ni7b2a46f2015-05-05 12:41:19 -0700526 if (numClosures > (jsize) RS_SCRIPT_GROUP_MAX_NUMBER_CLOSURES) {
Yang Ni4e90b9b2015-04-30 16:13:54 -0700527 ALOGE("Too many closures in script group");
528 goto exit;
529 }
530
531 closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures);
532 if (closures == nullptr) {
533 goto exit;
534 }
535
Yang Ni281c3252014-10-24 08:52:24 -0700536 for (int i = 0; i < numClosures; i++) {
537 closures[i] = (RsClosure)jClosures[i];
538 }
539
Yang Ni4e90b9b2015-04-30 16:13:54 -0700540 ret = (jlong)(uintptr_t)rsScriptGroup2Create(
Yang Ni35be56c2015-04-02 17:47:56 -0700541 (RsContext)con, nameUTF.c_str(), nameUTF.length(),
542 cacheDirUTF.c_str(), cacheDirUTF.length(),
Yang Niebf63402015-01-16 11:06:26 -0800543 closures, numClosures);
Yang Ni4e90b9b2015-04-30 16:13:54 -0700544
545exit:
546
547 _env->ReleaseLongArrayElements(closureArray, jClosures, JNI_ABORT);
548
549 return ret;
Yang Ni281c3252014-10-24 08:52:24 -0700550}
551
552static void
553nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) {
554 rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID);
555}
556
Jason Sams96ed4cf2010-06-15 12:15:57 -0700557static void
Tim Murray25207df2015-01-12 16:47:56 -0800558nScriptIntrinsicBLAS_Single(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
559 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
560 jfloat alpha, jlong A, jlong B, jfloat beta, jlong C, jint incX, jint incY,
561 jint KL, jint KU) {
562 RsBlasCall call;
563 memset(&call, 0, sizeof(call));
564 call.func = (RsBlasFunction)func;
565 call.transA = (RsBlasTranspose)TransA;
566 call.transB = (RsBlasTranspose)TransB;
567 call.side = (RsBlasSide)Side;
568 call.uplo = (RsBlasUplo)Uplo;
569 call.diag = (RsBlasDiag)Diag;
570 call.M = M;
571 call.N = N;
572 call.K = K;
573 call.alpha.f = alpha;
574 call.beta.f = beta;
575 call.incX = incX;
576 call.incY = incY;
577 call.KL = KL;
578 call.KU = KU;
579
580 RsAllocation in_allocs[3];
581 in_allocs[0] = (RsAllocation)A;
582 in_allocs[1] = (RsAllocation)B;
583 in_allocs[2] = (RsAllocation)C;
584
585 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
586 in_allocs, sizeof(in_allocs), nullptr,
587 &call, sizeof(call), nullptr, 0);
588}
589
590static void
591nScriptIntrinsicBLAS_Double(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
592 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
593 jdouble alpha, jlong A, jlong B, jdouble beta, jlong C, jint incX, jint incY,
594 jint KL, jint KU) {
595 RsBlasCall call;
596 memset(&call, 0, sizeof(call));
597 call.func = (RsBlasFunction)func;
598 call.transA = (RsBlasTranspose)TransA;
599 call.transB = (RsBlasTranspose)TransB;
600 call.side = (RsBlasSide)Side;
601 call.uplo = (RsBlasUplo)Uplo;
602 call.diag = (RsBlasDiag)Diag;
603 call.M = M;
604 call.N = N;
605 call.K = K;
606 call.alpha.d = alpha;
607 call.beta.d = beta;
608 call.incX = incX;
609 call.incY = incY;
610 call.KL = KL;
611 call.KU = KU;
612
613 RsAllocation in_allocs[3];
614 in_allocs[0] = (RsAllocation)A;
615 in_allocs[1] = (RsAllocation)B;
616 in_allocs[2] = (RsAllocation)C;
617
618 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
Miao Wang0b34f2a2015-09-30 15:38:07 -0700619 in_allocs, NELEM(in_allocs), nullptr,
Tim Murray25207df2015-01-12 16:47:56 -0800620 &call, sizeof(call), nullptr, 0);
621}
622
623static void
624nScriptIntrinsicBLAS_Complex(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
625 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
626 jfloat alphaX, jfloat alphaY, jlong A, jlong B, jfloat betaX,
627 jfloat betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
628 RsBlasCall call;
629 memset(&call, 0, sizeof(call));
630 call.func = (RsBlasFunction)func;
631 call.transA = (RsBlasTranspose)TransA;
632 call.transB = (RsBlasTranspose)TransB;
633 call.side = (RsBlasSide)Side;
634 call.uplo = (RsBlasUplo)Uplo;
635 call.diag = (RsBlasDiag)Diag;
636 call.M = M;
637 call.N = N;
638 call.K = K;
639 call.alpha.c.r = alphaX;
640 call.alpha.c.i = alphaY;
641 call.beta.c.r = betaX;
Miao Wange8cb7b32015-04-30 13:44:49 -0700642 call.beta.c.i = betaY;
Tim Murray25207df2015-01-12 16:47:56 -0800643 call.incX = incX;
644 call.incY = incY;
645 call.KL = KL;
646 call.KU = KU;
647
648 RsAllocation in_allocs[3];
649 in_allocs[0] = (RsAllocation)A;
650 in_allocs[1] = (RsAllocation)B;
651 in_allocs[2] = (RsAllocation)C;
652
653 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
Miao Wang0b34f2a2015-09-30 15:38:07 -0700654 in_allocs, NELEM(in_allocs), nullptr,
Tim Murray25207df2015-01-12 16:47:56 -0800655 &call, sizeof(call), nullptr, 0);
656}
657
658static void
659nScriptIntrinsicBLAS_Z(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA,
660 jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K,
661 jdouble alphaX, jdouble alphaY, jlong A, jlong B, jdouble betaX,
662 jdouble betaY, jlong C, jint incX, jint incY, jint KL, jint KU) {
663 RsBlasCall call;
664 memset(&call, 0, sizeof(call));
665 call.func = (RsBlasFunction)func;
666 call.transA = (RsBlasTranspose)TransA;
667 call.transB = (RsBlasTranspose)TransB;
668 call.side = (RsBlasSide)Side;
669 call.uplo = (RsBlasUplo)Uplo;
670 call.diag = (RsBlasDiag)Diag;
671 call.M = M;
672 call.N = N;
673 call.K = K;
674 call.alpha.z.r = alphaX;
675 call.alpha.z.i = alphaY;
676 call.beta.z.r = betaX;
Miao Wange8cb7b32015-04-30 13:44:49 -0700677 call.beta.z.i = betaY;
Tim Murray25207df2015-01-12 16:47:56 -0800678 call.incX = incX;
679 call.incY = incY;
680 call.KL = KL;
681 call.KU = KU;
682
683 RsAllocation in_allocs[3];
684 in_allocs[0] = (RsAllocation)A;
685 in_allocs[1] = (RsAllocation)B;
686 in_allocs[2] = (RsAllocation)C;
687
688 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
Miao Wang0b34f2a2015-09-30 15:38:07 -0700689 in_allocs, NELEM(in_allocs), nullptr,
Tim Murray25207df2015-01-12 16:47:56 -0800690 &call, sizeof(call), nullptr, 0);
691}
692
693
694static void
Tim Murray9cb16a22015-04-01 11:07:16 -0700695nScriptIntrinsicBLAS_BNNM(JNIEnv *_env, jobject _this, jlong con, jlong id, jint M, jint N, jint K,
696 jlong A, jint a_offset, jlong B, jint b_offset, jlong C, jint c_offset,
697 jint c_mult_int) {
698 RsBlasCall call;
699 memset(&call, 0, sizeof(call));
700 call.func = RsBlas_bnnm;
701 call.M = M;
702 call.N = N;
703 call.K = K;
Miao Wang25148062015-06-29 17:43:03 -0700704 call.a_offset = a_offset & 0xFF;
705 call.b_offset = b_offset & 0xFF;
Tim Murray9cb16a22015-04-01 11:07:16 -0700706 call.c_offset = c_offset;
707 call.c_mult_int = c_mult_int;
708
709 RsAllocation in_allocs[3];
710 in_allocs[0] = (RsAllocation)A;
711 in_allocs[1] = (RsAllocation)B;
712 in_allocs[2] = (RsAllocation)C;
713
714 rsScriptForEachMulti((RsContext)con, (RsScript)id, 0,
Miao Wang0b34f2a2015-09-30 15:38:07 -0700715 in_allocs, NELEM(in_allocs), nullptr,
Tim Murray9cb16a22015-04-01 11:07:16 -0700716 &call, sizeof(call), nullptr, 0);
717}
718
719
720static void
Tim Murray460a0492013-11-19 12:45:54 -0800721nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700722{
Andreas Gampe67333922014-11-10 20:35:59 -0800723 if (kLogApi) {
724 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
725 }
Jason Sams3eaa338e2009-06-10 15:04:38 -0700726 jint len = _env->GetArrayLength(str);
727 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800728 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700729 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
730}
731
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700732static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800733nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700734{
Andreas Gampe67333922014-11-10 20:35:59 -0800735 if (kLogApi) {
736 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
737 }
Chris Wailes488230c32014-08-14 11:22:40 -0700738 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800739 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700740 if(name == nullptr || strlen(name) == 0) {
741 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700742 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700743 return _env->NewStringUTF(name);
744}
745
Jason Sams7ce033d2009-08-18 14:14:24 -0700746static void
Tim Murray460a0492013-11-19 12:45:54 -0800747nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700748{
Andreas Gampe67333922014-11-10 20:35:59 -0800749 if (kLogApi) {
750 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
751 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800752 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700753}
754
Jason Sams3eaa338e2009-06-10 15:04:38 -0700755// ---------------------------------------------------------------------------
756
Tim Murrayeff663f2013-11-15 13:08:30 -0800757static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700758nDeviceCreate(JNIEnv *_env, jobject _this)
759{
Andreas Gampe67333922014-11-10 20:35:59 -0800760 if (kLogApi) {
761 ALOGD("nDeviceCreate");
762 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700763 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700764}
765
766static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800767nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700768{
Andreas Gampe67333922014-11-10 20:35:59 -0800769 if (kLogApi) {
770 ALOGD("nDeviceDestroy");
771 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700772 return rsDeviceDestroy((RsDevice)dev);
773}
774
Jason Samsebfb4362009-09-23 13:57:02 -0700775static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800776nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700777{
Andreas Gampe67333922014-11-10 20:35:59 -0800778 if (kLogApi) {
779 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
780 }
Jason Samsebfb4362009-09-23 13:57:02 -0700781 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
782}
783
Tim Murrayeff663f2013-11-15 13:08:30 -0800784static jlong
Jason Sams81cd2b12014-12-02 12:36:43 -0800785nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700786{
Andreas Gampe67333922014-11-10 20:35:59 -0800787 if (kLogApi) {
788 ALOGD("nContextCreate");
789 }
Jason Sams81cd2b12014-12-02 12:36:43 -0800790 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags);
Jason Sams704ff642010-02-09 16:05:07 -0800791}
792
Tim Murrayeff663f2013-11-15 13:08:30 -0800793static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800794nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000795 jint colorMin, jint colorPref,
796 jint alphaMin, jint alphaPref,
797 jint depthMin, jint depthPref,
798 jint stencilMin, jint stencilPref,
799 jint samplesMin, jint samplesPref, jfloat samplesQ,
800 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800801{
Jason Sams11c8af92010-10-13 15:31:10 -0700802 RsSurfaceConfig sc;
803 sc.alphaMin = alphaMin;
804 sc.alphaPref = alphaPref;
805 sc.colorMin = colorMin;
806 sc.colorPref = colorPref;
807 sc.depthMin = depthMin;
808 sc.depthPref = depthPref;
809 sc.samplesMin = samplesMin;
810 sc.samplesPref = samplesPref;
811 sc.samplesQ = samplesQ;
812
Andreas Gampe67333922014-11-10 20:35:59 -0800813 if (kLogApi) {
814 ALOGD("nContextCreateGL");
815 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700816 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700817}
818
819static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800820nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800821{
Andreas Gampe67333922014-11-10 20:35:59 -0800822 if (kLogApi) {
823 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
824 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800825 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800826}
827
Tim Murray47f31582015-04-07 15:43:24 -0700828static void
829nContextSetCacheDir(JNIEnv *_env, jobject _this, jlong con, jstring cacheDir)
830{
831 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
832
833 if (kLogApi) {
834 ALOGD("ContextSetCacheDir, con(%p), cacheDir(%s)", (RsContext)con, cacheDirUTF.c_str());
835 }
836 rsContextSetCacheDir((RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length());
837}
838
Jason Sams7d787b42009-11-15 12:14:26 -0800839
840
841static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800842nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800843{
Andreas Gampe67333922014-11-10 20:35:59 -0800844 if (kLogApi) {
845 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
846 width, height, (Surface *)wnd);
847 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800848
Chris Wailes488230c32014-08-14 11:22:40 -0700849 ANativeWindow * window = nullptr;
850 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800851
852 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700853 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800854 }
855
Tim Murrayeff663f2013-11-15 13:08:30 -0800856 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800857}
858
859static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800860nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700861{
Andreas Gampe67333922014-11-10 20:35:59 -0800862 if (kLogApi) {
863 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
864 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800865 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700866}
867
Jason Sams715333b2009-11-17 17:26:46 -0800868static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800869nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800870{
Andreas Gampe67333922014-11-10 20:35:59 -0800871 if (kLogApi) {
872 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
873 }
Jason Sams715333b2009-11-17 17:26:46 -0800874 rsContextDump((RsContext)con, bits);
875}
Jason Samsd19f10d2009-05-22 14:03:28 -0700876
877static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800878nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700879{
Andreas Gampe67333922014-11-10 20:35:59 -0800880 if (kLogApi) {
881 ALOGD("nContextPause, con(%p)", (RsContext)con);
882 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800883 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700884}
885
886static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800887nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700888{
Andreas Gampe67333922014-11-10 20:35:59 -0800889 if (kLogApi) {
890 ALOGD("nContextResume, con(%p)", (RsContext)con);
891 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800892 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700893}
894
Jason Sams1c415172010-11-08 17:06:46 -0800895
896static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800897nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800898{
Andreas Gampe67333922014-11-10 20:35:59 -0800899 if (kLogApi) {
900 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
901 }
Jason Sams1c415172010-11-08 17:06:46 -0800902 char buf[1024];
903
904 size_t receiveLen;
905 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800906 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700907 buf, sizeof(buf),
908 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700909 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800910 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100911 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800912 }
913 return _env->NewStringUTF(buf);
914}
915
Jason Samsedbfabd2011-05-17 15:01:29 -0700916static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800917nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700918{
Jason Sams516c3192009-10-06 13:58:47 -0700919 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800920 if (kLogApi) {
921 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
922 }
Chris Wailes488230c32014-08-14 11:22:40 -0700923 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700924 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800925 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800926 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700927 ptr, len * 4,
928 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700929 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700930 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100931 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700932 }
933 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000934 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800935}
936
937static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800938nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800939{
Andreas Gampe67333922014-11-10 20:35:59 -0800940 if (kLogApi) {
941 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
942 }
Chris Wailes488230c32014-08-14 11:22:40 -0700943 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800944 size_t receiveLen;
945 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800946 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700947 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800948 auxDataPtr[0] = (jint)subID;
949 auxDataPtr[1] = (jint)receiveLen;
950 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000951 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700952}
953
Tim Murrayeff663f2013-11-15 13:08:30 -0800954static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700955{
Andreas Gampe67333922014-11-10 20:35:59 -0800956 if (kLogApi) {
957 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
958 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800959 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700960}
961
Tim Murrayeff663f2013-11-15 13:08:30 -0800962static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700963{
Andreas Gampe67333922014-11-10 20:35:59 -0800964 if (kLogApi) {
965 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
966 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800967 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700968}
969
Jason Sams455d6442013-02-05 19:20:18 -0800970static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800971nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800972{
Chris Wailes488230c32014-08-14 11:22:40 -0700973 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800974 jint len = 0;
975 if (data) {
976 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700977 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800978 }
Andreas Gampe67333922014-11-10 20:35:59 -0800979 if (kLogApi) {
980 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
981 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800982 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800983 if (data) {
984 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
985 }
986}
987
988
Jason Sams516c3192009-10-06 13:58:47 -0700989
Tim Murray460a0492013-11-19 12:45:54 -0800990static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800991nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
992 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700993{
Andreas Gampe67333922014-11-10 20:35:59 -0800994 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100995 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con,
Andreas Gampe67333922014-11-10 20:35:59 -0800996 type, kind, norm, size);
997 }
998 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
999 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -07001000}
1001
Tim Murray460a0492013-11-19 12:45:54 -08001002static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001003nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +00001004 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -07001005{
Jason Sams718cd1f2009-12-23 14:35:29 -08001006 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -08001007 if (kLogApi) {
1008 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
1009 }
Jason Sams718cd1f2009-12-23 14:35:29 -08001010
Chris Wailes488230c32014-08-14 11:22:40 -07001011 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
1012 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001013
1014 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
1015 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
1016
1017 for(int i = 0; i < fieldCount; i ++) {
1018 ids[i] = (RsElement)jIds[i];
1019 arraySizes[i] = (uint32_t)jArraySizes[i];
1020 }
Jason Sams718cd1f2009-12-23 14:35:29 -08001021
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001022 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
1023
1024 const char **nameArray = names.c_str();
1025 size_t *sizeArray = names.c_str_len();
1026
Tim Murray3aa89c12014-08-18 17:51:22 -07001027 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001028 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -07001029 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001030 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001031
Ashok Bhat98071552014-02-12 09:54:43 +00001032 free(ids);
1033 free(arraySizes);
1034 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
1035 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
1036
Tim Murray3aa89c12014-08-18 17:51:22 -07001037 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -07001038}
1039
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001040static void
Tim Murray460a0492013-11-19 12:45:54 -08001041nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001042{
1043 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -08001044 if (kLogApi) {
1045 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
1046 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001047
1048 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
1049 assert(dataSize == 5);
1050
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001051 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -08001052 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001053
1054 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +00001055 const jint data = (jint)elementData[i];
1056 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001057 }
1058}
1059
1060
1061static void
Tim Murray460a0492013-11-19 12:45:54 -08001062nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +00001063 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001064 jobjectArray _names,
1065 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001066{
Ashok Bhat98071552014-02-12 09:54:43 +00001067 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -08001068 if (kLogApi) {
1069 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
1070 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001071
Ashok Bhat98071552014-02-12 09:54:43 +00001072 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
1073 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001074 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001075
Andreas Gampe67333922014-11-10 20:35:59 -08001076 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
1077 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001078
Ashok Bhat98071552014-02-12 09:54:43 +00001079 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001080 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001081 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001082 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +00001083 _env->SetLongArrayRegion(_IDs, i, 1, &id);
1084 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001085 }
1086
1087 free(ids);
1088 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001089 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001090}
1091
Jason Samsd19f10d2009-05-22 14:03:28 -07001092// -----------------------------------
1093
Tim Murray460a0492013-11-19 12:45:54 -08001094static jlong
1095nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -08001096 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -07001097{
Andreas Gampe67333922014-11-10 20:35:59 -08001098 if (kLogApi) {
1099 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 +01001100 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv);
Andreas Gampe67333922014-11-10 20:35:59 -08001101 }
Jason Sams3b9c52a2010-10-14 17:48:46 -07001102
Andreas Gampe67333922014-11-10 20:35:59 -08001103 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
1104 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -07001105}
1106
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001107static void
Ashok Bhat98071552014-02-12 09:54:43 +00001108nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001109{
1110 // We are packing 6 items: mDimX; mDimY; mDimZ;
1111 // mDimLOD; mDimFaces; mElement; into typeData
1112 int elementCount = _env->GetArrayLength(_typeData);
1113
1114 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001115 if (kLogApi) {
1116 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
1117 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001118
Ashok Bhat98071552014-02-12 09:54:43 +00001119 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -08001120 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001121
1122 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001123 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001124 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001125 }
1126}
1127
Jason Samsd19f10d2009-05-22 14:03:28 -07001128// -----------------------------------
1129
Tim Murray460a0492013-11-19 12:45:54 -08001130static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001131nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
1132 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -07001133{
Andreas Gampe67333922014-11-10 20:35:59 -08001134 if (kLogApi) {
1135 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
1136 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
1137 }
1138 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
1139 (RsAllocationMipmapControl)mips,
1140 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -07001141}
1142
Jason Samsd19f10d2009-05-22 14:03:28 -07001143static void
Tim Murray460a0492013-11-19 12:45:54 -08001144nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -08001145{
Andreas Gampe67333922014-11-10 20:35:59 -08001146 if (kLogApi) {
1147 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
1148 bits);
1149 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001150 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -08001151}
1152
Jason Sams72226e02013-02-22 12:45:54 -08001153static jobject
Tim Murray460a0492013-11-19 12:45:54 -08001154nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -08001155{
Andreas Gampe67333922014-11-10 20:35:59 -08001156 if (kLogApi) {
1157 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1158 }
Jason Sams615e7ce2012-01-13 14:01:20 -08001159
Andreas Gampe67333922014-11-10 20:35:59 -08001160 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
1161 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -08001162 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -07001163 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001164
Jason Sams72226e02013-02-22 12:45:54 -08001165 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
1166 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001167}
1168
1169static void
Tim Murray460a0492013-11-19 12:45:54 -08001170nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -08001171{
Andreas Gampe67333922014-11-10 20:35:59 -08001172 if (kLogApi) {
1173 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
1174 (RsAllocation)alloc, (Surface *)sur);
1175 }
Jason Sams163766c2012-02-15 12:04:24 -08001176
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001177 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -08001178 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -07001179 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -08001180 }
1181
Andreas Gampe67333922014-11-10 20:35:59 -08001182 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
1183 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -08001184}
1185
1186static void
Tim Murray460a0492013-11-19 12:45:54 -08001187nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001188{
Andreas Gampe67333922014-11-10 20:35:59 -08001189 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001190 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001191 }
Tim Murray460a0492013-11-19 12:45:54 -08001192 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001193}
1194
1195static void
Tim Murray460a0492013-11-19 12:45:54 -08001196nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -08001197{
Andreas Gampe67333922014-11-10 20:35:59 -08001198 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001199 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -08001200 }
Tim Murray460a0492013-11-19 12:45:54 -08001201 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -08001202}
1203
1204
1205static void
Tim Murray460a0492013-11-19 12:45:54 -08001206nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -08001207{
Andreas Gampe67333922014-11-10 20:35:59 -08001208 if (kLogApi) {
1209 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
1210 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001211 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -08001212}
1213
Tim Murray460a0492013-11-19 12:45:54 -08001214static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001215nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1216 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -07001217{
Jason Samsffe9f482009-06-01 17:45:53 -07001218 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001219 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -07001220 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -07001221
Jason Sams5476b452010-12-08 16:14:36 -08001222 bitmap.lockPixels();
1223 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001224 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001225 (RsType)type, (RsAllocationMipmapControl)mip,
1226 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001227 bitmap.unlockPixels();
1228 return id;
Jason Samsffe9f482009-06-01 17:45:53 -07001229}
Jason Samsfe08d992009-05-27 14:45:32 -07001230
Tim Murray460a0492013-11-19 12:45:54 -08001231static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001232nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
1233 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -08001234{
1235 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001236 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -08001237 const SkBitmap& bitmap(*nativeBitmap);
1238
1239 bitmap.lockPixels();
1240 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001241 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -08001242 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +00001243 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -08001244 bitmap.unlockPixels();
1245 return id;
1246}
1247
Tim Murray460a0492013-11-19 12:45:54 -08001248static jlong
Andreas Gampe67333922014-11-10 20:35:59 -08001249nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
1250 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001251{
1252 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001253 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001254 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001255
Jason Sams5476b452010-12-08 16:14:36 -08001256 bitmap.lockPixels();
1257 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -07001258 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -07001259 (RsType)type, (RsAllocationMipmapControl)mip,
1260 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -08001261 bitmap.unlockPixels();
1262 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -08001263}
1264
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001265static void
Tim Murray460a0492013-11-19 12:45:54 -08001266nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001267{
1268 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001269 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001270 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -08001271 int w = bitmap.width();
1272 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001273
Jason Sams4ef66502010-12-10 16:03:15 -08001274 bitmap.lockPixels();
1275 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001276 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001277 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -08001278 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -08001279 bitmap.unlockPixels();
1280}
1281
1282static void
Tim Murray460a0492013-11-19 12:45:54 -08001283nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -08001284{
1285 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001286 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -08001287 const SkBitmap& bitmap(*nativeBitmap);
1288
1289 bitmap.lockPixels();
1290 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -08001291 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -08001292 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -07001293 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -07001294}
1295
Stephen Hines414fa2c2014-04-17 01:02:42 -07001296// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -07001297static void
Tim Murray460a0492013-11-19 12:45:54 -08001298nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001299 jint count, jobject data, jint sizeBytes, jint dataType, jint mSize,
1300 jboolean usePadding)
Jason Samsd19f10d2009-05-22 14:03:28 -07001301{
Jason Samse729a942013-11-06 11:22:02 -08001302 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001303 if (kLogApi) {
1304 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1305 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
1306 dataType);
1307 }
Miao Wang87e908d2015-03-02 15:15:15 -08001308 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true,
1309 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -07001310}
1311
1312static void
Miao Wangc8e237e2015-02-20 18:36:32 -08001313nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1314 jint xoff, jint yoff, jint zoff,
1315 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -07001316{
1317 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -08001318 if (kLogApi) {
Miao Wangc8e237e2015-02-20 18:36:32 -08001319 ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1320 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
Andreas Gampe67333922014-11-10 20:35:59 -08001321 sizeBytes);
1322 }
Chris Wailes488230c32014-08-14 11:22:40 -07001323 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Miao Wangc8e237e2015-02-20 18:36:32 -08001324 rsAllocationElementData((RsContext)con, (RsAllocation)alloc,
1325 xoff, yoff, zoff,
1326 lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -07001327 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1328}
1329
Miao Wangc8e237e2015-02-20 18:36:32 -08001330
Stephen Hines414fa2c2014-04-17 01:02:42 -07001331// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -07001332static void
Tim Murray460a0492013-11-19 12:45:54 -08001333nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001334 jint w, jint h, jobject data, jint sizeBytes, jint dataType, jint mSize,
1335 jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001336{
Jason Samse729a942013-11-06 11:22:02 -08001337 RsAllocation *alloc = (RsAllocation *)_alloc;
1338 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001339 if (kLogApi) {
1340 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1341 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1342 }
Miao Wang87e908d2015-03-02 15:15:15 -08001343 int count = w * h;
1344 PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true,
1345 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -07001346}
1347
Stephen Hines414fa2c2014-04-17 01:02:42 -07001348// Copies from the Allocation pointed to by srcAlloc into the Allocation
1349// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -07001350static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001351nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001352 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001353 jint dstMip, jint dstFace,
1354 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -08001355 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001356 jint srcMip, jint srcFace)
1357{
Andreas Gampe67333922014-11-10 20:35:59 -08001358 if (kLogApi) {
1359 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1360 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
1361 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
1362 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
1363 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
1364 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001365
Tim Murrayeff663f2013-11-15 13:08:30 -08001366 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001367 (RsAllocation)dstAlloc,
1368 dstXoff, dstYoff,
1369 dstMip, dstFace,
1370 width, height,
1371 (RsAllocation)srcAlloc,
1372 srcXoff, srcYoff,
1373 srcMip, srcFace);
1374}
1375
Stephen Hines414fa2c2014-04-17 01:02:42 -07001376// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001377static void
Tim Murray460a0492013-11-19 12:45:54 -08001378nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001379 jint w, jint h, jint d, jobject data, jint sizeBytes, jint dataType,
1380 jint mSize, jboolean usePadding)
Jason Samsb05d6892013-04-09 15:59:24 -07001381{
Jason Samse729a942013-11-06 11:22:02 -08001382 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001383 if (kLogApi) {
1384 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1385 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1386 lod, w, h, d, sizeBytes);
1387 }
Miao Wang87e908d2015-03-02 15:15:15 -08001388 int count = w * h * d;
1389 PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true,
1390 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -07001391}
1392
Stephen Hines414fa2c2014-04-17 01:02:42 -07001393// Copies from the Allocation pointed to by srcAlloc into the Allocation
1394// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -07001395static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001396nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001397 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001398 jint dstMip,
1399 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -08001400 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -07001401 jint srcMip)
1402{
Andreas Gampe67333922014-11-10 20:35:59 -08001403 if (kLogApi) {
1404 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
1405 " dstMip(%i), width(%i), height(%i),"
1406 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
1407 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
1408 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
1409 }
Jason Samsb05d6892013-04-09 15:59:24 -07001410
Tim Murrayeff663f2013-11-15 13:08:30 -08001411 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -07001412 (RsAllocation)dstAlloc,
1413 dstXoff, dstYoff, dstZoff, dstMip,
1414 width, height, depth,
1415 (RsAllocation)srcAlloc,
1416 srcXoff, srcYoff, srcZoff, srcMip);
1417}
1418
Jason Sams21659ac2013-11-06 15:08:07 -08001419
Stephen Hines414fa2c2014-04-17 01:02:42 -07001420// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -07001421static void
Miao Wang87e908d2015-03-02 15:15:15 -08001422nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, jint dataType,
1423 jint mSize, jboolean usePadding)
Jason Sams40a29e82009-08-10 14:55:26 -07001424{
Jason Sams21659ac2013-11-06 15:08:07 -08001425 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001426 if (kLogApi) {
1427 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
1428 }
Miao Wang87e908d2015-03-02 15:15:15 -08001429 int count = 0;
1430 PER_ARRAY_TYPE(0, rsAllocationRead, false,
1431 (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -07001432}
1433
Stephen Hines414fa2c2014-04-17 01:02:42 -07001434// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -07001435static void
Tim Murray460a0492013-11-19 12:45:54 -08001436nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001437 jint count, jobject data, jint sizeBytes, jint dataType,
1438 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001439{
Jason Sams21659ac2013-11-06 15:08:07 -08001440 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -08001441 if (kLogApi) {
1442 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
1443 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
1444 }
Miao Wang87e908d2015-03-02 15:15:15 -08001445 PER_ARRAY_TYPE(0, rsAllocation1DRead, false,
1446 (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -08001447}
1448
Miao Wangc8e237e2015-02-20 18:36:32 -08001449// Copies from the Element in the Allocation pointed to by _alloc into the Java array data.
1450static void
Miao Wang45cec0a2015-03-04 16:40:21 -08001451nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
Miao Wangc8e237e2015-02-20 18:36:32 -08001452 jint xoff, jint yoff, jint zoff,
Miao Wang45cec0a2015-03-04 16:40:21 -08001453 jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Miao Wangc8e237e2015-02-20 18:36:32 -08001454{
Miao Wang45cec0a2015-03-04 16:40:21 -08001455 jint len = _env->GetArrayLength(data);
Miao Wangc8e237e2015-02-20 18:36:32 -08001456 if (kLogApi) {
Miao Wang45cec0a2015-03-04 16:40:21 -08001457 ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), "
1458 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len,
1459 sizeBytes);
Miao Wangc8e237e2015-02-20 18:36:32 -08001460 }
Miao Wang45cec0a2015-03-04 16:40:21 -08001461 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
1462 rsAllocationElementRead((RsContext)con, (RsAllocation)alloc,
1463 xoff, yoff, zoff,
Jason Samsa7e25092015-03-11 11:00:00 -07001464 lod, ptr, sizeBytes, compIdx);
Miao Wangbfa5e652015-05-04 15:29:25 -07001465 _env->ReleaseByteArrayElements(data, ptr, 0);
Miao Wangc8e237e2015-02-20 18:36:32 -08001466}
1467
Stephen Hines414fa2c2014-04-17 01:02:42 -07001468// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -08001469static void
Tim Murray460a0492013-11-19 12:45:54 -08001470nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Miao Wang87e908d2015-03-02 15:15:15 -08001471 jint w, jint h, jobject data, jint sizeBytes, jint dataType,
1472 jint mSize, jboolean usePadding)
Jason Samsfb9f82c2011-01-12 14:53:25 -08001473{
Jason Sams21659ac2013-11-06 15:08:07 -08001474 RsAllocation *alloc = (RsAllocation *)_alloc;
1475 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -08001476 if (kLogApi) {
1477 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
1478 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
1479 }
Miao Wang87e908d2015-03-02 15:15:15 -08001480 int count = w * h;
1481 PER_ARRAY_TYPE(0, rsAllocation2DRead, false,
1482 (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -07001483}
Miao Wang87e908d2015-03-02 15:15:15 -08001484
Miao Wangc8e237e2015-02-20 18:36:32 -08001485// Copies from the Allocation pointed to by _alloc into the Java object data.
1486static void
1487nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Miao Wang87e908d2015-03-02 15:15:15 -08001488 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType,
1489 jint mSize, jboolean usePadding)
Miao Wangc8e237e2015-02-20 18:36:32 -08001490{
1491 RsAllocation *alloc = (RsAllocation *)_alloc;
1492 if (kLogApi) {
1493 ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
1494 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
1495 lod, w, h, d, sizeBytes);
1496 }
Miao Wang87e908d2015-03-02 15:15:15 -08001497 int count = w * h * d;
1498 PER_ARRAY_TYPE(nullptr, rsAllocation3DRead, false,
1499 (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Miao Wangc8e237e2015-02-20 18:36:32 -08001500}
Jason Samsd19f10d2009-05-22 14:03:28 -07001501
Tim Murray460a0492013-11-19 12:45:54 -08001502static jlong
1503nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001504{
Andreas Gampe67333922014-11-10 20:35:59 -08001505 if (kLogApi) {
1506 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1507 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001508 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001509}
1510
Jason Sams5edc6082010-10-05 13:32:49 -07001511static void
Tim Murray460a0492013-11-19 12:45:54 -08001512nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -07001513{
Andreas Gampe67333922014-11-10 20:35:59 -08001514 if (kLogApi) {
1515 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
1516 (RsAllocation)alloc, dimX);
1517 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001518 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -07001519}
1520
Jason Sams46ba27e32015-02-06 17:45:15 -08001521
1522static jlong
1523nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type)
1524{
1525 if (kLogApi) {
1526 ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)",
1527 (RsContext)con, (RsAllocation)basealloc, (RsElement)type);
1528 }
1529 return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type,
1530 (RsAllocation)basealloc);
1531
1532}
1533
1534static void
1535nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
1536 jint x, jint y, jint z, jint face, jint lod,
1537 jint a1, jint a2, jint a3, jint a4)
1538{
1539 uint32_t params[] = {
1540 (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face,
1541 (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4
1542 };
1543 if (kLogApi) {
1544 ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)",
1545 (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4);
1546 }
1547 rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc,
1548 params, sizeof(params));
1549}
1550
1551
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001552// -----------------------------------
1553
Tim Murray460a0492013-11-19 12:45:54 -08001554static jlong
1555nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001556{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001557 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001558 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001559
Tim Murray3aa89c12014-08-18 17:51:22 -07001560 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001561 return id;
1562}
1563
Tim Murray460a0492013-11-19 12:45:54 -08001564static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001565nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001566{
1567 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001568 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001569 return 0;
1570 }
1571
1572 AutoJavaStringToUTF8 str(_env, _path);
1573 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001574 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001575 return 0;
1576 }
1577
Tim Murray3aa89c12014-08-18 17:51:22 -07001578 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001579 return id;
1580}
1581
Tim Murray460a0492013-11-19 12:45:54 -08001582static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001583nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001584{
1585 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001586 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001587
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001588 return id;
1589}
1590
Tim Murray460a0492013-11-19 12:45:54 -08001591static jint
1592nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001593{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001594 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001595 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001596 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001597}
1598
1599static void
Tim Murray460a0492013-11-19 12:45:54 -08001600nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001601{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001602 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001603 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
1604
Tim Murrayeff663f2013-11-15 13:08:30 -08001605 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001606
1607 for(jint i = 0; i < numEntries; i ++) {
1608 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
1609 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
1610 }
1611
1612 free(fileEntries);
1613}
1614
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001615static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001616nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001617{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001618 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001619 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001620 return id;
1621}
Jason Samsd19f10d2009-05-22 14:03:28 -07001622
1623// -----------------------------------
1624
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001625static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001626nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001627 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001628{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001629 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001630 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001631 fileNameUTF.c_str(), fileNameUTF.length(),
1632 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001633
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001634 return id;
1635}
1636
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001637static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001638nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001639 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001640{
1641 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1642 AutoJavaStringToUTF8 nameUTF(_env, name);
1643
Tim Murray3aa89c12014-08-18 17:51:22 -07001644 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001645 nameUTF.c_str(), nameUTF.length(),
1646 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001647 asset->getBuffer(false), asset->getLength());
1648 return id;
1649}
1650
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001651static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001652nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001653 jfloat fontSize, jint dpi)
1654{
1655 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001656 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001657 return 0;
1658 }
1659
1660 AutoJavaStringToUTF8 str(_env, _path);
1661 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001662 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001663 return 0;
1664 }
1665
Tim Murray3aa89c12014-08-18 17:51:22 -07001666 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001667 str.c_str(), str.length(),
1668 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001669 asset->getBuffer(false), asset->getLength());
1670 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001671 return id;
1672}
1673
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001674// -----------------------------------
1675
1676static void
Tim Murray460a0492013-11-19 12:45:54 -08001677nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001678{
Andreas Gampe67333922014-11-10 20:35:59 -08001679 if (kLogApi) {
1680 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1681 (RsScript)script, (RsAllocation)alloc, slot);
1682 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001683 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001684}
1685
1686static void
Tim Murray460a0492013-11-19 12:45:54 -08001687nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001688{
Andreas Gampe67333922014-11-10 20:35:59 -08001689 if (kLogApi) {
1690 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1691 slot, val);
1692 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001693 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001694}
1695
Tim Murray7c4caad2013-04-10 16:21:40 -07001696static jint
Tim Murray460a0492013-11-19 12:45:54 -08001697nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001698{
Andreas Gampe67333922014-11-10 20:35:59 -08001699 if (kLogApi) {
1700 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1701 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001702 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001703 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001704 return value;
1705}
1706
Jason Sams4d339932010-05-11 14:03:58 -07001707static void
Tim Murray460a0492013-11-19 12:45:54 -08001708nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001709{
Andreas Gampe67333922014-11-10 20:35:59 -08001710 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001711 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001712 slot, val);
1713 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001714 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001715}
1716
1717static void
Tim Murray460a0492013-11-19 12:45:54 -08001718nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001719{
Andreas Gampe67333922014-11-10 20:35:59 -08001720 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001721 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001722 slot, val);
1723 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001724 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001725}
1726
Tim Murray7c4caad2013-04-10 16:21:40 -07001727static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001728nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001729{
Andreas Gampe67333922014-11-10 20:35:59 -08001730 if (kLogApi) {
1731 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1732 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001733 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001734 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001735 return value;
1736}
1737
Stephen Hines031ec58c2010-10-11 10:54:21 -07001738static void
Tim Murray460a0492013-11-19 12:45:54 -08001739nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001740{
Andreas Gampe67333922014-11-10 20:35:59 -08001741 if (kLogApi) {
1742 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1743 slot, val);
1744 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001745 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001746}
1747
Tim Murray7c4caad2013-04-10 16:21:40 -07001748static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001749nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001750{
Andreas Gampe67333922014-11-10 20:35:59 -08001751 if (kLogApi) {
1752 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1753 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001754 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001755 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001756 return value;
1757}
1758
Jason Sams4d339932010-05-11 14:03:58 -07001759static void
Tim Murray460a0492013-11-19 12:45:54 -08001760nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001761{
Andreas Gampe67333922014-11-10 20:35:59 -08001762 if (kLogApi) {
1763 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1764 slot, val);
1765 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001766 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001767}
1768
Tim Murray7c4caad2013-04-10 16:21:40 -07001769static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001770nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001771{
Andreas Gampe67333922014-11-10 20:35:59 -08001772 if (kLogApi) {
1773 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1774 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001775 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001776 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001777 return value;
1778}
1779
Stephen Hinesca54ec32010-09-20 17:20:30 -07001780static void
Tim Murray460a0492013-11-19 12:45:54 -08001781nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001782{
Andreas Gampe67333922014-11-10 20:35:59 -08001783 if (kLogApi) {
1784 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1785 }
Jason Sams4d339932010-05-11 14:03:58 -07001786 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001787 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001788 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001789 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1790}
1791
Stephen Hinesadeb8092012-04-20 14:26:06 -07001792static void
Tim Murray460a0492013-11-19 12:45:54 -08001793nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001794{
Andreas Gampe67333922014-11-10 20:35:59 -08001795 if (kLogApi) {
1796 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1797 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001798 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001799 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001800 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001801 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001802}
1803
1804static void
Andreas Gampe67333922014-11-10 20:35:59 -08001805nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1806 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001807{
Andreas Gampe67333922014-11-10 20:35:59 -08001808 if (kLogApi) {
1809 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1810 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001811 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001812 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001813 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001814 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001815 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001816 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001817 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1818 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1819}
1820
Jason Samsd19f10d2009-05-22 14:03:28 -07001821
1822static void
Tim Murray460a0492013-11-19 12:45:54 -08001823nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001824{
Andreas Gampe67333922014-11-10 20:35:59 -08001825 if (kLogApi) {
1826 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1827 }
Romain Guy584a3752009-07-30 18:45:01 -07001828
1829 jint length = _env->GetArrayLength(timeZone);
1830 jbyte* timeZone_ptr;
1831 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1832
Tim Murrayeff663f2013-11-15 13:08:30 -08001833 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001834
1835 if (timeZone_ptr) {
1836 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1837 }
1838}
1839
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001840static void
Tim Murray460a0492013-11-19 12:45:54 -08001841nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001842{
Andreas Gampe67333922014-11-10 20:35:59 -08001843 if (kLogApi) {
1844 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1845 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001846 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001847}
1848
1849static void
Tim Murray460a0492013-11-19 12:45:54 -08001850nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001851{
Andreas Gampe67333922014-11-10 20:35:59 -08001852 if (kLogApi) {
1853 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1854 }
Jason Sams4d339932010-05-11 14:03:58 -07001855 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001856 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001857 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001858 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1859}
1860
Jason Sams6e494d32011-04-27 16:33:11 -07001861static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001862nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1863 jlongArray ains, jlong aout, jbyteArray params,
1864 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001865{
Andreas Gampe67333922014-11-10 20:35:59 -08001866 if (kLogApi) {
Chih-Hung Hsiehbce42202015-05-08 11:05:12 -07001867 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i) ains(%p) aout(%" PRId64 ")", (RsContext)con, (void *)script, slot, ains, aout);
Andreas Gampe67333922014-11-10 20:35:59 -08001868 }
Jason Sams6e494d32011-04-27 16:33:11 -07001869
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001870 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001871 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001872
Chris Wailes488230c32014-08-14 11:22:40 -07001873 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001874
Chris Wailes488230c32014-08-14 11:22:40 -07001875 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001876 in_len = _env->GetArrayLength(ains);
Yang Ni7b2a46f2015-05-05 12:41:19 -07001877 if (in_len > (jint)RS_KERNEL_MAX_ARGUMENTS) {
Yang Ni4e90b9b2015-04-30 16:13:54 -07001878 ALOGE("Too many arguments in kernel launch.");
1879 // TODO (b/20758983): Report back to Java and throw an exception
1880 return;
1881 }
Chris Wailes94961062014-06-11 12:01:28 -07001882
Yang Ni4e90b9b2015-04-30 16:13:54 -07001883 // TODO (b/20760800): Check in_ptr is not null
1884 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001885 if (sizeof(RsAllocation) == sizeof(jlong)) {
1886 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001887
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001888 } else {
1889 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001890
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001891 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
Yang Ni4e90b9b2015-04-30 16:13:54 -07001892 if (in_allocs == nullptr) {
1893 ALOGE("Failed launching kernel for lack of memory.");
1894 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
1895 return;
1896 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001897
1898 for (int index = in_len; --index >= 0;) {
1899 in_allocs[index] = (RsAllocation)in_ptr[index];
1900 }
1901 }
Chris Wailes94961062014-06-11 12:01:28 -07001902 }
1903
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001904 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001905 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001906
Chris Wailes488230c32014-08-14 11:22:40 -07001907 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001908 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001909 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001910 }
1911
Chris Wailes488230c32014-08-14 11:22:40 -07001912 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001913 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001914
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001915 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001916 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001917
Chris Wailes488230c32014-08-14 11:22:40 -07001918 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001919 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001920 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001921
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001922 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001923 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001924
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001925 sc.xStart = limit_ptr[0];
1926 sc.xEnd = limit_ptr[1];
1927 sc.yStart = limit_ptr[2];
1928 sc.yEnd = limit_ptr[3];
1929 sc.zStart = limit_ptr[4];
1930 sc.zEnd = limit_ptr[5];
1931 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Jason Sams14331ab2015-01-26 18:14:36 -08001932 sc.arrayStart = 0;
1933 sc.arrayEnd = 0;
1934 sc.array2Start = 0;
1935 sc.array2End = 0;
1936 sc.array3Start = 0;
1937 sc.array3End = 0;
1938 sc.array4Start = 0;
1939 sc.array4End = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001940
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001941 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001942 }
1943
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001944 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1945 in_allocs, in_len, (RsAllocation)aout,
1946 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001947
Chris Wailes488230c32014-08-14 11:22:40 -07001948 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001949 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001950 }
1951
Chris Wailes488230c32014-08-14 11:22:40 -07001952 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001953 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1954 }
1955
Chris Wailes488230c32014-08-14 11:22:40 -07001956 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001957 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1958 }
Chris Wailes94961062014-06-11 12:01:28 -07001959}
1960
Matt Wala36eb1f72015-07-20 15:35:27 -07001961static void
1962nScriptReduce(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1963 jlong ain, jlong aout, jintArray limits)
1964{
1965 if (kLogApi) {
1966 ALOGD("nScriptReduce, con(%p), s(%p), slot(%i) ain(%" PRId64 ") aout(%" PRId64 ")", (RsContext)con, (void *)script, slot, ain, aout);
1967 }
1968
1969 RsScriptCall sc, *sca = nullptr;
1970 uint32_t sc_size = 0;
1971
1972 jint limit_len = 0;
1973 jint *limit_ptr = nullptr;
1974
1975 // If the caller passed limits, reflect them in the RsScriptCall.
1976 if (limits != nullptr) {
1977 limit_len = _env->GetArrayLength(limits);
1978 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
1979
1980 // We expect to be passed an array [x1, x2] which specifies
1981 // the sub-range for a 1-dimensional reduction.
1982 assert(limit_len == 2);
1983 UNUSED(limit_len); // As the assert might not be compiled.
1984
1985 sc.xStart = limit_ptr[0];
1986 sc.xEnd = limit_ptr[1];
1987 sc.yStart = 0;
1988 sc.yEnd = 0;
1989 sc.zStart = 0;
1990 sc.zEnd = 0;
1991 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1992 sc.arrayStart = 0;
1993 sc.arrayEnd = 0;
1994 sc.array2Start = 0;
1995 sc.array2End = 0;
1996 sc.array3Start = 0;
1997 sc.array3End = 0;
1998 sc.array4Start = 0;
1999 sc.array4End = 0;
2000
2001 sca = &sc;
2002 sc_size = sizeof(sc);
2003 }
2004
2005 rsScriptReduce((RsContext)con, (RsScript)script, slot,
2006 (RsAllocation)ain, (RsAllocation)aout,
2007 sca, sc_size);
2008
2009 if (limits != nullptr) {
2010 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
2011 }
2012}
2013
Jason Sams22534172009-08-04 16:58:20 -07002014// -----------------------------------
2015
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002016static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002017nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07002018 jstring resName, jstring cacheDir,
2019 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07002020{
Andreas Gampe67333922014-11-10 20:35:59 -08002021 if (kLogApi) {
2022 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
2023 }
Jason Sams22534172009-08-04 16:58:20 -07002024
Jason Samse4a06c52011-03-16 16:29:28 -07002025 AutoJavaStringToUTF8 resNameUTF(_env, resName);
2026 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002027 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07002028 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07002029 jint _exception = 0;
2030 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07002031 if (!scriptRef) {
2032 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07002033 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07002034 goto exit;
2035 }
Jack Palevich43702d82009-05-28 13:38:16 -07002036 if (length < 0) {
2037 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07002038 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07002039 goto exit;
2040 }
Jason Samse4a06c52011-03-16 16:29:28 -07002041 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07002042 if (remaining < length) {
2043 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07002044 //jniThrowException(_env, "java/lang/IllegalArgumentException",
2045 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07002046 goto exit;
2047 }
Jason Samse4a06c52011-03-16 16:29:28 -07002048 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07002049 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07002050
Tim Murrayeff663f2013-11-15 13:08:30 -08002051 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07002052
Tim Murray3aa89c12014-08-18 17:51:22 -07002053 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07002054 resNameUTF.c_str(), resNameUTF.length(),
2055 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07002056 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07002057
Jack Palevich43702d82009-05-28 13:38:16 -07002058exit:
Jason Samse4a06c52011-03-16 16:29:28 -07002059 if (script_ptr) {
2060 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07002061 _exception ? JNI_ABORT: 0);
2062 }
Jason Samsd19f10d2009-05-22 14:03:28 -07002063
Tim Murray3aa89c12014-08-18 17:51:22 -07002064 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07002065}
2066
Tim Murray460a0492013-11-19 12:45:54 -08002067static jlong
2068nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07002069{
Andreas Gampe67333922014-11-10 20:35:59 -08002070 if (kLogApi) {
2071 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
2072 (void *)eid);
2073 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002074 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07002075}
2076
Tim Murray460a0492013-11-19 12:45:54 -08002077static jlong
2078nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07002079{
Andreas Gampe67333922014-11-10 20:35:59 -08002080 if (kLogApi) {
2081 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
2082 (void *)sid, slot, sig);
2083 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002084 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07002085}
2086
Tim Murray460a0492013-11-19 12:45:54 -08002087static jlong
Yang Nibe392ad2015-01-23 17:16:02 -08002088nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
2089{
2090 if (kLogApi) {
Elliott Hughes7ff53fa2015-02-05 21:36:10 -08002091 ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con,
Yang Nibe392ad2015-01-23 17:16:02 -08002092 (void *)sid, slot);
2093 }
2094 return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot);
2095}
2096
2097static jlong
Tim Murray460a0492013-11-19 12:45:54 -08002098nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07002099{
Andreas Gampe67333922014-11-10 20:35:59 -08002100 if (kLogApi) {
2101 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
2102 slot);
2103 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002104 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07002105}
2106
Tim Murray460a0492013-11-19 12:45:54 -08002107static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00002108nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
2109 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07002110{
Andreas Gampe67333922014-11-10 20:35:59 -08002111 if (kLogApi) {
2112 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
2113 }
Jason Sams08a81582012-09-18 12:32:10 -07002114
Ashok Bhat98071552014-02-12 09:54:43 +00002115 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07002116 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002117 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
2118 for(int i = 0; i < kernelsLen; ++i) {
2119 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
2120 }
Jason Sams08a81582012-09-18 12:32:10 -07002121
Ashok Bhat98071552014-02-12 09:54:43 +00002122 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07002123 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002124 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
2125 for(int i = 0; i < srcLen; ++i) {
2126 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
2127 }
Jason Sams08a81582012-09-18 12:32:10 -07002128
Ashok Bhat98071552014-02-12 09:54:43 +00002129 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07002130 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002131 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
2132 for(int i = 0; i < dstkLen; ++i) {
2133 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
2134 }
2135
2136 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07002137 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002138 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
2139 for(int i = 0; i < dstfLen; ++i) {
2140 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
2141 }
2142
2143 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07002144 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002145 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
2146 for(int i = 0; i < typesLen; ++i) {
2147 typesPtr[i] = (RsType)jTypesPtr[i];
2148 }
2149
Tim Murray3aa89c12014-08-18 17:51:22 -07002150 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00002151 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
2152 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
2153 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
2154 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
2155 (RsType *)typesPtr, typesLen * sizeof(RsType));
2156
2157 free(kernelsPtr);
2158 free(srcPtr);
2159 free(dstkPtr);
2160 free(dstfPtr);
2161 free(typesPtr);
2162 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
2163 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
2164 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
2165 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
2166 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07002167 return id;
2168}
2169
2170static void
Tim Murray460a0492013-11-19 12:45:54 -08002171nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07002172{
Andreas Gampe67333922014-11-10 20:35:59 -08002173 if (kLogApi) {
2174 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
2175 (void *)gid, (void *)kid, (void *)alloc);
2176 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002177 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07002178}
2179
2180static void
Tim Murray460a0492013-11-19 12:45:54 -08002181nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07002182{
Andreas Gampe67333922014-11-10 20:35:59 -08002183 if (kLogApi) {
2184 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
2185 (void *)gid, (void *)kid, (void *)alloc);
2186 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002187 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07002188}
2189
2190static void
Tim Murray460a0492013-11-19 12:45:54 -08002191nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07002192{
Andreas Gampe67333922014-11-10 20:35:59 -08002193 if (kLogApi) {
2194 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
2195 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002196 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07002197}
2198
Jason Samsd19f10d2009-05-22 14:03:28 -07002199// ---------------------------------------------------------------------------
2200
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002201static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002202nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07002203 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
2204 jboolean depthMask, jboolean ditherEnable,
2205 jint srcFunc, jint destFunc,
2206 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07002207{
Andreas Gampe67333922014-11-10 20:35:59 -08002208 if (kLogApi) {
2209 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
2210 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002211 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07002212 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
2213 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07002214}
2215
Jason Sams0011bcf2009-12-15 12:58:36 -08002216// ---------------------------------------------------------------------------
2217
2218static void
Tim Murray460a0492013-11-19 12:45:54 -08002219nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08002220{
Andreas Gampe67333922014-11-10 20:35:59 -08002221 if (kLogApi) {
2222 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
2223 (RsProgramVertex)vpv, slot, (RsAllocation)a);
2224 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002225 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08002226}
Jason Sams54c0ec12009-11-30 14:49:55 -08002227
Jason Sams68afd012009-12-17 16:55:08 -08002228static void
Tim Murray460a0492013-11-19 12:45:54 -08002229nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002230{
Andreas Gampe67333922014-11-10 20:35:59 -08002231 if (kLogApi) {
2232 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2233 (RsProgramFragment)vpf, slot, (RsAllocation)a);
2234 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002235 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08002236}
2237
2238static void
Tim Murray460a0492013-11-19 12:45:54 -08002239nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08002240{
Andreas Gampe67333922014-11-10 20:35:59 -08002241 if (kLogApi) {
2242 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
2243 (RsProgramFragment)vpf, slot, (RsSampler)a);
2244 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002245 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08002246}
2247
Jason Samsd19f10d2009-05-22 14:03:28 -07002248// ---------------------------------------------------------------------------
2249
Tim Murray460a0492013-11-19 12:45:54 -08002250static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002251nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002252 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002253{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002254 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002255 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002256 jint paramLen = _env->GetArrayLength(params);
2257
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002258 int texCount = _env->GetArrayLength(texNames);
2259 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2260 const char ** nameArray = names.c_str();
2261 size_t* sizeArray = names.c_str_len();
2262
Andreas Gampe67333922014-11-10 20:35:59 -08002263 if (kLogApi) {
2264 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2265 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002266
Ashok Bhat98071552014-02-12 09:54:43 +00002267 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2268 for(int i = 0; i < paramLen; ++i) {
2269 paramPtr[i] = (uintptr_t)jParamPtr[i];
2270 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002271 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002272 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002273 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002274
Ashok Bhat98071552014-02-12 09:54:43 +00002275 free(paramPtr);
2276 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08002277 return ret;
2278}
2279
2280
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002281// ---------------------------------------------------------------------------
2282
Tim Murray460a0492013-11-19 12:45:54 -08002283static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002284nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00002285 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002286{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08002287 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07002288 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08002289 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002290
Andreas Gampe67333922014-11-10 20:35:59 -08002291 if (kLogApi) {
2292 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
2293 }
Jason Sams0011bcf2009-12-15 12:58:36 -08002294
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002295 int texCount = _env->GetArrayLength(texNames);
2296 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
2297 const char ** nameArray = names.c_str();
2298 size_t* sizeArray = names.c_str_len();
2299
Ashok Bhat98071552014-02-12 09:54:43 +00002300 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
2301 for(int i = 0; i < paramLen; ++i) {
2302 paramPtr[i] = (uintptr_t)jParamPtr[i];
2303 }
2304
Tim Murray3aa89c12014-08-18 17:51:22 -07002305 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002306 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00002307 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08002308
Ashok Bhat98071552014-02-12 09:54:43 +00002309 free(paramPtr);
2310 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08002311 return ret;
2312}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07002313
Jason Samsebfb4362009-09-23 13:57:02 -07002314// ---------------------------------------------------------------------------
2315
Tim Murray460a0492013-11-19 12:45:54 -08002316static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002317nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07002318{
Andreas Gampe67333922014-11-10 20:35:59 -08002319 if (kLogApi) {
2320 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
2321 pointSprite, cull);
2322 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002323 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07002324}
2325
Jason Samsd19f10d2009-05-22 14:03:28 -07002326
2327// ---------------------------------------------------------------------------
2328
2329static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002330nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07002331{
Andreas Gampe67333922014-11-10 20:35:59 -08002332 if (kLogApi) {
2333 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
2334 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002335 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07002336}
2337
2338static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002339nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07002340{
Andreas Gampe67333922014-11-10 20:35:59 -08002341 if (kLogApi) {
2342 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
2343 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002344 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07002345}
2346
2347static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002348nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07002349{
Andreas Gampe67333922014-11-10 20:35:59 -08002350 if (kLogApi) {
2351 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
2352 (RsProgramFragment)pf);
2353 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002354 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07002355}
2356
Jason Sams0826a6f2009-06-15 19:04:56 -07002357static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002358nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07002359{
Andreas Gampe67333922014-11-10 20:35:59 -08002360 if (kLogApi) {
2361 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
2362 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002363 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07002364}
2365
Joe Onoratod7b37742009-08-09 22:57:44 -07002366static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002367nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07002368{
Andreas Gampe67333922014-11-10 20:35:59 -08002369 if (kLogApi) {
2370 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
2371 }
Tim Murrayeff663f2013-11-15 13:08:30 -08002372 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07002373}
2374
Joe Onoratod7b37742009-08-09 22:57:44 -07002375
Jason Sams02fb2cb2009-05-28 15:37:57 -07002376// ---------------------------------------------------------------------------
2377
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002378static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08002379nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002380 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07002381{
Andreas Gampe67333922014-11-10 20:35:59 -08002382 if (kLogApi) {
2383 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
2384 }
Tim Murray3aa89c12014-08-18 17:51:22 -07002385 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07002386 (RsSamplerValue)magFilter,
2387 (RsSamplerValue)minFilter,
2388 (RsSamplerValue)wrapS,
2389 (RsSamplerValue)wrapT,
2390 (RsSamplerValue)wrapR,
2391 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07002392}
2393
Jason Samsbba134c2009-06-22 15:49:21 -07002394// ---------------------------------------------------------------------------
2395
Tim Murray460a0492013-11-19 12:45:54 -08002396static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00002397nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07002398{
Andreas Gampe67333922014-11-10 20:35:59 -08002399 if (kLogApi) {
2400 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
2401 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002402
2403 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07002404 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002405 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
2406 for(int i = 0; i < vtxLen; ++i) {
2407 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
2408 }
2409
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002410 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07002411 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00002412 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
2413 for(int i = 0; i < idxLen; ++i) {
2414 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
2415 }
2416
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002417 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07002418 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002419
Tim Murray3aa89c12014-08-18 17:51:22 -07002420 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002421 (RsAllocation *)vtxPtr, vtxLen,
2422 (RsAllocation *)idxPtr, idxLen,
2423 (uint32_t *)primPtr, primLen);
2424
Ashok Bhat98071552014-02-12 09:54:43 +00002425 free(vtxPtr);
2426 free(idxPtr);
2427 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
2428 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07002429 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002430 return id;
2431}
2432
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002433static jint
Tim Murray460a0492013-11-19 12:45:54 -08002434nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002435{
Andreas Gampe67333922014-11-10 20:35:59 -08002436 if (kLogApi) {
2437 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2438 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002439 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002440 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002441 return vtxCount;
2442}
2443
2444static jint
Tim Murray460a0492013-11-19 12:45:54 -08002445nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002446{
Andreas Gampe67333922014-11-10 20:35:59 -08002447 if (kLogApi) {
2448 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2449 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002450 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08002451 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002452 return idxCount;
2453}
2454
2455static void
Ashok Bhat98071552014-02-12 09:54:43 +00002456nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002457{
Andreas Gampe67333922014-11-10 20:35:59 -08002458 if (kLogApi) {
2459 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2460 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002461
2462 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08002463 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002464
2465 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002466 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002467 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002468 }
2469
2470 free(allocs);
2471}
2472
2473static void
Ashok Bhat98071552014-02-12 09:54:43 +00002474nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002475{
Andreas Gampe67333922014-11-10 20:35:59 -08002476 if (kLogApi) {
2477 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
2478 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002479
2480 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
2481 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
2482
Tim Murrayeff663f2013-11-15 13:08:30 -08002483 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002484
2485 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07002486 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00002487 const jint prim = (jint)prims[i];
2488 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
2489 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002490 }
2491
2492 free(allocs);
2493 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002494}
2495
Tim Murray56f9e6f2014-05-16 11:47:26 -07002496static jint
2497nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
2498 return (jint)sizeof(void*);
2499}
2500
2501
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002502// ---------------------------------------------------------------------------
2503
Jason Samsd19f10d2009-05-22 14:03:28 -07002504
Jason Sams94d8e90a2009-06-10 16:09:05 -07002505static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07002506
2507static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08002508{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07002509
Tim Murrayeff663f2013-11-15 13:08:30 -08002510{"nDeviceCreate", "()J", (void*)nDeviceCreate },
2511{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
2512{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
2513{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
2514{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
2515{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08002516
Tim Murrayeff663f2013-11-15 13:08:30 -08002517{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
2518{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07002519
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07002520
Jason Sams2e1872f2010-08-17 16:25:41 -07002521// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08002522{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
2523{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
2524{"rsnContextFinish", "(J)V", (void*)nContextFinish },
2525{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
Tim Murray47f31582015-04-07 15:43:24 -07002526{"rsnContextSetCacheDir", "(JLjava/lang/String;)V", (void*)nContextSetCacheDir },
Tim Murrayeff663f2013-11-15 13:08:30 -08002527{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
2528{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
2529{"rsnContextDump", "(JI)V", (void*)nContextDump },
2530{"rsnContextPause", "(J)V", (void*)nContextPause },
2531{"rsnContextResume", "(J)V", (void*)nContextResume },
2532{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07002533{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002534{"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate },
Yang Ni281c3252014-10-24 08:52:24 -07002535{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
2536{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08002537{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
2538{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
2539{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07002540
Tim Murray460a0492013-11-19 12:45:54 -08002541{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002542{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08002543{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
2544{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
2545{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002546{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07002547
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002548{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
2549{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
2550{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07002551
Tim Murray460a0492013-11-19 12:45:54 -08002552{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002553{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08002554{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00002555{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07002556
Tim Murray460a0492013-11-19 12:45:54 -08002557{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002558{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07002559
Ashok Bhat98071552014-02-12 09:54:43 +00002560{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08002561{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
2562{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
2563{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08002564
Tim Murray460a0492013-11-19 12:45:54 -08002565{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
2566{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08002567
Tim Murray460a0492013-11-19 12:45:54 -08002568{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
2569{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
2570{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
2571{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
2572{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
Miao Wang87e908d2015-03-02 15:15:15 -08002573{"rsnAllocationData1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData1D },
Miao Wangc8e237e2015-02-20 18:36:32 -08002574{"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData },
Miao Wang87e908d2015-03-02 15:15:15 -08002575{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData2D },
Tim Murray460a0492013-11-19 12:45:54 -08002576{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002577{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData3D },
Tim Murray460a0492013-11-19 12:45:54 -08002578{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
Miao Wang87e908d2015-03-02 15:15:15 -08002579{"rsnAllocationRead", "(JJLjava/lang/Object;IIZ)V", (void*)nAllocationRead },
2580{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead1D },
Miao Wang45cec0a2015-03-04 16:40:21 -08002581{"rsnAllocationElementRead", "(JJIIIII[BI)V", (void*)nAllocationElementRead },
Miao Wang87e908d2015-03-02 15:15:15 -08002582{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead2D },
2583{"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead3D },
Tim Murray460a0492013-11-19 12:45:54 -08002584{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
2585{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
2586{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07002587
Jason Sams46ba27e32015-02-06 17:45:15 -08002588{"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate },
2589{"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset },
2590
Tim Murray460a0492013-11-19 12:45:54 -08002591{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
2592{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
2593{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
2594{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07002595
2596{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
Matt Wala36eb1f72015-07-20 15:35:27 -07002597{"rsnScriptReduce", "(JJIJJ[I)V", (void*)nScriptReduce },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07002598
Tim Murray460a0492013-11-19 12:45:54 -08002599{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
2600{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
2601{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
2602{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
2603{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
2604{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
2605{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
2606{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
2607{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
2608{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
2609{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
2610{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07002611
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002612{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002613{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2614{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
Yang Nibe392ad2015-01-23 17:16:02 -08002615{"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002616{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002617{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Ni35be56c2015-04-02 17:47:56 -07002618{"rsnScriptGroup2Create", "(JLjava/lang/String;Ljava/lang/String;[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002619{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2620{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2621{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002622{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002623
Tim Murray25207df2015-01-12 16:47:56 -08002624{"rsnScriptIntrinsicBLAS_Single", "(JJIIIIIIIIIFJJFJIIII)V", (void*)nScriptIntrinsicBLAS_Single },
2625{"rsnScriptIntrinsicBLAS_Double", "(JJIIIIIIIIIDJJDJIIII)V", (void*)nScriptIntrinsicBLAS_Double },
2626{"rsnScriptIntrinsicBLAS_Complex", "(JJIIIIIIIIIFFJJFFJIIII)V", (void*)nScriptIntrinsicBLAS_Complex },
2627{"rsnScriptIntrinsicBLAS_Z", "(JJIIIIIIIIIDDJJDDJIIII)V", (void*)nScriptIntrinsicBLAS_Z },
2628
Tim Murray9cb16a22015-04-01 11:07:16 -07002629{"rsnScriptIntrinsicBLAS_BNNM", "(JJIIIJIJIJII)V", (void*)nScriptIntrinsicBLAS_BNNM },
2630
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002631{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002632
Tim Murray460a0492013-11-19 12:45:54 -08002633{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2634{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2635{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002636
Ashok Bhat98071552014-02-12 09:54:43 +00002637{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002638{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002639{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002640
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002641{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2642{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2643{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2644{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2645{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002646
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002647{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002648
Ashok Bhat98071552014-02-12 09:54:43 +00002649{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002650
Tim Murray460a0492013-11-19 12:45:54 -08002651{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2652{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002653{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2654{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002655
Tim Murray56f9e6f2014-05-16 11:47:26 -07002656{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002657};
2658
2659static int registerFuncs(JNIEnv *_env)
2660{
2661 return android::AndroidRuntime::registerNativeMethods(
2662 _env, classPathName, methods, NELEM(methods));
2663}
2664
2665// ---------------------------------------------------------------------------
2666
2667jint JNI_OnLoad(JavaVM* vm, void* reserved)
2668{
Chris Wailes488230c32014-08-14 11:22:40 -07002669 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002670 jint result = -1;
2671
Jason Samsd19f10d2009-05-22 14:03:28 -07002672 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002673 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002674 goto bail;
2675 }
Chris Wailes488230c32014-08-14 11:22:40 -07002676 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002677
2678 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002679 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002680 goto bail;
2681 }
2682
2683 /* success -- return valid version number */
2684 result = JNI_VERSION_1_4;
2685
2686bail:
2687 return result;
2688}