blob: 68a0b83877664d6203ddf515d0660a1bec613092 [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 Sams3eaa338e2009-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
196static void
Tim Murray460a0492013-11-19 12:45:54 -0800197nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700198{
Andreas Gampe67333922014-11-10 20:35:59 -0800199 if (kLogApi) {
200 ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
201 }
Jason Sams3eaa338e2009-06-10 15:04:38 -0700202 jint len = _env->GetArrayLength(str);
203 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800204 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700205 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
206}
207
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700208static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800209nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700210{
Andreas Gampe67333922014-11-10 20:35:59 -0800211 if (kLogApi) {
212 ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
213 }
Chris Wailes488230c32014-08-14 11:22:40 -0700214 const char *name = nullptr;
Tim Murrayeff663f2013-11-15 13:08:30 -0800215 rsaGetName((RsContext)con, (void *)obj, &name);
Chris Wailes488230c32014-08-14 11:22:40 -0700216 if(name == nullptr || strlen(name) == 0) {
217 return nullptr;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700218 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700219 return _env->NewStringUTF(name);
220}
221
Jason Sams7ce033d2009-08-18 14:14:24 -0700222static void
Tim Murray460a0492013-11-19 12:45:54 -0800223nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700224{
Andreas Gampe67333922014-11-10 20:35:59 -0800225 if (kLogApi) {
226 ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
227 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800228 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700229}
230
Jason Sams3eaa338e2009-06-10 15:04:38 -0700231// ---------------------------------------------------------------------------
232
Tim Murrayeff663f2013-11-15 13:08:30 -0800233static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700234nDeviceCreate(JNIEnv *_env, jobject _this)
235{
Andreas Gampe67333922014-11-10 20:35:59 -0800236 if (kLogApi) {
237 ALOGD("nDeviceCreate");
238 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700239 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700240}
241
242static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800243nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700244{
Andreas Gampe67333922014-11-10 20:35:59 -0800245 if (kLogApi) {
246 ALOGD("nDeviceDestroy");
247 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700248 return rsDeviceDestroy((RsDevice)dev);
249}
250
Jason Samsebfb4362009-09-23 13:57:02 -0700251static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800252nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700253{
Andreas Gampe67333922014-11-10 20:35:59 -0800254 if (kLogApi) {
255 ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
256 }
Jason Samsebfb4362009-09-23 13:57:02 -0700257 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
258}
259
Tim Murrayeff663f2013-11-15 13:08:30 -0800260static jlong
Jason Sams81cd2b12014-12-02 12:36:43 -0800261nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700262{
Andreas Gampe67333922014-11-10 20:35:59 -0800263 if (kLogApi) {
264 ALOGD("nContextCreate");
265 }
Jason Sams81cd2b12014-12-02 12:36:43 -0800266 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags);
Jason Sams704ff642010-02-09 16:05:07 -0800267}
268
Tim Murrayeff663f2013-11-15 13:08:30 -0800269static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800270nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000271 jint colorMin, jint colorPref,
272 jint alphaMin, jint alphaPref,
273 jint depthMin, jint depthPref,
274 jint stencilMin, jint stencilPref,
275 jint samplesMin, jint samplesPref, jfloat samplesQ,
276 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800277{
Jason Sams11c8af92010-10-13 15:31:10 -0700278 RsSurfaceConfig sc;
279 sc.alphaMin = alphaMin;
280 sc.alphaPref = alphaPref;
281 sc.colorMin = colorMin;
282 sc.colorPref = colorPref;
283 sc.depthMin = depthMin;
284 sc.depthPref = depthPref;
285 sc.samplesMin = samplesMin;
286 sc.samplesPref = samplesPref;
287 sc.samplesQ = samplesQ;
288
Andreas Gampe67333922014-11-10 20:35:59 -0800289 if (kLogApi) {
290 ALOGD("nContextCreateGL");
291 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700292 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700293}
294
295static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800296nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800297{
Andreas Gampe67333922014-11-10 20:35:59 -0800298 if (kLogApi) {
299 ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
300 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800301 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800302}
303
304
305
306static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800307nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800308{
Andreas Gampe67333922014-11-10 20:35:59 -0800309 if (kLogApi) {
310 ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con,
311 width, height, (Surface *)wnd);
312 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800313
Chris Wailes488230c32014-08-14 11:22:40 -0700314 ANativeWindow * window = nullptr;
315 if (wnd == nullptr) {
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800316
317 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700318 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800319 }
320
Tim Murrayeff663f2013-11-15 13:08:30 -0800321 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800322}
323
324static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800325nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700326{
Andreas Gampe67333922014-11-10 20:35:59 -0800327 if (kLogApi) {
328 ALOGD("nContextDestroy, con(%p)", (RsContext)con);
329 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800330 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700331}
332
Jason Sams715333b2009-11-17 17:26:46 -0800333static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800334nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800335{
Andreas Gampe67333922014-11-10 20:35:59 -0800336 if (kLogApi) {
337 ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
338 }
Jason Sams715333b2009-11-17 17:26:46 -0800339 rsContextDump((RsContext)con, bits);
340}
Jason Samsd19f10d2009-05-22 14:03:28 -0700341
342static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800343nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700344{
Andreas Gampe67333922014-11-10 20:35:59 -0800345 if (kLogApi) {
346 ALOGD("nContextPause, con(%p)", (RsContext)con);
347 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800348 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700349}
350
351static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800352nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700353{
Andreas Gampe67333922014-11-10 20:35:59 -0800354 if (kLogApi) {
355 ALOGD("nContextResume, con(%p)", (RsContext)con);
356 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800357 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700358}
359
Jason Sams1c415172010-11-08 17:06:46 -0800360
361static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800362nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800363{
Andreas Gampe67333922014-11-10 20:35:59 -0800364 if (kLogApi) {
365 ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con);
366 }
Jason Sams1c415172010-11-08 17:06:46 -0800367 char buf[1024];
368
369 size_t receiveLen;
370 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800371 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700372 buf, sizeof(buf),
373 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700374 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800375 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100376 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800377 }
378 return _env->NewStringUTF(buf);
379}
380
Jason Samsedbfabd2011-05-17 15:01:29 -0700381static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800382nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700383{
Jason Sams516c3192009-10-06 13:58:47 -0700384 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800385 if (kLogApi) {
386 ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
387 }
Chris Wailes488230c32014-08-14 11:22:40 -0700388 jint *ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams516c3192009-10-06 13:58:47 -0700389 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800390 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800391 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700392 ptr, len * 4,
393 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700394 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700395 if (!id && receiveLen) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100396 ALOGV("message receive buffer too small. %zu", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700397 }
398 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000399 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800400}
401
402static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800403nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800404{
Andreas Gampe67333922014-11-10 20:35:59 -0800405 if (kLogApi) {
406 ALOGD("nContextPeekMessage, con(%p)", (RsContext)con);
407 }
Chris Wailes488230c32014-08-14 11:22:40 -0700408 jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr);
Jason Sams1c415172010-11-08 17:06:46 -0800409 size_t receiveLen;
410 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800411 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700412 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800413 auxDataPtr[0] = (jint)subID;
414 auxDataPtr[1] = (jint)receiveLen;
415 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000416 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700417}
418
Tim Murrayeff663f2013-11-15 13:08:30 -0800419static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700420{
Andreas Gampe67333922014-11-10 20:35:59 -0800421 if (kLogApi) {
422 ALOGD("nContextInitToClient, con(%p)", (RsContext)con);
423 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800424 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700425}
426
Tim Murrayeff663f2013-11-15 13:08:30 -0800427static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700428{
Andreas Gampe67333922014-11-10 20:35:59 -0800429 if (kLogApi) {
430 ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con);
431 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800432 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700433}
434
Jason Sams455d6442013-02-05 19:20:18 -0800435static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800436nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800437{
Chris Wailes488230c32014-08-14 11:22:40 -0700438 jint *ptr = nullptr;
Jason Sams455d6442013-02-05 19:20:18 -0800439 jint len = 0;
440 if (data) {
441 len = _env->GetArrayLength(data);
Stephen Hines4a043c12014-08-21 23:20:32 -0700442 ptr = _env->GetIntArrayElements(data, nullptr);
Jason Sams455d6442013-02-05 19:20:18 -0800443 }
Andreas Gampe67333922014-11-10 20:35:59 -0800444 if (kLogApi) {
445 ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
446 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800447 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800448 if (data) {
449 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
450 }
451}
452
453
Jason Sams516c3192009-10-06 13:58:47 -0700454
Tim Murray460a0492013-11-19 12:45:54 -0800455static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800456nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm,
457 jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700458{
Andreas Gampe67333922014-11-10 20:35:59 -0800459 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100460 ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con,
Andreas Gampe67333922014-11-10 20:35:59 -0800461 type, kind, norm, size);
462 }
463 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind,
464 norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700465}
466
Tim Murray460a0492013-11-19 12:45:54 -0800467static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800468nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000469 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700470{
Jason Sams718cd1f2009-12-23 14:35:29 -0800471 int fieldCount = _env->GetArrayLength(_ids);
Andreas Gampe67333922014-11-10 20:35:59 -0800472 if (kLogApi) {
473 ALOGD("nElementCreate2, con(%p)", (RsContext)con);
474 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800475
Chris Wailes488230c32014-08-14 11:22:40 -0700476 jlong *jIds = _env->GetLongArrayElements(_ids, nullptr);
477 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +0000478
479 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
480 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
481
482 for(int i = 0; i < fieldCount; i ++) {
483 ids[i] = (RsElement)jIds[i];
484 arraySizes[i] = (uint32_t)jArraySizes[i];
485 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800486
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800487 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
488
489 const char **nameArray = names.c_str();
490 size_t *sizeArray = names.c_str_len();
491
Tim Murray3aa89c12014-08-18 17:51:22 -0700492 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000493 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700494 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700495 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800496
Ashok Bhat98071552014-02-12 09:54:43 +0000497 free(ids);
498 free(arraySizes);
499 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
500 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
501
Tim Murray3aa89c12014-08-18 17:51:22 -0700502 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700503}
504
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700505static void
Tim Murray460a0492013-11-19 12:45:54 -0800506nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700507{
508 int dataSize = _env->GetArrayLength(_elementData);
Andreas Gampe67333922014-11-10 20:35:59 -0800509 if (kLogApi) {
510 ALOGD("nElementGetNativeData, con(%p)", (RsContext)con);
511 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700512
513 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
514 assert(dataSize == 5);
515
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000516 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800517 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700518
519 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000520 const jint data = (jint)elementData[i];
521 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700522 }
523}
524
525
526static void
Tim Murray460a0492013-11-19 12:45:54 -0800527nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000528 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700529 jobjectArray _names,
530 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700531{
Ashok Bhat98071552014-02-12 09:54:43 +0000532 uint32_t dataSize = _env->GetArrayLength(_IDs);
Andreas Gampe67333922014-11-10 20:35:59 -0800533 if (kLogApi) {
534 ALOGD("nElementGetSubElements, con(%p)", (RsContext)con);
535 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700536
Ashok Bhat98071552014-02-12 09:54:43 +0000537 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
538 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000539 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700540
Andreas Gampe67333922014-11-10 20:35:59 -0800541 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes,
542 (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700543
Ashok Bhat98071552014-02-12 09:54:43 +0000544 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700545 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000546 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700547 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000548 _env->SetLongArrayRegion(_IDs, i, 1, &id);
549 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700550 }
551
552 free(ids);
553 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700554 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700555}
556
Jason Samsd19f10d2009-05-22 14:03:28 -0700557// -----------------------------------
558
Tim Murray460a0492013-11-19 12:45:54 -0800559static jlong
560nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800561 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700562{
Andreas Gampe67333922014-11-10 20:35:59 -0800563 if (kLogApi) {
564 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 +0100565 (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv);
Andreas Gampe67333922014-11-10 20:35:59 -0800566 }
Jason Sams3b9c52a2010-10-14 17:48:46 -0700567
Andreas Gampe67333922014-11-10 20:35:59 -0800568 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips,
569 faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700570}
571
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700572static void
Ashok Bhat98071552014-02-12 09:54:43 +0000573nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700574{
575 // We are packing 6 items: mDimX; mDimY; mDimZ;
576 // mDimLOD; mDimFaces; mElement; into typeData
577 int elementCount = _env->GetArrayLength(_typeData);
578
579 assert(elementCount == 6);
Andreas Gampe67333922014-11-10 20:35:59 -0800580 if (kLogApi) {
581 ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con);
582 }
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700583
Ashok Bhat98071552014-02-12 09:54:43 +0000584 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -0800585 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700586
587 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700588 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000589 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700590 }
591}
592
Jason Samsd19f10d2009-05-22 14:03:28 -0700593// -----------------------------------
594
Tim Murray460a0492013-11-19 12:45:54 -0800595static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800596nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage,
597 jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700598{
Andreas Gampe67333922014-11-10 20:35:59 -0800599 if (kLogApi) {
600 ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)",
601 (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
602 }
603 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type,
604 (RsAllocationMipmapControl)mips,
605 (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700606}
607
Jason Samsd19f10d2009-05-22 14:03:28 -0700608static void
Tim Murray460a0492013-11-19 12:45:54 -0800609nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -0800610{
Andreas Gampe67333922014-11-10 20:35:59 -0800611 if (kLogApi) {
612 ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a,
613 bits);
614 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800615 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -0800616}
617
Jason Sams72226e02013-02-22 12:45:54 -0800618static jobject
Tim Murray460a0492013-11-19 12:45:54 -0800619nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800620{
Andreas Gampe67333922014-11-10 20:35:59 -0800621 if (kLogApi) {
622 ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
623 }
Jason Sams615e7ce2012-01-13 14:01:20 -0800624
Andreas Gampe67333922014-11-10 20:35:59 -0800625 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con,
626 (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -0800627 sp<IGraphicBufferProducer> bp = v;
Chris Wailes488230c32014-08-14 11:22:40 -0700628 v->decStrong(nullptr);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700629
Jason Sams72226e02013-02-22 12:45:54 -0800630 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
631 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700632}
633
634static void
Tim Murray460a0492013-11-19 12:45:54 -0800635nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800636{
Andreas Gampe67333922014-11-10 20:35:59 -0800637 if (kLogApi) {
638 ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con,
639 (RsAllocation)alloc, (Surface *)sur);
640 }
Jason Sams163766c2012-02-15 12:04:24 -0800641
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700642 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800643 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700644 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800645 }
646
Andreas Gampe67333922014-11-10 20:35:59 -0800647 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc,
648 static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800649}
650
651static void
Tim Murray460a0492013-11-19 12:45:54 -0800652nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800653{
Andreas Gampe67333922014-11-10 20:35:59 -0800654 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100655 ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -0800656 }
Tim Murray460a0492013-11-19 12:45:54 -0800657 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800658}
659
660static void
Tim Murray460a0492013-11-19 12:45:54 -0800661nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800662{
Andreas Gampe67333922014-11-10 20:35:59 -0800663 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +0100664 ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Andreas Gampe67333922014-11-10 20:35:59 -0800665 }
Tim Murray460a0492013-11-19 12:45:54 -0800666 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800667}
668
669
670static void
Tim Murray460a0492013-11-19 12:45:54 -0800671nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -0800672{
Andreas Gampe67333922014-11-10 20:35:59 -0800673 if (kLogApi) {
674 ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
675 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800676 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -0800677}
678
Tim Murray460a0492013-11-19 12:45:54 -0800679static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800680nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
681 jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700682{
Jason Samsffe9f482009-06-01 17:45:53 -0700683 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000684 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -0700685 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700686
Jason Sams5476b452010-12-08 16:14:36 -0800687 bitmap.lockPixels();
688 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700689 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700690 (RsType)type, (RsAllocationMipmapControl)mip,
691 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800692 bitmap.unlockPixels();
693 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700694}
Jason Samsfe08d992009-05-27 14:45:32 -0700695
Tim Murray460a0492013-11-19 12:45:54 -0800696static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800697nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
698 jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -0800699{
700 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000701 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -0800702 const SkBitmap& bitmap(*nativeBitmap);
703
704 bitmap.lockPixels();
705 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700706 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -0800707 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +0000708 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -0800709 bitmap.unlockPixels();
710 return id;
711}
712
Tim Murray460a0492013-11-19 12:45:54 -0800713static jlong
Andreas Gampe67333922014-11-10 20:35:59 -0800714nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
715 jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800716{
717 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000718 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800719 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800720
Jason Sams5476b452010-12-08 16:14:36 -0800721 bitmap.lockPixels();
722 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700723 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700724 (RsType)type, (RsAllocationMipmapControl)mip,
725 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800726 bitmap.unlockPixels();
727 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800728}
729
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700730static void
Tim Murray460a0492013-11-19 12:45:54 -0800731nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700732{
733 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000734 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700735 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800736 int w = bitmap.width();
737 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700738
Jason Sams4ef66502010-12-10 16:03:15 -0800739 bitmap.lockPixels();
740 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800741 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700742 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800743 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800744 bitmap.unlockPixels();
745}
746
747static void
Tim Murray460a0492013-11-19 12:45:54 -0800748nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -0800749{
750 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000751 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -0800752 const SkBitmap& bitmap(*nativeBitmap);
753
754 bitmap.lockPixels();
755 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800756 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800757 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700758 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700759}
760
Stephen Hines414fa2c2014-04-17 01:02:42 -0700761// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700762static void
Tim Murray460a0492013-11-19 12:45:54 -0800763nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000764 jint count, jobject data, jint sizeBytes, jint dataType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700765{
Jason Samse729a942013-11-06 11:22:02 -0800766 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800767 if (kLogApi) {
768 ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
769 "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes,
770 dataType);
771 }
772 PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count,
773 ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700774}
775
Stephen Hines414fa2c2014-04-17 01:02:42 -0700776// Copies from the Java array data into the Allocation pointed to by alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700777static void
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000778// native void rsnAllocationElementData1D(long con, long id, int xoff, int compIdx, byte[] d, int sizeBytes);
Andreas Gampe67333922014-11-10 20:35:59 -0800779nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod,
780 jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -0700781{
782 jint len = _env->GetArrayLength(data);
Andreas Gampe67333922014-11-10 20:35:59 -0800783 if (kLogApi) {
784 ALOGD("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), "
785 "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, offset, compIdx, len,
786 sizeBytes);
787 }
Chris Wailes488230c32014-08-14 11:22:40 -0700788 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -0800789 rsAllocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700790 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
791}
792
Stephen Hines414fa2c2014-04-17 01:02:42 -0700793// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -0700794static void
Tim Murray460a0492013-11-19 12:45:54 -0800795nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000796 jint w, jint h, jobject data, jint sizeBytes, jint dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800797{
Jason Samse729a942013-11-06 11:22:02 -0800798 RsAllocation *alloc = (RsAllocation *)_alloc;
799 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -0800800 if (kLogApi) {
801 ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
802 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
803 }
Chris Wailes488230c32014-08-14 11:22:40 -0700804 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 -0700805}
806
Stephen Hines414fa2c2014-04-17 01:02:42 -0700807// Copies from the Allocation pointed to by srcAlloc into the Allocation
808// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -0700809static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800810nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -0800811 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700812 jint dstMip, jint dstFace,
813 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -0800814 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700815 jint srcMip, jint srcFace)
816{
Andreas Gampe67333922014-11-10 20:35:59 -0800817 if (kLogApi) {
818 ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
819 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
820 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
821 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
822 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
823 }
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700824
Tim Murrayeff663f2013-11-15 13:08:30 -0800825 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700826 (RsAllocation)dstAlloc,
827 dstXoff, dstYoff,
828 dstMip, dstFace,
829 width, height,
830 (RsAllocation)srcAlloc,
831 srcXoff, srcYoff,
832 srcMip, srcFace);
833}
834
Stephen Hines414fa2c2014-04-17 01:02:42 -0700835// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700836static void
Tim Murray460a0492013-11-19 12:45:54 -0800837nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Jason Samse729a942013-11-06 11:22:02 -0800838 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
Jason Samsb05d6892013-04-09 15:59:24 -0700839{
Jason Samse729a942013-11-06 11:22:02 -0800840 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800841 if (kLogApi) {
842 ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i),"
843 " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff,
844 lod, w, h, d, sizeBytes);
845 }
Chris Wailes488230c32014-08-14 11:22:40 -0700846 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 -0700847}
848
Stephen Hines414fa2c2014-04-17 01:02:42 -0700849// Copies from the Allocation pointed to by srcAlloc into the Allocation
850// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -0700851static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800852nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -0800853 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700854 jint dstMip,
855 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -0800856 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700857 jint srcMip)
858{
Andreas Gampe67333922014-11-10 20:35:59 -0800859 if (kLogApi) {
860 ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
861 " dstMip(%i), width(%i), height(%i),"
862 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
863 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
864 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
865 }
Jason Samsb05d6892013-04-09 15:59:24 -0700866
Tim Murrayeff663f2013-11-15 13:08:30 -0800867 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -0700868 (RsAllocation)dstAlloc,
869 dstXoff, dstYoff, dstZoff, dstMip,
870 width, height, depth,
871 (RsAllocation)srcAlloc,
872 srcXoff, srcYoff, srcZoff, srcMip);
873}
874
Jason Sams21659ac2013-11-06 15:08:07 -0800875
Stephen Hines414fa2c2014-04-17 01:02:42 -0700876// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -0700877static void
Tim Murray460a0492013-11-19 12:45:54 -0800878nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType)
Jason Sams40a29e82009-08-10 14:55:26 -0700879{
Jason Sams21659ac2013-11-06 15:08:07 -0800880 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800881 if (kLogApi) {
882 ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
883 }
Stephen Hines414fa2c2014-04-17 01:02:42 -0700884 PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -0700885}
886
Stephen Hines414fa2c2014-04-17 01:02:42 -0700887// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -0700888static void
Tim Murray460a0492013-11-19 12:45:54 -0800889nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Jason Sams21659ac2013-11-06 15:08:07 -0800890 jint count, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800891{
Jason Sams21659ac2013-11-06 15:08:07 -0800892 RsAllocation *alloc = (RsAllocation *)_alloc;
Andreas Gampe67333922014-11-10 20:35:59 -0800893 if (kLogApi) {
894 ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), "
895 "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType);
896 }
Stephen Hines414fa2c2014-04-17 01:02:42 -0700897 PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800898}
899
Stephen Hines414fa2c2014-04-17 01:02:42 -0700900// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -0800901static void
Tim Murray460a0492013-11-19 12:45:54 -0800902nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Jason Sams21659ac2013-11-06 15:08:07 -0800903 jint w, jint h, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800904{
Jason Sams21659ac2013-11-06 15:08:07 -0800905 RsAllocation *alloc = (RsAllocation *)_alloc;
906 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
Andreas Gampe67333922014-11-10 20:35:59 -0800907 if (kLogApi) {
908 ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) "
909 "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
910 }
911 PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h,
912 ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700913}
Jason Samsd19f10d2009-05-22 14:03:28 -0700914
Tim Murray460a0492013-11-19 12:45:54 -0800915static jlong
916nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700917{
Andreas Gampe67333922014-11-10 20:35:59 -0800918 if (kLogApi) {
919 ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
920 }
Tim Murray3aa89c12014-08-18 17:51:22 -0700921 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700922}
923
Jason Sams5edc6082010-10-05 13:32:49 -0700924static void
Tim Murray460a0492013-11-19 12:45:54 -0800925nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -0700926{
Andreas Gampe67333922014-11-10 20:35:59 -0800927 if (kLogApi) {
928 ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con,
929 (RsAllocation)alloc, dimX);
930 }
Tim Murrayeff663f2013-11-15 13:08:30 -0800931 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -0700932}
933
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700934// -----------------------------------
935
Tim Murray460a0492013-11-19 12:45:54 -0800936static jlong
937nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700938{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700939 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000940 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700941
Tim Murray3aa89c12014-08-18 17:51:22 -0700942 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800943 return id;
944}
945
Tim Murray460a0492013-11-19 12:45:54 -0800946static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800947nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800948{
949 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -0700950 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800951 return 0;
952 }
953
954 AutoJavaStringToUTF8 str(_env, _path);
955 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -0700956 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800957 return 0;
958 }
959
Tim Murray3aa89c12014-08-18 17:51:22 -0700960 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800961 return id;
962}
963
Tim Murray460a0492013-11-19 12:45:54 -0800964static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800965nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800966{
967 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -0700968 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800969
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700970 return id;
971}
972
Tim Murray460a0492013-11-19 12:45:54 -0800973static jint
974nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700975{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700976 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -0800977 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000978 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700979}
980
981static void
Tim Murray460a0492013-11-19 12:45:54 -0800982nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700983{
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000984 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700985 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
986
Tim Murrayeff663f2013-11-15 13:08:30 -0800987 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700988
989 for(jint i = 0; i < numEntries; i ++) {
990 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
991 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
992 }
993
994 free(fileEntries);
995}
996
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000997static jlong
Tim Murray460a0492013-11-19 12:45:54 -0800998nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700999{
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001000 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -07001001 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -07001002 return id;
1003}
Jason Samsd19f10d2009-05-22 14:03:28 -07001004
1005// -----------------------------------
1006
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001007static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001008nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001009 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001010{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001011 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -07001012 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001013 fileNameUTF.c_str(), fileNameUTF.length(),
1014 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001015
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001016 return id;
1017}
1018
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001019static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001020nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001021 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001022{
1023 Asset* asset = reinterpret_cast<Asset*>(native_asset);
1024 AutoJavaStringToUTF8 nameUTF(_env, name);
1025
Tim Murray3aa89c12014-08-18 17:51:22 -07001026 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001027 nameUTF.c_str(), nameUTF.length(),
1028 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001029 asset->getBuffer(false), asset->getLength());
1030 return id;
1031}
1032
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001033static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001034nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001035 jfloat fontSize, jint dpi)
1036{
1037 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
Chris Wailes488230c32014-08-14 11:22:40 -07001038 if (mgr == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001039 return 0;
1040 }
1041
1042 AutoJavaStringToUTF8 str(_env, _path);
1043 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
Chris Wailes488230c32014-08-14 11:22:40 -07001044 if (asset == nullptr) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001045 return 0;
1046 }
1047
Tim Murray3aa89c12014-08-18 17:51:22 -07001048 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001049 str.c_str(), str.length(),
1050 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001051 asset->getBuffer(false), asset->getLength());
1052 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001053 return id;
1054}
1055
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001056// -----------------------------------
1057
1058static void
Tim Murray460a0492013-11-19 12:45:54 -08001059nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -07001060{
Andreas Gampe67333922014-11-10 20:35:59 -08001061 if (kLogApi) {
1062 ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con,
1063 (RsScript)script, (RsAllocation)alloc, slot);
1064 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001065 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -07001066}
1067
1068static void
Tim Murray460a0492013-11-19 12:45:54 -08001069nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -07001070{
Andreas Gampe67333922014-11-10 20:35:59 -08001071 if (kLogApi) {
1072 ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script,
1073 slot, val);
1074 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001075 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001076}
1077
Tim Murray7c4caad2013-04-10 16:21:40 -07001078static jint
Tim Murray460a0492013-11-19 12:45:54 -08001079nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001080{
Andreas Gampe67333922014-11-10 20:35:59 -08001081 if (kLogApi) {
1082 ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1083 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001084 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001085 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001086 return value;
1087}
1088
Jason Sams4d339932010-05-11 14:03:58 -07001089static void
Tim Murray460a0492013-11-19 12:45:54 -08001090nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001091{
Andreas Gampe67333922014-11-10 20:35:59 -08001092 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001093 ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001094 slot, val);
1095 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001096 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001097}
1098
1099static void
Tim Murray460a0492013-11-19 12:45:54 -08001100nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -07001101{
Andreas Gampe67333922014-11-10 20:35:59 -08001102 if (kLogApi) {
Bernhard Rosenkränzer09993f72014-11-17 20:25:28 +01001103 ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script,
Andreas Gampe67333922014-11-10 20:35:59 -08001104 slot, val);
1105 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001106 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -07001107}
1108
Tim Murray7c4caad2013-04-10 16:21:40 -07001109static jlong
Tim Murray460a0492013-11-19 12:45:54 -08001110nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001111{
Andreas Gampe67333922014-11-10 20:35:59 -08001112 if (kLogApi) {
1113 ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1114 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001115 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001116 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001117 return value;
1118}
1119
Stephen Hines031ec58c2010-10-11 10:54:21 -07001120static void
Tim Murray460a0492013-11-19 12:45:54 -08001121nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001122{
Andreas Gampe67333922014-11-10 20:35:59 -08001123 if (kLogApi) {
1124 ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script,
1125 slot, val);
1126 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001127 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001128}
1129
Tim Murray7c4caad2013-04-10 16:21:40 -07001130static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001131nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001132{
Andreas Gampe67333922014-11-10 20:35:59 -08001133 if (kLogApi) {
1134 ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1135 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001136 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001137 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001138 return value;
1139}
1140
Jason Sams4d339932010-05-11 14:03:58 -07001141static void
Tim Murray460a0492013-11-19 12:45:54 -08001142nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001143{
Andreas Gampe67333922014-11-10 20:35:59 -08001144 if (kLogApi) {
1145 ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script,
1146 slot, val);
1147 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001148 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001149}
1150
Tim Murray7c4caad2013-04-10 16:21:40 -07001151static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001152nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001153{
Andreas Gampe67333922014-11-10 20:35:59 -08001154 if (kLogApi) {
1155 ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1156 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001157 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001158 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001159 return value;
1160}
1161
Stephen Hinesca54ec32010-09-20 17:20:30 -07001162static void
Tim Murray460a0492013-11-19 12:45:54 -08001163nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001164{
Andreas Gampe67333922014-11-10 20:35:59 -08001165 if (kLogApi) {
1166 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1167 }
Jason Sams4d339932010-05-11 14:03:58 -07001168 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001169 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001170 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001171 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1172}
1173
Stephen Hinesadeb8092012-04-20 14:26:06 -07001174static void
Tim Murray460a0492013-11-19 12:45:54 -08001175nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001176{
Andreas Gampe67333922014-11-10 20:35:59 -08001177 if (kLogApi) {
1178 ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1179 }
Tim Murray7c4caad2013-04-10 16:21:40 -07001180 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001181 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001182 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001183 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001184}
1185
1186static void
Andreas Gampe67333922014-11-10 20:35:59 -08001187nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data,
1188 jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001189{
Andreas Gampe67333922014-11-10 20:35:59 -08001190 if (kLogApi) {
1191 ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1192 }
Stephen Hinesadeb8092012-04-20 14:26:06 -07001193 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001194 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001195 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
Chris Wailes488230c32014-08-14 11:22:40 -07001196 jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001197 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001198 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001199 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1200 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1201}
1202
Jason Samsd19f10d2009-05-22 14:03:28 -07001203
1204static void
Tim Murray460a0492013-11-19 12:45:54 -08001205nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001206{
Andreas Gampe67333922014-11-10 20:35:59 -08001207 if (kLogApi) {
1208 ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
1209 }
Romain Guy584a3752009-07-30 18:45:01 -07001210
1211 jint length = _env->GetArrayLength(timeZone);
1212 jbyte* timeZone_ptr;
1213 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1214
Tim Murrayeff663f2013-11-15 13:08:30 -08001215 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001216
1217 if (timeZone_ptr) {
1218 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1219 }
1220}
1221
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001222static void
Tim Murray460a0492013-11-19 12:45:54 -08001223nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001224{
Andreas Gampe67333922014-11-10 20:35:59 -08001225 if (kLogApi) {
1226 ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
1227 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001228 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001229}
1230
1231static void
Tim Murray460a0492013-11-19 12:45:54 -08001232nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001233{
Andreas Gampe67333922014-11-10 20:35:59 -08001234 if (kLogApi) {
1235 ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1236 }
Jason Sams4d339932010-05-11 14:03:58 -07001237 jint len = _env->GetArrayLength(data);
Chris Wailes488230c32014-08-14 11:22:40 -07001238 jbyte *ptr = _env->GetByteArrayElements(data, nullptr);
Tim Murrayeff663f2013-11-15 13:08:30 -08001239 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001240 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1241}
1242
Jason Sams6e494d32011-04-27 16:33:11 -07001243static void
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001244nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot,
1245 jlongArray ains, jlong aout, jbyteArray params,
1246 jintArray limits)
Jason Sams6e494d32011-04-27 16:33:11 -07001247{
Andreas Gampe67333922014-11-10 20:35:59 -08001248 if (kLogApi) {
1249 ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1250 }
Jason Sams6e494d32011-04-27 16:33:11 -07001251
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001252 jint in_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001253 jlong *in_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001254
Chris Wailes488230c32014-08-14 11:22:40 -07001255 RsAllocation *in_allocs = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001256
Chris Wailes488230c32014-08-14 11:22:40 -07001257 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001258 in_len = _env->GetArrayLength(ains);
Chris Wailes488230c32014-08-14 11:22:40 -07001259 in_ptr = _env->GetLongArrayElements(ains, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001260
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001261 if (sizeof(RsAllocation) == sizeof(jlong)) {
1262 in_allocs = (RsAllocation*)in_ptr;
Chris Wailes94961062014-06-11 12:01:28 -07001263
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001264 } else {
1265 // Convert from 64-bit jlong types to the native pointer type.
Chris Wailes94961062014-06-11 12:01:28 -07001266
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001267 in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation));
1268
1269 for (int index = in_len; --index >= 0;) {
1270 in_allocs[index] = (RsAllocation)in_ptr[index];
1271 }
1272 }
Chris Wailes94961062014-06-11 12:01:28 -07001273 }
1274
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001275 jint param_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001276 jbyte *param_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001277
Chris Wailes488230c32014-08-14 11:22:40 -07001278 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001279 param_len = _env->GetArrayLength(params);
Chris Wailes488230c32014-08-14 11:22:40 -07001280 param_ptr = _env->GetByteArrayElements(params, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001281 }
1282
Chris Wailes488230c32014-08-14 11:22:40 -07001283 RsScriptCall sc, *sca = nullptr;
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001284 uint32_t sc_size = 0;
Chris Wailes94961062014-06-11 12:01:28 -07001285
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001286 jint limit_len = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001287 jint *limit_ptr = nullptr;
Chris Wailes94961062014-06-11 12:01:28 -07001288
Chris Wailes488230c32014-08-14 11:22:40 -07001289 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001290 limit_len = _env->GetArrayLength(limits);
Chris Wailes488230c32014-08-14 11:22:40 -07001291 limit_ptr = _env->GetIntArrayElements(limits, nullptr);
Chris Wailes94961062014-06-11 12:01:28 -07001292
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001293 assert(limit_len == 6);
Andreas Gampe67333922014-11-10 20:35:59 -08001294 UNUSED(limit_len); // As the assert might not be compiled.
Chris Wailes94961062014-06-11 12:01:28 -07001295
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001296 sc.xStart = limit_ptr[0];
1297 sc.xEnd = limit_ptr[1];
1298 sc.yStart = limit_ptr[2];
1299 sc.yEnd = limit_ptr[3];
1300 sc.zStart = limit_ptr[4];
1301 sc.zEnd = limit_ptr[5];
1302 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
Chris Wailes94961062014-06-11 12:01:28 -07001303
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001304 sca = &sc;
Chris Wailes94961062014-06-11 12:01:28 -07001305 }
1306
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001307 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot,
1308 in_allocs, in_len, (RsAllocation)aout,
1309 param_ptr, param_len, sca, sc_size);
Chris Wailes94961062014-06-11 12:01:28 -07001310
Chris Wailes488230c32014-08-14 11:22:40 -07001311 if (ains != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001312 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
Chris Wailes94961062014-06-11 12:01:28 -07001313 }
1314
Chris Wailes488230c32014-08-14 11:22:40 -07001315 if (params != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001316 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1317 }
1318
Chris Wailes488230c32014-08-14 11:22:40 -07001319 if (limits != nullptr) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001320 _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT);
1321 }
Chris Wailes94961062014-06-11 12:01:28 -07001322}
1323
Jason Sams22534172009-08-04 16:58:20 -07001324// -----------------------------------
1325
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001326static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001327nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001328 jstring resName, jstring cacheDir,
1329 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001330{
Andreas Gampe67333922014-11-10 20:35:59 -08001331 if (kLogApi) {
1332 ALOGD("nScriptCCreate, con(%p)", (RsContext)con);
1333 }
Jason Sams22534172009-08-04 16:58:20 -07001334
Jason Samse4a06c52011-03-16 16:29:28 -07001335 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1336 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001337 jlong ret = 0;
Chris Wailes488230c32014-08-14 11:22:40 -07001338 jbyte* script_ptr = nullptr;
Jack Palevich43702d82009-05-28 13:38:16 -07001339 jint _exception = 0;
1340 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001341 if (!scriptRef) {
1342 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001343 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001344 goto exit;
1345 }
Jack Palevich43702d82009-05-28 13:38:16 -07001346 if (length < 0) {
1347 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001348 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001349 goto exit;
1350 }
Jason Samse4a06c52011-03-16 16:29:28 -07001351 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001352 if (remaining < length) {
1353 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001354 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1355 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001356 goto exit;
1357 }
Jason Samse4a06c52011-03-16 16:29:28 -07001358 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001359 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001360
Tim Murrayeff663f2013-11-15 13:08:30 -08001361 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001362
Tim Murray3aa89c12014-08-18 17:51:22 -07001363 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001364 resNameUTF.c_str(), resNameUTF.length(),
1365 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001366 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001367
Jack Palevich43702d82009-05-28 13:38:16 -07001368exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001369 if (script_ptr) {
1370 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001371 _exception ? JNI_ABORT: 0);
1372 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001373
Tim Murray3aa89c12014-08-18 17:51:22 -07001374 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001375}
1376
Tim Murray460a0492013-11-19 12:45:54 -08001377static jlong
1378nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001379{
Andreas Gampe67333922014-11-10 20:35:59 -08001380 if (kLogApi) {
1381 ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id,
1382 (void *)eid);
1383 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001384 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001385}
1386
Tim Murray460a0492013-11-19 12:45:54 -08001387static jlong
1388nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001389{
Andreas Gampe67333922014-11-10 20:35:59 -08001390 if (kLogApi) {
1391 ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con,
1392 (void *)sid, slot, sig);
1393 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001394 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001395}
1396
Tim Murray460a0492013-11-19 12:45:54 -08001397static jlong
1398nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001399{
Andreas Gampe67333922014-11-10 20:35:59 -08001400 if (kLogApi) {
1401 ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid,
1402 slot);
1403 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001404 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001405}
1406
Tim Murray460a0492013-11-19 12:45:54 -08001407static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001408nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1409 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001410{
Andreas Gampe67333922014-11-10 20:35:59 -08001411 if (kLogApi) {
1412 ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con);
1413 }
Jason Sams08a81582012-09-18 12:32:10 -07001414
Ashok Bhat98071552014-02-12 09:54:43 +00001415 jint kernelsLen = _env->GetArrayLength(_kernels);
Chris Wailes488230c32014-08-14 11:22:40 -07001416 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001417 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1418 for(int i = 0; i < kernelsLen; ++i) {
1419 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1420 }
Jason Sams08a81582012-09-18 12:32:10 -07001421
Ashok Bhat98071552014-02-12 09:54:43 +00001422 jint srcLen = _env->GetArrayLength(_src);
Chris Wailes488230c32014-08-14 11:22:40 -07001423 jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001424 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1425 for(int i = 0; i < srcLen; ++i) {
1426 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1427 }
Jason Sams08a81582012-09-18 12:32:10 -07001428
Ashok Bhat98071552014-02-12 09:54:43 +00001429 jint dstkLen = _env->GetArrayLength(_dstk);
Chris Wailes488230c32014-08-14 11:22:40 -07001430 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001431 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1432 for(int i = 0; i < dstkLen; ++i) {
1433 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1434 }
1435
1436 jint dstfLen = _env->GetArrayLength(_dstf);
Chris Wailes488230c32014-08-14 11:22:40 -07001437 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001438 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1439 for(int i = 0; i < dstfLen; ++i) {
1440 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1441 }
1442
1443 jint typesLen = _env->GetArrayLength(_types);
Chris Wailes488230c32014-08-14 11:22:40 -07001444 jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001445 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1446 for(int i = 0; i < typesLen; ++i) {
1447 typesPtr[i] = (RsType)jTypesPtr[i];
1448 }
1449
Tim Murray3aa89c12014-08-18 17:51:22 -07001450 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001451 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1452 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1453 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1454 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1455 (RsType *)typesPtr, typesLen * sizeof(RsType));
1456
1457 free(kernelsPtr);
1458 free(srcPtr);
1459 free(dstkPtr);
1460 free(dstfPtr);
1461 free(typesPtr);
1462 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1463 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1464 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1465 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1466 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001467 return id;
1468}
1469
1470static void
Tim Murray460a0492013-11-19 12:45:54 -08001471nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001472{
Andreas Gampe67333922014-11-10 20:35:59 -08001473 if (kLogApi) {
1474 ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1475 (void *)gid, (void *)kid, (void *)alloc);
1476 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001477 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001478}
1479
1480static void
Tim Murray460a0492013-11-19 12:45:54 -08001481nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001482{
Andreas Gampe67333922014-11-10 20:35:59 -08001483 if (kLogApi) {
1484 ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
1485 (void *)gid, (void *)kid, (void *)alloc);
1486 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001487 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001488}
1489
1490static void
Tim Murray460a0492013-11-19 12:45:54 -08001491nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001492{
Andreas Gampe67333922014-11-10 20:35:59 -08001493 if (kLogApi) {
1494 ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
1495 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001496 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001497}
1498
Jason Samsd19f10d2009-05-22 14:03:28 -07001499// ---------------------------------------------------------------------------
1500
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001501static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001502nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001503 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1504 jboolean depthMask, jboolean ditherEnable,
1505 jint srcFunc, jint destFunc,
1506 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001507{
Andreas Gampe67333922014-11-10 20:35:59 -08001508 if (kLogApi) {
1509 ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con);
1510 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001511 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07001512 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1513 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001514}
1515
Jason Sams0011bcf2009-12-15 12:58:36 -08001516// ---------------------------------------------------------------------------
1517
1518static void
Tim Murray460a0492013-11-19 12:45:54 -08001519nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001520{
Andreas Gampe67333922014-11-10 20:35:59 -08001521 if (kLogApi) {
1522 ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con,
1523 (RsProgramVertex)vpv, slot, (RsAllocation)a);
1524 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001525 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08001526}
Jason Sams54c0ec12009-11-30 14:49:55 -08001527
Jason Sams68afd012009-12-17 16:55:08 -08001528static void
Tim Murray460a0492013-11-19 12:45:54 -08001529nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001530{
Andreas Gampe67333922014-11-10 20:35:59 -08001531 if (kLogApi) {
1532 ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1533 (RsProgramFragment)vpf, slot, (RsAllocation)a);
1534 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001535 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08001536}
1537
1538static void
Tim Murray460a0492013-11-19 12:45:54 -08001539nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001540{
Andreas Gampe67333922014-11-10 20:35:59 -08001541 if (kLogApi) {
1542 ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con,
1543 (RsProgramFragment)vpf, slot, (RsSampler)a);
1544 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001545 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08001546}
1547
Jason Samsd19f10d2009-05-22 14:03:28 -07001548// ---------------------------------------------------------------------------
1549
Tim Murray460a0492013-11-19 12:45:54 -08001550static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001551nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001552 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001553{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001554 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001555 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001556 jint paramLen = _env->GetArrayLength(params);
1557
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001558 int texCount = _env->GetArrayLength(texNames);
1559 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1560 const char ** nameArray = names.c_str();
1561 size_t* sizeArray = names.c_str_len();
1562
Andreas Gampe67333922014-11-10 20:35:59 -08001563 if (kLogApi) {
1564 ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1565 }
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001566
Ashok Bhat98071552014-02-12 09:54:43 +00001567 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1568 for(int i = 0; i < paramLen; ++i) {
1569 paramPtr[i] = (uintptr_t)jParamPtr[i];
1570 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001571 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001572 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001573 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001574
Ashok Bhat98071552014-02-12 09:54:43 +00001575 free(paramPtr);
1576 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001577 return ret;
1578}
1579
1580
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001581// ---------------------------------------------------------------------------
1582
Tim Murray460a0492013-11-19 12:45:54 -08001583static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001584nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001585 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001586{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001587 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Chris Wailes488230c32014-08-14 11:22:40 -07001588 jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr);
Jason Sams0011bcf2009-12-15 12:58:36 -08001589 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001590
Andreas Gampe67333922014-11-10 20:35:59 -08001591 if (kLogApi) {
1592 ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
1593 }
Jason Sams0011bcf2009-12-15 12:58:36 -08001594
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001595 int texCount = _env->GetArrayLength(texNames);
1596 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1597 const char ** nameArray = names.c_str();
1598 size_t* sizeArray = names.c_str_len();
1599
Ashok Bhat98071552014-02-12 09:54:43 +00001600 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1601 for(int i = 0; i < paramLen; ++i) {
1602 paramPtr[i] = (uintptr_t)jParamPtr[i];
1603 }
1604
Tim Murray3aa89c12014-08-18 17:51:22 -07001605 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001606 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001607 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001608
Ashok Bhat98071552014-02-12 09:54:43 +00001609 free(paramPtr);
1610 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08001611 return ret;
1612}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001613
Jason Samsebfb4362009-09-23 13:57:02 -07001614// ---------------------------------------------------------------------------
1615
Tim Murray460a0492013-11-19 12:45:54 -08001616static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001617nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001618{
Andreas Gampe67333922014-11-10 20:35:59 -08001619 if (kLogApi) {
1620 ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con,
1621 pointSprite, cull);
1622 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001623 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001624}
1625
Jason Samsd19f10d2009-05-22 14:03:28 -07001626
1627// ---------------------------------------------------------------------------
1628
1629static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001630nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001631{
Andreas Gampe67333922014-11-10 20:35:59 -08001632 if (kLogApi) {
1633 ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
1634 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001635 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001636}
1637
1638static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001639nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001640{
Andreas Gampe67333922014-11-10 20:35:59 -08001641 if (kLogApi) {
1642 ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
1643 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001644 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001645}
1646
1647static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001648nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001649{
Andreas Gampe67333922014-11-10 20:35:59 -08001650 if (kLogApi) {
1651 ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con,
1652 (RsProgramFragment)pf);
1653 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001654 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001655}
1656
Jason Sams0826a6f2009-06-15 19:04:56 -07001657static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001658nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001659{
Andreas Gampe67333922014-11-10 20:35:59 -08001660 if (kLogApi) {
1661 ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
1662 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001663 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001664}
1665
Joe Onoratod7b37742009-08-09 22:57:44 -07001666static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001667nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001668{
Andreas Gampe67333922014-11-10 20:35:59 -08001669 if (kLogApi) {
1670 ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
1671 }
Tim Murrayeff663f2013-11-15 13:08:30 -08001672 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07001673}
1674
Joe Onoratod7b37742009-08-09 22:57:44 -07001675
Jason Sams02fb2cb2009-05-28 15:37:57 -07001676// ---------------------------------------------------------------------------
1677
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001678static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001679nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001680 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001681{
Andreas Gampe67333922014-11-10 20:35:59 -08001682 if (kLogApi) {
1683 ALOGD("nSamplerCreate, con(%p)", (RsContext)con);
1684 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001685 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001686 (RsSamplerValue)magFilter,
1687 (RsSamplerValue)minFilter,
1688 (RsSamplerValue)wrapS,
1689 (RsSamplerValue)wrapT,
1690 (RsSamplerValue)wrapR,
1691 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001692}
1693
Jason Samsbba134c2009-06-22 15:49:21 -07001694// ---------------------------------------------------------------------------
1695
Tim Murray460a0492013-11-19 12:45:54 -08001696static jlong
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001697nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) {
Andreas Gampe67333922014-11-10 20:35:59 -08001698 if (kLogApi) {
1699 ALOGD("nPathCreate, con(%p)", (RsContext)con);
1700 }
Jason Samsf15ed012011-10-31 13:23:43 -07001701
Tim Murray3aa89c12014-08-18 17:51:22 -07001702 jlong id = (jlong)(uintptr_t)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic,
Tim Murray460a0492013-11-19 12:45:54 -08001703 (RsAllocation)_vtx,
1704 (RsAllocation)_loop, q);
Jason Samsf15ed012011-10-31 13:23:43 -07001705 return id;
1706}
1707
Tim Murray460a0492013-11-19 12:45:54 -08001708static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001709nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001710{
Andreas Gampe67333922014-11-10 20:35:59 -08001711 if (kLogApi) {
1712 ALOGD("nMeshCreate, con(%p)", (RsContext)con);
1713 }
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001714
1715 jint vtxLen = _env->GetArrayLength(_vtx);
Chris Wailes488230c32014-08-14 11:22:40 -07001716 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001717 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
1718 for(int i = 0; i < vtxLen; ++i) {
1719 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
1720 }
1721
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001722 jint idxLen = _env->GetArrayLength(_idx);
Chris Wailes488230c32014-08-14 11:22:40 -07001723 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr);
Ashok Bhat98071552014-02-12 09:54:43 +00001724 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
1725 for(int i = 0; i < idxLen; ++i) {
1726 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
1727 }
1728
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001729 jint primLen = _env->GetArrayLength(_prim);
Chris Wailes488230c32014-08-14 11:22:40 -07001730 jint *primPtr = _env->GetIntArrayElements(_prim, nullptr);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001731
Tim Murray3aa89c12014-08-18 17:51:22 -07001732 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001733 (RsAllocation *)vtxPtr, vtxLen,
1734 (RsAllocation *)idxPtr, idxLen,
1735 (uint32_t *)primPtr, primLen);
1736
Ashok Bhat98071552014-02-12 09:54:43 +00001737 free(vtxPtr);
1738 free(idxPtr);
1739 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
1740 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001741 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001742 return id;
1743}
1744
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001745static jint
Tim Murray460a0492013-11-19 12:45:54 -08001746nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001747{
Andreas Gampe67333922014-11-10 20:35:59 -08001748 if (kLogApi) {
1749 ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1750 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001751 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001752 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001753 return vtxCount;
1754}
1755
1756static jint
Tim Murray460a0492013-11-19 12:45:54 -08001757nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001758{
Andreas Gampe67333922014-11-10 20:35:59 -08001759 if (kLogApi) {
1760 ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1761 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001762 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001763 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001764 return idxCount;
1765}
1766
1767static void
Ashok Bhat98071552014-02-12 09:54:43 +00001768nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001769{
Andreas Gampe67333922014-11-10 20:35:59 -08001770 if (kLogApi) {
1771 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1772 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001773
1774 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08001775 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001776
1777 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001778 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001779 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001780 }
1781
1782 free(allocs);
1783}
1784
1785static void
Ashok Bhat98071552014-02-12 09:54:43 +00001786nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001787{
Andreas Gampe67333922014-11-10 20:35:59 -08001788 if (kLogApi) {
1789 ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
1790 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001791
1792 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1793 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1794
Tim Murrayeff663f2013-11-15 13:08:30 -08001795 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001796
1797 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001798 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001799 const jint prim = (jint)prims[i];
1800 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
1801 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001802 }
1803
1804 free(allocs);
1805 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001806}
1807
Tim Murray56f9e6f2014-05-16 11:47:26 -07001808static jint
1809nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
1810 return (jint)sizeof(void*);
1811}
1812
1813
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001814// ---------------------------------------------------------------------------
1815
Jason Samsd19f10d2009-05-22 14:03:28 -07001816
Jason Sams94d8e90a2009-06-10 16:09:05 -07001817static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001818
1819static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001820{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001821
Tim Murrayeff663f2013-11-15 13:08:30 -08001822{"nDeviceCreate", "()J", (void*)nDeviceCreate },
1823{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
1824{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
1825{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
1826{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
1827{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001828
Tim Murrayeff663f2013-11-15 13:08:30 -08001829{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
1830{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001831
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001832
Jason Sams2e1872f2010-08-17 16:25:41 -07001833// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08001834{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
1835{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
1836{"rsnContextFinish", "(J)V", (void*)nContextFinish },
1837{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
1838{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
1839{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
1840{"rsnContextDump", "(JI)V", (void*)nContextDump },
1841{"rsnContextPause", "(J)V", (void*)nContextPause },
1842{"rsnContextResume", "(J)V", (void*)nContextResume },
1843{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Tim Murray460a0492013-11-19 12:45:54 -08001844{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
1845{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
1846{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001847
Tim Murray460a0492013-11-19 12:45:54 -08001848{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001849{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08001850{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
1851{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
1852{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001853{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001854
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001855{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
1856{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
1857{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001858
Tim Murray460a0492013-11-19 12:45:54 -08001859{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001860{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08001861{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00001862{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001863
Tim Murray460a0492013-11-19 12:45:54 -08001864{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001865{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001866
Ashok Bhat98071552014-02-12 09:54:43 +00001867{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08001868{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
1869{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
1870{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001871
Tim Murray460a0492013-11-19 12:45:54 -08001872{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1873{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08001874
Tim Murray460a0492013-11-19 12:45:54 -08001875{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
1876{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
1877{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
1878{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
1879{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
1880{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
1881{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D },
1882{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
1883{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
1884{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
1885{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
1886{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead },
1887{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
1888{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
1889{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
1890{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
1891{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001892
Tim Murray460a0492013-11-19 12:45:54 -08001893{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
1894{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
1895{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
1896{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
Chris Wailesbe7b1de2014-07-15 10:56:14 -07001897
1898{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach },
1899
Tim Murray460a0492013-11-19 12:45:54 -08001900{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
1901{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
1902{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
1903{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
1904{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
1905{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
1906{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
1907{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
1908{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
1909{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
1910{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
1911{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001912
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001913{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001914{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
1915{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
1916{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001917{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001918{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
1919{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
1920{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Jason Sams0011bcf2009-12-15 12:58:36 -08001921
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001922{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001923
Tim Murray460a0492013-11-19 12:45:54 -08001924{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
1925{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
1926{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001927
Ashok Bhat98071552014-02-12 09:54:43 +00001928{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001929{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001930{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001931
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001932{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
1933{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
1934{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
1935{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
1936{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001937
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001938{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001939
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001940{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001941{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001942
Tim Murray460a0492013-11-19 12:45:54 -08001943{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
1944{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00001945{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
1946{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001947
Tim Murray56f9e6f2014-05-16 11:47:26 -07001948{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07001949};
1950
1951static int registerFuncs(JNIEnv *_env)
1952{
1953 return android::AndroidRuntime::registerNativeMethods(
1954 _env, classPathName, methods, NELEM(methods));
1955}
1956
1957// ---------------------------------------------------------------------------
1958
1959jint JNI_OnLoad(JavaVM* vm, void* reserved)
1960{
Chris Wailes488230c32014-08-14 11:22:40 -07001961 JNIEnv* env = nullptr;
Jason Samsd19f10d2009-05-22 14:03:28 -07001962 jint result = -1;
1963
Jason Samsd19f10d2009-05-22 14:03:28 -07001964 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001965 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001966 goto bail;
1967 }
Chris Wailes488230c32014-08-14 11:22:40 -07001968 assert(env != nullptr);
Jason Samsd19f10d2009-05-22 14:03:28 -07001969
1970 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001971 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001972 goto bail;
1973 }
1974
1975 /* success -- return valid version number */
1976 result = JNI_VERSION_1_4;
1977
1978bail:
1979 return result;
1980}