blob: 460a51677b1b82f353242867675ea639154bed26 [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>
30#include <images/SkImageDecoder.h>
Jason Samsffe9f482009-06-01 17:45:53 -070031
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080032#include <androidfw/Asset.h>
33#include <androidfw/AssetManager.h>
34#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070035
Jason Samsd19f10d2009-05-22 14:03:28 -070036#include "jni.h"
37#include "JNIHelp.h"
38#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070039#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080040#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070041
Jason Sams1d6983a2012-02-16 16:07:49 -080042#include <rs.h>
43#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070044#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080045#include <gui/GLConsumer.h>
Mathias Agopian52800612013-02-14 17:11:20 -080046#include <gui/Surface.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070047#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070048
Steve Block3762c312012-01-06 19:20:56 +000049//#define LOG_API ALOGE
Jason Samsd19f10d2009-05-22 14:03:28 -070050#define LOG_API(...)
51
52using namespace android;
53
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080054class AutoJavaStringToUTF8 {
55public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080056 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080057 fCStr = env->GetStringUTFChars(str, NULL);
58 fLength = env->GetStringUTFLength(str);
59 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080060 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080061 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
62 }
63 const char* c_str() const { return fCStr; }
64 jsize length() const { return fLength; }
65
66private:
67 JNIEnv* fEnv;
68 jstring fJStr;
69 const char* fCStr;
70 jsize fLength;
71};
72
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080073class AutoJavaStringArrayToUTF8 {
74public:
75 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
76 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
77 mCStrings = NULL;
78 mSizeArray = NULL;
79 if (stringsLength > 0) {
80 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
81 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
82 for (jsize ct = 0; ct < stringsLength; ct ++) {
83 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
84 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL);
85 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
86 }
87 }
88 }
89 ~AutoJavaStringArrayToUTF8() {
90 for (jsize ct=0; ct < mStringsLength; ct++) {
91 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
92 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
93 }
94 free(mCStrings);
95 free(mSizeArray);
96 }
97 const char **c_str() const { return mCStrings; }
98 size_t *c_str_len() const { return mSizeArray; }
99 jsize length() const { return mStringsLength; }
100
101private:
102 JNIEnv *mEnv;
103 jobjectArray mStrings;
104 const char **mCStrings;
105 size_t *mSizeArray;
106 jsize mStringsLength;
107};
108
Jason Samsd19f10d2009-05-22 14:03:28 -0700109// ---------------------------------------------------------------------------
110
Jason Samsffe9f482009-06-01 17:45:53 -0700111static jfieldID gContextId = 0;
112static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -0700113static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700114
115static void _nInit(JNIEnv *_env, jclass _this)
116{
Jason Samsd19f10d2009-05-22 14:03:28 -0700117 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -0700118
119 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
120 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
Jason Samsd19f10d2009-05-22 14:03:28 -0700121}
122
Jason Samsd19f10d2009-05-22 14:03:28 -0700123// ---------------------------------------------------------------------------
124
Jason Sams3eaa338e2009-06-10 15:04:38 -0700125static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700126nContextFinish(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700127{
Jason Sams96ed4cf2010-06-15 12:15:57 -0700128 LOG_API("nContextFinish, con(%p)", con);
129 rsContextFinish(con);
130}
131
132static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700133nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700134{
Jason Sams07ae4062009-08-27 20:23:34 -0700135 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700136 jint len = _env->GetArrayLength(str);
137 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsbc948de2009-08-17 18:35:48 -0700138 rsAssignName(con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700139 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
140}
141
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700142static jstring
Jason Sams2e1872f2010-08-17 16:25:41 -0700143nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700144{
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700145 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700146 const char *name = NULL;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700147 rsaGetName(con, (void *)obj, &name);
148 if(name == NULL || strlen(name) == 0) {
149 return NULL;
150 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700151 return _env->NewStringUTF(name);
152}
153
Jason Sams7ce033d2009-08-18 14:14:24 -0700154static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700155nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700156{
Jason Sams7ce033d2009-08-18 14:14:24 -0700157 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
Jason Sams9c25aee2010-10-14 17:57:30 -0700158 rsObjDestroy(con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700159}
160
Jason Sams3eaa338e2009-06-10 15:04:38 -0700161// ---------------------------------------------------------------------------
162
Jason Samsd19f10d2009-05-22 14:03:28 -0700163static jint
164nDeviceCreate(JNIEnv *_env, jobject _this)
165{
166 LOG_API("nDeviceCreate");
167 return (jint)rsDeviceCreate();
168}
169
170static void
171nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
172{
173 LOG_API("nDeviceDestroy");
174 return rsDeviceDestroy((RsDevice)dev);
175}
176
Jason Samsebfb4362009-09-23 13:57:02 -0700177static void
178nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
179{
180 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
181 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
182}
183
Jason Samsd19f10d2009-05-22 14:03:28 -0700184static jint
Jason Samsadd26dc2013-02-22 18:43:45 -0800185nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer, jint ct)
Jason Samsd19f10d2009-05-22 14:03:28 -0700186{
187 LOG_API("nContextCreate");
Jason Samsadd26dc2013-02-22 18:43:45 -0800188 return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, false, false);
Jason Sams704ff642010-02-09 16:05:07 -0800189}
190
191static jint
Stephen Hines4382467a2011-08-01 15:02:34 -0700192nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700193 int colorMin, int colorPref,
194 int alphaMin, int alphaPref,
195 int depthMin, int depthPref,
196 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700197 int samplesMin, int samplesPref, float samplesQ,
198 int dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800199{
Jason Sams11c8af92010-10-13 15:31:10 -0700200 RsSurfaceConfig sc;
201 sc.alphaMin = alphaMin;
202 sc.alphaPref = alphaPref;
203 sc.colorMin = colorMin;
204 sc.colorPref = colorPref;
205 sc.depthMin = depthMin;
206 sc.depthPref = depthPref;
207 sc.samplesMin = samplesMin;
208 sc.samplesPref = samplesPref;
209 sc.samplesQ = samplesQ;
210
Jason Sams704ff642010-02-09 16:05:07 -0800211 LOG_API("nContextCreateGL");
Stephen Hines4382467a2011-08-01 15:02:34 -0700212 return (jint)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700213}
214
215static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700216nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800217{
Jason Sams7d787b42009-11-15 12:14:26 -0800218 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
219 rsContextSetPriority(con, p);
220}
221
222
223
224static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700225nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800226{
Jason Sams3bc47d42009-11-12 15:10:25 -0800227 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800228
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700229 ANativeWindow * window = NULL;
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800230 if (wnd == NULL) {
231
232 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700233 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800234 }
235
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700236 rsContextSetSurface(con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800237}
238
239static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700240nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700241{
Jason Sams2e1872f2010-08-17 16:25:41 -0700242 LOG_API("nContextDestroy, con(%p)", con);
243 rsContextDestroy(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700244}
245
Jason Sams715333b2009-11-17 17:26:46 -0800246static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700247nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800248{
Jason Sams715333b2009-11-17 17:26:46 -0800249 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
250 rsContextDump((RsContext)con, bits);
251}
Jason Samsd19f10d2009-05-22 14:03:28 -0700252
253static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700254nContextPause(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700255{
Jason Sams65e7aa52009-09-24 17:38:20 -0700256 LOG_API("nContextPause, con(%p)", con);
257 rsContextPause(con);
258}
259
260static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700261nContextResume(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700262{
Jason Sams65e7aa52009-09-24 17:38:20 -0700263 LOG_API("nContextResume, con(%p)", con);
264 rsContextResume(con);
265}
266
Jason Sams1c415172010-11-08 17:06:46 -0800267
268static jstring
269nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
270{
271 LOG_API("nContextGetErrorMessage, con(%p)", con);
272 char buf[1024];
273
274 size_t receiveLen;
275 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700276 int id = rsContextGetMessage(con,
277 buf, sizeof(buf),
278 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700279 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800280 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100281 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800282 }
283 return _env->NewStringUTF(buf);
284}
285
Jason Samsedbfabd2011-05-17 15:01:29 -0700286static jint
Jason Sams1c415172010-11-08 17:06:46 -0800287nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700288{
Jason Sams516c3192009-10-06 13:58:47 -0700289 jint len = _env->GetArrayLength(data);
290 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
291 jint *ptr = _env->GetIntArrayElements(data, NULL);
292 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800293 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700294 int id = rsContextGetMessage(con,
295 ptr, len * 4,
296 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700297 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700298 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100299 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700300 }
301 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Samsedbfabd2011-05-17 15:01:29 -0700302 return id;
Jason Sams1c415172010-11-08 17:06:46 -0800303}
304
305static jint
Jason Samsedbfabd2011-05-17 15:01:29 -0700306nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800307{
308 LOG_API("nContextPeekMessage, con(%p)", con);
309 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
310 size_t receiveLen;
311 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700312 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700313 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800314 auxDataPtr[0] = (jint)subID;
315 auxDataPtr[1] = (jint)receiveLen;
316 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Jason Sams516c3192009-10-06 13:58:47 -0700317 return id;
318}
319
Jason Sams2e1872f2010-08-17 16:25:41 -0700320static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700321{
Jason Sams516c3192009-10-06 13:58:47 -0700322 LOG_API("nContextInitToClient, con(%p)", con);
323 rsContextInitToClient(con);
324}
325
Jason Sams2e1872f2010-08-17 16:25:41 -0700326static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700327{
Jason Sams516c3192009-10-06 13:58:47 -0700328 LOG_API("nContextDeinitToClient, con(%p)", con);
329 rsContextDeinitToClient(con);
330}
331
Jason Sams455d6442013-02-05 19:20:18 -0800332static void
333nContextSendMessage(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray data)
334{
335 jint *ptr = NULL;
336 jint len = 0;
337 if (data) {
338 len = _env->GetArrayLength(data);
339 jint *ptr = _env->GetIntArrayElements(data, NULL);
340 }
341 LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", con, id, len);
342 rsContextSendMessage(con, id, (const uint8_t *)ptr, len * sizeof(int));
343 if (data) {
344 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
345 }
346}
347
348
Jason Sams516c3192009-10-06 13:58:47 -0700349
Jason Sams718cd1f2009-12-23 14:35:29 -0800350static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700351nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700352{
Jason Sams718cd1f2009-12-23 14:35:29 -0800353 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
354 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700355}
356
357static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800358nElementCreate2(JNIEnv *_env, jobject _this, RsContext con,
359 jintArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700360{
Jason Sams718cd1f2009-12-23 14:35:29 -0800361 int fieldCount = _env->GetArrayLength(_ids);
Jason Sams704ff642010-02-09 16:05:07 -0800362 LOG_API("nElementCreate2, con(%p)", con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800363
364 jint *ids = _env->GetIntArrayElements(_ids, NULL);
Jason Sams70d4e502010-09-02 17:35:23 -0700365 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
Jason Sams718cd1f2009-12-23 14:35:29 -0800366
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800367 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
368
369 const char **nameArray = names.c_str();
370 size_t *sizeArray = names.c_str_len();
371
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700372 jint id = (jint)rsElementCreate2(con,
373 (RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700374 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700375 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800376
Jason Sams718cd1f2009-12-23 14:35:29 -0800377 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
Jason Sams70d4e502010-09-02 17:35:23 -0700378 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
Jason Sams718cd1f2009-12-23 14:35:29 -0800379 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700380}
381
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700382static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700383nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700384{
385 int dataSize = _env->GetArrayLength(_elementData);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700386 LOG_API("nElementGetNativeData, con(%p)", con);
387
388 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
389 assert(dataSize == 5);
390
391 uint32_t elementData[5];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700392 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700393
394 for(jint i = 0; i < dataSize; i ++) {
395 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
396 }
397}
398
399
400static void
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700401nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
402 jintArray _IDs,
403 jobjectArray _names,
404 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700405{
406 int dataSize = _env->GetArrayLength(_IDs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700407 LOG_API("nElementGetSubElements, con(%p)", con);
408
409 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
410 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700411 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700412
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700413 rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700414
Jason Sams11c8af92010-10-13 15:31:10 -0700415 for(jint i = 0; i < dataSize; i++) {
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700416 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
417 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700418 _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700419 }
420
421 free(ids);
422 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700423 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700424}
425
Jason Samsd19f10d2009-05-22 14:03:28 -0700426// -----------------------------------
427
Jason Sams3b9c52a2010-10-14 17:48:46 -0700428static int
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800429nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800430 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700431{
Jason Samsb109cc72013-01-07 18:20:12 -0800432 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
433 con, eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700434
Jason Samsb109cc72013-01-07 18:20:12 -0800435 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700436 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700437}
438
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700439static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700440nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700441{
442 // We are packing 6 items: mDimX; mDimY; mDimZ;
443 // mDimLOD; mDimFaces; mElement; into typeData
444 int elementCount = _env->GetArrayLength(_typeData);
445
446 assert(elementCount == 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700447 LOG_API("nTypeCreate, con(%p)", con);
448
449 uint32_t typeData[6];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700450 rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700451
452 for(jint i = 0; i < elementCount; i ++) {
453 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
454 }
455}
456
Jason Samsd19f10d2009-05-22 14:03:28 -0700457// -----------------------------------
458
459static jint
Jason Sams857d0c72011-11-23 15:02:15 -0800460nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700461{
Jason Sams857d0c72011-11-23 15:02:15 -0800462 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer);
463 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700464}
465
Jason Samsd19f10d2009-05-22 14:03:28 -0700466static void
Jason Sams5476b452010-12-08 16:14:36 -0800467nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
468{
469 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
470 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
471}
472
Jason Sams72226e02013-02-22 12:45:54 -0800473static jobject
474nAllocationGetSurface(JNIEnv *_env, jobject _this, RsContext con, jint a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800475{
Jason Sams72226e02013-02-22 12:45:54 -0800476 LOG_API("nAllocationGetSurface, con(%p), a(%p)", con, (RsAllocation)a);
Jason Sams615e7ce2012-01-13 14:01:20 -0800477
Jason Sams72226e02013-02-22 12:45:54 -0800478 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface(con, (RsAllocation)a);
479 sp<IGraphicBufferProducer> bp = v;
480 v->decStrong(NULL);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700481
Jason Sams72226e02013-02-22 12:45:54 -0800482 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
483 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700484}
485
486static void
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700487nAllocationSetSurface(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800488{
Stephen Hines06883b72012-05-16 18:01:34 -0700489 LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)",
Jason Sams163766c2012-02-15 12:04:24 -0800490 con, alloc, (Surface *)sur);
491
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700492 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800493 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700494 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800495 }
496
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700497 rsAllocationSetSurface(con, alloc, static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800498}
499
500static void
501nAllocationIoSend(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
502{
503 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", con, alloc);
504 rsAllocationIoSend(con, alloc);
505}
506
507static void
508nAllocationIoReceive(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
509{
510 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", con, alloc);
511 rsAllocationIoReceive(con, alloc);
512}
513
514
515static void
Jason Samsf7086092011-01-12 13:28:37 -0800516nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
517{
518 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
519 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
520}
521
Jason Samsffe9f482009-06-01 17:45:53 -0700522static int
Jason Sams5476b452010-12-08 16:14:36 -0800523nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700524{
Jason Samsffe9f482009-06-01 17:45:53 -0700525 SkBitmap const * nativeBitmap =
526 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
527 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700528
Jason Sams5476b452010-12-08 16:14:36 -0800529 bitmap.lockPixels();
530 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700531 jint id = (jint)rsAllocationCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700532 (RsType)type, (RsAllocationMipmapControl)mip,
533 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800534 bitmap.unlockPixels();
535 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700536}
Jason Samsfe08d992009-05-27 14:45:32 -0700537
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800538static int
Tim Murraya3145512012-12-04 17:59:29 -0800539nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
540{
541 SkBitmap const * nativeBitmap =
542 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
543 const SkBitmap& bitmap(*nativeBitmap);
544
545 bitmap.lockPixels();
546 const void* ptr = bitmap.getPixels();
547 jint id = (jint)rsAllocationCreateTyped(con,
548 (RsType)type, (RsAllocationMipmapControl)mip,
549 (uint32_t)usage, (size_t)ptr);
550 bitmap.unlockPixels();
551 return id;
552}
553
554static int
Jason Sams5476b452010-12-08 16:14:36 -0800555nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800556{
557 SkBitmap const * nativeBitmap =
558 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
559 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800560
Jason Sams5476b452010-12-08 16:14:36 -0800561 bitmap.lockPixels();
562 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700563 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700564 (RsType)type, (RsAllocationMipmapControl)mip,
565 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800566 bitmap.unlockPixels();
567 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800568}
569
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700570static void
Jason Sams4ef66502010-12-10 16:03:15 -0800571nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700572{
573 SkBitmap const * nativeBitmap =
574 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
575 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800576 int w = bitmap.width();
577 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700578
Jason Sams4ef66502010-12-10 16:03:15 -0800579 bitmap.lockPixels();
580 const void* ptr = bitmap.getPixels();
Jason Samsf7086092011-01-12 13:28:37 -0800581 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700582 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800583 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800584 bitmap.unlockPixels();
585}
586
587static void
588nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
589{
590 SkBitmap const * nativeBitmap =
591 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
592 const SkBitmap& bitmap(*nativeBitmap);
593
594 bitmap.lockPixels();
595 void* ptr = bitmap.getPixels();
596 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
597 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700598 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700599}
600
Jason Sams8a647432010-03-01 15:31:04 -0800601static void ReleaseBitmapCallback(void *bmp)
602{
603 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
604 nativeBitmap->unlockPixels();
605}
606
Romain Guy650a3eb2009-08-31 14:06:43 -0700607
Jason Samsd19f10d2009-05-22 14:03:28 -0700608static void
Jason Sams49a05d72010-12-29 14:31:29 -0800609nAllocationData1D_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 -0700610{
Jason Samsd19f10d2009-05-22 14:03:28 -0700611 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800612 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 -0700613 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800614 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700615 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
616}
617
618static void
Jason Sams49a05d72010-12-29 14:31:29 -0800619nAllocationData1D_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 -0700620{
Jason Sams768bc022009-09-21 19:41:04 -0700621 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800622 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 -0700623 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800624 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700625 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
626}
627
628static void
Jason Sams49a05d72010-12-29 14:31:29 -0800629nAllocationData1D_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 -0700630{
Jason Sams768bc022009-09-21 19:41:04 -0700631 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800632 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 -0700633 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800634 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700635 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
636}
637
638static void
Jason Sams49a05d72010-12-29 14:31:29 -0800639nAllocationData1D_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 -0700640{
Jason Samsd19f10d2009-05-22 14:03:28 -0700641 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800642 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 -0700643 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800644 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700645 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
646}
647
648static void
Jason Sams49a05d72010-12-29 14:31:29 -0800649// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
650nAllocationElementData1D(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 -0700651{
652 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800653 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 -0700654 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Stephen Hines4cbe25a2012-01-18 18:46:27 -0800655 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700656 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
657}
658
659static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800660nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
661 jint w, jint h, jshortArray data, int sizeBytes)
662{
663 jint len = _env->GetArrayLength(data);
664 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);
665 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Tim Murray38faea302012-11-27 14:55:08 -0800666 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800667 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
668}
669
670static void
671nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
672 jint w, jint h, jbyteArray data, int sizeBytes)
673{
674 jint len = _env->GetArrayLength(data);
675 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);
676 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Tim Murray38faea302012-11-27 14:55:08 -0800677 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800678 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
679}
680
681static void
Jason Sams49a05d72010-12-29 14:31:29 -0800682nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
683 jint w, jint h, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700684{
Jason Samsd19f10d2009-05-22 14:03:28 -0700685 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800686 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 -0700687 jint *ptr = _env->GetIntArrayElements(data, NULL);
Tim Murray38faea302012-11-27 14:55:08 -0800688 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700689 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
690}
691
692static void
Jason Sams49a05d72010-12-29 14:31:29 -0800693nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
694 jint w, jint h, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700695{
Jason Samsd19f10d2009-05-22 14:03:28 -0700696 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800697 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 -0700698 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Tim Murray38faea302012-11-27 14:55:08 -0800699 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700700 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
701}
702
Jason Sams40a29e82009-08-10 14:55:26 -0700703static void
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700704nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
705 jint dstAlloc, jint dstXoff, jint dstYoff,
706 jint dstMip, jint dstFace,
707 jint width, jint height,
708 jint srcAlloc, jint srcXoff, jint srcYoff,
709 jint srcMip, jint srcFace)
710{
Jason Sams4c2e4c82012-02-07 15:32:08 -0800711 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700712 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
713 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
714 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
715 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
716
717 rsAllocationCopy2DRange(con,
718 (RsAllocation)dstAlloc,
719 dstXoff, dstYoff,
720 dstMip, dstFace,
721 width, height,
722 (RsAllocation)srcAlloc,
723 srcXoff, srcYoff,
724 srcMip, srcFace);
725}
726
727static void
Jason Samsb05d6892013-04-09 15:59:24 -0700728nAllocationData3D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod,
729 jint w, jint h, jint d, jshortArray data, int sizeBytes)
730{
731 jint len = _env->GetArrayLength(data);
732 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);
733 jshort *ptr = _env->GetShortArrayElements(data, NULL);
734 rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
735 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
736}
737
738static void
739nAllocationData3D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod,
740 jint w, jint h, jint d, jbyteArray data, int sizeBytes)
741{
742 jint len = _env->GetArrayLength(data);
743 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);
744 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
745 rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
746 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
747}
748
749static void
750nAllocationData3D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod,
751 jint w, jint h, jint d, jintArray data, int sizeBytes)
752{
753 jint len = _env->GetArrayLength(data);
754 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);
755 jint *ptr = _env->GetIntArrayElements(data, NULL);
756 rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
757 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
758}
759
760static void
761nAllocationData3D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod,
762 jint w, jint h, jint d, jfloatArray data, int sizeBytes)
763{
764 jint len = _env->GetArrayLength(data);
765 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);
766 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
767 rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
768 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
769}
770
771static void
772nAllocationData3D_alloc(JNIEnv *_env, jobject _this, RsContext con,
773 jint dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
774 jint dstMip,
775 jint width, jint height, jint depth,
776 jint srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
777 jint srcMip)
778{
779 LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
780 " dstMip(%i), width(%i), height(%i),"
781 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
782 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
783 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
784
785 rsAllocationCopy3DRange(con,
786 (RsAllocation)dstAlloc,
787 dstXoff, dstYoff, dstZoff, dstMip,
788 width, height, depth,
789 (RsAllocation)srcAlloc,
790 srcXoff, srcYoff, srcZoff, srcMip);
791}
792
793static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700794nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700795{
Jason Sams40a29e82009-08-10 14:55:26 -0700796 jint len = _env->GetArrayLength(data);
797 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
798 jint *ptr = _env->GetIntArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700799 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700800 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(int));
Joe Onoratoae209ac2009-08-31 17:23:53 -0700801 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700802}
803
804static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800805nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
806{
807 jint len = _env->GetArrayLength(data);
808 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
809 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700810 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700811 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(short));
Jason Samsfb9f82c2011-01-12 14:53:25 -0800812 _env->ReleaseShortArrayElements(data, ptr, 0);
813}
814
815static void
816nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
817{
818 jint len = _env->GetArrayLength(data);
819 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
820 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700821 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700822 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(char));
Jason Samsfb9f82c2011-01-12 14:53:25 -0800823 _env->ReleaseByteArrayElements(data, ptr, 0);
824}
825
826static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700827nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700828{
Jason Sams40a29e82009-08-10 14:55:26 -0700829 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700830 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700831 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700832 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700833 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(float));
Joe Onoratoae209ac2009-08-31 17:23:53 -0700834 _env->ReleaseFloatArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700835}
Jason Samsd19f10d2009-05-22 14:03:28 -0700836
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700837static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700838nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700839{
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700840 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700841 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700842}
843
Jason Sams5edc6082010-10-05 13:32:49 -0700844static void
845nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
846{
847 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
848 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
849}
850
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700851// -----------------------------------
852
853static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700854nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700855{
Steve Block71f2cf12011-10-20 11:56:00 +0100856 ALOGV("______nFileA3D %u", (uint32_t) native_asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700857
858 Asset* asset = reinterpret_cast<Asset*>(native_asset);
859
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800860 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
861 return id;
862}
863
864static int
865nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
866{
867 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
868 if (mgr == NULL) {
869 return 0;
870 }
871
872 AutoJavaStringToUTF8 str(_env, _path);
873 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
874 if (asset == NULL) {
875 return 0;
876 }
877
878 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
879 return id;
880}
881
882static int
883nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
884{
885 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
886 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
887
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700888 return id;
889}
890
891static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700892nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700893{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700894 int32_t numEntries = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700895 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700896 return numEntries;
897}
898
899static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700900nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700901{
Steve Block71f2cf12011-10-20 11:56:00 +0100902 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700903 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
904
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700905 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700906
907 for(jint i = 0; i < numEntries; i ++) {
908 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
909 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
910 }
911
912 free(fileEntries);
913}
914
915static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700916nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700917{
Steve Block71f2cf12011-10-20 11:56:00 +0100918 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700919 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700920 return id;
921}
Jason Samsd19f10d2009-05-22 14:03:28 -0700922
923// -----------------------------------
924
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700925static int
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800926nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
927 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700928{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800929 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700930 jint id = (jint)rsFontCreateFromFile(con,
931 fileNameUTF.c_str(), fileNameUTF.length(),
932 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700933
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800934 return id;
935}
936
937static int
938nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
939 jstring name, jfloat fontSize, jint dpi, jint native_asset)
940{
941 Asset* asset = reinterpret_cast<Asset*>(native_asset);
942 AutoJavaStringToUTF8 nameUTF(_env, name);
943
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700944 jint id = (jint)rsFontCreateFromMemory(con,
945 nameUTF.c_str(), nameUTF.length(),
946 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800947 asset->getBuffer(false), asset->getLength());
948 return id;
949}
950
951static int
952nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
953 jfloat fontSize, jint dpi)
954{
955 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
956 if (mgr == NULL) {
957 return 0;
958 }
959
960 AutoJavaStringToUTF8 str(_env, _path);
961 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
962 if (asset == NULL) {
963 return 0;
964 }
965
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700966 jint id = (jint)rsFontCreateFromMemory(con,
967 str.c_str(), str.length(),
968 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800969 asset->getBuffer(false), asset->getLength());
970 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700971 return id;
972}
973
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700974// -----------------------------------
975
976static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700977nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700978{
Jason Samsd19f10d2009-05-22 14:03:28 -0700979 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700980 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700981}
982
983static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700984nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700985{
Jason Samscfc04362010-09-14 14:59:03 -0700986 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700987 rsScriptSetVarI(con, (RsScript)script, slot, val);
988}
989
990static void
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800991nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
992{
993 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
994 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
995}
996
997static void
Stephen Hines031ec58c2010-10-11 10:54:21 -0700998nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
999{
1000 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
1001 rsScriptSetVarJ(con, (RsScript)script, slot, val);
1002}
1003
1004static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001005nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -07001006{
Stephen Hinesca54ec32010-09-20 17:20:30 -07001007 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -07001008 rsScriptSetVarF(con, (RsScript)script, slot, val);
1009}
1010
1011static void
Stephen Hinesca54ec32010-09-20 17:20:30 -07001012nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
1013{
1014 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
1015 rsScriptSetVarD(con, (RsScript)script, slot, val);
1016}
1017
1018static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001019nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001020{
Jason Sams4d339932010-05-11 14:03:58 -07001021 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1022 jint len = _env->GetArrayLength(data);
1023 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1024 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
1025 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1026}
1027
Stephen Hinesadeb8092012-04-20 14:26:06 -07001028static void
1029nScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims)
1030{
1031 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1032 jint len = _env->GetArrayLength(data);
1033 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1034 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
1035 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
1036 rsScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem,
1037 (const size_t*) dimsPtr, dimsLen);
1038 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1039 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1040}
1041
Jason Samsd19f10d2009-05-22 14:03:28 -07001042
1043static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001044nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001045{
Jason Sams07ae4062009-08-27 20:23:34 -07001046 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -07001047
1048 jint length = _env->GetArrayLength(timeZone);
1049 jbyte* timeZone_ptr;
1050 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1051
Jason Samsbc948de2009-08-17 18:35:48 -07001052 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001053
1054 if (timeZone_ptr) {
1055 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1056 }
1057}
1058
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001059static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001060nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001061{
Jason Samsbe2e8412009-09-16 15:04:38 -07001062 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
1063 rsScriptInvoke(con, (RsScript)obj, slot);
1064}
1065
1066static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001067nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001068{
Jason Sams4d339932010-05-11 14:03:58 -07001069 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1070 jint len = _env->GetArrayLength(data);
1071 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1072 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
1073 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1074}
1075
Jason Sams6e494d32011-04-27 16:33:11 -07001076static void
1077nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
1078 jint script, jint slot, jint ain, jint aout)
1079{
1080 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001081 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0);
Jason Sams6e494d32011-04-27 16:33:11 -07001082}
1083static void
1084nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
1085 jint script, jint slot, jint ain, jint aout, jbyteArray params)
1086{
1087 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1088 jint len = _env->GetArrayLength(params);
1089 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001090 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0);
Jason Sams6e494d32011-04-27 16:33:11 -07001091 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1092}
1093
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001094static void
1095nScriptForEachClipped(JNIEnv *_env, jobject _this, RsContext con,
1096 jint script, jint slot, jint ain, jint aout,
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001097 jint xstart, jint xend,
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001098 jint ystart, jint yend, jint zstart, jint zend)
1099{
1100 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001101 RsScriptCall sc;
1102 sc.xStart = xstart;
1103 sc.xEnd = xend;
1104 sc.yStart = ystart;
1105 sc.yEnd = yend;
1106 sc.zStart = zstart;
1107 sc.zEnd = zend;
1108 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1109 sc.arrayStart = 0;
1110 sc.arrayEnd = 0;
1111 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc));
1112}
1113
1114static void
1115nScriptForEachClippedV(JNIEnv *_env, jobject _this, RsContext con,
1116 jint script, jint slot, jint ain, jint aout,
1117 jbyteArray params, jint xstart, jint xend,
1118 jint ystart, jint yend, jint zstart, jint zend)
1119{
1120 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001121 jint len = _env->GetArrayLength(params);
1122 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
1123 RsScriptCall sc;
1124 sc.xStart = xstart;
1125 sc.xEnd = xend;
1126 sc.yStart = ystart;
1127 sc.yEnd = yend;
1128 sc.zStart = zstart;
1129 sc.zEnd = zend;
1130 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1131 sc.arrayStart = 0;
1132 sc.arrayEnd = 0;
1133 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc));
1134 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1135}
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001136
Jason Sams22534172009-08-04 16:58:20 -07001137// -----------------------------------
1138
Jason Samse4a06c52011-03-16 16:29:28 -07001139static jint
1140nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
1141 jstring resName, jstring cacheDir,
1142 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001143{
Jason Samse4a06c52011-03-16 16:29:28 -07001144 LOG_API("nScriptCCreate, con(%p)", con);
Jason Sams22534172009-08-04 16:58:20 -07001145
Jason Samse4a06c52011-03-16 16:29:28 -07001146 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1147 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
1148 jint ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -07001149 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -07001150 jint _exception = 0;
1151 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001152 if (!scriptRef) {
1153 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001154 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001155 goto exit;
1156 }
Jack Palevich43702d82009-05-28 13:38:16 -07001157 if (length < 0) {
1158 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001159 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001160 goto exit;
1161 }
Jason Samse4a06c52011-03-16 16:29:28 -07001162 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001163 if (remaining < length) {
1164 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001165 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1166 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001167 goto exit;
1168 }
Jason Samse4a06c52011-03-16 16:29:28 -07001169 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001170 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001171
Jason Samse4a06c52011-03-16 16:29:28 -07001172 //rsScriptCSetText(con, (const char *)script_ptr, length);
1173
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001174 ret = (jint)rsScriptCCreate(con,
1175 resNameUTF.c_str(), resNameUTF.length(),
1176 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001177 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001178
Jack Palevich43702d82009-05-28 13:38:16 -07001179exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001180 if (script_ptr) {
1181 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001182 _exception ? JNI_ABORT: 0);
1183 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001184
Jason Samse4a06c52011-03-16 16:29:28 -07001185 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001186}
1187
Jason Sams6ab97682012-08-10 12:09:43 -07001188static jint
1189nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, RsContext con, jint id, jint eid)
1190{
1191 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", con, id, (void *)eid);
1192 return (jint)rsScriptIntrinsicCreate(con, id, (RsElement)eid);
1193}
1194
Jason Sams08a81582012-09-18 12:32:10 -07001195static jint
1196nScriptKernelIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot, jint sig)
1197{
1198 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", con, (void *)sid, slot, sig);
1199 return (jint)rsScriptKernelIDCreate(con, (RsScript)sid, slot, sig);
1200}
1201
1202static jint
1203nScriptFieldIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot)
1204{
1205 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", con, (void *)sid, slot);
1206 return (jint)rsScriptFieldIDCreate(con, (RsScript)sid, slot);
1207}
1208
1209static jint
1210nScriptGroupCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _kernels, jintArray _src,
1211 jintArray _dstk, jintArray _dstf, jintArray _types)
1212{
1213 LOG_API("nScriptGroupCreate, con(%p)", con);
1214
1215 jint kernelsLen = _env->GetArrayLength(_kernels) * sizeof(int);
1216 jint *kernelsPtr = _env->GetIntArrayElements(_kernels, NULL);
1217 jint srcLen = _env->GetArrayLength(_src) * sizeof(int);
1218 jint *srcPtr = _env->GetIntArrayElements(_src, NULL);
1219 jint dstkLen = _env->GetArrayLength(_dstk) * sizeof(int);
1220 jint *dstkPtr = _env->GetIntArrayElements(_dstk, NULL);
1221 jint dstfLen = _env->GetArrayLength(_dstf) * sizeof(int);
1222 jint *dstfPtr = _env->GetIntArrayElements(_dstf, NULL);
1223 jint typesLen = _env->GetArrayLength(_types) * sizeof(int);
1224 jint *typesPtr = _env->GetIntArrayElements(_types, NULL);
1225
1226 int id = (int)rsScriptGroupCreate(con,
1227 (RsScriptKernelID *)kernelsPtr, kernelsLen,
1228 (RsScriptKernelID *)srcPtr, srcLen,
1229 (RsScriptKernelID *)dstkPtr, dstkLen,
1230 (RsScriptFieldID *)dstfPtr, dstfLen,
1231 (RsType *)typesPtr, typesLen);
1232
1233 _env->ReleaseIntArrayElements(_kernels, kernelsPtr, 0);
1234 _env->ReleaseIntArrayElements(_src, srcPtr, 0);
1235 _env->ReleaseIntArrayElements(_dstk, dstkPtr, 0);
1236 _env->ReleaseIntArrayElements(_dstf, dstfPtr, 0);
1237 _env->ReleaseIntArrayElements(_types, typesPtr, 0);
1238 return id;
1239}
1240
1241static void
1242nScriptGroupSetInput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
1243{
1244 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
1245 (void *)gid, (void *)kid, (void *)alloc);
1246 rsScriptGroupSetInput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
1247}
1248
1249static void
1250nScriptGroupSetOutput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
1251{
1252 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
1253 (void *)gid, (void *)kid, (void *)alloc);
1254 rsScriptGroupSetOutput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
1255}
1256
1257static void
1258nScriptGroupExecute(JNIEnv *_env, jobject _this, RsContext con, jint gid)
1259{
1260 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", con, (void *)gid);
1261 rsScriptGroupExecute(con, (RsScriptGroup)gid);
1262}
1263
Jason Samsd19f10d2009-05-22 14:03:28 -07001264// ---------------------------------------------------------------------------
1265
Jason Samsd19f10d2009-05-22 14:03:28 -07001266static jint
Jason Sams331bf9b2011-04-06 11:23:54 -07001267nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
1268 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1269 jboolean depthMask, jboolean ditherEnable,
1270 jint srcFunc, jint destFunc,
1271 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001272{
Jason Sams54db59c2010-05-13 18:30:11 -07001273 LOG_API("nProgramStoreCreate, con(%p)", con);
Jason Sams331bf9b2011-04-06 11:23:54 -07001274 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
1275 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1276 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001277}
1278
Jason Sams0011bcf2009-12-15 12:58:36 -08001279// ---------------------------------------------------------------------------
1280
1281static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001282nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001283{
Jason Sams0011bcf2009-12-15 12:58:36 -08001284 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
1285 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
1286}
Jason Sams54c0ec12009-11-30 14:49:55 -08001287
Jason Sams68afd012009-12-17 16:55:08 -08001288static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001289nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001290{
Jason Sams68afd012009-12-17 16:55:08 -08001291 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1292 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1293}
1294
1295static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001296nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001297{
Jason Sams68afd012009-12-17 16:55:08 -08001298 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1299 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1300}
1301
Jason Samsd19f10d2009-05-22 14:03:28 -07001302// ---------------------------------------------------------------------------
1303
Jason Samsd19f10d2009-05-22 14:03:28 -07001304static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001305nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1306 jobjectArray texNames, jintArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001307{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001308 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001309 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1310 jint paramLen = _env->GetArrayLength(params);
1311
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001312 int texCount = _env->GetArrayLength(texNames);
1313 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1314 const char ** nameArray = names.c_str();
1315 size_t* sizeArray = names.c_str_len();
1316
Jason Sams991040c2011-01-17 15:59:39 -08001317 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001318
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001319 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1320 nameArray, texCount, sizeArray,
1321 (uint32_t *)paramPtr, paramLen);
1322
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001323 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1324 return ret;
1325}
1326
1327
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001328// ---------------------------------------------------------------------------
1329
Jason Sams0011bcf2009-12-15 12:58:36 -08001330static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001331nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1332 jobjectArray texNames, jintArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001333{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001334 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams0011bcf2009-12-15 12:58:36 -08001335 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1336 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001337
Jason Sams991040c2011-01-17 15:59:39 -08001338 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001339
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001340 int texCount = _env->GetArrayLength(texNames);
1341 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1342 const char ** nameArray = names.c_str();
1343 size_t* sizeArray = names.c_str_len();
1344
1345 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1346 nameArray, texCount, sizeArray,
1347 (uint32_t *)paramPtr, paramLen);
1348
Jason Sams0011bcf2009-12-15 12:58:36 -08001349 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1350 return ret;
1351}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001352
Jason Samsebfb4362009-09-23 13:57:02 -07001353// ---------------------------------------------------------------------------
1354
1355static jint
Jason Sams94aaed32011-09-23 14:18:53 -07001356nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001357{
Jason Sams94aaed32011-09-23 14:18:53 -07001358 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", con, pointSprite, cull);
1359 return (jint)rsProgramRasterCreate(con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001360}
1361
Jason Samsd19f10d2009-05-22 14:03:28 -07001362
1363// ---------------------------------------------------------------------------
1364
1365static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001366nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001367{
Jason Samsd19f10d2009-05-22 14:03:28 -07001368 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001369 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001370}
1371
1372static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001373nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001374{
Jason Sams54db59c2010-05-13 18:30:11 -07001375 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1376 rsContextBindProgramStore(con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001377}
1378
1379static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001380nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001381{
Jason Samsd19f10d2009-05-22 14:03:28 -07001382 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001383 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001384}
1385
Jason Sams0826a6f2009-06-15 19:04:56 -07001386static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001387nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001388{
Jason Sams0826a6f2009-06-15 19:04:56 -07001389 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001390 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001391}
1392
Joe Onoratod7b37742009-08-09 22:57:44 -07001393static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001394nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001395{
Jason Samsebfb4362009-09-23 13:57:02 -07001396 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1397 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1398}
1399
Joe Onoratod7b37742009-08-09 22:57:44 -07001400
Jason Sams02fb2cb2009-05-28 15:37:57 -07001401// ---------------------------------------------------------------------------
1402
Jason Sams02fb2cb2009-05-28 15:37:57 -07001403static jint
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001404nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1405 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001406{
Jason Samsbba134c2009-06-22 15:49:21 -07001407 LOG_API("nSamplerCreate, con(%p)", con);
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001408 return (jint)rsSamplerCreate(con,
1409 (RsSamplerValue)magFilter,
1410 (RsSamplerValue)minFilter,
1411 (RsSamplerValue)wrapS,
1412 (RsSamplerValue)wrapT,
1413 (RsSamplerValue)wrapR,
1414 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001415}
1416
Jason Samsbba134c2009-06-22 15:49:21 -07001417// ---------------------------------------------------------------------------
1418
Jason Samsf15ed012011-10-31 13:23:43 -07001419//native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
1420static jint
1421nPathCreate(JNIEnv *_env, jobject _this, RsContext con, jint prim, jboolean isStatic, jint _vtx, jint _loop, jfloat q) {
1422 LOG_API("nPathCreate, con(%p)", con);
1423
1424 int id = (int)rsPathCreate(con, (RsPathPrimitive)prim, isStatic,
1425 (RsAllocation)_vtx,
1426 (RsAllocation)_loop, q);
1427 return id;
1428}
1429
Jason Samsbba134c2009-06-22 15:49:21 -07001430static jint
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001431nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001432{
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001433 LOG_API("nMeshCreate, con(%p)", con);
1434
1435 jint vtxLen = _env->GetArrayLength(_vtx);
1436 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
1437 jint idxLen = _env->GetArrayLength(_idx);
1438 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
1439 jint primLen = _env->GetArrayLength(_prim);
1440 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1441
1442 int id = (int)rsMeshCreate(con,
1443 (RsAllocation *)vtxPtr, vtxLen,
1444 (RsAllocation *)idxPtr, idxLen,
1445 (uint32_t *)primPtr, primLen);
1446
1447 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
1448 _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
1449 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001450 return id;
1451}
1452
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001453static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001454nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001455{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001456 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1457 jint vtxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001458 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001459 return vtxCount;
1460}
1461
1462static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001463nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001464{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001465 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1466 jint idxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001467 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001468 return idxCount;
1469}
1470
1471static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001472nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001473{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001474 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1475
1476 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001477 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001478
1479 for(jint i = 0; i < numVtxIDs; i ++) {
1480 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1481 }
1482
1483 free(allocs);
1484}
1485
1486static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001487nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001488{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001489 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1490
1491 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1492 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1493
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001494 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001495
1496 for(jint i = 0; i < numIndices; i ++) {
1497 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1498 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1499 }
1500
1501 free(allocs);
1502 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001503}
1504
1505// ---------------------------------------------------------------------------
1506
Jason Samsd19f10d2009-05-22 14:03:28 -07001507
Jason Sams94d8e90a2009-06-10 16:09:05 -07001508static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001509
1510static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001511{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001512
Jason Sams1c415172010-11-08 17:06:46 -08001513{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1514{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1515{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
Jason Samsedbfabd2011-05-17 15:01:29 -07001516{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001517{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
Jason Samsedbfabd2011-05-17 15:01:29 -07001518{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001519
1520{"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1521{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001522
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001523
Jason Sams2e1872f2010-08-17 16:25:41 -07001524// All methods below are thread protected in java.
Jason Samsadd26dc2013-02-22 18:43:45 -08001525{"rsnContextCreate", "(IIII)I", (void*)nContextCreate },
Stephen Hines4382467a2011-08-01 15:02:34 -07001526{"rsnContextCreateGL", "(IIIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
Jason Sams2e1872f2010-08-17 16:25:41 -07001527{"rsnContextFinish", "(I)V", (void*)nContextFinish },
1528{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1529{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001530{"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams2e1872f2010-08-17 16:25:41 -07001531{"rsnContextDump", "(II)V", (void*)nContextDump },
1532{"rsnContextPause", "(I)V", (void*)nContextPause },
1533{"rsnContextResume", "(I)V", (void*)nContextResume },
Jason Sams455d6442013-02-05 19:20:18 -08001534{"rsnContextSendMessage", "(II[I)V", (void*)nContextSendMessage },
Jason Sams2e1872f2010-08-17 16:25:41 -07001535{"rsnAssignName", "(II[B)V", (void*)nAssignName },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001536{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
Jason Sams2e1872f2010-08-17 16:25:41 -07001537{"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001538
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001539{"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
Jason Sams2e1872f2010-08-17 16:25:41 -07001540{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001541{"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
Jason Sams2e1872f2010-08-17 16:25:41 -07001542{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001543{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Jason Sams2e1872f2010-08-17 16:25:41 -07001544{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001545
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -08001546{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001547{"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1548{"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001549
Jason Sams2e1872f2010-08-17 16:25:41 -07001550{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
Jason Sams70d4e502010-09-02 17:35:23 -07001551{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
Jason Sams2e1872f2010-08-17 16:25:41 -07001552{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001553{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001554
Jason Samsb109cc72013-01-07 18:20:12 -08001555{"rsnTypeCreate", "(IIIIIZZI)I", (void*)nTypeCreate },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001556{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001557
Jason Sams857d0c72011-11-23 15:02:15 -08001558{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped },
Jason Sams5476b452010-12-08 16:14:36 -08001559{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
Tim Murraya3145512012-12-04 17:59:29 -08001560{"rsnAllocationCreateBitmapBackedAllocation", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateBitmapBackedAllocation },
Jason Sams5476b452010-12-08 16:14:36 -08001561{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001562
Jason Sams4ef66502010-12-10 16:03:15 -08001563{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1564{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1565
Jason Sams5476b452010-12-08 16:14:36 -08001566{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
Jason Sams72226e02013-02-22 12:45:54 -08001567{"rsnAllocationGetSurface", "(II)Landroid/view/Surface;", (void*)nAllocationGetSurface },
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001568{"rsnAllocationSetSurface", "(IILandroid/view/Surface;)V", (void*)nAllocationSetSurface },
Jason Sams163766c2012-02-15 12:04:24 -08001569{"rsnAllocationIoSend", "(II)V", (void*)nAllocationIoSend },
1570{"rsnAllocationIoReceive", "(II)V", (void*)nAllocationIoReceive },
Jason Sams49a05d72010-12-29 14:31:29 -08001571{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i },
1572{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s },
1573{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b },
1574{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f },
1575{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
1576{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001577{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s },
1578{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b },
Jason Sams49a05d72010-12-29 14:31:29 -08001579{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f },
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001580{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc },
Jason Samsb05d6892013-04-09 15:59:24 -07001581{"rsnAllocationData3D", "(IIIIIIIII[II)V", (void*)nAllocationData3D_i },
1582{"rsnAllocationData3D", "(IIIIIIIII[SI)V", (void*)nAllocationData3D_s },
1583{"rsnAllocationData3D", "(IIIIIIIII[BI)V", (void*)nAllocationData3D_b },
1584{"rsnAllocationData3D", "(IIIIIIIII[FI)V", (void*)nAllocationData3D_f },
1585{"rsnAllocationData3D", "(IIIIIIIIIIIIII)V", (void*)nAllocationData3D_alloc },
Jason Sams2e1872f2010-08-17 16:25:41 -07001586{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001587{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s },
1588{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b },
Jason Sams2e1872f2010-08-17 16:25:41 -07001589{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
Jason Sams2e1872f2010-08-17 16:25:41 -07001590{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
Jason Sams5edc6082010-10-05 13:32:49 -07001591{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
Jason Samsf7086092011-01-12 13:28:37 -08001592{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001593
Jason Sams2e1872f2010-08-17 16:25:41 -07001594{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1595{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1596{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1597{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
Jason Sams6e494d32011-04-27 16:33:11 -07001598{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1599{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001600{"rsnScriptForEachClipped", "(IIIIIIIIIII)V", (void*)nScriptForEachClipped },
1601{"rsnScriptForEachClipped", "(IIIII[BIIIIII)V", (void*)nScriptForEachClippedV },
Jason Sams2e1872f2010-08-17 16:25:41 -07001602{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
Stephen Hines031ec58c2010-10-11 10:54:21 -07001603{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
Jason Sams2e1872f2010-08-17 16:25:41 -07001604{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
Stephen Hinesca54ec32010-09-20 17:20:30 -07001605{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
Jason Sams2e1872f2010-08-17 16:25:41 -07001606{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
Stephen Hinesadeb8092012-04-20 14:26:06 -07001607{"rsnScriptSetVarVE", "(III[BI[I)V", (void*)nScriptSetVarVE },
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001608{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001609
Jason Samse4a06c52011-03-16 16:29:28 -07001610{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
Jason Sams6ab97682012-08-10 12:09:43 -07001611{"rsnScriptIntrinsicCreate", "(III)I", (void*)nScriptIntrinsicCreate },
Jason Sams08a81582012-09-18 12:32:10 -07001612{"rsnScriptKernelIDCreate", "(IIII)I", (void*)nScriptKernelIDCreate },
1613{"rsnScriptFieldIDCreate", "(III)I", (void*)nScriptFieldIDCreate },
1614{"rsnScriptGroupCreate", "(I[I[I[I[I[I)I", (void*)nScriptGroupCreate },
1615{"rsnScriptGroupSetInput", "(IIII)V", (void*)nScriptGroupSetInput },
1616{"rsnScriptGroupSetOutput", "(IIII)V", (void*)nScriptGroupSetOutput },
1617{"rsnScriptGroupExecute", "(II)V", (void*)nScriptGroupExecute },
Jason Sams0011bcf2009-12-15 12:58:36 -08001618
Jason Sams331bf9b2011-04-06 11:23:54 -07001619{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001620
Jason Sams2e1872f2010-08-17 16:25:41 -07001621{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1622{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1623{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001624
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001625{"rsnProgramFragmentCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate },
Jason Sams94aaed32011-09-23 14:18:53 -07001626{"rsnProgramRasterCreate", "(IZI)I", (void*)nProgramRasterCreate },
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001627{"rsnProgramVertexCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001628
Jason Sams2e1872f2010-08-17 16:25:41 -07001629{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001630{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
Jason Sams2e1872f2010-08-17 16:25:41 -07001631{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1632{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1633{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001634
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001635{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001636
Jason Samsf15ed012011-10-31 13:23:43 -07001637{"rsnPathCreate", "(IIZIIF)I", (void*)nPathCreate },
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001638{"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001639
1640{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1641{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001642{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
Jason Sams2e1872f2010-08-17 16:25:41 -07001643{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001644
Jason Samsd19f10d2009-05-22 14:03:28 -07001645};
1646
1647static int registerFuncs(JNIEnv *_env)
1648{
1649 return android::AndroidRuntime::registerNativeMethods(
1650 _env, classPathName, methods, NELEM(methods));
1651}
1652
1653// ---------------------------------------------------------------------------
1654
1655jint JNI_OnLoad(JavaVM* vm, void* reserved)
1656{
1657 JNIEnv* env = NULL;
1658 jint result = -1;
1659
Jason Samsd19f10d2009-05-22 14:03:28 -07001660 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001661 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001662 goto bail;
1663 }
1664 assert(env != NULL);
1665
1666 if (registerFuncs(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001667 ALOGE("ERROR: MediaPlayer native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001668 goto bail;
1669 }
1670
1671 /* success -- return valid version number */
1672 result = JNI_VERSION_1_4;
1673
1674bail:
1675 return result;
1676}