blob: aa16951677b7ef9bdc71d0951c6e4a5e57f32f99 [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>
Jason Samsd19f10d2009-05-22 14:03:28 -070025
Jason Samsffe9f482009-06-01 17:45:53 -070026#include <core/SkBitmap.h>
Romain Guy650a3eb2009-08-31 14:06:43 -070027#include <core/SkPixelRef.h>
28#include <core/SkStream.h>
29#include <core/SkTemplates.h>
Jason Samsffe9f482009-06-01 17:45:53 -070030
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080031#include <androidfw/Asset.h>
32#include <androidfw/AssetManager.h>
33#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070034
Jason Samsd19f10d2009-05-22 14:03:28 -070035#include "jni.h"
36#include "JNIHelp.h"
37#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070038#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080039#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070040
Jason Sams1d6983a2012-02-16 16:07:49 -080041#include <rs.h>
42#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070043#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080044#include <gui/GLConsumer.h>
Mathias Agopian52800612013-02-14 17:11:20 -080045#include <gui/Surface.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070046#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070047
Steve Block3762c312012-01-06 19:20:56 +000048//#define LOG_API ALOGE
Jason Samsd19f10d2009-05-22 14:03:28 -070049#define LOG_API(...)
50
51using namespace android;
52
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080053class AutoJavaStringToUTF8 {
54public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080055 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080056 fCStr = env->GetStringUTFChars(str, NULL);
57 fLength = env->GetStringUTFLength(str);
58 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080059 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080060 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
61 }
62 const char* c_str() const { return fCStr; }
63 jsize length() const { return fLength; }
64
65private:
66 JNIEnv* fEnv;
67 jstring fJStr;
68 const char* fCStr;
69 jsize fLength;
70};
71
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080072class AutoJavaStringArrayToUTF8 {
73public:
74 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
75 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
76 mCStrings = NULL;
77 mSizeArray = NULL;
78 if (stringsLength > 0) {
79 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
80 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
81 for (jsize ct = 0; ct < stringsLength; ct ++) {
82 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
83 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL);
84 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
85 }
86 }
87 }
88 ~AutoJavaStringArrayToUTF8() {
89 for (jsize ct=0; ct < mStringsLength; ct++) {
90 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
91 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
92 }
93 free(mCStrings);
94 free(mSizeArray);
95 }
96 const char **c_str() const { return mCStrings; }
97 size_t *c_str_len() const { return mSizeArray; }
98 jsize length() const { return mStringsLength; }
99
100private:
101 JNIEnv *mEnv;
102 jobjectArray mStrings;
103 const char **mCStrings;
104 size_t *mSizeArray;
105 jsize mStringsLength;
106};
107
Jason Samsd19f10d2009-05-22 14:03:28 -0700108// ---------------------------------------------------------------------------
109
Jason Samsffe9f482009-06-01 17:45:53 -0700110static jfieldID gContextId = 0;
111static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -0700112static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700113
114static void _nInit(JNIEnv *_env, jclass _this)
115{
Jason Samsd19f10d2009-05-22 14:03:28 -0700116 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -0700117
118 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhata0398432014-01-20 20:08:01 +0000119 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700120}
121
Jason Samsd19f10d2009-05-22 14:03:28 -0700122// ---------------------------------------------------------------------------
123
Jason Sams3eaa3382009-06-10 15:04:38 -0700124static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700125nContextFinish(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700126{
Jason Sams96ed4cf2010-06-15 12:15:57 -0700127 LOG_API("nContextFinish, con(%p)", con);
128 rsContextFinish(con);
129}
130
131static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700132nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str)
Jason Sams3eaa3382009-06-10 15:04:38 -0700133{
Jason Sams07ae4062009-08-27 20:23:34 -0700134 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
Jason Sams3eaa3382009-06-10 15:04:38 -0700135 jint len = _env->GetArrayLength(str);
136 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsbc948de2009-08-17 18:35:48 -0700137 rsAssignName(con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa3382009-06-10 15:04:38 -0700138 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
139}
140
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700141static jstring
Jason Sams2e1872f2010-08-17 16:25:41 -0700142nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700143{
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700144 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700145 const char *name = NULL;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700146 rsaGetName(con, (void *)obj, &name);
147 if(name == NULL || strlen(name) == 0) {
148 return NULL;
149 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700150 return _env->NewStringUTF(name);
151}
152
Jason Sams7ce033d2009-08-18 14:14:24 -0700153static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700154nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700155{
Jason Sams7ce033d2009-08-18 14:14:24 -0700156 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
Jason Sams9c25aee2010-10-14 17:57:30 -0700157 rsObjDestroy(con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700158}
159
Jason Sams3eaa3382009-06-10 15:04:38 -0700160// ---------------------------------------------------------------------------
161
Jason Samsd19f10d2009-05-22 14:03:28 -0700162static jint
163nDeviceCreate(JNIEnv *_env, jobject _this)
164{
165 LOG_API("nDeviceCreate");
166 return (jint)rsDeviceCreate();
167}
168
169static void
170nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
171{
172 LOG_API("nDeviceDestroy");
173 return rsDeviceDestroy((RsDevice)dev);
174}
175
Jason Samsebfb4362009-09-23 13:57:02 -0700176static void
177nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
178{
179 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
180 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
181}
182
Jason Samsd19f10d2009-05-22 14:03:28 -0700183static jint
Jason Samsadd26dc2013-02-22 18:43:45 -0800184nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer, jint ct)
Jason Samsd19f10d2009-05-22 14:03:28 -0700185{
186 LOG_API("nContextCreate");
Tim Murray9578e642013-09-09 16:15:56 -0700187 return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, 0);
Jason Sams704ff642010-02-09 16:05:07 -0800188}
189
190static jint
Stephen Hines4382467a2011-08-01 15:02:34 -0700191nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700192 int colorMin, int colorPref,
193 int alphaMin, int alphaPref,
194 int depthMin, int depthPref,
195 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700196 int samplesMin, int samplesPref, float samplesQ,
197 int dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800198{
Jason Sams11c8af92010-10-13 15:31:10 -0700199 RsSurfaceConfig sc;
200 sc.alphaMin = alphaMin;
201 sc.alphaPref = alphaPref;
202 sc.colorMin = colorMin;
203 sc.colorPref = colorPref;
204 sc.depthMin = depthMin;
205 sc.depthPref = depthPref;
206 sc.samplesMin = samplesMin;
207 sc.samplesPref = samplesPref;
208 sc.samplesQ = samplesQ;
209
Jason Sams704ff642010-02-09 16:05:07 -0800210 LOG_API("nContextCreateGL");
Stephen Hines4382467a2011-08-01 15:02:34 -0700211 return (jint)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700212}
213
214static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700215nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800216{
Jason Sams7d787b42009-11-15 12:14:26 -0800217 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
218 rsContextSetPriority(con, p);
219}
220
221
222
223static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700224nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800225{
Jason Sams3bc47d42009-11-12 15:10:25 -0800226 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800227
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700228 ANativeWindow * window = NULL;
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800229 if (wnd == NULL) {
230
231 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700232 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800233 }
234
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700235 rsContextSetSurface(con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800236}
237
238static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700239nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700240{
Jason Sams2e1872f2010-08-17 16:25:41 -0700241 LOG_API("nContextDestroy, con(%p)", con);
242 rsContextDestroy(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700243}
244
Jason Sams715333b2009-11-17 17:26:46 -0800245static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700246nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800247{
Jason Sams715333b2009-11-17 17:26:46 -0800248 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
249 rsContextDump((RsContext)con, bits);
250}
Jason Samsd19f10d2009-05-22 14:03:28 -0700251
252static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700253nContextPause(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700254{
Jason Sams65e7aa52009-09-24 17:38:20 -0700255 LOG_API("nContextPause, con(%p)", con);
256 rsContextPause(con);
257}
258
259static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700260nContextResume(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700261{
Jason Sams65e7aa52009-09-24 17:38:20 -0700262 LOG_API("nContextResume, con(%p)", con);
263 rsContextResume(con);
264}
265
Jason Sams1c415172010-11-08 17:06:46 -0800266
267static jstring
268nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
269{
270 LOG_API("nContextGetErrorMessage, con(%p)", con);
271 char buf[1024];
272
273 size_t receiveLen;
274 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700275 int id = rsContextGetMessage(con,
276 buf, sizeof(buf),
277 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700278 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800279 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100280 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800281 }
282 return _env->NewStringUTF(buf);
283}
284
Jason Samsedbfabd2011-05-17 15:01:29 -0700285static jint
Jason Sams1c415172010-11-08 17:06:46 -0800286nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700287{
Jason Sams516c3192009-10-06 13:58:47 -0700288 jint len = _env->GetArrayLength(data);
289 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
290 jint *ptr = _env->GetIntArrayElements(data, NULL);
291 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800292 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700293 int id = rsContextGetMessage(con,
294 ptr, len * 4,
295 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700296 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700297 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100298 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700299 }
300 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Samsedbfabd2011-05-17 15:01:29 -0700301 return id;
Jason Sams1c415172010-11-08 17:06:46 -0800302}
303
304static jint
Jason Samsedbfabd2011-05-17 15:01:29 -0700305nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800306{
307 LOG_API("nContextPeekMessage, con(%p)", con);
308 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
309 size_t receiveLen;
310 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700311 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700312 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800313 auxDataPtr[0] = (jint)subID;
314 auxDataPtr[1] = (jint)receiveLen;
315 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Jason Sams516c3192009-10-06 13:58:47 -0700316 return id;
317}
318
Jason Sams2e1872f2010-08-17 16:25:41 -0700319static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700320{
Jason Sams516c3192009-10-06 13:58:47 -0700321 LOG_API("nContextInitToClient, con(%p)", con);
322 rsContextInitToClient(con);
323}
324
Jason Sams2e1872f2010-08-17 16:25:41 -0700325static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700326{
Jason Sams516c3192009-10-06 13:58:47 -0700327 LOG_API("nContextDeinitToClient, con(%p)", con);
328 rsContextDeinitToClient(con);
329}
330
Jason Sams455d6442013-02-05 19:20:18 -0800331static void
332nContextSendMessage(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray data)
333{
334 jint *ptr = NULL;
335 jint len = 0;
336 if (data) {
337 len = _env->GetArrayLength(data);
Stephen Hines57cf5602013-12-18 16:21:30 -0800338 ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams455d6442013-02-05 19:20:18 -0800339 }
340 LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", con, id, len);
341 rsContextSendMessage(con, id, (const uint8_t *)ptr, len * sizeof(int));
342 if (data) {
343 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
344 }
345}
346
347
Jason Sams516c3192009-10-06 13:58:47 -0700348
Jason Sams718cd1f2009-12-23 14:35:29 -0800349static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700350nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700351{
Jason Sams718cd1f2009-12-23 14:35:29 -0800352 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
353 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700354}
355
356static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800357nElementCreate2(JNIEnv *_env, jobject _this, RsContext con,
358 jintArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700359{
Jason Sams718cd1f2009-12-23 14:35:29 -0800360 int fieldCount = _env->GetArrayLength(_ids);
Jason Sams704ff642010-02-09 16:05:07 -0800361 LOG_API("nElementCreate2, con(%p)", con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800362
363 jint *ids = _env->GetIntArrayElements(_ids, NULL);
Jason Sams70d4e502010-09-02 17:35:23 -0700364 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
Jason Sams718cd1f2009-12-23 14:35:29 -0800365
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800366 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
367
368 const char **nameArray = names.c_str();
369 size_t *sizeArray = names.c_str_len();
370
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700371 jint id = (jint)rsElementCreate2(con,
372 (RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700373 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700374 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800375
Jason Sams718cd1f2009-12-23 14:35:29 -0800376 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
Jason Sams70d4e502010-09-02 17:35:23 -0700377 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
Jason Sams718cd1f2009-12-23 14:35:29 -0800378 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700379}
380
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700381static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700382nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700383{
384 int dataSize = _env->GetArrayLength(_elementData);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700385 LOG_API("nElementGetNativeData, con(%p)", con);
386
387 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
388 assert(dataSize == 5);
389
390 uint32_t elementData[5];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700391 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700392
393 for(jint i = 0; i < dataSize; i ++) {
394 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
395 }
396}
397
398
399static void
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700400nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
401 jintArray _IDs,
402 jobjectArray _names,
403 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700404{
405 int dataSize = _env->GetArrayLength(_IDs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700406 LOG_API("nElementGetSubElements, con(%p)", con);
407
408 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
409 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700410 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700411
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700412 rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700413
Jason Sams11c8af92010-10-13 15:31:10 -0700414 for(jint i = 0; i < dataSize; i++) {
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700415 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
416 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700417 _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700418 }
419
420 free(ids);
421 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700422 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700423}
424
Jason Samsd19f10d2009-05-22 14:03:28 -0700425// -----------------------------------
426
Jason Sams3b9c52a2010-10-14 17:48:46 -0700427static int
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800428nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800429 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700430{
Jason Samsb109cc72013-01-07 18:20:12 -0800431 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
432 con, eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700433
Jason Samsb109cc72013-01-07 18:20:12 -0800434 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700435 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700436}
437
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700438static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700439nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700440{
441 // We are packing 6 items: mDimX; mDimY; mDimZ;
442 // mDimLOD; mDimFaces; mElement; into typeData
443 int elementCount = _env->GetArrayLength(_typeData);
444
445 assert(elementCount == 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700446 LOG_API("nTypeCreate, con(%p)", con);
447
448 uint32_t typeData[6];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700449 rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700450
451 for(jint i = 0; i < elementCount; i ++) {
452 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
453 }
454}
455
Jason Samsd19f10d2009-05-22 14:03:28 -0700456// -----------------------------------
457
458static jint
Jason Sams857d0c72011-11-23 15:02:15 -0800459nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700460{
Jason Sams857d0c72011-11-23 15:02:15 -0800461 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer);
462 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700463}
464
Jason Samsd19f10d2009-05-22 14:03:28 -0700465static void
Jason Sams5476b452010-12-08 16:14:36 -0800466nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
467{
468 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
469 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
470}
471
Jason Sams72226e02013-02-22 12:45:54 -0800472static jobject
473nAllocationGetSurface(JNIEnv *_env, jobject _this, RsContext con, jint a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800474{
Jason Sams72226e02013-02-22 12:45:54 -0800475 LOG_API("nAllocationGetSurface, con(%p), a(%p)", con, (RsAllocation)a);
Jason Sams615e7ce2012-01-13 14:01:20 -0800476
Jason Sams72226e02013-02-22 12:45:54 -0800477 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface(con, (RsAllocation)a);
478 sp<IGraphicBufferProducer> bp = v;
479 v->decStrong(NULL);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700480
Jason Sams72226e02013-02-22 12:45:54 -0800481 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
482 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700483}
484
485static void
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700486nAllocationSetSurface(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800487{
Stephen Hines06883b72012-05-16 18:01:34 -0700488 LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)",
Jason Sams163766c2012-02-15 12:04:24 -0800489 con, alloc, (Surface *)sur);
490
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700491 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800492 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700493 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800494 }
495
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700496 rsAllocationSetSurface(con, alloc, static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800497}
498
499static void
500nAllocationIoSend(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
501{
502 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", con, alloc);
503 rsAllocationIoSend(con, alloc);
504}
505
506static void
507nAllocationIoReceive(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
508{
509 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", con, alloc);
510 rsAllocationIoReceive(con, alloc);
511}
512
513
514static void
Jason Samsf7086092011-01-12 13:28:37 -0800515nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
516{
517 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
518 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
519}
520
Jason Samsffe9f482009-06-01 17:45:53 -0700521static int
Jason Sams5476b452010-12-08 16:14:36 -0800522nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700523{
Jason Samsffe9f482009-06-01 17:45:53 -0700524 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000525 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -0700526 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700527
Jason Sams5476b452010-12-08 16:14:36 -0800528 bitmap.lockPixels();
529 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700530 jint id = (jint)rsAllocationCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700531 (RsType)type, (RsAllocationMipmapControl)mip,
532 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800533 bitmap.unlockPixels();
534 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700535}
Jason Samsfe08d992009-05-27 14:45:32 -0700536
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800537static int
Tim Murraya3145512012-12-04 17:59:29 -0800538nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
539{
540 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000541 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -0800542 const SkBitmap& bitmap(*nativeBitmap);
543
544 bitmap.lockPixels();
545 const void* ptr = bitmap.getPixels();
546 jint id = (jint)rsAllocationCreateTyped(con,
547 (RsType)type, (RsAllocationMipmapControl)mip,
548 (uint32_t)usage, (size_t)ptr);
549 bitmap.unlockPixels();
550 return id;
551}
552
553static int
Jason Sams5476b452010-12-08 16:14:36 -0800554nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800555{
556 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000557 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800558 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800559
Jason Sams5476b452010-12-08 16:14:36 -0800560 bitmap.lockPixels();
561 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700562 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700563 (RsType)type, (RsAllocationMipmapControl)mip,
564 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800565 bitmap.unlockPixels();
566 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800567}
568
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700569static void
Jason Sams4ef66502010-12-10 16:03:15 -0800570nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700571{
572 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000573 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700574 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800575 int w = bitmap.width();
576 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700577
Jason Sams4ef66502010-12-10 16:03:15 -0800578 bitmap.lockPixels();
579 const void* ptr = bitmap.getPixels();
Jason Samsf7086092011-01-12 13:28:37 -0800580 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700581 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea32012-11-27 14:55:08 -0800582 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800583 bitmap.unlockPixels();
584}
585
586static void
587nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
588{
589 SkBitmap const * nativeBitmap =
Ashok Bhata0398432014-01-20 20:08:01 +0000590 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -0800591 const SkBitmap& bitmap(*nativeBitmap);
592
593 bitmap.lockPixels();
594 void* ptr = bitmap.getPixels();
595 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
596 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700597 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700598}
599
Jason Sams8a647432010-03-01 15:31:04 -0800600static void ReleaseBitmapCallback(void *bmp)
601{
602 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
603 nativeBitmap->unlockPixels();
604}
605
Romain Guy650a3eb2009-08-31 14:06:43 -0700606
Jason Samsd19f10d2009-05-22 14:03:28 -0700607static void
Jason Sams49a05d72010-12-29 14:31:29 -0800608nAllocationData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700609{
Jason Samsd19f10d2009-05-22 14:03:28 -0700610 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800611 LOG_API("nAllocation1DData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700612 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800613 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700614 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
615}
616
617static void
Jason Sams49a05d72010-12-29 14:31:29 -0800618nAllocationData1D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jshortArray data, int sizeBytes)
Jason Sams768bc022009-09-21 19:41:04 -0700619{
Jason Sams768bc022009-09-21 19:41:04 -0700620 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800621 LOG_API("nAllocation1DData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700622 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800623 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700624 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
625}
626
627static void
Jason Sams49a05d72010-12-29 14:31:29 -0800628nAllocationData1D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jbyteArray data, int sizeBytes)
Jason Sams768bc022009-09-21 19:41:04 -0700629{
Jason Sams768bc022009-09-21 19:41:04 -0700630 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800631 LOG_API("nAllocation1DData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700632 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800633 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700634 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
635}
636
637static void
Jason Sams49a05d72010-12-29 14:31:29 -0800638nAllocationData1D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700639{
Jason Samsd19f10d2009-05-22 14:03:28 -0700640 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800641 LOG_API("nAllocation1DData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700642 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800643 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700644 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
645}
646
647static void
Jason Sams49a05d72010-12-29 14:31:29 -0800648// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
649nAllocationElementData1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint compIdx, jbyteArray data, int sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -0700650{
651 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800652 LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes);
Jason Sams49bdaf02010-08-31 13:50:42 -0700653 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Stephen Hines4cbe25a2012-01-18 18:46:27 -0800654 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700655 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
656}
657
658static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800659nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
660 jint w, jint h, jshortArray data, int sizeBytes)
661{
662 jint len = _env->GetArrayLength(data);
663 LOG_API("nAllocation2DData_s, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
664 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Tim Murray38faea32012-11-27 14:55:08 -0800665 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800666 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
667}
668
669static void
670nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
671 jint w, jint h, jbyteArray data, int sizeBytes)
672{
673 jint len = _env->GetArrayLength(data);
674 LOG_API("nAllocation2DData_b, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
675 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Tim Murray38faea32012-11-27 14:55:08 -0800676 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800677 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
678}
679
680static void
Jason Sams49a05d72010-12-29 14:31:29 -0800681nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
682 jint w, jint h, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700683{
Jason Samsd19f10d2009-05-22 14:03:28 -0700684 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800685 LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
Jason Samsd19f10d2009-05-22 14:03:28 -0700686 jint *ptr = _env->GetIntArrayElements(data, NULL);
Tim Murray38faea32012-11-27 14:55:08 -0800687 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700688 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
689}
690
691static void
Jason Sams49a05d72010-12-29 14:31:29 -0800692nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
693 jint w, jint h, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700694{
Jason Samsd19f10d2009-05-22 14:03:28 -0700695 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800696 LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
Jason Samsd19f10d2009-05-22 14:03:28 -0700697 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Tim Murray38faea32012-11-27 14:55:08 -0800698 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700699 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
700}
701
Jason Sams40a29e82009-08-10 14:55:26 -0700702static void
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700703nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
704 jint dstAlloc, jint dstXoff, jint dstYoff,
705 jint dstMip, jint dstFace,
706 jint width, jint height,
707 jint srcAlloc, jint srcXoff, jint srcYoff,
708 jint srcMip, jint srcFace)
709{
Jason Sams4c2e4c82012-02-07 15:32:08 -0800710 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700711 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
712 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
713 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
714 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
715
716 rsAllocationCopy2DRange(con,
717 (RsAllocation)dstAlloc,
718 dstXoff, dstYoff,
719 dstMip, dstFace,
720 width, height,
721 (RsAllocation)srcAlloc,
722 srcXoff, srcYoff,
723 srcMip, srcFace);
724}
725
726static void
Jason Samsb05d6892013-04-09 15:59:24 -0700727nAllocationData3D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod,
728 jint w, jint h, jint d, jshortArray data, int sizeBytes)
729{
730 jint len = _env->GetArrayLength(data);
731 LOG_API("nAllocation3DData_s, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len);
732 jshort *ptr = _env->GetShortArrayElements(data, NULL);
733 rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
734 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
735}
736
737static void
738nAllocationData3D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod,
739 jint w, jint h, jint d, jbyteArray data, int sizeBytes)
740{
741 jint len = _env->GetArrayLength(data);
742 LOG_API("nAllocation3DData_b, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len);
743 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
744 rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
745 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
746}
747
748static void
749nAllocationData3D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod,
750 jint w, jint h, jint d, jintArray data, int sizeBytes)
751{
752 jint len = _env->GetArrayLength(data);
753 LOG_API("nAllocation3DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len);
754 jint *ptr = _env->GetIntArrayElements(data, NULL);
755 rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
756 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
757}
758
759static void
760nAllocationData3D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod,
761 jint w, jint h, jint d, jfloatArray data, int sizeBytes)
762{
763 jint len = _env->GetArrayLength(data);
764 LOG_API("nAllocation3DData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len);
765 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
766 rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
767 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
768}
769
770static void
771nAllocationData3D_alloc(JNIEnv *_env, jobject _this, RsContext con,
772 jint dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
773 jint dstMip,
774 jint width, jint height, jint depth,
775 jint srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
776 jint srcMip)
777{
778 LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
779 " dstMip(%i), width(%i), height(%i),"
780 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
781 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
782 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
783
784 rsAllocationCopy3DRange(con,
785 (RsAllocation)dstAlloc,
786 dstXoff, dstYoff, dstZoff, dstMip,
787 width, height, depth,
788 (RsAllocation)srcAlloc,
789 srcXoff, srcYoff, srcZoff, srcMip);
790}
791
792static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700793nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700794{
Jason Sams40a29e82009-08-10 14:55:26 -0700795 jint len = _env->GetArrayLength(data);
796 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
797 jint *ptr = _env->GetIntArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700798 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700799 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(int));
Joe Onoratoae209ac2009-08-31 17:23:53 -0700800 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700801}
802
803static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800804nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
805{
806 jint len = _env->GetArrayLength(data);
807 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
808 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700809 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700810 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(short));
Jason Samsfb9f82c2011-01-12 14:53:25 -0800811 _env->ReleaseShortArrayElements(data, ptr, 0);
812}
813
814static void
815nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
816{
817 jint len = _env->GetArrayLength(data);
818 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
819 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700820 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700821 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(char));
Jason Samsfb9f82c2011-01-12 14:53:25 -0800822 _env->ReleaseByteArrayElements(data, ptr, 0);
823}
824
825static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700826nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700827{
Jason Sams40a29e82009-08-10 14:55:26 -0700828 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700829 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700830 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700831 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700832 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(float));
Joe Onoratoae209ac2009-08-31 17:23:53 -0700833 _env->ReleaseFloatArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700834}
Jason Samsd19f10d2009-05-22 14:03:28 -0700835
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700836static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700837nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700838{
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700839 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700840 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700841}
842
Jason Sams5edc6082010-10-05 13:32:49 -0700843static void
844nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
845{
846 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
847 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
848}
849
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700850// -----------------------------------
851
852static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700853nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700854{
Steve Block71f2cf12011-10-20 11:56:00 +0100855 ALOGV("______nFileA3D %u", (uint32_t) native_asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700856
857 Asset* asset = reinterpret_cast<Asset*>(native_asset);
858
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800859 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
860 return id;
861}
862
863static int
864nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
865{
866 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
867 if (mgr == NULL) {
868 return 0;
869 }
870
871 AutoJavaStringToUTF8 str(_env, _path);
872 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
873 if (asset == NULL) {
874 return 0;
875 }
876
877 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
878 return id;
879}
880
881static int
882nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
883{
884 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
885 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
886
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700887 return id;
888}
889
890static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700891nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700892{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700893 int32_t numEntries = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700894 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700895 return numEntries;
896}
897
898static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700899nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700900{
Steve Block71f2cf12011-10-20 11:56:00 +0100901 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700902 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
903
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700904 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700905
906 for(jint i = 0; i < numEntries; i ++) {
907 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
908 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
909 }
910
911 free(fileEntries);
912}
913
914static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700915nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700916{
Steve Block71f2cf12011-10-20 11:56:00 +0100917 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700918 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700919 return id;
920}
Jason Samsd19f10d2009-05-22 14:03:28 -0700921
922// -----------------------------------
923
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700924static int
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800925nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
926 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700927{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800928 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700929 jint id = (jint)rsFontCreateFromFile(con,
930 fileNameUTF.c_str(), fileNameUTF.length(),
931 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700932
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800933 return id;
934}
935
936static int
937nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
938 jstring name, jfloat fontSize, jint dpi, jint native_asset)
939{
940 Asset* asset = reinterpret_cast<Asset*>(native_asset);
941 AutoJavaStringToUTF8 nameUTF(_env, name);
942
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700943 jint id = (jint)rsFontCreateFromMemory(con,
944 nameUTF.c_str(), nameUTF.length(),
945 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800946 asset->getBuffer(false), asset->getLength());
947 return id;
948}
949
950static int
951nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
952 jfloat fontSize, jint dpi)
953{
954 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
955 if (mgr == NULL) {
956 return 0;
957 }
958
959 AutoJavaStringToUTF8 str(_env, _path);
960 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
961 if (asset == NULL) {
962 return 0;
963 }
964
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700965 jint id = (jint)rsFontCreateFromMemory(con,
966 str.c_str(), str.length(),
967 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800968 asset->getBuffer(false), asset->getLength());
969 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700970 return id;
971}
972
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700973// -----------------------------------
974
975static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700976nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700977{
Jason Samsd19f10d2009-05-22 14:03:28 -0700978 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700979 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700980}
981
982static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700983nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700984{
Jason Samscfc04362010-09-14 14:59:03 -0700985 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700986 rsScriptSetVarI(con, (RsScript)script, slot, val);
987}
988
Tim Murray7c4caad2013-04-10 16:21:40 -0700989static jint
990nScriptGetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot)
991{
992 LOG_API("nScriptGetVarI, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
993 int value = 0;
994 rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value));
995 return value;
996}
997
Jason Sams4d339932010-05-11 14:03:58 -0700998static void
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800999nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
1000{
1001 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
1002 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
1003}
1004
1005static void
Stephen Hines031ec58c2010-10-11 10:54:21 -07001006nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
1007{
1008 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
1009 rsScriptSetVarJ(con, (RsScript)script, slot, val);
1010}
1011
Tim Murray7c4caad2013-04-10 16:21:40 -07001012static jlong
1013nScriptGetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot)
1014{
1015 LOG_API("nScriptGetVarJ, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1016 jlong value = 0;
1017 rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value));
1018 return value;
1019}
1020
Stephen Hines031ec58c2010-10-11 10:54:21 -07001021static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001022nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001023{
Stephen Hinesca54ec32010-09-20 17:20:30 -07001024 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001025 rsScriptSetVarF(con, (RsScript)script, slot, val);
1026}
1027
Tim Murray7c4caad2013-04-10 16:21:40 -07001028static jfloat
1029nScriptGetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot)
1030{
1031 LOG_API("nScriptGetVarF, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1032 jfloat value = 0;
1033 rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value));
1034 return value;
1035}
1036
Jason Sams4d339932010-05-11 14:03:58 -07001037static void
Stephen Hinesca54ec32010-09-20 17:20:30 -07001038nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
1039{
1040 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
1041 rsScriptSetVarD(con, (RsScript)script, slot, val);
1042}
1043
Tim Murray7c4caad2013-04-10 16:21:40 -07001044static jdouble
1045nScriptGetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot)
1046{
1047 LOG_API("nScriptGetVarD, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1048 jdouble value = 0;
1049 rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value));
1050 return value;
1051}
1052
Stephen Hinesca54ec32010-09-20 17:20:30 -07001053static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001054nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001055{
Jason Sams4d339932010-05-11 14:03:58 -07001056 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1057 jint len = _env->GetArrayLength(data);
1058 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1059 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
1060 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1061}
1062
Stephen Hinesadeb8092012-04-20 14:26:06 -07001063static void
Tim Murray7c4caad2013-04-10 16:21:40 -07001064nScriptGetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
1065{
1066 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1067 jint len = _env->GetArrayLength(data);
1068 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1069 rsScriptGetVarV(con, (RsScript)script, slot, ptr, len);
1070 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1071}
1072
1073static void
Stephen Hinesadeb8092012-04-20 14:26:06 -07001074nScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims)
1075{
1076 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1077 jint len = _env->GetArrayLength(data);
1078 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1079 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
1080 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
1081 rsScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem,
1082 (const size_t*) dimsPtr, dimsLen);
1083 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1084 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1085}
1086
Jason Samsd19f10d2009-05-22 14:03:28 -07001087
1088static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001089nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001090{
Jason Sams07ae4062009-08-27 20:23:34 -07001091 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -07001092
1093 jint length = _env->GetArrayLength(timeZone);
1094 jbyte* timeZone_ptr;
1095 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1096
Jason Samsbc948de2009-08-17 18:35:48 -07001097 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001098
1099 if (timeZone_ptr) {
1100 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1101 }
1102}
1103
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001104static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001105nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001106{
Jason Samsbe2e8412009-09-16 15:04:38 -07001107 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
1108 rsScriptInvoke(con, (RsScript)obj, slot);
1109}
1110
1111static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001112nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001113{
Jason Sams4d339932010-05-11 14:03:58 -07001114 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1115 jint len = _env->GetArrayLength(data);
1116 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1117 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
1118 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1119}
1120
Jason Sams6e494d32011-04-27 16:33:11 -07001121static void
1122nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
1123 jint script, jint slot, jint ain, jint aout)
1124{
1125 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001126 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0);
Jason Sams6e494d32011-04-27 16:33:11 -07001127}
1128static void
1129nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
1130 jint script, jint slot, jint ain, jint aout, jbyteArray params)
1131{
1132 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1133 jint len = _env->GetArrayLength(params);
1134 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001135 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0);
Jason Sams6e494d32011-04-27 16:33:11 -07001136 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1137}
1138
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001139static void
1140nScriptForEachClipped(JNIEnv *_env, jobject _this, RsContext con,
1141 jint script, jint slot, jint ain, jint aout,
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001142 jint xstart, jint xend,
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001143 jint ystart, jint yend, jint zstart, jint zend)
1144{
1145 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001146 RsScriptCall sc;
1147 sc.xStart = xstart;
1148 sc.xEnd = xend;
1149 sc.yStart = ystart;
1150 sc.yEnd = yend;
1151 sc.zStart = zstart;
1152 sc.zEnd = zend;
1153 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1154 sc.arrayStart = 0;
1155 sc.arrayEnd = 0;
1156 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc));
1157}
1158
1159static void
1160nScriptForEachClippedV(JNIEnv *_env, jobject _this, RsContext con,
1161 jint script, jint slot, jint ain, jint aout,
1162 jbyteArray params, jint xstart, jint xend,
1163 jint ystart, jint yend, jint zstart, jint zend)
1164{
1165 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001166 jint len = _env->GetArrayLength(params);
1167 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
1168 RsScriptCall sc;
1169 sc.xStart = xstart;
1170 sc.xEnd = xend;
1171 sc.yStart = ystart;
1172 sc.yEnd = yend;
1173 sc.zStart = zstart;
1174 sc.zEnd = zend;
1175 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1176 sc.arrayStart = 0;
1177 sc.arrayEnd = 0;
1178 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc));
1179 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1180}
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001181
Jason Sams22534172009-08-04 16:58:20 -07001182// -----------------------------------
1183
Jason Samse4a06c52011-03-16 16:29:28 -07001184static jint
1185nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
1186 jstring resName, jstring cacheDir,
1187 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001188{
Jason Samse4a06c52011-03-16 16:29:28 -07001189 LOG_API("nScriptCCreate, con(%p)", con);
Jason Sams22534172009-08-04 16:58:20 -07001190
Jason Samse4a06c52011-03-16 16:29:28 -07001191 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1192 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
1193 jint ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -07001194 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -07001195 jint _exception = 0;
1196 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001197 if (!scriptRef) {
1198 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001199 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001200 goto exit;
1201 }
Jack Palevich43702d82009-05-28 13:38:16 -07001202 if (length < 0) {
1203 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001204 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001205 goto exit;
1206 }
Jason Samse4a06c52011-03-16 16:29:28 -07001207 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001208 if (remaining < length) {
1209 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001210 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1211 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001212 goto exit;
1213 }
Jason Samse4a06c52011-03-16 16:29:28 -07001214 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001215 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001216
Jason Samse4a06c52011-03-16 16:29:28 -07001217 //rsScriptCSetText(con, (const char *)script_ptr, length);
1218
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001219 ret = (jint)rsScriptCCreate(con,
1220 resNameUTF.c_str(), resNameUTF.length(),
1221 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001222 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001223
Jack Palevich43702d82009-05-28 13:38:16 -07001224exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001225 if (script_ptr) {
1226 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001227 _exception ? JNI_ABORT: 0);
1228 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001229
Jason Samse4a06c52011-03-16 16:29:28 -07001230 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001231}
1232
Jason Sams6ab97682012-08-10 12:09:43 -07001233static jint
1234nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, RsContext con, jint id, jint eid)
1235{
1236 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", con, id, (void *)eid);
1237 return (jint)rsScriptIntrinsicCreate(con, id, (RsElement)eid);
1238}
1239
Jason Sams08a81582012-09-18 12:32:10 -07001240static jint
1241nScriptKernelIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot, jint sig)
1242{
1243 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", con, (void *)sid, slot, sig);
1244 return (jint)rsScriptKernelIDCreate(con, (RsScript)sid, slot, sig);
1245}
1246
1247static jint
1248nScriptFieldIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot)
1249{
1250 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", con, (void *)sid, slot);
1251 return (jint)rsScriptFieldIDCreate(con, (RsScript)sid, slot);
1252}
1253
1254static jint
1255nScriptGroupCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _kernels, jintArray _src,
1256 jintArray _dstk, jintArray _dstf, jintArray _types)
1257{
1258 LOG_API("nScriptGroupCreate, con(%p)", con);
1259
1260 jint kernelsLen = _env->GetArrayLength(_kernels) * sizeof(int);
1261 jint *kernelsPtr = _env->GetIntArrayElements(_kernels, NULL);
1262 jint srcLen = _env->GetArrayLength(_src) * sizeof(int);
1263 jint *srcPtr = _env->GetIntArrayElements(_src, NULL);
1264 jint dstkLen = _env->GetArrayLength(_dstk) * sizeof(int);
1265 jint *dstkPtr = _env->GetIntArrayElements(_dstk, NULL);
1266 jint dstfLen = _env->GetArrayLength(_dstf) * sizeof(int);
1267 jint *dstfPtr = _env->GetIntArrayElements(_dstf, NULL);
1268 jint typesLen = _env->GetArrayLength(_types) * sizeof(int);
1269 jint *typesPtr = _env->GetIntArrayElements(_types, NULL);
1270
1271 int id = (int)rsScriptGroupCreate(con,
1272 (RsScriptKernelID *)kernelsPtr, kernelsLen,
1273 (RsScriptKernelID *)srcPtr, srcLen,
1274 (RsScriptKernelID *)dstkPtr, dstkLen,
1275 (RsScriptFieldID *)dstfPtr, dstfLen,
1276 (RsType *)typesPtr, typesLen);
1277
1278 _env->ReleaseIntArrayElements(_kernels, kernelsPtr, 0);
1279 _env->ReleaseIntArrayElements(_src, srcPtr, 0);
1280 _env->ReleaseIntArrayElements(_dstk, dstkPtr, 0);
1281 _env->ReleaseIntArrayElements(_dstf, dstfPtr, 0);
1282 _env->ReleaseIntArrayElements(_types, typesPtr, 0);
1283 return id;
1284}
1285
1286static void
1287nScriptGroupSetInput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
1288{
1289 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
1290 (void *)gid, (void *)kid, (void *)alloc);
1291 rsScriptGroupSetInput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
1292}
1293
1294static void
1295nScriptGroupSetOutput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
1296{
1297 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
1298 (void *)gid, (void *)kid, (void *)alloc);
1299 rsScriptGroupSetOutput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
1300}
1301
1302static void
1303nScriptGroupExecute(JNIEnv *_env, jobject _this, RsContext con, jint gid)
1304{
1305 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", con, (void *)gid);
1306 rsScriptGroupExecute(con, (RsScriptGroup)gid);
1307}
1308
Jason Samsd19f10d2009-05-22 14:03:28 -07001309// ---------------------------------------------------------------------------
1310
Jason Samsd19f10d2009-05-22 14:03:28 -07001311static jint
Jason Sams331bf9b2011-04-06 11:23:54 -07001312nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
1313 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1314 jboolean depthMask, jboolean ditherEnable,
1315 jint srcFunc, jint destFunc,
1316 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001317{
Jason Sams54db59c2010-05-13 18:30:11 -07001318 LOG_API("nProgramStoreCreate, con(%p)", con);
Jason Sams331bf9b2011-04-06 11:23:54 -07001319 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
1320 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1321 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001322}
1323
Jason Sams0011bcf2009-12-15 12:58:36 -08001324// ---------------------------------------------------------------------------
1325
1326static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001327nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001328{
Jason Sams0011bcf2009-12-15 12:58:36 -08001329 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
1330 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
1331}
Jason Sams54c0ec12009-11-30 14:49:55 -08001332
Jason Sams68afd012009-12-17 16:55:08 -08001333static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001334nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001335{
Jason Sams68afd012009-12-17 16:55:08 -08001336 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1337 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1338}
1339
1340static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001341nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001342{
Jason Sams68afd012009-12-17 16:55:08 -08001343 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1344 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1345}
1346
Jason Samsd19f10d2009-05-22 14:03:28 -07001347// ---------------------------------------------------------------------------
1348
Jason Samsd19f10d2009-05-22 14:03:28 -07001349static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001350nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1351 jobjectArray texNames, jintArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001352{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001353 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001354 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1355 jint paramLen = _env->GetArrayLength(params);
1356
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001357 int texCount = _env->GetArrayLength(texNames);
1358 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1359 const char ** nameArray = names.c_str();
1360 size_t* sizeArray = names.c_str_len();
1361
Jason Sams991040c2011-01-17 15:59:39 -08001362 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001363
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001364 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1365 nameArray, texCount, sizeArray,
1366 (uint32_t *)paramPtr, paramLen);
1367
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001368 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1369 return ret;
1370}
1371
1372
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001373// ---------------------------------------------------------------------------
1374
Jason Sams0011bcf2009-12-15 12:58:36 -08001375static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001376nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1377 jobjectArray texNames, jintArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001378{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001379 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams0011bcf2009-12-15 12:58:36 -08001380 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1381 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001382
Jason Sams991040c2011-01-17 15:59:39 -08001383 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001384
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001385 int texCount = _env->GetArrayLength(texNames);
1386 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1387 const char ** nameArray = names.c_str();
1388 size_t* sizeArray = names.c_str_len();
1389
1390 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1391 nameArray, texCount, sizeArray,
1392 (uint32_t *)paramPtr, paramLen);
1393
Jason Sams0011bcf2009-12-15 12:58:36 -08001394 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1395 return ret;
1396}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001397
Jason Samsebfb4362009-09-23 13:57:02 -07001398// ---------------------------------------------------------------------------
1399
1400static jint
Jason Sams94aaed32011-09-23 14:18:53 -07001401nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001402{
Jason Sams94aaed32011-09-23 14:18:53 -07001403 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", con, pointSprite, cull);
1404 return (jint)rsProgramRasterCreate(con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001405}
1406
Jason Samsd19f10d2009-05-22 14:03:28 -07001407
1408// ---------------------------------------------------------------------------
1409
1410static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001411nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001412{
Jason Samsd19f10d2009-05-22 14:03:28 -07001413 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001414 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001415}
1416
1417static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001418nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001419{
Jason Sams54db59c2010-05-13 18:30:11 -07001420 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1421 rsContextBindProgramStore(con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001422}
1423
1424static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001425nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001426{
Jason Samsd19f10d2009-05-22 14:03:28 -07001427 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001428 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001429}
1430
Jason Sams0826a6f2009-06-15 19:04:56 -07001431static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001432nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001433{
Jason Sams0826a6f2009-06-15 19:04:56 -07001434 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001435 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001436}
1437
Joe Onoratod7b37742009-08-09 22:57:44 -07001438static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001439nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001440{
Jason Samsebfb4362009-09-23 13:57:02 -07001441 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1442 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1443}
1444
Joe Onoratod7b37742009-08-09 22:57:44 -07001445
Jason Sams02fb2cb2009-05-28 15:37:57 -07001446// ---------------------------------------------------------------------------
1447
Jason Sams02fb2cb2009-05-28 15:37:57 -07001448static jint
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001449nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1450 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001451{
Jason Samsbba134c2009-06-22 15:49:21 -07001452 LOG_API("nSamplerCreate, con(%p)", con);
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001453 return (jint)rsSamplerCreate(con,
1454 (RsSamplerValue)magFilter,
1455 (RsSamplerValue)minFilter,
1456 (RsSamplerValue)wrapS,
1457 (RsSamplerValue)wrapT,
1458 (RsSamplerValue)wrapR,
1459 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001460}
1461
Jason Samsbba134c2009-06-22 15:49:21 -07001462// ---------------------------------------------------------------------------
1463
Jason Samsf15ed012011-10-31 13:23:43 -07001464//native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
1465static jint
1466nPathCreate(JNIEnv *_env, jobject _this, RsContext con, jint prim, jboolean isStatic, jint _vtx, jint _loop, jfloat q) {
1467 LOG_API("nPathCreate, con(%p)", con);
1468
1469 int id = (int)rsPathCreate(con, (RsPathPrimitive)prim, isStatic,
1470 (RsAllocation)_vtx,
1471 (RsAllocation)_loop, q);
1472 return id;
1473}
1474
Jason Samsbba134c2009-06-22 15:49:21 -07001475static jint
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001476nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001477{
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001478 LOG_API("nMeshCreate, con(%p)", con);
1479
1480 jint vtxLen = _env->GetArrayLength(_vtx);
1481 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
1482 jint idxLen = _env->GetArrayLength(_idx);
1483 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
1484 jint primLen = _env->GetArrayLength(_prim);
1485 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1486
1487 int id = (int)rsMeshCreate(con,
1488 (RsAllocation *)vtxPtr, vtxLen,
1489 (RsAllocation *)idxPtr, idxLen,
1490 (uint32_t *)primPtr, primLen);
1491
1492 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
1493 _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
1494 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001495 return id;
1496}
1497
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001498static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001499nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001500{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001501 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1502 jint vtxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001503 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001504 return vtxCount;
1505}
1506
1507static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001508nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001509{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001510 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1511 jint idxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001512 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001513 return idxCount;
1514}
1515
1516static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001517nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001518{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001519 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1520
1521 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001522 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001523
1524 for(jint i = 0; i < numVtxIDs; i ++) {
1525 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1526 }
1527
1528 free(allocs);
1529}
1530
1531static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001532nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001533{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001534 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1535
1536 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1537 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1538
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001539 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001540
1541 for(jint i = 0; i < numIndices; i ++) {
1542 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1543 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1544 }
1545
1546 free(allocs);
1547 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001548}
1549
1550// ---------------------------------------------------------------------------
1551
Jason Samsd19f10d2009-05-22 14:03:28 -07001552
Jason Sams94d8e90a2009-06-10 16:09:05 -07001553static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001554
1555static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001556{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001557
Jason Sams1c415172010-11-08 17:06:46 -08001558{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1559{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1560{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
Jason Samsedbfabd2011-05-17 15:01:29 -07001561{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001562{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
Jason Samsedbfabd2011-05-17 15:01:29 -07001563{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001564
1565{"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1566{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001567
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001568
Jason Sams2e1872f2010-08-17 16:25:41 -07001569// All methods below are thread protected in java.
Jason Samsadd26dc2013-02-22 18:43:45 -08001570{"rsnContextCreate", "(IIII)I", (void*)nContextCreate },
Stephen Hines4382467a2011-08-01 15:02:34 -07001571{"rsnContextCreateGL", "(IIIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
Jason Sams2e1872f2010-08-17 16:25:41 -07001572{"rsnContextFinish", "(I)V", (void*)nContextFinish },
1573{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1574{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001575{"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams2e1872f2010-08-17 16:25:41 -07001576{"rsnContextDump", "(II)V", (void*)nContextDump },
1577{"rsnContextPause", "(I)V", (void*)nContextPause },
1578{"rsnContextResume", "(I)V", (void*)nContextResume },
Jason Sams455d6442013-02-05 19:20:18 -08001579{"rsnContextSendMessage", "(II[I)V", (void*)nContextSendMessage },
Jason Sams2e1872f2010-08-17 16:25:41 -07001580{"rsnAssignName", "(II[B)V", (void*)nAssignName },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001581{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
Jason Sams2e1872f2010-08-17 16:25:41 -07001582{"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001583
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001584{"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
Jason Sams2e1872f2010-08-17 16:25:41 -07001585{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001586{"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
Jason Sams2e1872f2010-08-17 16:25:41 -07001587{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001588{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Jason Sams2e1872f2010-08-17 16:25:41 -07001589{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001590
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -08001591{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001592{"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1593{"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001594
Jason Sams2e1872f2010-08-17 16:25:41 -07001595{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
Jason Sams70d4e502010-09-02 17:35:23 -07001596{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
Jason Sams2e1872f2010-08-17 16:25:41 -07001597{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001598{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001599
Jason Samsb109cc72013-01-07 18:20:12 -08001600{"rsnTypeCreate", "(IIIIIZZI)I", (void*)nTypeCreate },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001601{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001602
Jason Sams857d0c72011-11-23 15:02:15 -08001603{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped },
Jason Sams5476b452010-12-08 16:14:36 -08001604{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
Tim Murraya3145512012-12-04 17:59:29 -08001605{"rsnAllocationCreateBitmapBackedAllocation", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateBitmapBackedAllocation },
Jason Sams5476b452010-12-08 16:14:36 -08001606{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001607
Jason Sams4ef66502010-12-10 16:03:15 -08001608{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1609{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1610
Jason Sams5476b452010-12-08 16:14:36 -08001611{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
Jason Sams72226e02013-02-22 12:45:54 -08001612{"rsnAllocationGetSurface", "(II)Landroid/view/Surface;", (void*)nAllocationGetSurface },
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001613{"rsnAllocationSetSurface", "(IILandroid/view/Surface;)V", (void*)nAllocationSetSurface },
Jason Sams163766c2012-02-15 12:04:24 -08001614{"rsnAllocationIoSend", "(II)V", (void*)nAllocationIoSend },
1615{"rsnAllocationIoReceive", "(II)V", (void*)nAllocationIoReceive },
Jason Sams49a05d72010-12-29 14:31:29 -08001616{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i },
1617{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s },
1618{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b },
1619{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f },
1620{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
1621{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001622{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s },
1623{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b },
Jason Sams49a05d72010-12-29 14:31:29 -08001624{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f },
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001625{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc },
Jason Samsb05d6892013-04-09 15:59:24 -07001626{"rsnAllocationData3D", "(IIIIIIIII[II)V", (void*)nAllocationData3D_i },
1627{"rsnAllocationData3D", "(IIIIIIIII[SI)V", (void*)nAllocationData3D_s },
1628{"rsnAllocationData3D", "(IIIIIIIII[BI)V", (void*)nAllocationData3D_b },
1629{"rsnAllocationData3D", "(IIIIIIIII[FI)V", (void*)nAllocationData3D_f },
1630{"rsnAllocationData3D", "(IIIIIIIIIIIIII)V", (void*)nAllocationData3D_alloc },
Jason Sams2e1872f2010-08-17 16:25:41 -07001631{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001632{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s },
1633{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b },
Jason Sams2e1872f2010-08-17 16:25:41 -07001634{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
Jason Sams2e1872f2010-08-17 16:25:41 -07001635{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
Jason Sams5edc6082010-10-05 13:32:49 -07001636{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
Jason Samsf7086092011-01-12 13:28:37 -08001637{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001638
Jason Sams2e1872f2010-08-17 16:25:41 -07001639{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1640{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1641{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1642{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
Jason Sams6e494d32011-04-27 16:33:11 -07001643{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1644{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001645{"rsnScriptForEachClipped", "(IIIIIIIIIII)V", (void*)nScriptForEachClipped },
1646{"rsnScriptForEachClipped", "(IIIII[BIIIIII)V", (void*)nScriptForEachClippedV },
Jason Sams2e1872f2010-08-17 16:25:41 -07001647{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
Tim Murray7c4caad2013-04-10 16:21:40 -07001648{"rsnScriptGetVarI", "(III)I", (void*)nScriptGetVarI },
Stephen Hines031ec58c2010-10-11 10:54:21 -07001649{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
Tim Murray7c4caad2013-04-10 16:21:40 -07001650{"rsnScriptGetVarJ", "(III)J", (void*)nScriptGetVarJ },
Jason Sams2e1872f2010-08-17 16:25:41 -07001651{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
Tim Murray7c4caad2013-04-10 16:21:40 -07001652{"rsnScriptGetVarF", "(III)F", (void*)nScriptGetVarF },
Stephen Hinesca54ec32010-09-20 17:20:30 -07001653{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
Tim Murray7c4caad2013-04-10 16:21:40 -07001654{"rsnScriptGetVarD", "(III)D", (void*)nScriptGetVarD },
Jason Sams2e1872f2010-08-17 16:25:41 -07001655{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
Tim Murray7c4caad2013-04-10 16:21:40 -07001656{"rsnScriptGetVarV", "(III[B)V", (void*)nScriptGetVarV },
Stephen Hinesadeb8092012-04-20 14:26:06 -07001657{"rsnScriptSetVarVE", "(III[BI[I)V", (void*)nScriptSetVarVE },
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001658{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001659
Jason Samse4a06c52011-03-16 16:29:28 -07001660{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
Jason Sams6ab97682012-08-10 12:09:43 -07001661{"rsnScriptIntrinsicCreate", "(III)I", (void*)nScriptIntrinsicCreate },
Jason Sams08a81582012-09-18 12:32:10 -07001662{"rsnScriptKernelIDCreate", "(IIII)I", (void*)nScriptKernelIDCreate },
1663{"rsnScriptFieldIDCreate", "(III)I", (void*)nScriptFieldIDCreate },
1664{"rsnScriptGroupCreate", "(I[I[I[I[I[I)I", (void*)nScriptGroupCreate },
1665{"rsnScriptGroupSetInput", "(IIII)V", (void*)nScriptGroupSetInput },
1666{"rsnScriptGroupSetOutput", "(IIII)V", (void*)nScriptGroupSetOutput },
1667{"rsnScriptGroupExecute", "(II)V", (void*)nScriptGroupExecute },
Jason Sams0011bcf2009-12-15 12:58:36 -08001668
Jason Sams331bf9b2011-04-06 11:23:54 -07001669{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001670
Jason Sams2e1872f2010-08-17 16:25:41 -07001671{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1672{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1673{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001674
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001675{"rsnProgramFragmentCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate },
Jason Sams94aaed32011-09-23 14:18:53 -07001676{"rsnProgramRasterCreate", "(IZI)I", (void*)nProgramRasterCreate },
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001677{"rsnProgramVertexCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001678
Jason Sams2e1872f2010-08-17 16:25:41 -07001679{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001680{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
Jason Sams2e1872f2010-08-17 16:25:41 -07001681{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1682{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1683{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001684
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001685{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001686
Jason Samsf15ed012011-10-31 13:23:43 -07001687{"rsnPathCreate", "(IIZIIF)I", (void*)nPathCreate },
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001688{"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001689
1690{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1691{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001692{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
Jason Sams2e1872f2010-08-17 16:25:41 -07001693{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001694
Jason Samsd19f10d2009-05-22 14:03:28 -07001695};
1696
1697static int registerFuncs(JNIEnv *_env)
1698{
1699 return android::AndroidRuntime::registerNativeMethods(
1700 _env, classPathName, methods, NELEM(methods));
1701}
1702
1703// ---------------------------------------------------------------------------
1704
1705jint JNI_OnLoad(JavaVM* vm, void* reserved)
1706{
1707 JNIEnv* env = NULL;
1708 jint result = -1;
1709
Jason Samsd19f10d2009-05-22 14:03:28 -07001710 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001711 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001712 goto bail;
1713 }
1714 assert(env != NULL);
1715
1716 if (registerFuncs(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001717 ALOGE("ERROR: MediaPlayer native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001718 goto bail;
1719 }
1720
1721 /* success -- return valid version number */
1722 result = JNI_VERSION_1_4;
1723
1724bail:
1725 return result;
1726}