blob: 09f69527cd41754c494abcb986e2be491b255886 [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>
Jason Samsfaa32b32011-06-20 16:58:04 -070045#include <gui/SurfaceTexture.h>
46#include <gui/SurfaceTextureClient.h>
47#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
Stephen Hines4382467a2011-08-01 15:02:34 -0700185nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700186{
187 LOG_API("nContextCreate");
Stephen Hines4382467a2011-08-01 15:02:34 -0700188 return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer);
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 {
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700233 window = android_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 Samsfaa32b32011-06-20 16:58:04 -0700240nContextSetSurfaceTexture(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject sur)
241{
242 LOG_API("nContextSetSurfaceTexture, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)sur);
243
244 sp<ANativeWindow> window;
245 sp<SurfaceTexture> st;
246 if (sur == 0) {
247
248 } else {
249 st = SurfaceTexture_getSurfaceTexture(_env, sur);
250 window = new SurfaceTextureClient(st);
251 }
252
253 rsContextSetSurface(con, width, height, window.get());
254}
255
256static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700257nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700258{
Jason Sams2e1872f2010-08-17 16:25:41 -0700259 LOG_API("nContextDestroy, con(%p)", con);
260 rsContextDestroy(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700261}
262
Jason Sams715333b2009-11-17 17:26:46 -0800263static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700264nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800265{
Jason Sams715333b2009-11-17 17:26:46 -0800266 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
267 rsContextDump((RsContext)con, bits);
268}
Jason Samsd19f10d2009-05-22 14:03:28 -0700269
270static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700271nContextPause(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700272{
Jason Sams65e7aa52009-09-24 17:38:20 -0700273 LOG_API("nContextPause, con(%p)", con);
274 rsContextPause(con);
275}
276
277static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700278nContextResume(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700279{
Jason Sams65e7aa52009-09-24 17:38:20 -0700280 LOG_API("nContextResume, con(%p)", con);
281 rsContextResume(con);
282}
283
Jason Sams1c415172010-11-08 17:06:46 -0800284
285static jstring
286nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
287{
288 LOG_API("nContextGetErrorMessage, con(%p)", con);
289 char buf[1024];
290
291 size_t receiveLen;
292 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700293 int id = rsContextGetMessage(con,
294 buf, sizeof(buf),
295 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700296 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800297 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100298 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800299 }
300 return _env->NewStringUTF(buf);
301}
302
Jason Samsedbfabd2011-05-17 15:01:29 -0700303static jint
Jason Sams1c415172010-11-08 17:06:46 -0800304nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700305{
Jason Sams516c3192009-10-06 13:58:47 -0700306 jint len = _env->GetArrayLength(data);
307 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
308 jint *ptr = _env->GetIntArrayElements(data, NULL);
309 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800310 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700311 int id = rsContextGetMessage(con,
312 ptr, len * 4,
313 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700314 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700315 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100316 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700317 }
318 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Samsedbfabd2011-05-17 15:01:29 -0700319 return id;
Jason Sams1c415172010-11-08 17:06:46 -0800320}
321
322static jint
Jason Samsedbfabd2011-05-17 15:01:29 -0700323nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800324{
325 LOG_API("nContextPeekMessage, con(%p)", con);
326 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
327 size_t receiveLen;
328 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700329 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700330 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800331 auxDataPtr[0] = (jint)subID;
332 auxDataPtr[1] = (jint)receiveLen;
333 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Jason Sams516c3192009-10-06 13:58:47 -0700334 return id;
335}
336
Jason Sams2e1872f2010-08-17 16:25:41 -0700337static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700338{
Jason Sams516c3192009-10-06 13:58:47 -0700339 LOG_API("nContextInitToClient, con(%p)", con);
340 rsContextInitToClient(con);
341}
342
Jason Sams2e1872f2010-08-17 16:25:41 -0700343static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700344{
Jason Sams516c3192009-10-06 13:58:47 -0700345 LOG_API("nContextDeinitToClient, con(%p)", con);
346 rsContextDeinitToClient(con);
347}
348
349
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,
430 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces)
Jason Samsd19f10d2009-05-22 14:03:28 -0700431{
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800432 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
433 con, eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700434
Jason Samsc5765372011-04-28 18:26:48 -0700435 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
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 Sams615e7ce2012-01-13 14:01:20 -0800473static jint
474nAllocationGetSurfaceTextureID(JNIEnv *_env, jobject _this, RsContext con, jint a)
475{
476 LOG_API("nAllocationGetSurfaceTextureID, con(%p), a(%p)", con, (RsAllocation)a);
477 return rsAllocationGetSurfaceTextureID(con, (RsAllocation)a);
478}
479
Jason Samsf7086092011-01-12 13:28:37 -0800480static void
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700481nAllocationGetSurfaceTextureID2(JNIEnv *_env, jobject _this, RsContext con, jint a, jobject jst)
482{
483 LOG_API("nAllocationGetSurfaceTextureID2, con(%p), a(%p)", con, (RsAllocation)a);
484 sp<SurfaceTexture> st = SurfaceTexture_getSurfaceTexture(_env, jst);
485
486 rsAllocationGetSurfaceTextureID2(con, (RsAllocation)a, st.get(), sizeof(SurfaceTexture *));
487}
488
489static void
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700490nAllocationSetSurface(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800491{
Stephen Hines06883b72012-05-16 18:01:34 -0700492 LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)",
Jason Sams163766c2012-02-15 12:04:24 -0800493 con, alloc, (Surface *)sur);
494
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700495 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800496 if (sur != 0) {
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700497 s = Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800498 }
499
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700500 rsAllocationSetSurface(con, alloc, static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800501}
502
503static void
504nAllocationIoSend(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
505{
506 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", con, alloc);
507 rsAllocationIoSend(con, alloc);
508}
509
510static void
511nAllocationIoReceive(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
512{
513 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", con, alloc);
514 rsAllocationIoReceive(con, alloc);
515}
516
517
518static void
Jason Samsf7086092011-01-12 13:28:37 -0800519nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
520{
521 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
522 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
523}
524
Jason Samsffe9f482009-06-01 17:45:53 -0700525static int
Jason Sams5476b452010-12-08 16:14:36 -0800526nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700527{
Jason Samsffe9f482009-06-01 17:45:53 -0700528 SkBitmap const * nativeBitmap =
529 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
530 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700531
Jason Sams5476b452010-12-08 16:14:36 -0800532 bitmap.lockPixels();
533 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700534 jint id = (jint)rsAllocationCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700535 (RsType)type, (RsAllocationMipmapControl)mip,
536 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800537 bitmap.unlockPixels();
538 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700539}
Jason Samsfe08d992009-05-27 14:45:32 -0700540
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800541static int
Jason Sams5476b452010-12-08 16:14:36 -0800542nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800543{
544 SkBitmap const * nativeBitmap =
545 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
546 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800547
Jason Sams5476b452010-12-08 16:14:36 -0800548 bitmap.lockPixels();
549 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700550 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700551 (RsType)type, (RsAllocationMipmapControl)mip,
552 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800553 bitmap.unlockPixels();
554 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800555}
556
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700557static void
Jason Sams4ef66502010-12-10 16:03:15 -0800558nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700559{
560 SkBitmap const * nativeBitmap =
561 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
562 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800563 int w = bitmap.width();
564 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700565
Jason Sams4ef66502010-12-10 16:03:15 -0800566 bitmap.lockPixels();
567 const void* ptr = bitmap.getPixels();
Jason Samsf7086092011-01-12 13:28:37 -0800568 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700569 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Jason Samsf7086092011-01-12 13:28:37 -0800570 w, h, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800571 bitmap.unlockPixels();
572}
573
574static void
575nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
576{
577 SkBitmap const * nativeBitmap =
578 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
579 const SkBitmap& bitmap(*nativeBitmap);
580
581 bitmap.lockPixels();
582 void* ptr = bitmap.getPixels();
583 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
584 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700585 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700586}
587
Jason Sams8a647432010-03-01 15:31:04 -0800588static void ReleaseBitmapCallback(void *bmp)
589{
590 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
591 nativeBitmap->unlockPixels();
592}
593
Romain Guy650a3eb2009-08-31 14:06:43 -0700594
Jason Samsd19f10d2009-05-22 14:03:28 -0700595static void
Jason Sams49a05d72010-12-29 14:31:29 -0800596nAllocationData1D_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 -0700597{
Jason Samsd19f10d2009-05-22 14:03:28 -0700598 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800599 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 -0700600 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800601 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700602 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
603}
604
605static void
Jason Sams49a05d72010-12-29 14:31:29 -0800606nAllocationData1D_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 -0700607{
Jason Sams768bc022009-09-21 19:41:04 -0700608 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800609 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 -0700610 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800611 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700612 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
613}
614
615static void
Jason Sams49a05d72010-12-29 14:31:29 -0800616nAllocationData1D_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 -0700617{
Jason Sams768bc022009-09-21 19:41:04 -0700618 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800619 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 -0700620 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800621 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700622 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
623}
624
625static void
Jason Sams49a05d72010-12-29 14:31:29 -0800626nAllocationData1D_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 -0700627{
Jason Samsd19f10d2009-05-22 14:03:28 -0700628 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800629 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 -0700630 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800631 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700632 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
633}
634
635static void
Jason Sams49a05d72010-12-29 14:31:29 -0800636// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
637nAllocationElementData1D(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 -0700638{
639 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800640 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 -0700641 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Stephen Hines4cbe25a2012-01-18 18:46:27 -0800642 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700643 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
644}
645
646static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800647nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
648 jint w, jint h, jshortArray data, int sizeBytes)
649{
650 jint len = _env->GetArrayLength(data);
651 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);
652 jshort *ptr = _env->GetShortArrayElements(data, NULL);
653 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
654 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
655}
656
657static void
658nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
659 jint w, jint h, jbyteArray data, int sizeBytes)
660{
661 jint len = _env->GetArrayLength(data);
662 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);
663 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
664 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
665 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
666}
667
668static void
Jason Sams49a05d72010-12-29 14:31:29 -0800669nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
670 jint w, jint h, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700671{
Jason Samsd19f10d2009-05-22 14:03:28 -0700672 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800673 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 -0700674 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800675 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700676 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
677}
678
679static void
Jason Sams49a05d72010-12-29 14:31:29 -0800680nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
681 jint w, jint h, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700682{
Jason Samsd19f10d2009-05-22 14:03:28 -0700683 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800684 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 -0700685 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800686 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700687 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
688}
689
Jason Sams40a29e82009-08-10 14:55:26 -0700690static void
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700691nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
692 jint dstAlloc, jint dstXoff, jint dstYoff,
693 jint dstMip, jint dstFace,
694 jint width, jint height,
695 jint srcAlloc, jint srcXoff, jint srcYoff,
696 jint srcMip, jint srcFace)
697{
Jason Sams4c2e4c82012-02-07 15:32:08 -0800698 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700699 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
700 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
701 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
702 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
703
704 rsAllocationCopy2DRange(con,
705 (RsAllocation)dstAlloc,
706 dstXoff, dstYoff,
707 dstMip, dstFace,
708 width, height,
709 (RsAllocation)srcAlloc,
710 srcXoff, srcYoff,
711 srcMip, srcFace);
712}
713
714static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700715nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700716{
Jason Sams40a29e82009-08-10 14:55:26 -0700717 jint len = _env->GetArrayLength(data);
718 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
719 jint *ptr = _env->GetIntArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700720 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700721 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(int));
Joe Onoratoae209ac2009-08-31 17:23:53 -0700722 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700723}
724
725static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800726nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
727{
728 jint len = _env->GetArrayLength(data);
729 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
730 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700731 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700732 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(short));
Jason Samsfb9f82c2011-01-12 14:53:25 -0800733 _env->ReleaseShortArrayElements(data, ptr, 0);
734}
735
736static void
737nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
738{
739 jint len = _env->GetArrayLength(data);
740 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
741 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700742 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700743 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(char));
Jason Samsfb9f82c2011-01-12 14:53:25 -0800744 _env->ReleaseByteArrayElements(data, ptr, 0);
745}
746
747static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700748nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700749{
Jason Sams40a29e82009-08-10 14:55:26 -0700750 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700751 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700752 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700753 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700754 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(float));
Joe Onoratoae209ac2009-08-31 17:23:53 -0700755 _env->ReleaseFloatArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700756}
Jason Samsd19f10d2009-05-22 14:03:28 -0700757
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700758static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700759nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700760{
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700761 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700762 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700763}
764
Jason Sams5edc6082010-10-05 13:32:49 -0700765static void
766nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
767{
768 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
769 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
770}
771
772static void
773nAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY)
774{
775 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY);
776 rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY);
777}
778
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700779// -----------------------------------
780
781static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700782nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700783{
Steve Block71f2cf12011-10-20 11:56:00 +0100784 ALOGV("______nFileA3D %u", (uint32_t) native_asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700785
786 Asset* asset = reinterpret_cast<Asset*>(native_asset);
787
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800788 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
789 return id;
790}
791
792static int
793nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
794{
795 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
796 if (mgr == NULL) {
797 return 0;
798 }
799
800 AutoJavaStringToUTF8 str(_env, _path);
801 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
802 if (asset == NULL) {
803 return 0;
804 }
805
806 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
807 return id;
808}
809
810static int
811nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
812{
813 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
814 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
815
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700816 return id;
817}
818
819static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700820nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700821{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700822 int32_t numEntries = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700823 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700824 return numEntries;
825}
826
827static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700828nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700829{
Steve Block71f2cf12011-10-20 11:56:00 +0100830 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700831 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
832
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700833 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700834
835 for(jint i = 0; i < numEntries; i ++) {
836 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
837 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
838 }
839
840 free(fileEntries);
841}
842
843static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700844nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700845{
Steve Block71f2cf12011-10-20 11:56:00 +0100846 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700847 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700848 return id;
849}
Jason Samsd19f10d2009-05-22 14:03:28 -0700850
851// -----------------------------------
852
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700853static int
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800854nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
855 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700856{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800857 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700858 jint id = (jint)rsFontCreateFromFile(con,
859 fileNameUTF.c_str(), fileNameUTF.length(),
860 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700861
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800862 return id;
863}
864
865static int
866nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
867 jstring name, jfloat fontSize, jint dpi, jint native_asset)
868{
869 Asset* asset = reinterpret_cast<Asset*>(native_asset);
870 AutoJavaStringToUTF8 nameUTF(_env, name);
871
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700872 jint id = (jint)rsFontCreateFromMemory(con,
873 nameUTF.c_str(), nameUTF.length(),
874 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800875 asset->getBuffer(false), asset->getLength());
876 return id;
877}
878
879static int
880nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
881 jfloat fontSize, jint dpi)
882{
883 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
884 if (mgr == NULL) {
885 return 0;
886 }
887
888 AutoJavaStringToUTF8 str(_env, _path);
889 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
890 if (asset == NULL) {
891 return 0;
892 }
893
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700894 jint id = (jint)rsFontCreateFromMemory(con,
895 str.c_str(), str.length(),
896 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800897 asset->getBuffer(false), asset->getLength());
898 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700899 return id;
900}
901
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700902// -----------------------------------
903
904static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700905nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700906{
Jason Samsd19f10d2009-05-22 14:03:28 -0700907 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700908 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700909}
910
911static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700912nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700913{
Jason Samscfc04362010-09-14 14:59:03 -0700914 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700915 rsScriptSetVarI(con, (RsScript)script, slot, val);
916}
917
918static void
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800919nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
920{
921 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
922 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
923}
924
925static void
Stephen Hines031ec58c2010-10-11 10:54:21 -0700926nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
927{
928 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
929 rsScriptSetVarJ(con, (RsScript)script, slot, val);
930}
931
932static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700933nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700934{
Stephen Hinesca54ec32010-09-20 17:20:30 -0700935 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700936 rsScriptSetVarF(con, (RsScript)script, slot, val);
937}
938
939static void
Stephen Hinesca54ec32010-09-20 17:20:30 -0700940nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
941{
942 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
943 rsScriptSetVarD(con, (RsScript)script, slot, val);
944}
945
946static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700947nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700948{
Jason Sams4d339932010-05-11 14:03:58 -0700949 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
950 jint len = _env->GetArrayLength(data);
951 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
952 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
953 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
954}
955
Stephen Hinesadeb8092012-04-20 14:26:06 -0700956static void
957nScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims)
958{
959 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
960 jint len = _env->GetArrayLength(data);
961 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
962 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
963 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
964 rsScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem,
965 (const size_t*) dimsPtr, dimsLen);
966 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
967 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
968}
969
Jason Samsd19f10d2009-05-22 14:03:28 -0700970
971static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700972nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -0700973{
Jason Sams07ae4062009-08-27 20:23:34 -0700974 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -0700975
976 jint length = _env->GetArrayLength(timeZone);
977 jbyte* timeZone_ptr;
978 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
979
Jason Samsbc948de2009-08-17 18:35:48 -0700980 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -0700981
982 if (timeZone_ptr) {
983 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
984 }
985}
986
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700987static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700988nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -0700989{
Jason Samsbe2e8412009-09-16 15:04:38 -0700990 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
991 rsScriptInvoke(con, (RsScript)obj, slot);
992}
993
994static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700995nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700996{
Jason Sams4d339932010-05-11 14:03:58 -0700997 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
998 jint len = _env->GetArrayLength(data);
999 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1000 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
1001 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1002}
1003
Jason Sams6e494d32011-04-27 16:33:11 -07001004static void
1005nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
1006 jint script, jint slot, jint ain, jint aout)
1007{
1008 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1009 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0);
1010}
1011static void
1012nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
1013 jint script, jint slot, jint ain, jint aout, jbyteArray params)
1014{
1015 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1016 jint len = _env->GetArrayLength(params);
1017 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
1018 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len);
1019 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1020}
1021
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001022
Jason Sams22534172009-08-04 16:58:20 -07001023// -----------------------------------
1024
Jason Samse4a06c52011-03-16 16:29:28 -07001025static jint
1026nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
1027 jstring resName, jstring cacheDir,
1028 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001029{
Jason Samse4a06c52011-03-16 16:29:28 -07001030 LOG_API("nScriptCCreate, con(%p)", con);
Jason Sams22534172009-08-04 16:58:20 -07001031
Jason Samse4a06c52011-03-16 16:29:28 -07001032 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1033 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
1034 jint ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -07001035 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -07001036 jint _exception = 0;
1037 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001038 if (!scriptRef) {
1039 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001040 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001041 goto exit;
1042 }
Jack Palevich43702d82009-05-28 13:38:16 -07001043 if (length < 0) {
1044 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001045 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001046 goto exit;
1047 }
Jason Samse4a06c52011-03-16 16:29:28 -07001048 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001049 if (remaining < length) {
1050 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001051 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1052 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001053 goto exit;
1054 }
Jason Samse4a06c52011-03-16 16:29:28 -07001055 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001056 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001057
Jason Samse4a06c52011-03-16 16:29:28 -07001058 //rsScriptCSetText(con, (const char *)script_ptr, length);
1059
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001060 ret = (jint)rsScriptCCreate(con,
1061 resNameUTF.c_str(), resNameUTF.length(),
1062 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001063 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001064
Jack Palevich43702d82009-05-28 13:38:16 -07001065exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001066 if (script_ptr) {
1067 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001068 _exception ? JNI_ABORT: 0);
1069 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001070
Jason Samse4a06c52011-03-16 16:29:28 -07001071 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001072}
1073
1074// ---------------------------------------------------------------------------
1075
Jason Samsd19f10d2009-05-22 14:03:28 -07001076static jint
Jason Sams331bf9b2011-04-06 11:23:54 -07001077nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
1078 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1079 jboolean depthMask, jboolean ditherEnable,
1080 jint srcFunc, jint destFunc,
1081 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001082{
Jason Sams54db59c2010-05-13 18:30:11 -07001083 LOG_API("nProgramStoreCreate, con(%p)", con);
Jason Sams331bf9b2011-04-06 11:23:54 -07001084 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
1085 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1086 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001087}
1088
Jason Sams0011bcf2009-12-15 12:58:36 -08001089// ---------------------------------------------------------------------------
1090
1091static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001092nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001093{
Jason Sams0011bcf2009-12-15 12:58:36 -08001094 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
1095 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
1096}
Jason Sams54c0ec12009-11-30 14:49:55 -08001097
Jason Sams68afd012009-12-17 16:55:08 -08001098static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001099nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001100{
Jason Sams68afd012009-12-17 16:55:08 -08001101 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1102 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1103}
1104
1105static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001106nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001107{
Jason Sams68afd012009-12-17 16:55:08 -08001108 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1109 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1110}
1111
Jason Samsd19f10d2009-05-22 14:03:28 -07001112// ---------------------------------------------------------------------------
1113
Jason Samsd19f10d2009-05-22 14:03:28 -07001114static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001115nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1116 jobjectArray texNames, jintArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001117{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001118 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001119 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1120 jint paramLen = _env->GetArrayLength(params);
1121
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001122 int texCount = _env->GetArrayLength(texNames);
1123 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1124 const char ** nameArray = names.c_str();
1125 size_t* sizeArray = names.c_str_len();
1126
Jason Sams991040c2011-01-17 15:59:39 -08001127 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001128
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001129 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1130 nameArray, texCount, sizeArray,
1131 (uint32_t *)paramPtr, paramLen);
1132
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001133 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1134 return ret;
1135}
1136
1137
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001138// ---------------------------------------------------------------------------
1139
Jason Sams0011bcf2009-12-15 12:58:36 -08001140static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001141nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1142 jobjectArray texNames, jintArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001143{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001144 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams0011bcf2009-12-15 12:58:36 -08001145 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1146 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001147
Jason Sams991040c2011-01-17 15:59:39 -08001148 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001149
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001150 int texCount = _env->GetArrayLength(texNames);
1151 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1152 const char ** nameArray = names.c_str();
1153 size_t* sizeArray = names.c_str_len();
1154
1155 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1156 nameArray, texCount, sizeArray,
1157 (uint32_t *)paramPtr, paramLen);
1158
Jason Sams0011bcf2009-12-15 12:58:36 -08001159 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1160 return ret;
1161}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001162
Jason Samsebfb4362009-09-23 13:57:02 -07001163// ---------------------------------------------------------------------------
1164
1165static jint
Jason Sams94aaed32011-09-23 14:18:53 -07001166nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001167{
Jason Sams94aaed32011-09-23 14:18:53 -07001168 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", con, pointSprite, cull);
1169 return (jint)rsProgramRasterCreate(con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001170}
1171
Jason Samsd19f10d2009-05-22 14:03:28 -07001172
1173// ---------------------------------------------------------------------------
1174
1175static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001176nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001177{
Jason Samsd19f10d2009-05-22 14:03:28 -07001178 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001179 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001180}
1181
1182static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001183nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001184{
Jason Sams54db59c2010-05-13 18:30:11 -07001185 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1186 rsContextBindProgramStore(con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001187}
1188
1189static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001190nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001191{
Jason Samsd19f10d2009-05-22 14:03:28 -07001192 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001193 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001194}
1195
Jason Sams0826a6f2009-06-15 19:04:56 -07001196static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001197nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001198{
Jason Sams0826a6f2009-06-15 19:04:56 -07001199 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001200 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001201}
1202
Joe Onoratod7b37742009-08-09 22:57:44 -07001203static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001204nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001205{
Jason Samsebfb4362009-09-23 13:57:02 -07001206 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1207 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1208}
1209
Joe Onoratod7b37742009-08-09 22:57:44 -07001210
Jason Sams02fb2cb2009-05-28 15:37:57 -07001211// ---------------------------------------------------------------------------
1212
Jason Sams02fb2cb2009-05-28 15:37:57 -07001213static jint
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001214nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1215 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001216{
Jason Samsbba134c2009-06-22 15:49:21 -07001217 LOG_API("nSamplerCreate, con(%p)", con);
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001218 return (jint)rsSamplerCreate(con,
1219 (RsSamplerValue)magFilter,
1220 (RsSamplerValue)minFilter,
1221 (RsSamplerValue)wrapS,
1222 (RsSamplerValue)wrapT,
1223 (RsSamplerValue)wrapR,
1224 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001225}
1226
Jason Samsbba134c2009-06-22 15:49:21 -07001227// ---------------------------------------------------------------------------
1228
Jason Samsf15ed012011-10-31 13:23:43 -07001229//native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
1230static jint
1231nPathCreate(JNIEnv *_env, jobject _this, RsContext con, jint prim, jboolean isStatic, jint _vtx, jint _loop, jfloat q) {
1232 LOG_API("nPathCreate, con(%p)", con);
1233
1234 int id = (int)rsPathCreate(con, (RsPathPrimitive)prim, isStatic,
1235 (RsAllocation)_vtx,
1236 (RsAllocation)_loop, q);
1237 return id;
1238}
1239
Jason Samsbba134c2009-06-22 15:49:21 -07001240static jint
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001241nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001242{
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001243 LOG_API("nMeshCreate, con(%p)", con);
1244
1245 jint vtxLen = _env->GetArrayLength(_vtx);
1246 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
1247 jint idxLen = _env->GetArrayLength(_idx);
1248 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
1249 jint primLen = _env->GetArrayLength(_prim);
1250 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1251
1252 int id = (int)rsMeshCreate(con,
1253 (RsAllocation *)vtxPtr, vtxLen,
1254 (RsAllocation *)idxPtr, idxLen,
1255 (uint32_t *)primPtr, primLen);
1256
1257 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
1258 _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
1259 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001260 return id;
1261}
1262
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001263static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001264nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001265{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001266 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1267 jint vtxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001268 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001269 return vtxCount;
1270}
1271
1272static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001273nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001274{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001275 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1276 jint idxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001277 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001278 return idxCount;
1279}
1280
1281static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001282nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001283{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001284 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1285
1286 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001287 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001288
1289 for(jint i = 0; i < numVtxIDs; i ++) {
1290 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1291 }
1292
1293 free(allocs);
1294}
1295
1296static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001297nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001298{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001299 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1300
1301 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1302 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1303
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001304 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001305
1306 for(jint i = 0; i < numIndices; i ++) {
1307 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1308 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1309 }
1310
1311 free(allocs);
1312 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001313}
1314
1315// ---------------------------------------------------------------------------
1316
Jason Samsd19f10d2009-05-22 14:03:28 -07001317
Jason Sams94d8e90a2009-06-10 16:09:05 -07001318static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001319
1320static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001321{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001322
Jason Sams1c415172010-11-08 17:06:46 -08001323{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1324{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1325{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
Jason Samsedbfabd2011-05-17 15:01:29 -07001326{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001327{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
Jason Samsedbfabd2011-05-17 15:01:29 -07001328{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001329
1330{"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1331{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001332
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001333
Jason Sams2e1872f2010-08-17 16:25:41 -07001334// All methods below are thread protected in java.
Stephen Hines4382467a2011-08-01 15:02:34 -07001335{"rsnContextCreate", "(III)I", (void*)nContextCreate },
1336{"rsnContextCreateGL", "(IIIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
Jason Sams2e1872f2010-08-17 16:25:41 -07001337{"rsnContextFinish", "(I)V", (void*)nContextFinish },
1338{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1339{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
Jason Samsfaa32b32011-06-20 16:58:04 -07001340{"rsnContextSetSurfaceTexture", "(IIILandroid/graphics/SurfaceTexture;)V", (void*)nContextSetSurfaceTexture },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001341{"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams2e1872f2010-08-17 16:25:41 -07001342{"rsnContextDump", "(II)V", (void*)nContextDump },
1343{"rsnContextPause", "(I)V", (void*)nContextPause },
1344{"rsnContextResume", "(I)V", (void*)nContextResume },
1345{"rsnAssignName", "(II[B)V", (void*)nAssignName },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001346{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
Jason Sams2e1872f2010-08-17 16:25:41 -07001347{"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001348
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001349{"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
Jason Sams2e1872f2010-08-17 16:25:41 -07001350{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001351{"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
Jason Sams2e1872f2010-08-17 16:25:41 -07001352{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001353{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Jason Sams2e1872f2010-08-17 16:25:41 -07001354{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001355
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -08001356{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001357{"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1358{"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001359
Jason Sams2e1872f2010-08-17 16:25:41 -07001360{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
Jason Sams70d4e502010-09-02 17:35:23 -07001361{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
Jason Sams2e1872f2010-08-17 16:25:41 -07001362{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001363{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001364
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001365{"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001366{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001367
Jason Sams857d0c72011-11-23 15:02:15 -08001368{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped },
Jason Sams5476b452010-12-08 16:14:36 -08001369{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
1370{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001371
Jason Sams4ef66502010-12-10 16:03:15 -08001372{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1373{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1374
Jason Sams5476b452010-12-08 16:14:36 -08001375{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
Jason Sams615e7ce2012-01-13 14:01:20 -08001376{"rsnAllocationGetSurfaceTextureID", "(II)I", (void*)nAllocationGetSurfaceTextureID },
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001377{"rsnAllocationGetSurfaceTextureID2","(IILandroid/graphics/SurfaceTexture;)V",(void*)nAllocationGetSurfaceTextureID2 },
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001378{"rsnAllocationSetSurface", "(IILandroid/view/Surface;)V", (void*)nAllocationSetSurface },
Jason Sams163766c2012-02-15 12:04:24 -08001379{"rsnAllocationIoSend", "(II)V", (void*)nAllocationIoSend },
1380{"rsnAllocationIoReceive", "(II)V", (void*)nAllocationIoReceive },
Jason Sams49a05d72010-12-29 14:31:29 -08001381{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i },
1382{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s },
1383{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b },
1384{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f },
1385{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
1386{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001387{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s },
1388{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b },
Jason Sams49a05d72010-12-29 14:31:29 -08001389{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f },
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001390{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc },
Jason Sams2e1872f2010-08-17 16:25:41 -07001391{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001392{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s },
1393{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b },
Jason Sams2e1872f2010-08-17 16:25:41 -07001394{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
Jason Sams2e1872f2010-08-17 16:25:41 -07001395{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
Jason Sams5edc6082010-10-05 13:32:49 -07001396{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
1397{"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D },
Jason Samsf7086092011-01-12 13:28:37 -08001398{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001399
Jason Sams2e1872f2010-08-17 16:25:41 -07001400{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1401{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1402{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1403{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
Jason Sams6e494d32011-04-27 16:33:11 -07001404{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1405{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
Jason Sams2e1872f2010-08-17 16:25:41 -07001406{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
Stephen Hines031ec58c2010-10-11 10:54:21 -07001407{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
Jason Sams2e1872f2010-08-17 16:25:41 -07001408{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
Stephen Hinesca54ec32010-09-20 17:20:30 -07001409{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
Jason Sams2e1872f2010-08-17 16:25:41 -07001410{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
Stephen Hinesadeb8092012-04-20 14:26:06 -07001411{"rsnScriptSetVarVE", "(III[BI[I)V", (void*)nScriptSetVarVE },
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001412{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001413
Jason Samse4a06c52011-03-16 16:29:28 -07001414{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
Jason Sams0011bcf2009-12-15 12:58:36 -08001415
Jason Sams331bf9b2011-04-06 11:23:54 -07001416{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001417
Jason Sams2e1872f2010-08-17 16:25:41 -07001418{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1419{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1420{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001421
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001422{"rsnProgramFragmentCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate },
Jason Sams94aaed32011-09-23 14:18:53 -07001423{"rsnProgramRasterCreate", "(IZI)I", (void*)nProgramRasterCreate },
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001424{"rsnProgramVertexCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001425
Jason Sams2e1872f2010-08-17 16:25:41 -07001426{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001427{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
Jason Sams2e1872f2010-08-17 16:25:41 -07001428{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1429{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1430{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001431
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001432{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001433
Jason Samsf15ed012011-10-31 13:23:43 -07001434{"rsnPathCreate", "(IIZIIF)I", (void*)nPathCreate },
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001435{"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001436
1437{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1438{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001439{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
Jason Sams2e1872f2010-08-17 16:25:41 -07001440{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001441
Jason Samsd19f10d2009-05-22 14:03:28 -07001442};
1443
1444static int registerFuncs(JNIEnv *_env)
1445{
1446 return android::AndroidRuntime::registerNativeMethods(
1447 _env, classPathName, methods, NELEM(methods));
1448}
1449
1450// ---------------------------------------------------------------------------
1451
1452jint JNI_OnLoad(JavaVM* vm, void* reserved)
1453{
1454 JNIEnv* env = NULL;
1455 jint result = -1;
1456
Jason Samsd19f10d2009-05-22 14:03:28 -07001457 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001458 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001459 goto bail;
1460 }
1461 assert(env != NULL);
1462
1463 if (registerFuncs(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001464 ALOGE("ERROR: MediaPlayer native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001465 goto bail;
1466 }
1467
1468 /* success -- return valid version number */
1469 result = JNI_VERSION_1_4;
1470
1471bail:
1472 return result;
1473}