blob: 9d4c64f27674c940e923ba116883d8046230a47f [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 Samsfaa32b32011-06-20 16:58:04 -070044#include <gui/SurfaceTexture.h>
45#include <gui/SurfaceTextureClient.h>
46#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070047
Steve Block3762c312012-01-06 19:20:56 +000048//#define LOG_API ALOGE
Jason Samsd19f10d2009-05-22 14:03:28 -070049#define LOG_API(...)
50
51using namespace android;
52
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080053class AutoJavaStringToUTF8 {
54public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080055 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080056 fCStr = env->GetStringUTFChars(str, NULL);
57 fLength = env->GetStringUTFLength(str);
58 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080059 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080060 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
61 }
62 const char* c_str() const { return fCStr; }
63 jsize length() const { return fLength; }
64
65private:
66 JNIEnv* fEnv;
67 jstring fJStr;
68 const char* fCStr;
69 jsize fLength;
70};
71
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080072class AutoJavaStringArrayToUTF8 {
73public:
74 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
75 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
76 mCStrings = NULL;
77 mSizeArray = NULL;
78 if (stringsLength > 0) {
79 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
80 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
81 for (jsize ct = 0; ct < stringsLength; ct ++) {
82 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
83 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL);
84 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
85 }
86 }
87 }
88 ~AutoJavaStringArrayToUTF8() {
89 for (jsize ct=0; ct < mStringsLength; ct++) {
90 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
91 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
92 }
93 free(mCStrings);
94 free(mSizeArray);
95 }
96 const char **c_str() const { return mCStrings; }
97 size_t *c_str_len() const { return mSizeArray; }
98 jsize length() const { return mStringsLength; }
99
100private:
101 JNIEnv *mEnv;
102 jobjectArray mStrings;
103 const char **mCStrings;
104 size_t *mSizeArray;
105 jsize mStringsLength;
106};
107
Jason Samsd19f10d2009-05-22 14:03:28 -0700108// ---------------------------------------------------------------------------
109
Jason Samsffe9f482009-06-01 17:45:53 -0700110static jfieldID gContextId = 0;
111static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -0700112static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700113
114static void _nInit(JNIEnv *_env, jclass _this)
115{
Jason Samsd19f10d2009-05-22 14:03:28 -0700116 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -0700117
118 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
119 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
Jason Samsd19f10d2009-05-22 14:03:28 -0700120}
121
Jason Samsd19f10d2009-05-22 14:03:28 -0700122// ---------------------------------------------------------------------------
123
Jason Sams3eaa338e2009-06-10 15:04:38 -0700124static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700125nContextFinish(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700126{
Jason Sams96ed4cf2010-06-15 12:15:57 -0700127 LOG_API("nContextFinish, con(%p)", con);
128 rsContextFinish(con);
129}
130
131static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700132nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700133{
Jason Sams07ae4062009-08-27 20:23:34 -0700134 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700135 jint len = _env->GetArrayLength(str);
136 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsbc948de2009-08-17 18:35:48 -0700137 rsAssignName(con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700138 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
139}
140
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700141static jstring
Jason Sams2e1872f2010-08-17 16:25:41 -0700142nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700143{
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700144 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700145 const char *name = NULL;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700146 rsaGetName(con, (void *)obj, &name);
147 if(name == NULL || strlen(name) == 0) {
148 return NULL;
149 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700150 return _env->NewStringUTF(name);
151}
152
Jason Sams7ce033d2009-08-18 14:14:24 -0700153static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700154nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700155{
Jason Sams7ce033d2009-08-18 14:14:24 -0700156 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
Jason Sams9c25aee2010-10-14 17:57:30 -0700157 rsObjDestroy(con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700158}
159
Jason Sams3eaa338e2009-06-10 15:04:38 -0700160// ---------------------------------------------------------------------------
161
Jason Samsd19f10d2009-05-22 14:03:28 -0700162static jint
163nDeviceCreate(JNIEnv *_env, jobject _this)
164{
165 LOG_API("nDeviceCreate");
166 return (jint)rsDeviceCreate();
167}
168
169static void
170nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
171{
172 LOG_API("nDeviceDestroy");
173 return rsDeviceDestroy((RsDevice)dev);
174}
175
Jason Samsebfb4362009-09-23 13:57:02 -0700176static void
177nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
178{
179 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
180 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
181}
182
Jason Samsd19f10d2009-05-22 14:03:28 -0700183static jint
Stephen Hines4382467a2011-08-01 15:02:34 -0700184nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700185{
186 LOG_API("nContextCreate");
Stephen Hines4382467a2011-08-01 15:02:34 -0700187 return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer);
Jason Sams704ff642010-02-09 16:05:07 -0800188}
189
190static jint
Stephen Hines4382467a2011-08-01 15:02:34 -0700191nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700192 int colorMin, int colorPref,
193 int alphaMin, int alphaPref,
194 int depthMin, int depthPref,
195 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700196 int samplesMin, int samplesPref, float samplesQ,
197 int dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800198{
Jason Sams11c8af92010-10-13 15:31:10 -0700199 RsSurfaceConfig sc;
200 sc.alphaMin = alphaMin;
201 sc.alphaPref = alphaPref;
202 sc.colorMin = colorMin;
203 sc.colorPref = colorPref;
204 sc.depthMin = depthMin;
205 sc.depthPref = depthPref;
206 sc.samplesMin = samplesMin;
207 sc.samplesPref = samplesPref;
208 sc.samplesQ = samplesQ;
209
Jason Sams704ff642010-02-09 16:05:07 -0800210 LOG_API("nContextCreateGL");
Stephen Hines4382467a2011-08-01 15:02:34 -0700211 return (jint)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700212}
213
214static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700215nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800216{
Jason Sams7d787b42009-11-15 12:14:26 -0800217 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
218 rsContextSetPriority(con, p);
219}
220
221
222
223static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700224nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800225{
Jason Sams3bc47d42009-11-12 15:10:25 -0800226 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800227
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700228 ANativeWindow * window = NULL;
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800229 if (wnd == NULL) {
230
231 } else {
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700232 window = android_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800233 }
234
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700235 rsContextSetSurface(con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800236}
237
238static void
Jason Samsfaa32b32011-06-20 16:58:04 -0700239nContextSetSurfaceTexture(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject sur)
240{
241 LOG_API("nContextSetSurfaceTexture, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)sur);
242
243 sp<ANativeWindow> window;
244 sp<SurfaceTexture> st;
245 if (sur == 0) {
246
247 } else {
248 st = SurfaceTexture_getSurfaceTexture(_env, sur);
249 window = new SurfaceTextureClient(st);
250 }
251
252 rsContextSetSurface(con, width, height, window.get());
253}
254
255static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700256nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700257{
Jason Sams2e1872f2010-08-17 16:25:41 -0700258 LOG_API("nContextDestroy, con(%p)", con);
259 rsContextDestroy(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700260}
261
Jason Sams715333b2009-11-17 17:26:46 -0800262static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700263nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800264{
Jason Sams715333b2009-11-17 17:26:46 -0800265 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
266 rsContextDump((RsContext)con, bits);
267}
Jason Samsd19f10d2009-05-22 14:03:28 -0700268
269static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700270nContextPause(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700271{
Jason Sams65e7aa52009-09-24 17:38:20 -0700272 LOG_API("nContextPause, con(%p)", con);
273 rsContextPause(con);
274}
275
276static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700277nContextResume(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700278{
Jason Sams65e7aa52009-09-24 17:38:20 -0700279 LOG_API("nContextResume, con(%p)", con);
280 rsContextResume(con);
281}
282
Jason Sams1c415172010-11-08 17:06:46 -0800283
284static jstring
285nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
286{
287 LOG_API("nContextGetErrorMessage, con(%p)", con);
288 char buf[1024];
289
290 size_t receiveLen;
291 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700292 int id = rsContextGetMessage(con,
293 buf, sizeof(buf),
294 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700295 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800296 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100297 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800298 }
299 return _env->NewStringUTF(buf);
300}
301
Jason Samsedbfabd2011-05-17 15:01:29 -0700302static jint
Jason Sams1c415172010-11-08 17:06:46 -0800303nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700304{
Jason Sams516c3192009-10-06 13:58:47 -0700305 jint len = _env->GetArrayLength(data);
306 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
307 jint *ptr = _env->GetIntArrayElements(data, NULL);
308 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800309 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700310 int id = rsContextGetMessage(con,
311 ptr, len * 4,
312 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700313 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700314 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100315 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700316 }
317 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Samsedbfabd2011-05-17 15:01:29 -0700318 return id;
Jason Sams1c415172010-11-08 17:06:46 -0800319}
320
321static jint
Jason Samsedbfabd2011-05-17 15:01:29 -0700322nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800323{
324 LOG_API("nContextPeekMessage, con(%p)", con);
325 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
326 size_t receiveLen;
327 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700328 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700329 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800330 auxDataPtr[0] = (jint)subID;
331 auxDataPtr[1] = (jint)receiveLen;
332 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Jason Sams516c3192009-10-06 13:58:47 -0700333 return id;
334}
335
Jason Sams2e1872f2010-08-17 16:25:41 -0700336static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700337{
Jason Sams516c3192009-10-06 13:58:47 -0700338 LOG_API("nContextInitToClient, con(%p)", con);
339 rsContextInitToClient(con);
340}
341
Jason Sams2e1872f2010-08-17 16:25:41 -0700342static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700343{
Jason Sams516c3192009-10-06 13:58:47 -0700344 LOG_API("nContextDeinitToClient, con(%p)", con);
345 rsContextDeinitToClient(con);
346}
347
348
Jason Sams718cd1f2009-12-23 14:35:29 -0800349static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700350nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700351{
Jason Sams718cd1f2009-12-23 14:35:29 -0800352 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
353 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700354}
355
356static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800357nElementCreate2(JNIEnv *_env, jobject _this, RsContext con,
358 jintArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700359{
Jason Sams718cd1f2009-12-23 14:35:29 -0800360 int fieldCount = _env->GetArrayLength(_ids);
Jason Sams704ff642010-02-09 16:05:07 -0800361 LOG_API("nElementCreate2, con(%p)", con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800362
363 jint *ids = _env->GetIntArrayElements(_ids, NULL);
Jason Sams70d4e502010-09-02 17:35:23 -0700364 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
Jason Sams718cd1f2009-12-23 14:35:29 -0800365
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800366 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
367
368 const char **nameArray = names.c_str();
369 size_t *sizeArray = names.c_str_len();
370
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700371 jint id = (jint)rsElementCreate2(con,
372 (RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700373 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700374 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800375
Jason Sams718cd1f2009-12-23 14:35:29 -0800376 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
Jason Sams70d4e502010-09-02 17:35:23 -0700377 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
Jason Sams718cd1f2009-12-23 14:35:29 -0800378 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700379}
380
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700381static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700382nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700383{
384 int dataSize = _env->GetArrayLength(_elementData);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700385 LOG_API("nElementGetNativeData, con(%p)", con);
386
387 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
388 assert(dataSize == 5);
389
390 uint32_t elementData[5];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700391 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700392
393 for(jint i = 0; i < dataSize; i ++) {
394 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
395 }
396}
397
398
399static void
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700400nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
401 jintArray _IDs,
402 jobjectArray _names,
403 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700404{
405 int dataSize = _env->GetArrayLength(_IDs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700406 LOG_API("nElementGetSubElements, con(%p)", con);
407
408 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
409 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700410 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700411
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700412 rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700413
Jason Sams11c8af92010-10-13 15:31:10 -0700414 for(jint i = 0; i < dataSize; i++) {
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700415 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
416 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700417 _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700418 }
419
420 free(ids);
421 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700422 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700423}
424
Jason Samsd19f10d2009-05-22 14:03:28 -0700425// -----------------------------------
426
Jason Sams3b9c52a2010-10-14 17:48:46 -0700427static int
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800428nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
429 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces)
Jason Samsd19f10d2009-05-22 14:03:28 -0700430{
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800431 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
432 con, eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700433
Jason Samsc5765372011-04-28 18:26:48 -0700434 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700435 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700436}
437
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700438static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700439nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700440{
441 // We are packing 6 items: mDimX; mDimY; mDimZ;
442 // mDimLOD; mDimFaces; mElement; into typeData
443 int elementCount = _env->GetArrayLength(_typeData);
444
445 assert(elementCount == 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700446 LOG_API("nTypeCreate, con(%p)", con);
447
448 uint32_t typeData[6];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700449 rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700450
451 for(jint i = 0; i < elementCount; i ++) {
452 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
453 }
454}
455
Jason Samsd19f10d2009-05-22 14:03:28 -0700456// -----------------------------------
457
458static jint
Jason Sams857d0c72011-11-23 15:02:15 -0800459nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700460{
Jason Sams857d0c72011-11-23 15:02:15 -0800461 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer);
462 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700463}
464
Jason Samsd19f10d2009-05-22 14:03:28 -0700465static void
Jason Sams5476b452010-12-08 16:14:36 -0800466nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
467{
468 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
469 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
470}
471
Jason Sams615e7ce2012-01-13 14:01:20 -0800472static jint
473nAllocationGetSurfaceTextureID(JNIEnv *_env, jobject _this, RsContext con, jint a)
474{
475 LOG_API("nAllocationGetSurfaceTextureID, con(%p), a(%p)", con, (RsAllocation)a);
476 return rsAllocationGetSurfaceTextureID(con, (RsAllocation)a);
477}
478
Jason Samsf7086092011-01-12 13:28:37 -0800479static void
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700480nAllocationGetSurfaceTextureID2(JNIEnv *_env, jobject _this, RsContext con, jint a, jobject jst)
481{
482 LOG_API("nAllocationGetSurfaceTextureID2, con(%p), a(%p)", con, (RsAllocation)a);
483 sp<SurfaceTexture> st = SurfaceTexture_getSurfaceTexture(_env, jst);
484
485 rsAllocationGetSurfaceTextureID2(con, (RsAllocation)a, st.get(), sizeof(SurfaceTexture *));
486}
487
488static void
Jason Sams163766c2012-02-15 12:04:24 -0800489nAllocationSetSurfaceTexture(JNIEnv *_env, jobject _this, RsContext con,
490 RsAllocation alloc, jobject sur)
491{
492 LOG_API("nAllocationSetSurfaceTexture, con(%p), alloc(%p), surface(%p)",
493 con, alloc, (Surface *)sur);
494
495 sp<ANativeWindow> window;
496 if (sur != 0) {
497 sp<SurfaceTexture> st = SurfaceTexture_getSurfaceTexture(_env, sur);
498 window = new SurfaceTextureClient(st);
499 }
500
501 rsAllocationSetSurface(con, alloc, window.get());
502}
503
504static void
505nAllocationIoSend(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
506{
507 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", con, alloc);
508 rsAllocationIoSend(con, alloc);
509}
510
511static void
512nAllocationIoReceive(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
513{
514 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", con, alloc);
515 rsAllocationIoReceive(con, alloc);
516}
517
518
519static void
Jason Samsf7086092011-01-12 13:28:37 -0800520nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
521{
522 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
523 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
524}
525
Jason Samsffe9f482009-06-01 17:45:53 -0700526static int
Jason Sams5476b452010-12-08 16:14:36 -0800527nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700528{
Jason Samsffe9f482009-06-01 17:45:53 -0700529 SkBitmap const * nativeBitmap =
530 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
531 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700532
Jason Sams5476b452010-12-08 16:14:36 -0800533 bitmap.lockPixels();
534 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700535 jint id = (jint)rsAllocationCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700536 (RsType)type, (RsAllocationMipmapControl)mip,
537 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800538 bitmap.unlockPixels();
539 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700540}
Jason Samsfe08d992009-05-27 14:45:32 -0700541
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800542static int
Jason Sams5476b452010-12-08 16:14:36 -0800543nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800544{
545 SkBitmap const * nativeBitmap =
546 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
547 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800548
Jason Sams5476b452010-12-08 16:14:36 -0800549 bitmap.lockPixels();
550 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700551 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700552 (RsType)type, (RsAllocationMipmapControl)mip,
553 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800554 bitmap.unlockPixels();
555 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800556}
557
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700558static void
Jason Sams4ef66502010-12-10 16:03:15 -0800559nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700560{
561 SkBitmap const * nativeBitmap =
562 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
563 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800564 int w = bitmap.width();
565 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700566
Jason Sams4ef66502010-12-10 16:03:15 -0800567 bitmap.lockPixels();
568 const void* ptr = bitmap.getPixels();
Jason Samsf7086092011-01-12 13:28:37 -0800569 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700570 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Jason Samsf7086092011-01-12 13:28:37 -0800571 w, h, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800572 bitmap.unlockPixels();
573}
574
575static void
576nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
577{
578 SkBitmap const * nativeBitmap =
579 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
580 const SkBitmap& bitmap(*nativeBitmap);
581
582 bitmap.lockPixels();
583 void* ptr = bitmap.getPixels();
584 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
585 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700586 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700587}
588
Jason Sams8a647432010-03-01 15:31:04 -0800589static void ReleaseBitmapCallback(void *bmp)
590{
591 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
592 nativeBitmap->unlockPixels();
593}
594
Romain Guy650a3eb2009-08-31 14:06:43 -0700595
Jason Samsd19f10d2009-05-22 14:03:28 -0700596static void
Jason Sams49a05d72010-12-29 14:31:29 -0800597nAllocationData1D_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 -0700598{
Jason Samsd19f10d2009-05-22 14:03:28 -0700599 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800600 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 -0700601 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800602 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700603 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
604}
605
606static void
Jason Sams49a05d72010-12-29 14:31:29 -0800607nAllocationData1D_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 -0700608{
Jason Sams768bc022009-09-21 19:41:04 -0700609 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800610 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 -0700611 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800612 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700613 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
614}
615
616static void
Jason Sams49a05d72010-12-29 14:31:29 -0800617nAllocationData1D_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 -0700618{
Jason Sams768bc022009-09-21 19:41:04 -0700619 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800620 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 -0700621 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800622 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700623 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
624}
625
626static void
Jason Sams49a05d72010-12-29 14:31:29 -0800627nAllocationData1D_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 -0700628{
Jason Samsd19f10d2009-05-22 14:03:28 -0700629 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800630 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 -0700631 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800632 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700633 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
634}
635
636static void
Jason Sams49a05d72010-12-29 14:31:29 -0800637// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
638nAllocationElementData1D(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 -0700639{
640 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800641 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 -0700642 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Stephen Hines4cbe25a2012-01-18 18:46:27 -0800643 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700644 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
645}
646
647static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800648nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
649 jint w, jint h, jshortArray data, int sizeBytes)
650{
651 jint len = _env->GetArrayLength(data);
652 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);
653 jshort *ptr = _env->GetShortArrayElements(data, NULL);
654 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
655 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
656}
657
658static void
659nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
660 jint w, jint h, jbyteArray data, int sizeBytes)
661{
662 jint len = _env->GetArrayLength(data);
663 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);
664 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
665 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
666 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
667}
668
669static void
Jason Sams49a05d72010-12-29 14:31:29 -0800670nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
671 jint w, jint h, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700672{
Jason Samsd19f10d2009-05-22 14:03:28 -0700673 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800674 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 -0700675 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800676 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700677 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
678}
679
680static void
Jason Sams49a05d72010-12-29 14:31:29 -0800681nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
682 jint w, jint h, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700683{
Jason Samsd19f10d2009-05-22 14:03:28 -0700684 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800685 LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
Jason Samsd19f10d2009-05-22 14:03:28 -0700686 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800687 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700688 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
689}
690
Jason Sams40a29e82009-08-10 14:55:26 -0700691static void
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700692nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
693 jint dstAlloc, jint dstXoff, jint dstYoff,
694 jint dstMip, jint dstFace,
695 jint width, jint height,
696 jint srcAlloc, jint srcXoff, jint srcYoff,
697 jint srcMip, jint srcFace)
698{
Jason Sams4c2e4c82012-02-07 15:32:08 -0800699 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700700 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
701 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
702 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
703 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
704
705 rsAllocationCopy2DRange(con,
706 (RsAllocation)dstAlloc,
707 dstXoff, dstYoff,
708 dstMip, dstFace,
709 width, height,
710 (RsAllocation)srcAlloc,
711 srcXoff, srcYoff,
712 srcMip, srcFace);
713}
714
715static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700716nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700717{
Jason Sams40a29e82009-08-10 14:55:26 -0700718 jint len = _env->GetArrayLength(data);
719 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
720 jint *ptr = _env->GetIntArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700721 jsize length = _env->GetArrayLength(data);
722 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Joe Onoratoae209ac2009-08-31 17:23:53 -0700723 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700724}
725
726static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800727nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
728{
729 jint len = _env->GetArrayLength(data);
730 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
731 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700732 jsize length = _env->GetArrayLength(data);
733 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800734 _env->ReleaseShortArrayElements(data, ptr, 0);
735}
736
737static void
738nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
739{
740 jint len = _env->GetArrayLength(data);
741 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
742 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700743 jsize length = _env->GetArrayLength(data);
744 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800745 _env->ReleaseByteArrayElements(data, ptr, 0);
746}
747
748static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700749nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700750{
Jason Sams40a29e82009-08-10 14:55:26 -0700751 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700752 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700753 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700754 jsize length = _env->GetArrayLength(data);
755 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Joe Onoratoae209ac2009-08-31 17:23:53 -0700756 _env->ReleaseFloatArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700757}
Jason Samsd19f10d2009-05-22 14:03:28 -0700758
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700759static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700760nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700761{
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700762 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700763 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700764}
765
Jason Sams5edc6082010-10-05 13:32:49 -0700766static void
767nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
768{
769 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
770 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
771}
772
773static void
774nAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY)
775{
776 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY);
777 rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY);
778}
779
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700780// -----------------------------------
781
782static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700783nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700784{
Steve Block71f2cf12011-10-20 11:56:00 +0100785 ALOGV("______nFileA3D %u", (uint32_t) native_asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700786
787 Asset* asset = reinterpret_cast<Asset*>(native_asset);
788
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800789 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
790 return id;
791}
792
793static int
794nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
795{
796 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
797 if (mgr == NULL) {
798 return 0;
799 }
800
801 AutoJavaStringToUTF8 str(_env, _path);
802 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
803 if (asset == NULL) {
804 return 0;
805 }
806
807 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
808 return id;
809}
810
811static int
812nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
813{
814 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
815 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
816
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700817 return id;
818}
819
820static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700821nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700822{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700823 int32_t numEntries = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700824 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700825 return numEntries;
826}
827
828static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700829nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700830{
Steve Block71f2cf12011-10-20 11:56:00 +0100831 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700832 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
833
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700834 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700835
836 for(jint i = 0; i < numEntries; i ++) {
837 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
838 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
839 }
840
841 free(fileEntries);
842}
843
844static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700845nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700846{
Steve Block71f2cf12011-10-20 11:56:00 +0100847 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700848 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700849 return id;
850}
Jason Samsd19f10d2009-05-22 14:03:28 -0700851
852// -----------------------------------
853
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700854static int
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800855nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
856 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700857{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800858 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700859 jint id = (jint)rsFontCreateFromFile(con,
860 fileNameUTF.c_str(), fileNameUTF.length(),
861 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700862
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800863 return id;
864}
865
866static int
867nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
868 jstring name, jfloat fontSize, jint dpi, jint native_asset)
869{
870 Asset* asset = reinterpret_cast<Asset*>(native_asset);
871 AutoJavaStringToUTF8 nameUTF(_env, name);
872
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700873 jint id = (jint)rsFontCreateFromMemory(con,
874 nameUTF.c_str(), nameUTF.length(),
875 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800876 asset->getBuffer(false), asset->getLength());
877 return id;
878}
879
880static int
881nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
882 jfloat fontSize, jint dpi)
883{
884 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
885 if (mgr == NULL) {
886 return 0;
887 }
888
889 AutoJavaStringToUTF8 str(_env, _path);
890 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
891 if (asset == NULL) {
892 return 0;
893 }
894
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700895 jint id = (jint)rsFontCreateFromMemory(con,
896 str.c_str(), str.length(),
897 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800898 asset->getBuffer(false), asset->getLength());
899 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700900 return id;
901}
902
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700903// -----------------------------------
904
905static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700906nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700907{
Jason Samsd19f10d2009-05-22 14:03:28 -0700908 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700909 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700910}
911
912static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700913nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700914{
Jason Samscfc04362010-09-14 14:59:03 -0700915 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700916 rsScriptSetVarI(con, (RsScript)script, slot, val);
917}
918
919static void
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800920nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
921{
922 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
923 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
924}
925
926static void
Stephen Hines031ec58c2010-10-11 10:54:21 -0700927nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
928{
929 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
930 rsScriptSetVarJ(con, (RsScript)script, slot, val);
931}
932
933static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700934nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700935{
Stephen Hinesca54ec32010-09-20 17:20:30 -0700936 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700937 rsScriptSetVarF(con, (RsScript)script, slot, val);
938}
939
940static void
Stephen Hinesca54ec32010-09-20 17:20:30 -0700941nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
942{
943 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
944 rsScriptSetVarD(con, (RsScript)script, slot, val);
945}
946
947static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700948nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700949{
Jason Sams4d339932010-05-11 14:03:58 -0700950 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
951 jint len = _env->GetArrayLength(data);
952 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
953 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
954 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
955}
956
Jason Samsd19f10d2009-05-22 14:03:28 -0700957
958static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700959nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -0700960{
Jason Sams07ae4062009-08-27 20:23:34 -0700961 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -0700962
963 jint length = _env->GetArrayLength(timeZone);
964 jbyte* timeZone_ptr;
965 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
966
Jason Samsbc948de2009-08-17 18:35:48 -0700967 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -0700968
969 if (timeZone_ptr) {
970 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
971 }
972}
973
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700974static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700975nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -0700976{
Jason Samsbe2e8412009-09-16 15:04:38 -0700977 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
978 rsScriptInvoke(con, (RsScript)obj, slot);
979}
980
981static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700982nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700983{
Jason Sams4d339932010-05-11 14:03:58 -0700984 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
985 jint len = _env->GetArrayLength(data);
986 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
987 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
988 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
989}
990
Jason Sams6e494d32011-04-27 16:33:11 -0700991static void
992nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
993 jint script, jint slot, jint ain, jint aout)
994{
995 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
996 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0);
997}
998static void
999nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
1000 jint script, jint slot, jint ain, jint aout, jbyteArray params)
1001{
1002 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1003 jint len = _env->GetArrayLength(params);
1004 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
1005 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len);
1006 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1007}
1008
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001009
Jason Sams22534172009-08-04 16:58:20 -07001010// -----------------------------------
1011
Jason Samse4a06c52011-03-16 16:29:28 -07001012static jint
1013nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
1014 jstring resName, jstring cacheDir,
1015 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001016{
Jason Samse4a06c52011-03-16 16:29:28 -07001017 LOG_API("nScriptCCreate, con(%p)", con);
Jason Sams22534172009-08-04 16:58:20 -07001018
Jason Samse4a06c52011-03-16 16:29:28 -07001019 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1020 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
1021 jint ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -07001022 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -07001023 jint _exception = 0;
1024 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001025 if (!scriptRef) {
1026 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001027 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001028 goto exit;
1029 }
Jack Palevich43702d82009-05-28 13:38:16 -07001030 if (length < 0) {
1031 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001032 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001033 goto exit;
1034 }
Jason Samse4a06c52011-03-16 16:29:28 -07001035 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001036 if (remaining < length) {
1037 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001038 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1039 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001040 goto exit;
1041 }
Jason Samse4a06c52011-03-16 16:29:28 -07001042 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001043 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001044
Jason Samse4a06c52011-03-16 16:29:28 -07001045 //rsScriptCSetText(con, (const char *)script_ptr, length);
1046
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001047 ret = (jint)rsScriptCCreate(con,
1048 resNameUTF.c_str(), resNameUTF.length(),
1049 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001050 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001051
Jack Palevich43702d82009-05-28 13:38:16 -07001052exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001053 if (script_ptr) {
1054 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001055 _exception ? JNI_ABORT: 0);
1056 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001057
Jason Samse4a06c52011-03-16 16:29:28 -07001058 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001059}
1060
1061// ---------------------------------------------------------------------------
1062
Jason Samsd19f10d2009-05-22 14:03:28 -07001063static jint
Jason Sams331bf9b2011-04-06 11:23:54 -07001064nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
1065 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1066 jboolean depthMask, jboolean ditherEnable,
1067 jint srcFunc, jint destFunc,
1068 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001069{
Jason Sams54db59c2010-05-13 18:30:11 -07001070 LOG_API("nProgramStoreCreate, con(%p)", con);
Jason Sams331bf9b2011-04-06 11:23:54 -07001071 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
1072 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1073 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001074}
1075
Jason Sams0011bcf2009-12-15 12:58:36 -08001076// ---------------------------------------------------------------------------
1077
1078static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001079nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001080{
Jason Sams0011bcf2009-12-15 12:58:36 -08001081 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
1082 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
1083}
Jason Sams54c0ec12009-11-30 14:49:55 -08001084
Jason Sams68afd012009-12-17 16:55:08 -08001085static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001086nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001087{
Jason Sams68afd012009-12-17 16:55:08 -08001088 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1089 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1090}
1091
1092static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001093nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001094{
Jason Sams68afd012009-12-17 16:55:08 -08001095 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1096 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1097}
1098
Jason Samsd19f10d2009-05-22 14:03:28 -07001099// ---------------------------------------------------------------------------
1100
Jason Samsd19f10d2009-05-22 14:03:28 -07001101static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001102nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1103 jobjectArray texNames, jintArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001104{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001105 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001106 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1107 jint paramLen = _env->GetArrayLength(params);
1108
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001109 int texCount = _env->GetArrayLength(texNames);
1110 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1111 const char ** nameArray = names.c_str();
1112 size_t* sizeArray = names.c_str_len();
1113
Jason Sams991040c2011-01-17 15:59:39 -08001114 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001115
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001116 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1117 nameArray, texCount, sizeArray,
1118 (uint32_t *)paramPtr, paramLen);
1119
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001120 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1121 return ret;
1122}
1123
1124
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001125// ---------------------------------------------------------------------------
1126
Jason Sams0011bcf2009-12-15 12:58:36 -08001127static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001128nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1129 jobjectArray texNames, jintArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001130{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001131 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams0011bcf2009-12-15 12:58:36 -08001132 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1133 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001134
Jason Sams991040c2011-01-17 15:59:39 -08001135 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001136
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001137 int texCount = _env->GetArrayLength(texNames);
1138 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1139 const char ** nameArray = names.c_str();
1140 size_t* sizeArray = names.c_str_len();
1141
1142 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1143 nameArray, texCount, sizeArray,
1144 (uint32_t *)paramPtr, paramLen);
1145
Jason Sams0011bcf2009-12-15 12:58:36 -08001146 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1147 return ret;
1148}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001149
Jason Samsebfb4362009-09-23 13:57:02 -07001150// ---------------------------------------------------------------------------
1151
1152static jint
Jason Sams94aaed32011-09-23 14:18:53 -07001153nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001154{
Jason Sams94aaed32011-09-23 14:18:53 -07001155 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", con, pointSprite, cull);
1156 return (jint)rsProgramRasterCreate(con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001157}
1158
Jason Samsd19f10d2009-05-22 14:03:28 -07001159
1160// ---------------------------------------------------------------------------
1161
1162static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001163nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001164{
Jason Samsd19f10d2009-05-22 14:03:28 -07001165 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001166 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001167}
1168
1169static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001170nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001171{
Jason Sams54db59c2010-05-13 18:30:11 -07001172 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1173 rsContextBindProgramStore(con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001174}
1175
1176static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001177nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001178{
Jason Samsd19f10d2009-05-22 14:03:28 -07001179 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001180 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001181}
1182
Jason Sams0826a6f2009-06-15 19:04:56 -07001183static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001184nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001185{
Jason Sams0826a6f2009-06-15 19:04:56 -07001186 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001187 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001188}
1189
Joe Onoratod7b37742009-08-09 22:57:44 -07001190static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001191nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001192{
Jason Samsebfb4362009-09-23 13:57:02 -07001193 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1194 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1195}
1196
Joe Onoratod7b37742009-08-09 22:57:44 -07001197
Jason Sams02fb2cb2009-05-28 15:37:57 -07001198// ---------------------------------------------------------------------------
1199
Jason Sams02fb2cb2009-05-28 15:37:57 -07001200static jint
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001201nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1202 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001203{
Jason Samsbba134c2009-06-22 15:49:21 -07001204 LOG_API("nSamplerCreate, con(%p)", con);
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001205 return (jint)rsSamplerCreate(con,
1206 (RsSamplerValue)magFilter,
1207 (RsSamplerValue)minFilter,
1208 (RsSamplerValue)wrapS,
1209 (RsSamplerValue)wrapT,
1210 (RsSamplerValue)wrapR,
1211 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001212}
1213
Jason Samsbba134c2009-06-22 15:49:21 -07001214// ---------------------------------------------------------------------------
1215
Jason Samsf15ed012011-10-31 13:23:43 -07001216//native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
1217static jint
1218nPathCreate(JNIEnv *_env, jobject _this, RsContext con, jint prim, jboolean isStatic, jint _vtx, jint _loop, jfloat q) {
1219 LOG_API("nPathCreate, con(%p)", con);
1220
1221 int id = (int)rsPathCreate(con, (RsPathPrimitive)prim, isStatic,
1222 (RsAllocation)_vtx,
1223 (RsAllocation)_loop, q);
1224 return id;
1225}
1226
Jason Samsbba134c2009-06-22 15:49:21 -07001227static jint
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001228nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001229{
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001230 LOG_API("nMeshCreate, con(%p)", con);
1231
1232 jint vtxLen = _env->GetArrayLength(_vtx);
1233 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
1234 jint idxLen = _env->GetArrayLength(_idx);
1235 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
1236 jint primLen = _env->GetArrayLength(_prim);
1237 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1238
1239 int id = (int)rsMeshCreate(con,
1240 (RsAllocation *)vtxPtr, vtxLen,
1241 (RsAllocation *)idxPtr, idxLen,
1242 (uint32_t *)primPtr, primLen);
1243
1244 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
1245 _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
1246 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001247 return id;
1248}
1249
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001250static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001251nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001252{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001253 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1254 jint vtxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001255 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001256 return vtxCount;
1257}
1258
1259static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001260nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001261{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001262 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1263 jint idxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001264 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001265 return idxCount;
1266}
1267
1268static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001269nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001270{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001271 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1272
1273 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001274 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001275
1276 for(jint i = 0; i < numVtxIDs; i ++) {
1277 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1278 }
1279
1280 free(allocs);
1281}
1282
1283static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001284nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001285{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001286 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1287
1288 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1289 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1290
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001291 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001292
1293 for(jint i = 0; i < numIndices; i ++) {
1294 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1295 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1296 }
1297
1298 free(allocs);
1299 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001300}
1301
1302// ---------------------------------------------------------------------------
1303
Jason Samsd19f10d2009-05-22 14:03:28 -07001304
Jason Sams94d8e90a2009-06-10 16:09:05 -07001305static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001306
1307static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001308{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001309
Jason Sams1c415172010-11-08 17:06:46 -08001310{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1311{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1312{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
Jason Samsedbfabd2011-05-17 15:01:29 -07001313{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001314{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
Jason Samsedbfabd2011-05-17 15:01:29 -07001315{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001316
1317{"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1318{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001319
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001320
Jason Sams2e1872f2010-08-17 16:25:41 -07001321// All methods below are thread protected in java.
Stephen Hines4382467a2011-08-01 15:02:34 -07001322{"rsnContextCreate", "(III)I", (void*)nContextCreate },
1323{"rsnContextCreateGL", "(IIIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
Jason Sams2e1872f2010-08-17 16:25:41 -07001324{"rsnContextFinish", "(I)V", (void*)nContextFinish },
1325{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1326{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
Jason Samsfaa32b32011-06-20 16:58:04 -07001327{"rsnContextSetSurfaceTexture", "(IIILandroid/graphics/SurfaceTexture;)V", (void*)nContextSetSurfaceTexture },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001328{"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams2e1872f2010-08-17 16:25:41 -07001329{"rsnContextDump", "(II)V", (void*)nContextDump },
1330{"rsnContextPause", "(I)V", (void*)nContextPause },
1331{"rsnContextResume", "(I)V", (void*)nContextResume },
1332{"rsnAssignName", "(II[B)V", (void*)nAssignName },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001333{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
Jason Sams2e1872f2010-08-17 16:25:41 -07001334{"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001335
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001336{"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
Jason Sams2e1872f2010-08-17 16:25:41 -07001337{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001338{"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
Jason Sams2e1872f2010-08-17 16:25:41 -07001339{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001340{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Jason Sams2e1872f2010-08-17 16:25:41 -07001341{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001342
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -08001343{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001344{"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1345{"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001346
Jason Sams2e1872f2010-08-17 16:25:41 -07001347{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
Jason Sams70d4e502010-09-02 17:35:23 -07001348{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
Jason Sams2e1872f2010-08-17 16:25:41 -07001349{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001350{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001351
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001352{"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001353{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001354
Jason Sams857d0c72011-11-23 15:02:15 -08001355{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped },
Jason Sams5476b452010-12-08 16:14:36 -08001356{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
1357{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001358
Jason Sams4ef66502010-12-10 16:03:15 -08001359{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1360{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1361
Jason Sams5476b452010-12-08 16:14:36 -08001362{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
Jason Sams615e7ce2012-01-13 14:01:20 -08001363{"rsnAllocationGetSurfaceTextureID", "(II)I", (void*)nAllocationGetSurfaceTextureID },
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001364{"rsnAllocationGetSurfaceTextureID2","(IILandroid/graphics/SurfaceTexture;)V",(void*)nAllocationGetSurfaceTextureID2 },
1365{"rsnAllocationSetSurfaceTexture", "(IILandroid/graphics/SurfaceTexture;)V",(void*)nAllocationSetSurfaceTexture },
Jason Sams163766c2012-02-15 12:04:24 -08001366{"rsnAllocationIoSend", "(II)V", (void*)nAllocationIoSend },
1367{"rsnAllocationIoReceive", "(II)V", (void*)nAllocationIoReceive },
Jason Sams49a05d72010-12-29 14:31:29 -08001368{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i },
1369{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s },
1370{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b },
1371{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f },
1372{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
1373{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001374{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s },
1375{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b },
Jason Sams49a05d72010-12-29 14:31:29 -08001376{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f },
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001377{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc },
Jason Sams2e1872f2010-08-17 16:25:41 -07001378{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001379{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s },
1380{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b },
Jason Sams2e1872f2010-08-17 16:25:41 -07001381{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
Jason Sams2e1872f2010-08-17 16:25:41 -07001382{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
Jason Sams5edc6082010-10-05 13:32:49 -07001383{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
1384{"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D },
Jason Samsf7086092011-01-12 13:28:37 -08001385{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001386
Jason Sams2e1872f2010-08-17 16:25:41 -07001387{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1388{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1389{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1390{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
Jason Sams6e494d32011-04-27 16:33:11 -07001391{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1392{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
Jason Sams2e1872f2010-08-17 16:25:41 -07001393{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
Stephen Hines031ec58c2010-10-11 10:54:21 -07001394{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
Jason Sams2e1872f2010-08-17 16:25:41 -07001395{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
Stephen Hinesca54ec32010-09-20 17:20:30 -07001396{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
Jason Sams2e1872f2010-08-17 16:25:41 -07001397{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001398{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001399
Jason Samse4a06c52011-03-16 16:29:28 -07001400{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
Jason Sams0011bcf2009-12-15 12:58:36 -08001401
Jason Sams331bf9b2011-04-06 11:23:54 -07001402{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001403
Jason Sams2e1872f2010-08-17 16:25:41 -07001404{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1405{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1406{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001407
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001408{"rsnProgramFragmentCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate },
Jason Sams94aaed32011-09-23 14:18:53 -07001409{"rsnProgramRasterCreate", "(IZI)I", (void*)nProgramRasterCreate },
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001410{"rsnProgramVertexCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001411
Jason Sams2e1872f2010-08-17 16:25:41 -07001412{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001413{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
Jason Sams2e1872f2010-08-17 16:25:41 -07001414{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1415{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1416{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001417
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001418{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001419
Jason Samsf15ed012011-10-31 13:23:43 -07001420{"rsnPathCreate", "(IIZIIF)I", (void*)nPathCreate },
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001421{"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001422
1423{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1424{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001425{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
Jason Sams2e1872f2010-08-17 16:25:41 -07001426{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001427
Jason Samsd19f10d2009-05-22 14:03:28 -07001428};
1429
1430static int registerFuncs(JNIEnv *_env)
1431{
1432 return android::AndroidRuntime::registerNativeMethods(
1433 _env, classPathName, methods, NELEM(methods));
1434}
1435
1436// ---------------------------------------------------------------------------
1437
1438jint JNI_OnLoad(JavaVM* vm, void* reserved)
1439{
1440 JNIEnv* env = NULL;
1441 jint result = -1;
1442
Jason Samsd19f10d2009-05-22 14:03:28 -07001443 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001444 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001445 goto bail;
1446 }
1447 assert(env != NULL);
1448
1449 if (registerFuncs(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001450 ALOGE("ERROR: MediaPlayer native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001451 goto bail;
1452 }
1453
1454 /* success -- return valid version number */
1455 result = JNI_VERSION_1_4;
1456
1457bail:
1458 return result;
1459}