blob: cbcba398073c654745f01e4789f9845502325099 [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
Stephen Hines4cbe25a2012-01-18 18:46:27 -08002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Samsd19f10d2009-05-22 14:03:28 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jason Samsf29ca502009-06-23 12:22:47 -070017#define LOG_TAG "libRS_jni"
18
Jason Samsd19f10d2009-05-22 14:03:28 -070019#include <stdlib.h>
20#include <stdio.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <math.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070024#include <utils/misc.h>
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +010025#include <inttypes.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070026
Derek Sollenbergereece0dd2014-02-27 14:31:29 -050027#include <SkBitmap.h>
Jason Samsffe9f482009-06-01 17:45:53 -070028
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080029#include <androidfw/Asset.h>
30#include <androidfw/AssetManager.h>
31#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070032
Jason Samsd19f10d2009-05-22 14:03:28 -070033#include "jni.h"
34#include "JNIHelp.h"
35#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070036#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080037#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070038
Jason Sams1d6983a2012-02-16 16:07:49 -080039#include <rs.h>
40#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070041#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080042#include <gui/GLConsumer.h>
Mathias Agopian52800612013-02-14 17:11:20 -080043#include <gui/Surface.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070044#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070045
Steve Block3762c312012-01-06 19:20:56 +000046//#define LOG_API ALOGE
Andreas Gampe67333922014-11-10 20:35:59 -080047static constexpr bool kLogApi = false;
Jason Samsd19f10d2009-05-22 14:03:28 -070048
49using namespace android;
50
Andreas Gampe67333922014-11-10 20:35:59 -080051template <typename... T>
52void UNUSED(T... t) {}
53
Stephen Hines414fa2c2014-04-17 01:02:42 -070054#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \
Jason Samse729a942013-11-06 11:22:02 -080055 jint len = 0; \
Chris Wailes488230c32014-08-14 11:22:40 -070056 void *ptr = 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. */ \
61 relFlag = JNI_ABORT; \
62 } \
Jason Samse729a942013-11-06 11:22:02 -080063 switch(dataType) { \
64 case RS_TYPE_FLOAT_32: \
65 len = _env->GetArrayLength((jfloatArray)data); \
66 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080067 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080068 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070069 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080070 return; \
71 case RS_TYPE_FLOAT_64: \
72 len = _env->GetArrayLength((jdoubleArray)data); \
73 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080074 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -080075 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070076 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080077 return; \
78 case RS_TYPE_SIGNED_8: \
79 case RS_TYPE_UNSIGNED_8: \
80 len = _env->GetArrayLength((jbyteArray)data); \
81 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080082 typeBytes = 1; \
Jason Samse729a942013-11-06 11:22:02 -080083 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070084 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080085 return; \
86 case RS_TYPE_SIGNED_16: \
87 case RS_TYPE_UNSIGNED_16: \
88 len = _env->GetArrayLength((jshortArray)data); \
89 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080090 typeBytes = 2; \
Jason Samse729a942013-11-06 11:22:02 -080091 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070092 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080093 return; \
94 case RS_TYPE_SIGNED_32: \
95 case RS_TYPE_UNSIGNED_32: \
96 len = _env->GetArrayLength((jintArray)data); \
97 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080098 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080099 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700100 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800101 return; \
102 case RS_TYPE_SIGNED_64: \
103 case RS_TYPE_UNSIGNED_64: \
104 len = _env->GetArrayLength((jlongArray)data); \
105 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800106 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -0800107 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700108 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800109 return; \
110 default: \
111 break; \
112 } \
Andreas Gampe67333922014-11-10 20:35:59 -0800113 UNUSED(len, ptr, typeBytes, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800114}
115
116
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800117class AutoJavaStringToUTF8 {
118public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800119 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Chris Wailes488230c32014-08-14 11:22:40 -0700120 fCStr = env->GetStringUTFChars(str, nullptr);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800121 fLength = env->GetStringUTFLength(str);
122 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800123 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800124 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
125 }
126 const char* c_str() const { return fCStr; }
127 jsize length() const { return fLength; }
128
129private:
130 JNIEnv* fEnv;
131 jstring fJStr;
132 const char* fCStr;
133 jsize fLength;
134};
135
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800136class AutoJavaStringArrayToUTF8 {
137public:
138 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
139 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
Chris Wailes488230c32014-08-14 11:22:40 -0700140 mCStrings = nullptr;
141 mSizeArray = nullptr;
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800142 if (stringsLength > 0) {
143 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
144 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
145 for (jsize ct = 0; ct < stringsLength; ct ++) {
146 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
Chris Wailes488230c32014-08-14 11:22:40 -0700147 mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800148 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
149 }
150 }
151 }
152 ~AutoJavaStringArrayToUTF8() {
153 for (jsize ct=0; ct < mStringsLength; ct++) {
154 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
155 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
156 }
157 free(mCStrings);
158 free(mSizeArray);
159 }
160 const char **c_str() const { return mCStrings; }
161 size_t *c_str_len() const { return mSizeArray; }
162 jsize length() const { return mStringsLength; }
163
164private:
165 JNIEnv *mEnv;
166 jobjectArray mStrings;
167 const char **mCStrings;
168 size_t *mSizeArray;
169 jsize mStringsLength;
170};
171
Jason Samsd19f10d2009-05-22 14:03:28 -0700172// ---------------------------------------------------------------------------
173
Jason Samsffe9f482009-06-01 17:45:53 -0700174static jfieldID gContextId = 0;
175static jfieldID gNativeBitmapID = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700176
177static void _nInit(JNIEnv *_env, jclass _this)
178{
Tim Murrayeff663f2013-11-15 13:08:30 -0800179 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsffe9f482009-06-01 17:45:53 -0700180
181 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000182 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700183}
184
Jason Samsd19f10d2009-05-22 14:03:28 -0700185// ---------------------------------------------------------------------------
186
Jason Sams3eaa3382009-06-10 15:04:38 -0700187static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800188nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700189{
Andreas Gampe67333922014-11-10 20:35:59 -0800190 if (kLogApi) {
191 ALOGD("nContextFinish, con(%p)", (RsContext)con);
192 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800193 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700194}
195
Yang Ni281c3252014-10-24 08:52:24 -0700196static jlong
197nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID,
198 jlong returnValue, jlongArray fieldIDArray,
199 jlongArray valueArray, jintArray sizeArray,
200 jlongArray depClosureArray, jlongArray depFieldIDArray) {
201 jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr);
202 jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray);
203 RsScriptFieldID* fieldIDs =
204 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length);
205 for (int i = 0; i< fieldIDs_length; i++) {
206 fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i];
207 }
208
209 jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr);
210 jsize values_length = _env->GetArrayLength(valueArray);
211 uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length);
212 for (int i = 0; i < values_length; i++) {
213 values[i] = (uintptr_t)jValues[i];
214 }
215
216 jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr);
217 jsize sizes_length = _env->GetArrayLength(sizeArray);
218
219 jlong* jDepClosures =
220 _env->GetLongArrayElements(depClosureArray, nullptr);
221 jsize depClosures_length = _env->GetArrayLength(depClosureArray);
222 RsClosure* depClosures =
223 (RsClosure*)alloca(sizeof(RsClosure) * depClosures_length);
224 for (int i = 0; i < depClosures_length; i++) {
225 depClosures[i] = (RsClosure)jDepClosures[i];
226 }
227
228 jlong* jDepFieldIDs =
229 _env->GetLongArrayElements(depFieldIDArray, nullptr);
230 jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray);
231 RsScriptFieldID* depFieldIDs =
232 (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * depFieldIDs_length);
233 for (int i = 0; i < depClosures_length; i++) {
234 depFieldIDs[i] = (RsClosure)jDepFieldIDs[i];
235 }
236
237 return (jlong)(uintptr_t)rsClosureCreate(
238 (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue,
239 fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length,
240 (size_t*)sizes, (size_t)sizes_length,
241 depClosures, (size_t)depClosures_length,
242 depFieldIDs, (size_t)depFieldIDs_length);
243}
244
245static void
246nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
247 jint index, jlong value, jint size) {
248 rsClosureSetArg((RsContext)con, (RsClosure)closureID, (uint32_t)index,
249 (uintptr_t)value, (size_t)size);
250}
251
252static void
253nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID,
254 jlong fieldID, jlong value, jint size) {
255 rsClosureSetGlobal((RsContext)con, (RsClosure)closureID,
256 (RsScriptFieldID)fieldID, (uintptr_t)value, (size_t)size);
257}
258
259static long
260nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con,
Yang Niebf63402015-01-16 11:06:26 -0800261 jstring cacheDir, jlongArray closureArray) {
262 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
263
Yang Ni281c3252014-10-24 08:52:24 -0700264 jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr);
265 jsize numClosures = _env->GetArrayLength(closureArray);
266 RsClosure* closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures);
267 for (int i = 0; i < numClosures; i++) {
268 closures[i] = (RsClosure)jClosures[i];
269 }
270
Yang Niebf63402015-01-16 11:06:26 -0800271 return (jlong)(uintptr_t)rsScriptGroup2Create(
272 (RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length(),
273 closures, numClosures);
Yang Ni281c3252014-10-24 08:52:24 -0700274}
275
276static void
277nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) {
278 rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID);
279}
280
Jason Sams96ed4cf2010-06-15 12:15:57 -0700281static void
Tim Murray460a0492013-11-19 12:45:54 -0800282nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa3382009-06-10 15:04:38 -0700283{
Andreas Gampe67333922014-11-10 20:35:59 -0800284 if (kLogApi) {
285 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
286 }
Jason Sams3eaa3382009-06-10 15:04:38 -0700287 jint len = _env->GetArrayLength(str);
288 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800289 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa3382009-06-10 15:04:38 -0700290 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
291}
292
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700293static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800294nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700295{
Andreas Gampe67333922014-11-10 20:35:59 -0800296 if (kLogApi) {
297 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
298 }
Chris Wailes488230c32014-08-14 11:22:40 -0700299 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800300 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700301 if(name == nullptr || strlen(name) == 0) {
302 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700303 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700304 return _env->NewStringUTF(name);
305}
306
Jason Sams7ce033d2009-08-18 14:14:24 -0700307static void
Tim Murray460a0492013-11-19 12:45:54 -0800308nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700309{
Andreas Gampe67333922014-11-10 20:35:59 -0800310 if (kLogApi) {
311 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
312 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800313 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700314}
315
Jason Sams3eaa3382009-06-10 15:04:38 -0700316// ---------------------------------------------------------------------------
317
Tim Murrayeff663f2013-11-15 13:08:30 -0800318static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700319nDeviceCreate(JNIEnv *_env, jobject _this)
320{
Andreas Gampe67333922014-11-10 20:35:59 -0800321 if (kLogApi) {
322 ALOGD("nDeviceCreate");
323 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700324 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700325}
326
327static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800328nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700329{
Andreas Gampe67333922014-11-10 20:35:59 -0800330 if (kLogApi) {
331 ALOGD("nDeviceDestroy");
332 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700333 return rsDeviceDestroy((RsDevice)dev);
334}
335
Jason Samsebfb4362009-09-23 13:57:02 -0700336static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800337nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700338{
Andreas Gampe67333922014-11-10 20:35:59 -0800339 if (kLogApi) {
340 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
341 }
Jason Samsebfb4362009-09-23 13:57:02 -0700342 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
343}
344
Tim Murrayeff663f2013-11-15 13:08:30 -0800345static jlong
Jason Sams81cd2b12014-12-02 12:36:43 -0800346nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700347{
Andreas Gampe67333922014-11-10 20:35:59 -0800348 if (kLogApi) {
349 ALOGD("nContextCreate");
350 }
Jason Sams81cd2b12014-12-02 12:36:43 -0800351 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags);
Jason Sams704ff642010-02-09 16:05:07 -0800352}
353
Tim Murrayeff663f2013-11-15 13:08:30 -0800354static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800355nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000356 jint colorMin, jint colorPref,
357 jint alphaMin, jint alphaPref,
358 jint depthMin, jint depthPref,
359 jint stencilMin, jint stencilPref,
360 jint samplesMin, jint samplesPref, jfloat samplesQ,
361 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800362{
Jason Sams11c8af92010-10-13 15:31:10 -0700363 RsSurfaceConfig sc;
364 sc.alphaMin = alphaMin;
365 sc.alphaPref = alphaPref;
366 sc.colorMin = colorMin;
367 sc.colorPref = colorPref;
368 sc.depthMin = depthMin;
369 sc.depthPref = depthPref;
370 sc.samplesMin = samplesMin;
371 sc.samplesPref = samplesPref;
372 sc.samplesQ = samplesQ;
373
Andreas Gampe67333922014-11-10 20:35:59 -0800374 if (kLogApi) {
375 ALOGD("nContextCreateGL");
376 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700377 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700378}
379
380static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800381nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800382{
Andreas Gampe67333922014-11-10 20:35:59 -0800383 if (kLogApi) {
384 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
385 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800386 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800387}
388
389
390
391static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800392nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800393{
Andreas Gampe67333922014-11-10 20:35:59 -0800394 if (kLogApi) {
395 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
396 width, height, (Surface *)wnd);
397 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800398
Chris Wailes488230c32014-08-14 11:22:40 -0700399 ANativeWindow * window = nullptr;
400 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800401
402 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700403 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800404 }
405
Tim Murrayeff663f2013-11-15 13:08:30 -0800406 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800407}
408
409static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800410nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700411{
Andreas Gampe67333922014-11-10 20:35:59 -0800412 if (kLogApi) {
413 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
414 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800415 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700416}
417
Jason Sams715333b2009-11-17 17:26:46 -0800418static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800419nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800420{
Andreas Gampe67333922014-11-10 20:35:59 -0800421 if (kLogApi) {
422 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
423 }
Jason Sams715333b2009-11-17 17:26:46 -0800424 rsContextDump((RsContext)con, bits);
425}
Jason Samsd19f10d2009-05-22 14:03:28 -0700426
427static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800428nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700429{
Andreas Gampe67333922014-11-10 20:35:59 -0800430 if (kLogApi) {
431 ALOGD("nContextPause, con(%p)", (RsContext)con);
432 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800433 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700434}
435
436static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800437nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700438{
Andreas Gampe67333922014-11-10 20:35:59 -0800439 if (kLogApi) {
440 ALOGD("nContextResume, con(%p)", (RsContext)con);
441 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800442 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700443}
444
Jason Sams1c415172010-11-08 17:06:46 -0800445
446static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800447nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800448{
Andreas Gampe67333922014-11-10 20:35:59 -0800449 if (kLogApi) {
450 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
451 }
Jason Sams1c415172010-11-08 17:06:46 -0800452 char buf[1024];
453
454 size_t receiveLen;
455 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800456 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700457 buf, sizeof(buf),
458 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700459 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800460 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100461 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800462 }
463 return _env->NewStringUTF(buf);
464}
465
Jason Samsedbfabd2011-05-17 15:01:29 -0700466static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800467nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700468{
Jason Sams516c3192009-10-06 13:58:47 -0700469 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800470 if (kLogApi) {
471 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
472 }
Chris Wailes488230c32014-08-14 11:22:40 -0700473 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700474 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800475 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800476 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700477 ptr, len * 4,
478 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700479 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700480 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100481 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700482 }
483 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000484 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800485}
486
487static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800488nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800489{
Andreas Gampe67333922014-11-10 20:35:59 -0800490 if (kLogApi) {
491 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
492 }
Chris Wailes488230c32014-08-14 11:22:40 -0700493 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800494 size_t receiveLen;
495 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800496 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700497 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800498 auxDataPtr[0] = (jint)subID;
499 auxDataPtr[1] = (jint)receiveLen;
500 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000501 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700502}
503
Tim Murrayeff663f2013-11-15 13:08:30 -0800504static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700505{
Andreas Gampe67333922014-11-10 20:35:59 -0800506 if (kLogApi) {
507 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
508 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800509 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700510}
511
Tim Murrayeff663f2013-11-15 13:08:30 -0800512static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700513{
Andreas Gampe67333922014-11-10 20:35:59 -0800514 if (kLogApi) {
515 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
516 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800517 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700518}
519
Jason Sams455d6442013-02-05 19:20:18 -0800520static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800521nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800522{
Chris Wailes488230c32014-08-14 11:22:40 -0700523 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800524 jint len = 0;
525 if (data) {
526 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700527 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800528 }
Andreas Gampe67333922014-11-10 20:35:59 -0800529 if (kLogApi) {
530 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
531 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800532 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800533 if (data) {
534 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
535 }
536}
537
538
Jason Sams516c3192009-10-06 13:58:47 -0700539
Tim Murray460a0492013-11-19 12:45:54 -0800540static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800541nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
542 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700543{
Andreas Gampe67333922014-11-10 20:35:59 -0800544 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100545 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con,
Andreas Gampe67333922014-11-10 20:35:59 -0800546 type, kind, norm, size);
547 }
548 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
549 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700550}
551
Tim Murray460a0492013-11-19 12:45:54 -0800552static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800553nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000554 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700555{
Jason Sams718cd1f2009-12-23 14:35:29 -0800556 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -0800557 if (kLogApi) {
558 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
559 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800560
Chris Wailes488230c32014-08-14 11:22:40 -0700561 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
562 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000563
564 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
565 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
566
567 for(int i = 0; i < fieldCount; i ++) {
568 ids[i] = (RsElement)jIds[i];
569 arraySizes[i] = (uint32_t)jArraySizes[i];
570 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800571
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800572 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
573
574 const char **nameArray = names.c_str();
575 size_t *sizeArray = names.c_str_len();
576
Tim Murray3aa89c12014-08-18 17:51:22 -0700577 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000578 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700579 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700580 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800581
Ashok Bhat98071552014-02-12 09:54:43 +0000582 free(ids);
583 free(arraySizes);
584 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
585 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
586
Tim Murray3aa89c12014-08-18 17:51:22 -0700587 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700588}
589
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700590static void
Tim Murray460a0492013-11-19 12:45:54 -0800591nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700592{
593 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -0800594 if (kLogApi) {
595 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
596 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700597
598 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
599 assert(dataSize == 5);
600
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000601 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800602 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700603
604 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000605 const jint data = (jint)elementData[i];
606 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700607 }
608}
609
610
611static void
Tim Murray460a0492013-11-19 12:45:54 -0800612nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000613 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700614 jobjectArray _names,
615 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700616{
Ashok Bhat98071552014-02-12 09:54:43 +0000617 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -0800618 if (kLogApi) {
619 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
620 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700621
Ashok Bhat98071552014-02-12 09:54:43 +0000622 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
623 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000624 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700625
Andreas Gampe67333922014-11-10 20:35:59 -0800626 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
627 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700628
Ashok Bhat98071552014-02-12 09:54:43 +0000629 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700630 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000631 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700632 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000633 _env->SetLongArrayRegion(_IDs, i, 1, &id);
634 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700635 }
636
637 free(ids);
638 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700639 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700640}
641
Jason Samsd19f10d2009-05-22 14:03:28 -0700642// -----------------------------------
643
Tim Murray460a0492013-11-19 12:45:54 -0800644static jlong
645nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800646 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700647{
Andreas Gampe67333922014-11-10 20:35:59 -0800648 if (kLogApi) {
649 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 +0100650 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv);
Andreas Gampe67333922014-11-10 20:35:59 -0800651 }
Jason Sams3b9c52a2010-10-14 17:48:46 -0700652
Andreas Gampe67333922014-11-10 20:35:59 -0800653 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
654 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700655}
656
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700657static void
Ashok Bhat98071552014-02-12 09:54:43 +0000658nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700659{
660 // We are packing 6 items: mDimX; mDimY; mDimZ;
661 // mDimLOD; mDimFaces; mElement; into typeData
662 int elementCount = _env->GetArrayLength(_typeData);
663
664 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -0800665 if (kLogApi) {
666 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
667 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700668
Ashok Bhat98071552014-02-12 09:54:43 +0000669 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -0800670 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700671
672 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700673 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000674 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700675 }
676}
677
Jason Samsd19f10d2009-05-22 14:03:28 -0700678// -----------------------------------
679
Tim Murray460a0492013-11-19 12:45:54 -0800680static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800681nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
682 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700683{
Andreas Gampe67333922014-11-10 20:35:59 -0800684 if (kLogApi) {
685 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
686 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
687 }
688 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
689 (RsAllocationMipmapControl)mips,
690 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700691}
692
Jason Samsd19f10d2009-05-22 14:03:28 -0700693static void
Tim Murray460a0492013-11-19 12:45:54 -0800694nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -0800695{
Andreas Gampe67333922014-11-10 20:35:59 -0800696 if (kLogApi) {
697 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
698 bits);
699 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800700 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -0800701}
702
Jason Sams72226e02013-02-22 12:45:54 -0800703static jobject
Tim Murray460a0492013-11-19 12:45:54 -0800704nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800705{
Andreas Gampe67333922014-11-10 20:35:59 -0800706 if (kLogApi) {
707 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
708 }
Jason Sams615e7ce2012-01-13 14:01:20 -0800709
Andreas Gampe67333922014-11-10 20:35:59 -0800710 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
711 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -0800712 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -0700713 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700714
Jason Sams72226e02013-02-22 12:45:54 -0800715 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
716 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700717}
718
719static void
Tim Murray460a0492013-11-19 12:45:54 -0800720nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800721{
Andreas Gampe67333922014-11-10 20:35:59 -0800722 if (kLogApi) {
723 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
724 (RsAllocation)alloc, (Surface *)sur);
725 }
Jason Sams163766c2012-02-15 12:04:24 -0800726
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700727 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800728 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700729 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800730 }
731
Andreas Gampe67333922014-11-10 20:35:59 -0800732 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
733 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800734}
735
736static void
Tim Murray460a0492013-11-19 12:45:54 -0800737nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800738{
Andreas Gampe67333922014-11-10 20:35:59 -0800739 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100740 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -0800741 }
Tim Murray460a0492013-11-19 12:45:54 -0800742 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800743}
744
745static void
Tim Murray460a0492013-11-19 12:45:54 -0800746nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800747{
Andreas Gampe67333922014-11-10 20:35:59 -0800748 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100749 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -0800750 }
Tim Murray460a0492013-11-19 12:45:54 -0800751 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800752}
753
754
755static void
Tim Murray460a0492013-11-19 12:45:54 -0800756nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -0800757{
Andreas Gampe67333922014-11-10 20:35:59 -0800758 if (kLogApi) {
759 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
760 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800761 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -0800762}
763
Tim Murray460a0492013-11-19 12:45:54 -0800764static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800765nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
766 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700767{
Jason Samsffe9f482009-06-01 17:45:53 -0700768 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000769 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -0700770 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700771
Jason Sams5476b452010-12-08 16:14:36 -0800772 bitmap.lockPixels();
773 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700774 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700775 (RsType)type, (RsAllocationMipmapControl)mip,
776 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800777 bitmap.unlockPixels();
778 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700779}
Jason Samsfe08d992009-05-27 14:45:32 -0700780
Tim Murray460a0492013-11-19 12:45:54 -0800781static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800782nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
783 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -0800784{
785 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000786 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -0800787 const SkBitmap& bitmap(*nativeBitmap);
788
789 bitmap.lockPixels();
790 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700791 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -0800792 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +0000793 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -0800794 bitmap.unlockPixels();
795 return id;
796}
797
Tim Murray460a0492013-11-19 12:45:54 -0800798static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800799nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
800 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800801{
802 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000803 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800804 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800805
Jason Sams5476b452010-12-08 16:14:36 -0800806 bitmap.lockPixels();
807 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700808 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700809 (RsType)type, (RsAllocationMipmapControl)mip,
810 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800811 bitmap.unlockPixels();
812 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800813}
814
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700815static void
Tim Murray460a0492013-11-19 12:45:54 -0800816nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700817{
818 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000819 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700820 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800821 int w = bitmap.width();
822 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700823
Jason Sams4ef66502010-12-10 16:03:15 -0800824 bitmap.lockPixels();
825 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800826 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700827 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea32012-11-27 14:55:08 -0800828 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800829 bitmap.unlockPixels();
830}
831
832static void
Tim Murray460a0492013-11-19 12:45:54 -0800833nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -0800834{
835 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000836 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -0800837 const SkBitmap& bitmap(*nativeBitmap);
838
839 bitmap.lockPixels();
840 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800841 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800842 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700843 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700844}
845
Stephen Hines414fa2c2014-04-17 01:02:42 -0700846// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700847static void
Tim Murray460a0492013-11-19 12:45:54 -0800848nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000849 jint count, jobject data, jint sizeBytes, jint dataType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700850{
Jason Samse729a942013-11-06 11:22:02 -0800851 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800852 if (kLogApi) {
853 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
854 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
855 dataType);
856 }
857 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count,
858 ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700859}
860
Stephen Hines414fa2c2014-04-17 01:02:42 -0700861// Copies from the Java array data into the Allocation pointed to by alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700862static void
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000863// native void rsnAllocationElementData1D(long con, long id, int xoff, int compIdx, byte[] d, int sizeBytes);
Andreas Gampe67333922014-11-10 20:35:59 -0800864nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod,
865 jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -0700866{
867 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800868 if (kLogApi) {
869 ALOGD("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), "
870 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, offset, compIdx, len,
871 sizeBytes);
872 }
Chris Wailes488230c32014-08-14 11:22:40 -0700873 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -0800874 rsAllocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700875 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
876}
877
Stephen Hines414fa2c2014-04-17 01:02:42 -0700878// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -0700879static void
Tim Murray460a0492013-11-19 12:45:54 -0800880nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000881 jint w, jint h, jobject data, jint sizeBytes, jint dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800882{
Jason Samse729a942013-11-06 11:22:02 -0800883 RsAllocation *alloc = (RsAllocation *)_alloc;
884 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -0800885 if (kLogApi) {
886 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
887 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
888 }
Chris Wailes488230c32014-08-14 11:22:40 -0700889 PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700890}
891
Stephen Hines414fa2c2014-04-17 01:02:42 -0700892// Copies from the Allocation pointed to by srcAlloc into the Allocation
893// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -0700894static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800895nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -0800896 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700897 jint dstMip, jint dstFace,
898 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -0800899 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700900 jint srcMip, jint srcFace)
901{
Andreas Gampe67333922014-11-10 20:35:59 -0800902 if (kLogApi) {
903 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
904 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
905 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
906 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
907 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
908 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700909
Tim Murrayeff663f2013-11-15 13:08:30 -0800910 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700911 (RsAllocation)dstAlloc,
912 dstXoff, dstYoff,
913 dstMip, dstFace,
914 width, height,
915 (RsAllocation)srcAlloc,
916 srcXoff, srcYoff,
917 srcMip, srcFace);
918}
919
Stephen Hines414fa2c2014-04-17 01:02:42 -0700920// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700921static void
Tim Murray460a0492013-11-19 12:45:54 -0800922nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Jason Samse729a942013-11-06 11:22:02 -0800923 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
Jason Samsb05d6892013-04-09 15:59:24 -0700924{
Jason Samse729a942013-11-06 11:22:02 -0800925 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800926 if (kLogApi) {
927 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
928 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
929 lod, w, h, d, sizeBytes);
930 }
Chris Wailes488230c32014-08-14 11:22:40 -0700931 PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -0700932}
933
Stephen Hines414fa2c2014-04-17 01:02:42 -0700934// Copies from the Allocation pointed to by srcAlloc into the Allocation
935// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -0700936static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800937nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -0800938 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700939 jint dstMip,
940 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -0800941 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700942 jint srcMip)
943{
Andreas Gampe67333922014-11-10 20:35:59 -0800944 if (kLogApi) {
945 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
946 " dstMip(%i), width(%i), height(%i),"
947 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
948 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
949 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
950 }
Jason Samsb05d6892013-04-09 15:59:24 -0700951
Tim Murrayeff663f2013-11-15 13:08:30 -0800952 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -0700953 (RsAllocation)dstAlloc,
954 dstXoff, dstYoff, dstZoff, dstMip,
955 width, height, depth,
956 (RsAllocation)srcAlloc,
957 srcXoff, srcYoff, srcZoff, srcMip);
958}
959
Jason Sams21659ac2013-11-06 15:08:07 -0800960
Stephen Hines414fa2c2014-04-17 01:02:42 -0700961// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -0700962static void
Tim Murray460a0492013-11-19 12:45:54 -0800963nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType)
Jason Sams40a29e82009-08-10 14:55:26 -0700964{
Jason Sams21659ac2013-11-06 15:08:07 -0800965 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800966 if (kLogApi) {
967 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
968 }
Stephen Hines414fa2c2014-04-17 01:02:42 -0700969 PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -0700970}
971
Stephen Hines414fa2c2014-04-17 01:02:42 -0700972// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -0700973static void
Tim Murray460a0492013-11-19 12:45:54 -0800974nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Jason Sams21659ac2013-11-06 15:08:07 -0800975 jint count, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800976{
Jason Sams21659ac2013-11-06 15:08:07 -0800977 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800978 if (kLogApi) {
979 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
980 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
981 }
Stephen Hines414fa2c2014-04-17 01:02:42 -0700982 PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800983}
984
Stephen Hines414fa2c2014-04-17 01:02:42 -0700985// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -0800986static void
Tim Murray460a0492013-11-19 12:45:54 -0800987nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Jason Sams21659ac2013-11-06 15:08:07 -0800988 jint w, jint h, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800989{
Jason Sams21659ac2013-11-06 15:08:07 -0800990 RsAllocation *alloc = (RsAllocation *)_alloc;
991 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -0800992 if (kLogApi) {
993 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
994 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
995 }
996 PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h,
997 ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700998}
Jason Samsd19f10d2009-05-22 14:03:28 -0700999
Tim Murray460a0492013-11-19 12:45:54 -08001000static jlong
1001nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001002{
Andreas Gampe67333922014-11-10 20:35:59 -08001003 if (kLogApi) {
1004 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
1005 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001006 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -07001007}
1008
Jason Sams5edc6082010-10-05 13:32:49 -07001009static void
Tim Murray460a0492013-11-19 12:45:54 -08001010nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -07001011{
Andreas Gampe67333922014-11-10 20:35:59 -08001012 if (kLogApi) {
1013 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
1014 (RsAllocation)alloc, dimX);
1015 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001016 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -07001017}
1018
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001019// -----------------------------------
1020
Tim Murray460a0492013-11-19 12:45:54 -08001021static jlong
1022nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001023{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001024 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001025 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001026
Tim Murray3aa89c12014-08-18 17:51:22 -07001027 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001028 return id;
1029}
1030
Tim Murray460a0492013-11-19 12:45:54 -08001031static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001032nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001033{
1034 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001035 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001036 return 0;
1037 }
1038
1039 AutoJavaStringToUTF8 str(_env, _path);
1040 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001041 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001042 return 0;
1043 }
1044
Tim Murray3aa89c12014-08-18 17:51:22 -07001045 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001046 return id;
1047}
1048
Tim Murray460a0492013-11-19 12:45:54 -08001049static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001050nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001051{
1052 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001053 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001054
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001055 return id;
1056}
1057
Tim Murray460a0492013-11-19 12:45:54 -08001058static jint
1059nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001060{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001061 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001062 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001063 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001064}
1065
1066static void
Tim Murray460a0492013-11-19 12:45:54 -08001067nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001068{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001069 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001070 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
1071
Tim Murrayeff663f2013-11-15 13:08:30 -08001072 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001073
1074 for(jint i = 0; i < numEntries; i ++) {
1075 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
1076 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
1077 }
1078
1079 free(fileEntries);
1080}
1081
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001082static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001083nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001084{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001085 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001086 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001087 return id;
1088}
Jason Samsd19f10d2009-05-22 14:03:28 -07001089
1090// -----------------------------------
1091
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001092static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001093nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001094 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001095{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001096 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001097 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001098 fileNameUTF.c_str(), fileNameUTF.length(),
1099 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001100
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001101 return id;
1102}
1103
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001104static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001105nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001106 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001107{
1108 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1109 AutoJavaStringToUTF8 nameUTF(_env, name);
1110
Tim Murray3aa89c12014-08-18 17:51:22 -07001111 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001112 nameUTF.c_str(), nameUTF.length(),
1113 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001114 asset->getBuffer(false), asset->getLength());
1115 return id;
1116}
1117
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001118static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001119nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001120 jfloat fontSize, jint dpi)
1121{
1122 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001123 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001124 return 0;
1125 }
1126
1127 AutoJavaStringToUTF8 str(_env, _path);
1128 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001129 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001130 return 0;
1131 }
1132
Tim Murray3aa89c12014-08-18 17:51:22 -07001133 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001134 str.c_str(), str.length(),
1135 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001136 asset->getBuffer(false), asset->getLength());
1137 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001138 return id;
1139}
1140
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001141// -----------------------------------
1142
1143static void
Tim Murray460a0492013-11-19 12:45:54 -08001144nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001145{
Andreas Gampe67333922014-11-10 20:35:59 -08001146 if (kLogApi) {
1147 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1148 (RsScript)script, (RsAllocation)alloc, slot);
1149 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001150 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001151}
1152
1153static void
Tim Murray460a0492013-11-19 12:45:54 -08001154nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001155{
Andreas Gampe67333922014-11-10 20:35:59 -08001156 if (kLogApi) {
1157 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1158 slot, val);
1159 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001160 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001161}
1162
Tim Murray7c4caad2013-04-10 16:21:40 -07001163static jint
Tim Murray460a0492013-11-19 12:45:54 -08001164nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001165{
Andreas Gampe67333922014-11-10 20:35:59 -08001166 if (kLogApi) {
1167 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1168 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001169 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001170 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001171 return value;
1172}
1173
Jason Sams4d339932010-05-11 14:03:58 -07001174static void
Tim Murray460a0492013-11-19 12:45:54 -08001175nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001176{
Andreas Gampe67333922014-11-10 20:35:59 -08001177 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001178 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001179 slot, val);
1180 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001181 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001182}
1183
1184static void
Tim Murray460a0492013-11-19 12:45:54 -08001185nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001186{
Andreas Gampe67333922014-11-10 20:35:59 -08001187 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001188 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001189 slot, val);
1190 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001191 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001192}
1193
Tim Murray7c4caad2013-04-10 16:21:40 -07001194static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001195nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001196{
Andreas Gampe67333922014-11-10 20:35:59 -08001197 if (kLogApi) {
1198 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1199 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001200 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001201 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001202 return value;
1203}
1204
Stephen Hines031ec58c2010-10-11 10:54:21 -07001205static void
Tim Murray460a0492013-11-19 12:45:54 -08001206nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001207{
Andreas Gampe67333922014-11-10 20:35:59 -08001208 if (kLogApi) {
1209 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1210 slot, val);
1211 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001212 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001213}
1214
Tim Murray7c4caad2013-04-10 16:21:40 -07001215static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001216nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001217{
Andreas Gampe67333922014-11-10 20:35:59 -08001218 if (kLogApi) {
1219 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1220 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001221 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001222 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001223 return value;
1224}
1225
Jason Sams4d339932010-05-11 14:03:58 -07001226static void
Tim Murray460a0492013-11-19 12:45:54 -08001227nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001228{
Andreas Gampe67333922014-11-10 20:35:59 -08001229 if (kLogApi) {
1230 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1231 slot, val);
1232 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001233 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001234}
1235
Tim Murray7c4caad2013-04-10 16:21:40 -07001236static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001237nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001238{
Andreas Gampe67333922014-11-10 20:35:59 -08001239 if (kLogApi) {
1240 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1241 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001242 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001243 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001244 return value;
1245}
1246
Stephen Hinesca54ec32010-09-20 17:20:30 -07001247static void
Tim Murray460a0492013-11-19 12:45:54 -08001248nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001249{
Andreas Gampe67333922014-11-10 20:35:59 -08001250 if (kLogApi) {
1251 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1252 }
Jason Sams4d339932010-05-11 14:03:58 -07001253 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001254 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001255 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001256 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1257}
1258
Stephen Hinesadeb8092012-04-20 14:26:06 -07001259static void
Tim Murray460a0492013-11-19 12:45:54 -08001260nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001261{
Andreas Gampe67333922014-11-10 20:35:59 -08001262 if (kLogApi) {
1263 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1264 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001265 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001266 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001267 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001268 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001269}
1270
1271static void
Andreas Gampe67333922014-11-10 20:35:59 -08001272nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1273 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001274{
Andreas Gampe67333922014-11-10 20:35:59 -08001275 if (kLogApi) {
1276 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1277 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001278 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001279 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001280 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001281 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001282 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001283 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001284 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1285 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1286}
1287
Jason Samsd19f10d2009-05-22 14:03:28 -07001288
1289static void
Tim Murray460a0492013-11-19 12:45:54 -08001290nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001291{
Andreas Gampe67333922014-11-10 20:35:59 -08001292 if (kLogApi) {
1293 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1294 }
Romain Guy584a3752009-07-30 18:45:01 -07001295
1296 jint length = _env->GetArrayLength(timeZone);
1297 jbyte* timeZone_ptr;
1298 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1299
Tim Murrayeff663f2013-11-15 13:08:30 -08001300 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001301
1302 if (timeZone_ptr) {
1303 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1304 }
1305}
1306
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001307static void
Tim Murray460a0492013-11-19 12:45:54 -08001308nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001309{
Andreas Gampe67333922014-11-10 20:35:59 -08001310 if (kLogApi) {
1311 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1312 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001313 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001314}
1315
1316static void
Tim Murray460a0492013-11-19 12:45:54 -08001317nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001318{
Andreas Gampe67333922014-11-10 20:35:59 -08001319 if (kLogApi) {
1320 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1321 }
Jason Sams4d339932010-05-11 14:03:58 -07001322 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001323 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001324 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001325 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1326}
1327
Jason Sams6e494d32011-04-27 16:33:11 -07001328static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001329nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1330 jlongArray ains, jlong aout, jbyteArray params,
1331 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001332{
Andreas Gampe67333922014-11-10 20:35:59 -08001333 if (kLogApi) {
1334 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1335 }
Jason Sams6e494d32011-04-27 16:33:11 -07001336
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001337 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001338 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001339
Chris Wailes488230c32014-08-14 11:22:40 -07001340 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001341
Chris Wailes488230c32014-08-14 11:22:40 -07001342 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001343 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001344 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001345
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001346 if (sizeof(RsAllocation) == sizeof(jlong)) {
1347 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001348
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001349 } else {
1350 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001351
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001352 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1353
1354 for (int index = in_len; --index >= 0;) {
1355 in_allocs[index] = (RsAllocation)in_ptr[index];
1356 }
1357 }
Chris Wailes94961062014-06-11 12:01:28 -07001358 }
1359
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001360 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001361 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001362
Chris Wailes488230c32014-08-14 11:22:40 -07001363 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001364 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001365 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001366 }
1367
Chris Wailes488230c32014-08-14 11:22:40 -07001368 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001369 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001370
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001371 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001372 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001373
Chris Wailes488230c32014-08-14 11:22:40 -07001374 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001375 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001376 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001377
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001378 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001379 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001380
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001381 sc.xStart = limit_ptr[0];
1382 sc.xEnd = limit_ptr[1];
1383 sc.yStart = limit_ptr[2];
1384 sc.yEnd = limit_ptr[3];
1385 sc.zStart = limit_ptr[4];
1386 sc.zEnd = limit_ptr[5];
1387 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Jason Sams14331ab2015-01-26 18:14:36 -08001388 sc.arrayStart = 0;
1389 sc.arrayEnd = 0;
1390 sc.array2Start = 0;
1391 sc.array2End = 0;
1392 sc.array3Start = 0;
1393 sc.array3End = 0;
1394 sc.array4Start = 0;
1395 sc.array4End = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001396
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001397 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001398 }
1399
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001400 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1401 in_allocs, in_len, (RsAllocation)aout,
1402 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001403
Chris Wailes488230c32014-08-14 11:22:40 -07001404 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001405 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001406 }
1407
Chris Wailes488230c32014-08-14 11:22:40 -07001408 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001409 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1410 }
1411
Chris Wailes488230c32014-08-14 11:22:40 -07001412 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001413 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1414 }
Chris Wailes94961062014-06-11 12:01:28 -07001415}
1416
Jason Sams22534172009-08-04 16:58:20 -07001417// -----------------------------------
1418
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001419static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001420nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001421 jstring resName, jstring cacheDir,
1422 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001423{
Andreas Gampe67333922014-11-10 20:35:59 -08001424 if (kLogApi) {
1425 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1426 }
Jason Sams22534172009-08-04 16:58:20 -07001427
Jason Samse4a06c52011-03-16 16:29:28 -07001428 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1429 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001430 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001431 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001432 jint _exception = 0;
1433 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001434 if (!scriptRef) {
1435 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001436 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001437 goto exit;
1438 }
Jack Palevich43702d82009-05-28 13:38:16 -07001439 if (length < 0) {
1440 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001441 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001442 goto exit;
1443 }
Jason Samse4a06c52011-03-16 16:29:28 -07001444 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001445 if (remaining < length) {
1446 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001447 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1448 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001449 goto exit;
1450 }
Jason Samse4a06c52011-03-16 16:29:28 -07001451 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001452 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001453
Tim Murrayeff663f2013-11-15 13:08:30 -08001454 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001455
Tim Murray3aa89c12014-08-18 17:51:22 -07001456 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001457 resNameUTF.c_str(), resNameUTF.length(),
1458 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001459 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001460
Jack Palevich43702d82009-05-28 13:38:16 -07001461exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001462 if (script_ptr) {
1463 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001464 _exception ? JNI_ABORT: 0);
1465 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001466
Tim Murray3aa89c12014-08-18 17:51:22 -07001467 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001468}
1469
Tim Murray460a0492013-11-19 12:45:54 -08001470static jlong
1471nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001472{
Andreas Gampe67333922014-11-10 20:35:59 -08001473 if (kLogApi) {
1474 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1475 (void *)eid);
1476 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001477 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001478}
1479
Tim Murray460a0492013-11-19 12:45:54 -08001480static jlong
1481nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001482{
Andreas Gampe67333922014-11-10 20:35:59 -08001483 if (kLogApi) {
1484 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1485 (void *)sid, slot, sig);
1486 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001487 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001488}
1489
Tim Murray460a0492013-11-19 12:45:54 -08001490static jlong
1491nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001492{
Andreas Gampe67333922014-11-10 20:35:59 -08001493 if (kLogApi) {
1494 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1495 slot);
1496 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001497 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001498}
1499
Tim Murray460a0492013-11-19 12:45:54 -08001500static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001501nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1502 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001503{
Andreas Gampe67333922014-11-10 20:35:59 -08001504 if (kLogApi) {
1505 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1506 }
Jason Sams08a81582012-09-18 12:32:10 -07001507
Ashok Bhat98071552014-02-12 09:54:43 +00001508 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001509 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001510 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1511 for(int i = 0; i < kernelsLen; ++i) {
1512 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1513 }
Jason Sams08a81582012-09-18 12:32:10 -07001514
Ashok Bhat98071552014-02-12 09:54:43 +00001515 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001516 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001517 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1518 for(int i = 0; i < srcLen; ++i) {
1519 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1520 }
Jason Sams08a81582012-09-18 12:32:10 -07001521
Ashok Bhat98071552014-02-12 09:54:43 +00001522 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001523 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001524 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1525 for(int i = 0; i < dstkLen; ++i) {
1526 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1527 }
1528
1529 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001530 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001531 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1532 for(int i = 0; i < dstfLen; ++i) {
1533 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1534 }
1535
1536 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001537 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001538 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1539 for(int i = 0; i < typesLen; ++i) {
1540 typesPtr[i] = (RsType)jTypesPtr[i];
1541 }
1542
Tim Murray3aa89c12014-08-18 17:51:22 -07001543 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001544 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1545 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1546 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1547 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1548 (RsType *)typesPtr, typesLen * sizeof(RsType));
1549
1550 free(kernelsPtr);
1551 free(srcPtr);
1552 free(dstkPtr);
1553 free(dstfPtr);
1554 free(typesPtr);
1555 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1556 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1557 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1558 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1559 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001560 return id;
1561}
1562
1563static void
Tim Murray460a0492013-11-19 12:45:54 -08001564nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001565{
Andreas Gampe67333922014-11-10 20:35:59 -08001566 if (kLogApi) {
1567 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1568 (void *)gid, (void *)kid, (void *)alloc);
1569 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001570 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001571}
1572
1573static void
Tim Murray460a0492013-11-19 12:45:54 -08001574nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001575{
Andreas Gampe67333922014-11-10 20:35:59 -08001576 if (kLogApi) {
1577 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1578 (void *)gid, (void *)kid, (void *)alloc);
1579 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001580 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001581}
1582
1583static void
Tim Murray460a0492013-11-19 12:45:54 -08001584nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001585{
Andreas Gampe67333922014-11-10 20:35:59 -08001586 if (kLogApi) {
1587 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
1588 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001589 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001590}
1591
Jason Samsd19f10d2009-05-22 14:03:28 -07001592// ---------------------------------------------------------------------------
1593
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001594static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001595nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001596 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1597 jboolean depthMask, jboolean ditherEnable,
1598 jint srcFunc, jint destFunc,
1599 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001600{
Andreas Gampe67333922014-11-10 20:35:59 -08001601 if (kLogApi) {
1602 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
1603 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001604 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07001605 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1606 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001607}
1608
Jason Sams0011bcf2009-12-15 12:58:36 -08001609// ---------------------------------------------------------------------------
1610
1611static void
Tim Murray460a0492013-11-19 12:45:54 -08001612nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001613{
Andreas Gampe67333922014-11-10 20:35:59 -08001614 if (kLogApi) {
1615 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
1616 (RsProgramVertex)vpv, slot, (RsAllocation)a);
1617 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001618 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08001619}
Jason Sams54c0ec12009-11-30 14:49:55 -08001620
Jason Sams68afd012009-12-17 16:55:08 -08001621static void
Tim Murray460a0492013-11-19 12:45:54 -08001622nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001623{
Andreas Gampe67333922014-11-10 20:35:59 -08001624 if (kLogApi) {
1625 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1626 (RsProgramFragment)vpf, slot, (RsAllocation)a);
1627 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001628 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08001629}
1630
1631static void
Tim Murray460a0492013-11-19 12:45:54 -08001632nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001633{
Andreas Gampe67333922014-11-10 20:35:59 -08001634 if (kLogApi) {
1635 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1636 (RsProgramFragment)vpf, slot, (RsSampler)a);
1637 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001638 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08001639}
1640
Jason Samsd19f10d2009-05-22 14:03:28 -07001641// ---------------------------------------------------------------------------
1642
Tim Murray460a0492013-11-19 12:45:54 -08001643static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001644nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001645 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001646{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001647 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001648 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001649 jint paramLen = _env->GetArrayLength(params);
1650
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001651 int texCount = _env->GetArrayLength(texNames);
1652 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1653 const char ** nameArray = names.c_str();
1654 size_t* sizeArray = names.c_str_len();
1655
Andreas Gampe67333922014-11-10 20:35:59 -08001656 if (kLogApi) {
1657 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1658 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001659
Ashok Bhat98071552014-02-12 09:54:43 +00001660 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1661 for(int i = 0; i < paramLen; ++i) {
1662 paramPtr[i] = (uintptr_t)jParamPtr[i];
1663 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001664 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001665 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001666 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001667
Ashok Bhat98071552014-02-12 09:54:43 +00001668 free(paramPtr);
1669 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001670 return ret;
1671}
1672
1673
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001674// ---------------------------------------------------------------------------
1675
Tim Murray460a0492013-11-19 12:45:54 -08001676static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001677nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001678 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001679{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001680 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001681 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08001682 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001683
Andreas Gampe67333922014-11-10 20:35:59 -08001684 if (kLogApi) {
1685 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1686 }
Jason Sams0011bcf2009-12-15 12:58:36 -08001687
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001688 int texCount = _env->GetArrayLength(texNames);
1689 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1690 const char ** nameArray = names.c_str();
1691 size_t* sizeArray = names.c_str_len();
1692
Ashok Bhat98071552014-02-12 09:54:43 +00001693 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1694 for(int i = 0; i < paramLen; ++i) {
1695 paramPtr[i] = (uintptr_t)jParamPtr[i];
1696 }
1697
Tim Murray3aa89c12014-08-18 17:51:22 -07001698 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001699 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001700 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001701
Ashok Bhat98071552014-02-12 09:54:43 +00001702 free(paramPtr);
1703 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08001704 return ret;
1705}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001706
Jason Samsebfb4362009-09-23 13:57:02 -07001707// ---------------------------------------------------------------------------
1708
Tim Murray460a0492013-11-19 12:45:54 -08001709static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001710nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001711{
Andreas Gampe67333922014-11-10 20:35:59 -08001712 if (kLogApi) {
1713 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
1714 pointSprite, cull);
1715 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001716 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001717}
1718
Jason Samsd19f10d2009-05-22 14:03:28 -07001719
1720// ---------------------------------------------------------------------------
1721
1722static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001723nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001724{
Andreas Gampe67333922014-11-10 20:35:59 -08001725 if (kLogApi) {
1726 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
1727 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001728 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001729}
1730
1731static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001732nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001733{
Andreas Gampe67333922014-11-10 20:35:59 -08001734 if (kLogApi) {
1735 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
1736 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001737 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001738}
1739
1740static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001741nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001742{
Andreas Gampe67333922014-11-10 20:35:59 -08001743 if (kLogApi) {
1744 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
1745 (RsProgramFragment)pf);
1746 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001747 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001748}
1749
Jason Sams0826a6f2009-06-15 19:04:56 -07001750static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001751nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001752{
Andreas Gampe67333922014-11-10 20:35:59 -08001753 if (kLogApi) {
1754 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
1755 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001756 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001757}
1758
Joe Onoratod7b37742009-08-09 22:57:44 -07001759static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001760nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001761{
Andreas Gampe67333922014-11-10 20:35:59 -08001762 if (kLogApi) {
1763 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
1764 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001765 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07001766}
1767
Joe Onoratod7b37742009-08-09 22:57:44 -07001768
Jason Sams02fb2cb2009-05-28 15:37:57 -07001769// ---------------------------------------------------------------------------
1770
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001771static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001772nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001773 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001774{
Andreas Gampe67333922014-11-10 20:35:59 -08001775 if (kLogApi) {
1776 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
1777 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001778 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001779 (RsSamplerValue)magFilter,
1780 (RsSamplerValue)minFilter,
1781 (RsSamplerValue)wrapS,
1782 (RsSamplerValue)wrapT,
1783 (RsSamplerValue)wrapR,
1784 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001785}
1786
Jason Samsbba134c2009-06-22 15:49:21 -07001787// ---------------------------------------------------------------------------
1788
Tim Murray460a0492013-11-19 12:45:54 -08001789static jlong
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001790nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) {
Andreas Gampe67333922014-11-10 20:35:59 -08001791 if (kLogApi) {
1792 ALOGD("nPathCreate, con(%p)", (RsContext)con);
1793 }
Jason Samsf15ed012011-10-31 13:23:43 -07001794
Tim Murray3aa89c12014-08-18 17:51:22 -07001795 jlong id = (jlong)(uintptr_t)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic,
Tim Murray460a0492013-11-19 12:45:54 -08001796 (RsAllocation)_vtx,
1797 (RsAllocation)_loop, q);
Jason Samsf15ed012011-10-31 13:23:43 -07001798 return id;
1799}
1800
Tim Murray460a0492013-11-19 12:45:54 -08001801static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001802nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001803{
Andreas Gampe67333922014-11-10 20:35:59 -08001804 if (kLogApi) {
1805 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
1806 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001807
1808 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07001809 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001810 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
1811 for(int i = 0; i < vtxLen; ++i) {
1812 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
1813 }
1814
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001815 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07001816 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001817 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
1818 for(int i = 0; i < idxLen; ++i) {
1819 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
1820 }
1821
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001822 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07001823 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001824
Tim Murray3aa89c12014-08-18 17:51:22 -07001825 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001826 (RsAllocation *)vtxPtr, vtxLen,
1827 (RsAllocation *)idxPtr, idxLen,
1828 (uint32_t *)primPtr, primLen);
1829
Ashok Bhat98071552014-02-12 09:54:43 +00001830 free(vtxPtr);
1831 free(idxPtr);
1832 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
1833 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001834 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001835 return id;
1836}
1837
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001838static jint
Tim Murray460a0492013-11-19 12:45:54 -08001839nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001840{
Andreas Gampe67333922014-11-10 20:35:59 -08001841 if (kLogApi) {
1842 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1843 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001844 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001845 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001846 return vtxCount;
1847}
1848
1849static jint
Tim Murray460a0492013-11-19 12:45:54 -08001850nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001851{
Andreas Gampe67333922014-11-10 20:35:59 -08001852 if (kLogApi) {
1853 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1854 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001855 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001856 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001857 return idxCount;
1858}
1859
1860static void
Ashok Bhat98071552014-02-12 09:54:43 +00001861nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001862{
Andreas Gampe67333922014-11-10 20:35:59 -08001863 if (kLogApi) {
1864 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1865 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001866
1867 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08001868 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001869
1870 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001871 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001872 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001873 }
1874
1875 free(allocs);
1876}
1877
1878static void
Ashok Bhat98071552014-02-12 09:54:43 +00001879nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001880{
Andreas Gampe67333922014-11-10 20:35:59 -08001881 if (kLogApi) {
1882 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1883 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001884
1885 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1886 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1887
Tim Murrayeff663f2013-11-15 13:08:30 -08001888 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001889
1890 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001891 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001892 const jint prim = (jint)prims[i];
1893 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
1894 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001895 }
1896
1897 free(allocs);
1898 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001899}
1900
Tim Murray56f9e6f2014-05-16 11:47:26 -07001901static jint
1902nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
1903 return (jint)sizeof(void*);
1904}
1905
1906
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001907// ---------------------------------------------------------------------------
1908
Jason Samsd19f10d2009-05-22 14:03:28 -07001909
Jason Sams94d8e90a2009-06-10 16:09:05 -07001910static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001911
1912static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001913{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001914
Tim Murrayeff663f2013-11-15 13:08:30 -08001915{"nDeviceCreate", "()J", (void*)nDeviceCreate },
1916{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
1917{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
1918{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
1919{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
1920{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001921
Tim Murrayeff663f2013-11-15 13:08:30 -08001922{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
1923{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001924
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001925
Jason Sams2e1872f2010-08-17 16:25:41 -07001926// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08001927{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
1928{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
1929{"rsnContextFinish", "(J)V", (void*)nContextFinish },
1930{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
1931{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
1932{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
1933{"rsnContextDump", "(JI)V", (void*)nContextDump },
1934{"rsnContextPause", "(J)V", (void*)nContextPause },
1935{"rsnContextResume", "(J)V", (void*)nContextResume },
1936{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Yang Ni281c3252014-10-24 08:52:24 -07001937{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate },
1938{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg },
1939{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal },
Tim Murray460a0492013-11-19 12:45:54 -08001940{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
1941{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
1942{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001943
Tim Murray460a0492013-11-19 12:45:54 -08001944{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001945{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08001946{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
1947{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
1948{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001949{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001950
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001951{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
1952{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
1953{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001954
Tim Murray460a0492013-11-19 12:45:54 -08001955{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001956{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08001957{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00001958{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001959
Tim Murray460a0492013-11-19 12:45:54 -08001960{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001961{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001962
Ashok Bhat98071552014-02-12 09:54:43 +00001963{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08001964{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
1965{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
1966{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001967
Tim Murray460a0492013-11-19 12:45:54 -08001968{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1969{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08001970
Tim Murray460a0492013-11-19 12:45:54 -08001971{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
1972{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
1973{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
1974{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
1975{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
1976{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
1977{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D },
1978{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
1979{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
1980{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
1981{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
1982{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead },
1983{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
1984{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
1985{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
1986{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
1987{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001988
Tim Murray460a0492013-11-19 12:45:54 -08001989{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
1990{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
1991{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
1992{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001993
1994{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
1995
Tim Murray460a0492013-11-19 12:45:54 -08001996{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
1997{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
1998{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
1999{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
2000{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
2001{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
2002{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
2003{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
2004{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
2005{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
2006{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
2007{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07002008
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002009{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002010{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
2011{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
2012{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002013{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Yang Niebf63402015-01-16 11:06:26 -08002014{"rsnScriptGroup2Create", "(JLjava/lang/String;[J)J", (void*)nScriptGroup2Create },
Tim Murray460a0492013-11-19 12:45:54 -08002015{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
2016{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
2017{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Yang Ni281c3252014-10-24 08:52:24 -07002018{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute },
Jason Sams0011bcf2009-12-15 12:58:36 -08002019
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002020{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002021
Tim Murray460a0492013-11-19 12:45:54 -08002022{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
2023{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
2024{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07002025
Ashok Bhat98071552014-02-12 09:54:43 +00002026{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08002027{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002028{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07002029
Narayan Kamath78c0ce52014-03-19 10:15:51 +00002030{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
2031{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
2032{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
2033{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
2034{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07002035
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002036{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07002037
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002038{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00002039{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07002040
Tim Murray460a0492013-11-19 12:45:54 -08002041{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
2042{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00002043{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
2044{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07002045
Tim Murray56f9e6f2014-05-16 11:47:26 -07002046{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07002047};
2048
2049static int registerFuncs(JNIEnv *_env)
2050{
2051 return android::AndroidRuntime::registerNativeMethods(
2052 _env, classPathName, methods, NELEM(methods));
2053}
2054
2055// ---------------------------------------------------------------------------
2056
2057jint JNI_OnLoad(JavaVM* vm, void* reserved)
2058{
Chris Wailes488230c32014-08-14 11:22:40 -07002059 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07002060 jint result = -1;
2061
Jason Samsd19f10d2009-05-22 14:03:28 -07002062 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00002063 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002064 goto bail;
2065 }
Chris Wailes488230c32014-08-14 11:22:40 -07002066 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07002067
2068 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00002069 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07002070 goto bail;
2071 }
2072
2073 /* success -- return valid version number */
2074 result = JNI_VERSION_1_4;
2075
2076bail:
2077 return result;
2078}