blob: 27ea8f6ecc8a1f95925aa61d95b0449495e696de [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
Mathias Agopian000479f2010-02-09 17:46:37 -080026#include <surfaceflinger/Surface.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070027
Jason Samsffe9f482009-06-01 17:45:53 -070028#include <core/SkBitmap.h>
Romain Guy650a3eb2009-08-31 14:06:43 -070029#include <core/SkPixelRef.h>
30#include <core/SkStream.h>
31#include <core/SkTemplates.h>
32#include <images/SkImageDecoder.h>
Jason Samsffe9f482009-06-01 17:45:53 -070033
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080034#include <androidfw/Asset.h>
35#include <androidfw/AssetManager.h>
36#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070037
Jason Samsd19f10d2009-05-22 14:03:28 -070038#include "jni.h"
39#include "JNIHelp.h"
40#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070041#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080042#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070043
Jason Sams1d6983a2012-02-16 16:07:49 -080044#include <rs.h>
45#include <rsEnv.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070046#include <gui/SurfaceTexture.h>
47#include <gui/SurfaceTextureClient.h>
48#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070049
Steve Block3762c312012-01-06 19:20:56 +000050//#define LOG_API ALOGE
Jason Samsd19f10d2009-05-22 14:03:28 -070051#define LOG_API(...)
52
53using namespace android;
54
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080055class AutoJavaStringToUTF8 {
56public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080057 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080058 fCStr = env->GetStringUTFChars(str, NULL);
59 fLength = env->GetStringUTFLength(str);
60 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080061 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080062 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
63 }
64 const char* c_str() const { return fCStr; }
65 jsize length() const { return fLength; }
66
67private:
68 JNIEnv* fEnv;
69 jstring fJStr;
70 const char* fCStr;
71 jsize fLength;
72};
73
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080074class AutoJavaStringArrayToUTF8 {
75public:
76 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
77 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
78 mCStrings = NULL;
79 mSizeArray = NULL;
80 if (stringsLength > 0) {
81 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
82 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
83 for (jsize ct = 0; ct < stringsLength; ct ++) {
84 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
85 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL);
86 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
87 }
88 }
89 }
90 ~AutoJavaStringArrayToUTF8() {
91 for (jsize ct=0; ct < mStringsLength; ct++) {
92 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
93 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
94 }
95 free(mCStrings);
96 free(mSizeArray);
97 }
98 const char **c_str() const { return mCStrings; }
99 size_t *c_str_len() const { return mSizeArray; }
100 jsize length() const { return mStringsLength; }
101
102private:
103 JNIEnv *mEnv;
104 jobjectArray mStrings;
105 const char **mCStrings;
106 size_t *mSizeArray;
107 jsize mStringsLength;
108};
109
Jason Samsd19f10d2009-05-22 14:03:28 -0700110// ---------------------------------------------------------------------------
111
Jason Samsffe9f482009-06-01 17:45:53 -0700112static jfieldID gContextId = 0;
113static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -0700114static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700115
116static void _nInit(JNIEnv *_env, jclass _this)
117{
Jason Samsd19f10d2009-05-22 14:03:28 -0700118 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -0700119
120 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
121 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
Jason Samsd19f10d2009-05-22 14:03:28 -0700122}
123
Jason Samsd19f10d2009-05-22 14:03:28 -0700124// ---------------------------------------------------------------------------
125
Jason Sams3eaa338e2009-06-10 15:04:38 -0700126static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700127nContextFinish(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700128{
Jason Sams96ed4cf2010-06-15 12:15:57 -0700129 LOG_API("nContextFinish, con(%p)", con);
130 rsContextFinish(con);
131}
132
133static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700134nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700135{
Jason Sams07ae4062009-08-27 20:23:34 -0700136 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700137 jint len = _env->GetArrayLength(str);
138 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsbc948de2009-08-17 18:35:48 -0700139 rsAssignName(con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700140 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
141}
142
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700143static jstring
Jason Sams2e1872f2010-08-17 16:25:41 -0700144nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700145{
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700146 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700147 const char *name = NULL;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700148 rsaGetName(con, (void *)obj, &name);
149 if(name == NULL || strlen(name) == 0) {
150 return NULL;
151 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700152 return _env->NewStringUTF(name);
153}
154
Jason Sams7ce033d2009-08-18 14:14:24 -0700155static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700156nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700157{
Jason Sams7ce033d2009-08-18 14:14:24 -0700158 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
Jason Sams9c25aee2010-10-14 17:57:30 -0700159 rsObjDestroy(con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700160}
161
Jason Sams3eaa338e2009-06-10 15:04:38 -0700162// ---------------------------------------------------------------------------
163
Jason Samsd19f10d2009-05-22 14:03:28 -0700164static jint
165nDeviceCreate(JNIEnv *_env, jobject _this)
166{
167 LOG_API("nDeviceCreate");
168 return (jint)rsDeviceCreate();
169}
170
171static void
172nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
173{
174 LOG_API("nDeviceDestroy");
175 return rsDeviceDestroy((RsDevice)dev);
176}
177
Jason Samsebfb4362009-09-23 13:57:02 -0700178static void
179nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
180{
181 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
182 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
183}
184
Jason Samsd19f10d2009-05-22 14:03:28 -0700185static jint
Stephen Hines4382467a2011-08-01 15:02:34 -0700186nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700187{
188 LOG_API("nContextCreate");
Stephen Hines4382467a2011-08-01 15:02:34 -0700189 return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer);
Jason Sams704ff642010-02-09 16:05:07 -0800190}
191
192static jint
Stephen Hines4382467a2011-08-01 15:02:34 -0700193nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700194 int colorMin, int colorPref,
195 int alphaMin, int alphaPref,
196 int depthMin, int depthPref,
197 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700198 int samplesMin, int samplesPref, float samplesQ,
199 int dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800200{
Jason Sams11c8af92010-10-13 15:31:10 -0700201 RsSurfaceConfig sc;
202 sc.alphaMin = alphaMin;
203 sc.alphaPref = alphaPref;
204 sc.colorMin = colorMin;
205 sc.colorPref = colorPref;
206 sc.depthMin = depthMin;
207 sc.depthPref = depthPref;
208 sc.samplesMin = samplesMin;
209 sc.samplesPref = samplesPref;
210 sc.samplesQ = samplesQ;
211
Jason Sams704ff642010-02-09 16:05:07 -0800212 LOG_API("nContextCreateGL");
Stephen Hines4382467a2011-08-01 15:02:34 -0700213 return (jint)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700214}
215
216static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700217nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800218{
Jason Sams7d787b42009-11-15 12:14:26 -0800219 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
220 rsContextSetPriority(con, p);
221}
222
223
224
225static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700226nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800227{
Jason Sams3bc47d42009-11-12 15:10:25 -0800228 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800229
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700230 ANativeWindow * window = NULL;
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800231 if (wnd == NULL) {
232
233 } else {
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700234 window = android_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800235 }
236
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700237 rsContextSetSurface(con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800238}
239
240static void
Jason Samsfaa32b32011-06-20 16:58:04 -0700241nContextSetSurfaceTexture(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject sur)
242{
243 LOG_API("nContextSetSurfaceTexture, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)sur);
244
245 sp<ANativeWindow> window;
246 sp<SurfaceTexture> st;
247 if (sur == 0) {
248
249 } else {
250 st = SurfaceTexture_getSurfaceTexture(_env, sur);
251 window = new SurfaceTextureClient(st);
252 }
253
254 rsContextSetSurface(con, width, height, window.get());
255}
256
257static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700258nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700259{
Jason Sams2e1872f2010-08-17 16:25:41 -0700260 LOG_API("nContextDestroy, con(%p)", con);
261 rsContextDestroy(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700262}
263
Jason Sams715333b2009-11-17 17:26:46 -0800264static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700265nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800266{
Jason Sams715333b2009-11-17 17:26:46 -0800267 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
268 rsContextDump((RsContext)con, bits);
269}
Jason Samsd19f10d2009-05-22 14:03:28 -0700270
271static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700272nContextPause(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700273{
Jason Sams65e7aa52009-09-24 17:38:20 -0700274 LOG_API("nContextPause, con(%p)", con);
275 rsContextPause(con);
276}
277
278static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700279nContextResume(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700280{
Jason Sams65e7aa52009-09-24 17:38:20 -0700281 LOG_API("nContextResume, con(%p)", con);
282 rsContextResume(con);
283}
284
Jason Sams1c415172010-11-08 17:06:46 -0800285
286static jstring
287nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
288{
289 LOG_API("nContextGetErrorMessage, con(%p)", con);
290 char buf[1024];
291
292 size_t receiveLen;
293 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700294 int id = rsContextGetMessage(con,
295 buf, sizeof(buf),
296 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700297 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800298 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100299 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800300 }
301 return _env->NewStringUTF(buf);
302}
303
Jason Samsedbfabd2011-05-17 15:01:29 -0700304static jint
Jason Sams1c415172010-11-08 17:06:46 -0800305nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700306{
Jason Sams516c3192009-10-06 13:58:47 -0700307 jint len = _env->GetArrayLength(data);
308 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
309 jint *ptr = _env->GetIntArrayElements(data, NULL);
310 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800311 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700312 int id = rsContextGetMessage(con,
313 ptr, len * 4,
314 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700315 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700316 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100317 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700318 }
319 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Samsedbfabd2011-05-17 15:01:29 -0700320 return id;
Jason Sams1c415172010-11-08 17:06:46 -0800321}
322
323static jint
Jason Samsedbfabd2011-05-17 15:01:29 -0700324nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800325{
326 LOG_API("nContextPeekMessage, con(%p)", con);
327 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
328 size_t receiveLen;
329 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700330 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700331 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800332 auxDataPtr[0] = (jint)subID;
333 auxDataPtr[1] = (jint)receiveLen;
334 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Jason Sams516c3192009-10-06 13:58:47 -0700335 return id;
336}
337
Jason Sams2e1872f2010-08-17 16:25:41 -0700338static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700339{
Jason Sams516c3192009-10-06 13:58:47 -0700340 LOG_API("nContextInitToClient, con(%p)", con);
341 rsContextInitToClient(con);
342}
343
Jason Sams2e1872f2010-08-17 16:25:41 -0700344static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700345{
Jason Sams516c3192009-10-06 13:58:47 -0700346 LOG_API("nContextDeinitToClient, con(%p)", con);
347 rsContextDeinitToClient(con);
348}
349
350
Jason Sams718cd1f2009-12-23 14:35:29 -0800351static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700352nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700353{
Jason Sams718cd1f2009-12-23 14:35:29 -0800354 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
355 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700356}
357
358static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800359nElementCreate2(JNIEnv *_env, jobject _this, RsContext con,
360 jintArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700361{
Jason Sams718cd1f2009-12-23 14:35:29 -0800362 int fieldCount = _env->GetArrayLength(_ids);
Jason Sams704ff642010-02-09 16:05:07 -0800363 LOG_API("nElementCreate2, con(%p)", con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800364
365 jint *ids = _env->GetIntArrayElements(_ids, NULL);
Jason Sams70d4e502010-09-02 17:35:23 -0700366 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
Jason Sams718cd1f2009-12-23 14:35:29 -0800367
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800368 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
369
370 const char **nameArray = names.c_str();
371 size_t *sizeArray = names.c_str_len();
372
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700373 jint id = (jint)rsElementCreate2(con,
374 (RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700375 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700376 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800377
Jason Sams718cd1f2009-12-23 14:35:29 -0800378 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
Jason Sams70d4e502010-09-02 17:35:23 -0700379 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
Jason Sams718cd1f2009-12-23 14:35:29 -0800380 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700381}
382
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700383static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700384nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700385{
386 int dataSize = _env->GetArrayLength(_elementData);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700387 LOG_API("nElementGetNativeData, con(%p)", con);
388
389 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
390 assert(dataSize == 5);
391
392 uint32_t elementData[5];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700393 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700394
395 for(jint i = 0; i < dataSize; i ++) {
396 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
397 }
398}
399
400
401static void
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700402nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
403 jintArray _IDs,
404 jobjectArray _names,
405 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700406{
407 int dataSize = _env->GetArrayLength(_IDs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700408 LOG_API("nElementGetSubElements, con(%p)", con);
409
410 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
411 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700412 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700413
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700414 rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700415
Jason Sams11c8af92010-10-13 15:31:10 -0700416 for(jint i = 0; i < dataSize; i++) {
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700417 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
418 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700419 _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700420 }
421
422 free(ids);
423 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700424 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700425}
426
Jason Samsd19f10d2009-05-22 14:03:28 -0700427// -----------------------------------
428
Jason Sams3b9c52a2010-10-14 17:48:46 -0700429static int
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800430nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
431 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces)
Jason Samsd19f10d2009-05-22 14:03:28 -0700432{
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800433 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
434 con, eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700435
Jason Samsc5765372011-04-28 18:26:48 -0700436 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700437 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700438}
439
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700440static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700441nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700442{
443 // We are packing 6 items: mDimX; mDimY; mDimZ;
444 // mDimLOD; mDimFaces; mElement; into typeData
445 int elementCount = _env->GetArrayLength(_typeData);
446
447 assert(elementCount == 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700448 LOG_API("nTypeCreate, con(%p)", con);
449
450 uint32_t typeData[6];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700451 rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700452
453 for(jint i = 0; i < elementCount; i ++) {
454 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
455 }
456}
457
Jason Samsd19f10d2009-05-22 14:03:28 -0700458// -----------------------------------
459
460static jint
Jason Sams857d0c72011-11-23 15:02:15 -0800461nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700462{
Jason Sams857d0c72011-11-23 15:02:15 -0800463 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer);
464 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700465}
466
Jason Samsd19f10d2009-05-22 14:03:28 -0700467static void
Jason Sams5476b452010-12-08 16:14:36 -0800468nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
469{
470 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
471 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
472}
473
Jason Sams615e7ce2012-01-13 14:01:20 -0800474static jint
475nAllocationGetSurfaceTextureID(JNIEnv *_env, jobject _this, RsContext con, jint a)
476{
477 LOG_API("nAllocationGetSurfaceTextureID, con(%p), a(%p)", con, (RsAllocation)a);
478 return rsAllocationGetSurfaceTextureID(con, (RsAllocation)a);
479}
480
Jason Samsf7086092011-01-12 13:28:37 -0800481static void
Jason Sams163766c2012-02-15 12:04:24 -0800482nAllocationSetSurfaceTexture(JNIEnv *_env, jobject _this, RsContext con,
483 RsAllocation alloc, jobject sur)
484{
485 LOG_API("nAllocationSetSurfaceTexture, con(%p), alloc(%p), surface(%p)",
486 con, alloc, (Surface *)sur);
487
488 sp<ANativeWindow> window;
489 if (sur != 0) {
490 sp<SurfaceTexture> st = SurfaceTexture_getSurfaceTexture(_env, sur);
491 window = new SurfaceTextureClient(st);
492 }
493
494 rsAllocationSetSurface(con, alloc, window.get());
495}
496
497static void
498nAllocationIoSend(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
499{
500 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", con, alloc);
501 rsAllocationIoSend(con, alloc);
502}
503
504static void
505nAllocationIoReceive(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
506{
507 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", con, alloc);
508 rsAllocationIoReceive(con, alloc);
509}
510
511
512static void
Jason Samsf7086092011-01-12 13:28:37 -0800513nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
514{
515 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
516 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
517}
518
Jason Samsffe9f482009-06-01 17:45:53 -0700519static int
Jason Sams5476b452010-12-08 16:14:36 -0800520nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700521{
Jason Samsffe9f482009-06-01 17:45:53 -0700522 SkBitmap const * nativeBitmap =
523 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
524 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700525
Jason Sams5476b452010-12-08 16:14:36 -0800526 bitmap.lockPixels();
527 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700528 jint id = (jint)rsAllocationCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700529 (RsType)type, (RsAllocationMipmapControl)mip,
530 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800531 bitmap.unlockPixels();
532 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700533}
Jason Samsfe08d992009-05-27 14:45:32 -0700534
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800535static int
Jason Sams5476b452010-12-08 16:14:36 -0800536nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800537{
538 SkBitmap const * nativeBitmap =
539 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
540 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800541
Jason Sams5476b452010-12-08 16:14:36 -0800542 bitmap.lockPixels();
543 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700544 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700545 (RsType)type, (RsAllocationMipmapControl)mip,
546 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800547 bitmap.unlockPixels();
548 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800549}
550
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700551static void
Jason Sams4ef66502010-12-10 16:03:15 -0800552nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700553{
554 SkBitmap const * nativeBitmap =
555 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
556 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800557 int w = bitmap.width();
558 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700559
Jason Sams4ef66502010-12-10 16:03:15 -0800560 bitmap.lockPixels();
561 const void* ptr = bitmap.getPixels();
Jason Samsf7086092011-01-12 13:28:37 -0800562 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700563 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Jason Samsf7086092011-01-12 13:28:37 -0800564 w, h, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800565 bitmap.unlockPixels();
566}
567
568static void
569nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
570{
571 SkBitmap const * nativeBitmap =
572 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
573 const SkBitmap& bitmap(*nativeBitmap);
574
575 bitmap.lockPixels();
576 void* ptr = bitmap.getPixels();
577 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
578 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700579 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700580}
581
Jason Sams8a647432010-03-01 15:31:04 -0800582static void ReleaseBitmapCallback(void *bmp)
583{
584 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
585 nativeBitmap->unlockPixels();
586}
587
Romain Guy650a3eb2009-08-31 14:06:43 -0700588
Jason Samsd19f10d2009-05-22 14:03:28 -0700589static void
Jason Sams49a05d72010-12-29 14:31:29 -0800590nAllocationData1D_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 -0700591{
Jason Samsd19f10d2009-05-22 14:03:28 -0700592 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800593 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 -0700594 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800595 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700596 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
597}
598
599static void
Jason Sams49a05d72010-12-29 14:31:29 -0800600nAllocationData1D_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 -0700601{
Jason Sams768bc022009-09-21 19:41:04 -0700602 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800603 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 -0700604 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800605 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700606 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
607}
608
609static void
Jason Sams49a05d72010-12-29 14:31:29 -0800610nAllocationData1D_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 -0700611{
Jason Sams768bc022009-09-21 19:41:04 -0700612 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800613 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 -0700614 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800615 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700616 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
617}
618
619static void
Jason Sams49a05d72010-12-29 14:31:29 -0800620nAllocationData1D_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 -0700621{
Jason Samsd19f10d2009-05-22 14:03:28 -0700622 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800623 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 -0700624 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800625 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700626 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
627}
628
629static void
Jason Sams49a05d72010-12-29 14:31:29 -0800630// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
631nAllocationElementData1D(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 -0700632{
633 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800634 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 -0700635 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Stephen Hines4cbe25a2012-01-18 18:46:27 -0800636 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700637 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
638}
639
640static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800641nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
642 jint w, jint h, jshortArray data, int sizeBytes)
643{
644 jint len = _env->GetArrayLength(data);
645 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);
646 jshort *ptr = _env->GetShortArrayElements(data, NULL);
647 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
648 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
649}
650
651static void
652nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
653 jint w, jint h, jbyteArray data, int sizeBytes)
654{
655 jint len = _env->GetArrayLength(data);
656 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);
657 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
658 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
659 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
660}
661
662static void
Jason Sams49a05d72010-12-29 14:31:29 -0800663nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
664 jint w, jint h, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700665{
Jason Samsd19f10d2009-05-22 14:03:28 -0700666 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800667 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 -0700668 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800669 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700670 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
671}
672
673static void
Jason Sams49a05d72010-12-29 14:31:29 -0800674nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
675 jint w, jint h, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700676{
Jason Samsd19f10d2009-05-22 14:03:28 -0700677 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800678 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 -0700679 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800680 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700681 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
682}
683
Jason Sams40a29e82009-08-10 14:55:26 -0700684static void
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700685nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
686 jint dstAlloc, jint dstXoff, jint dstYoff,
687 jint dstMip, jint dstFace,
688 jint width, jint height,
689 jint srcAlloc, jint srcXoff, jint srcYoff,
690 jint srcMip, jint srcFace)
691{
Jason Sams4c2e4c82012-02-07 15:32:08 -0800692 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700693 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
694 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
695 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
696 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
697
698 rsAllocationCopy2DRange(con,
699 (RsAllocation)dstAlloc,
700 dstXoff, dstYoff,
701 dstMip, dstFace,
702 width, height,
703 (RsAllocation)srcAlloc,
704 srcXoff, srcYoff,
705 srcMip, srcFace);
706}
707
708static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700709nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700710{
Jason Sams40a29e82009-08-10 14:55:26 -0700711 jint len = _env->GetArrayLength(data);
712 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
713 jint *ptr = _env->GetIntArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700714 jsize length = _env->GetArrayLength(data);
715 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Joe Onoratoae209ac2009-08-31 17:23:53 -0700716 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700717}
718
719static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800720nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
721{
722 jint len = _env->GetArrayLength(data);
723 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
724 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700725 jsize length = _env->GetArrayLength(data);
726 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800727 _env->ReleaseShortArrayElements(data, ptr, 0);
728}
729
730static void
731nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
732{
733 jint len = _env->GetArrayLength(data);
734 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
735 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700736 jsize length = _env->GetArrayLength(data);
737 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800738 _env->ReleaseByteArrayElements(data, ptr, 0);
739}
740
741static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700742nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700743{
Jason Sams40a29e82009-08-10 14:55:26 -0700744 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700745 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700746 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700747 jsize length = _env->GetArrayLength(data);
748 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Joe Onoratoae209ac2009-08-31 17:23:53 -0700749 _env->ReleaseFloatArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700750}
Jason Samsd19f10d2009-05-22 14:03:28 -0700751
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700752static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700753nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700754{
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700755 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700756 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700757}
758
Jason Sams5edc6082010-10-05 13:32:49 -0700759static void
760nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
761{
762 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
763 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
764}
765
766static void
767nAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY)
768{
769 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY);
770 rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY);
771}
772
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700773// -----------------------------------
774
775static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700776nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700777{
Steve Block71f2cf12011-10-20 11:56:00 +0100778 ALOGV("______nFileA3D %u", (uint32_t) native_asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700779
780 Asset* asset = reinterpret_cast<Asset*>(native_asset);
781
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800782 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
783 return id;
784}
785
786static int
787nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
788{
789 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
790 if (mgr == NULL) {
791 return 0;
792 }
793
794 AutoJavaStringToUTF8 str(_env, _path);
795 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
796 if (asset == NULL) {
797 return 0;
798 }
799
800 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
801 return id;
802}
803
804static int
805nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
806{
807 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
808 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
809
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700810 return id;
811}
812
813static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700814nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700815{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700816 int32_t numEntries = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700817 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700818 return numEntries;
819}
820
821static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700822nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700823{
Steve Block71f2cf12011-10-20 11:56:00 +0100824 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700825 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
826
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700827 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700828
829 for(jint i = 0; i < numEntries; i ++) {
830 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
831 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
832 }
833
834 free(fileEntries);
835}
836
837static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700838nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700839{
Steve Block71f2cf12011-10-20 11:56:00 +0100840 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700841 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700842 return id;
843}
Jason Samsd19f10d2009-05-22 14:03:28 -0700844
845// -----------------------------------
846
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700847static int
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800848nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
849 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700850{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800851 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700852 jint id = (jint)rsFontCreateFromFile(con,
853 fileNameUTF.c_str(), fileNameUTF.length(),
854 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700855
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800856 return id;
857}
858
859static int
860nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
861 jstring name, jfloat fontSize, jint dpi, jint native_asset)
862{
863 Asset* asset = reinterpret_cast<Asset*>(native_asset);
864 AutoJavaStringToUTF8 nameUTF(_env, name);
865
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700866 jint id = (jint)rsFontCreateFromMemory(con,
867 nameUTF.c_str(), nameUTF.length(),
868 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800869 asset->getBuffer(false), asset->getLength());
870 return id;
871}
872
873static int
874nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
875 jfloat fontSize, jint dpi)
876{
877 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
878 if (mgr == NULL) {
879 return 0;
880 }
881
882 AutoJavaStringToUTF8 str(_env, _path);
883 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
884 if (asset == NULL) {
885 return 0;
886 }
887
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700888 jint id = (jint)rsFontCreateFromMemory(con,
889 str.c_str(), str.length(),
890 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800891 asset->getBuffer(false), asset->getLength());
892 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700893 return id;
894}
895
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700896// -----------------------------------
897
898static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700899nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700900{
Jason Samsd19f10d2009-05-22 14:03:28 -0700901 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700902 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700903}
904
905static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700906nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700907{
Jason Samscfc04362010-09-14 14:59:03 -0700908 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700909 rsScriptSetVarI(con, (RsScript)script, slot, val);
910}
911
912static void
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800913nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
914{
915 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
916 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
917}
918
919static void
Stephen Hines031ec58c2010-10-11 10:54:21 -0700920nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
921{
922 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
923 rsScriptSetVarJ(con, (RsScript)script, slot, val);
924}
925
926static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700927nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700928{
Stephen Hinesca54ec32010-09-20 17:20:30 -0700929 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700930 rsScriptSetVarF(con, (RsScript)script, slot, val);
931}
932
933static void
Stephen Hinesca54ec32010-09-20 17:20:30 -0700934nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
935{
936 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
937 rsScriptSetVarD(con, (RsScript)script, slot, val);
938}
939
940static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700941nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700942{
Jason Sams4d339932010-05-11 14:03:58 -0700943 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
944 jint len = _env->GetArrayLength(data);
945 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
946 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
947 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
948}
949
Jason Samsd19f10d2009-05-22 14:03:28 -0700950
951static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700952nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -0700953{
Jason Sams07ae4062009-08-27 20:23:34 -0700954 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -0700955
956 jint length = _env->GetArrayLength(timeZone);
957 jbyte* timeZone_ptr;
958 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
959
Jason Samsbc948de2009-08-17 18:35:48 -0700960 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -0700961
962 if (timeZone_ptr) {
963 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
964 }
965}
966
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700967static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700968nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -0700969{
Jason Samsbe2e8412009-09-16 15:04:38 -0700970 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
971 rsScriptInvoke(con, (RsScript)obj, slot);
972}
973
974static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700975nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700976{
Jason Sams4d339932010-05-11 14:03:58 -0700977 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
978 jint len = _env->GetArrayLength(data);
979 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
980 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
981 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
982}
983
Jason Sams6e494d32011-04-27 16:33:11 -0700984static void
985nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
986 jint script, jint slot, jint ain, jint aout)
987{
988 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
989 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0);
990}
991static void
992nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
993 jint script, jint slot, jint ain, jint aout, jbyteArray params)
994{
995 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
996 jint len = _env->GetArrayLength(params);
997 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
998 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len);
999 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1000}
1001
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001002
Jason Sams22534172009-08-04 16:58:20 -07001003// -----------------------------------
1004
Jason Samse4a06c52011-03-16 16:29:28 -07001005static jint
1006nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
1007 jstring resName, jstring cacheDir,
1008 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001009{
Jason Samse4a06c52011-03-16 16:29:28 -07001010 LOG_API("nScriptCCreate, con(%p)", con);
Jason Sams22534172009-08-04 16:58:20 -07001011
Jason Samse4a06c52011-03-16 16:29:28 -07001012 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1013 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
1014 jint ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -07001015 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -07001016 jint _exception = 0;
1017 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001018 if (!scriptRef) {
1019 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001020 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001021 goto exit;
1022 }
Jack Palevich43702d82009-05-28 13:38:16 -07001023 if (length < 0) {
1024 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001025 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001026 goto exit;
1027 }
Jason Samse4a06c52011-03-16 16:29:28 -07001028 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001029 if (remaining < length) {
1030 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001031 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1032 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001033 goto exit;
1034 }
Jason Samse4a06c52011-03-16 16:29:28 -07001035 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001036 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001037
Jason Samse4a06c52011-03-16 16:29:28 -07001038 //rsScriptCSetText(con, (const char *)script_ptr, length);
1039
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001040 ret = (jint)rsScriptCCreate(con,
1041 resNameUTF.c_str(), resNameUTF.length(),
1042 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001043 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001044
Jack Palevich43702d82009-05-28 13:38:16 -07001045exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001046 if (script_ptr) {
1047 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001048 _exception ? JNI_ABORT: 0);
1049 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001050
Jason Samse4a06c52011-03-16 16:29:28 -07001051 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001052}
1053
1054// ---------------------------------------------------------------------------
1055
Jason Samsd19f10d2009-05-22 14:03:28 -07001056static jint
Jason Sams331bf9b2011-04-06 11:23:54 -07001057nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
1058 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1059 jboolean depthMask, jboolean ditherEnable,
1060 jint srcFunc, jint destFunc,
1061 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001062{
Jason Sams54db59c2010-05-13 18:30:11 -07001063 LOG_API("nProgramStoreCreate, con(%p)", con);
Jason Sams331bf9b2011-04-06 11:23:54 -07001064 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
1065 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1066 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001067}
1068
Jason Sams0011bcf2009-12-15 12:58:36 -08001069// ---------------------------------------------------------------------------
1070
1071static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001072nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001073{
Jason Sams0011bcf2009-12-15 12:58:36 -08001074 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
1075 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
1076}
Jason Sams54c0ec12009-11-30 14:49:55 -08001077
Jason Sams68afd012009-12-17 16:55:08 -08001078static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001079nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001080{
Jason Sams68afd012009-12-17 16:55:08 -08001081 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1082 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1083}
1084
1085static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001086nProgramBindSampler(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("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1089 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1090}
1091
Jason Samsd19f10d2009-05-22 14:03:28 -07001092// ---------------------------------------------------------------------------
1093
Jason Samsd19f10d2009-05-22 14:03:28 -07001094static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001095nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1096 jobjectArray texNames, jintArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001097{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001098 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001099 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1100 jint paramLen = _env->GetArrayLength(params);
1101
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001102 int texCount = _env->GetArrayLength(texNames);
1103 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1104 const char ** nameArray = names.c_str();
1105 size_t* sizeArray = names.c_str_len();
1106
Jason Sams991040c2011-01-17 15:59:39 -08001107 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001108
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001109 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1110 nameArray, texCount, sizeArray,
1111 (uint32_t *)paramPtr, paramLen);
1112
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001113 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1114 return ret;
1115}
1116
1117
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001118// ---------------------------------------------------------------------------
1119
Jason Sams0011bcf2009-12-15 12:58:36 -08001120static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001121nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1122 jobjectArray texNames, jintArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001123{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001124 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams0011bcf2009-12-15 12:58:36 -08001125 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1126 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001127
Jason Sams991040c2011-01-17 15:59:39 -08001128 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001129
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001130 int texCount = _env->GetArrayLength(texNames);
1131 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1132 const char ** nameArray = names.c_str();
1133 size_t* sizeArray = names.c_str_len();
1134
1135 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1136 nameArray, texCount, sizeArray,
1137 (uint32_t *)paramPtr, paramLen);
1138
Jason Sams0011bcf2009-12-15 12:58:36 -08001139 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1140 return ret;
1141}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001142
Jason Samsebfb4362009-09-23 13:57:02 -07001143// ---------------------------------------------------------------------------
1144
1145static jint
Jason Sams94aaed32011-09-23 14:18:53 -07001146nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001147{
Jason Sams94aaed32011-09-23 14:18:53 -07001148 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", con, pointSprite, cull);
1149 return (jint)rsProgramRasterCreate(con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001150}
1151
Jason Samsd19f10d2009-05-22 14:03:28 -07001152
1153// ---------------------------------------------------------------------------
1154
1155static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001156nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001157{
Jason Samsd19f10d2009-05-22 14:03:28 -07001158 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001159 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001160}
1161
1162static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001163nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001164{
Jason Sams54db59c2010-05-13 18:30:11 -07001165 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1166 rsContextBindProgramStore(con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001167}
1168
1169static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001170nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001171{
Jason Samsd19f10d2009-05-22 14:03:28 -07001172 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001173 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001174}
1175
Jason Sams0826a6f2009-06-15 19:04:56 -07001176static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001177nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001178{
Jason Sams0826a6f2009-06-15 19:04:56 -07001179 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001180 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001181}
1182
Joe Onoratod7b37742009-08-09 22:57:44 -07001183static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001184nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001185{
Jason Samsebfb4362009-09-23 13:57:02 -07001186 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1187 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1188}
1189
Joe Onoratod7b37742009-08-09 22:57:44 -07001190
Jason Sams02fb2cb2009-05-28 15:37:57 -07001191// ---------------------------------------------------------------------------
1192
Jason Sams02fb2cb2009-05-28 15:37:57 -07001193static jint
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001194nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1195 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001196{
Jason Samsbba134c2009-06-22 15:49:21 -07001197 LOG_API("nSamplerCreate, con(%p)", con);
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001198 return (jint)rsSamplerCreate(con,
1199 (RsSamplerValue)magFilter,
1200 (RsSamplerValue)minFilter,
1201 (RsSamplerValue)wrapS,
1202 (RsSamplerValue)wrapT,
1203 (RsSamplerValue)wrapR,
1204 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001205}
1206
Jason Samsbba134c2009-06-22 15:49:21 -07001207// ---------------------------------------------------------------------------
1208
Jason Samsf15ed012011-10-31 13:23:43 -07001209//native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
1210static jint
1211nPathCreate(JNIEnv *_env, jobject _this, RsContext con, jint prim, jboolean isStatic, jint _vtx, jint _loop, jfloat q) {
1212 LOG_API("nPathCreate, con(%p)", con);
1213
1214 int id = (int)rsPathCreate(con, (RsPathPrimitive)prim, isStatic,
1215 (RsAllocation)_vtx,
1216 (RsAllocation)_loop, q);
1217 return id;
1218}
1219
Jason Samsbba134c2009-06-22 15:49:21 -07001220static jint
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001221nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001222{
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001223 LOG_API("nMeshCreate, con(%p)", con);
1224
1225 jint vtxLen = _env->GetArrayLength(_vtx);
1226 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
1227 jint idxLen = _env->GetArrayLength(_idx);
1228 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
1229 jint primLen = _env->GetArrayLength(_prim);
1230 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1231
1232 int id = (int)rsMeshCreate(con,
1233 (RsAllocation *)vtxPtr, vtxLen,
1234 (RsAllocation *)idxPtr, idxLen,
1235 (uint32_t *)primPtr, primLen);
1236
1237 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
1238 _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
1239 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001240 return id;
1241}
1242
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001243static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001244nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001245{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001246 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1247 jint vtxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001248 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001249 return vtxCount;
1250}
1251
1252static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001253nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001254{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001255 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1256 jint idxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001257 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001258 return idxCount;
1259}
1260
1261static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001262nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001263{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001264 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1265
1266 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001267 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001268
1269 for(jint i = 0; i < numVtxIDs; i ++) {
1270 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1271 }
1272
1273 free(allocs);
1274}
1275
1276static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001277nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001278{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001279 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1280
1281 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1282 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1283
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001284 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001285
1286 for(jint i = 0; i < numIndices; i ++) {
1287 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1288 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1289 }
1290
1291 free(allocs);
1292 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001293}
1294
1295// ---------------------------------------------------------------------------
1296
Jason Samsd19f10d2009-05-22 14:03:28 -07001297
Jason Sams94d8e90a2009-06-10 16:09:05 -07001298static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001299
1300static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001301{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001302
Jason Sams1c415172010-11-08 17:06:46 -08001303{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1304{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1305{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
Jason Samsedbfabd2011-05-17 15:01:29 -07001306{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001307{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
Jason Samsedbfabd2011-05-17 15:01:29 -07001308{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001309
1310{"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1311{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001312
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001313
Jason Sams2e1872f2010-08-17 16:25:41 -07001314// All methods below are thread protected in java.
Stephen Hines4382467a2011-08-01 15:02:34 -07001315{"rsnContextCreate", "(III)I", (void*)nContextCreate },
1316{"rsnContextCreateGL", "(IIIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
Jason Sams2e1872f2010-08-17 16:25:41 -07001317{"rsnContextFinish", "(I)V", (void*)nContextFinish },
1318{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1319{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
Jason Samsfaa32b32011-06-20 16:58:04 -07001320{"rsnContextSetSurfaceTexture", "(IIILandroid/graphics/SurfaceTexture;)V", (void*)nContextSetSurfaceTexture },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001321{"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams2e1872f2010-08-17 16:25:41 -07001322{"rsnContextDump", "(II)V", (void*)nContextDump },
1323{"rsnContextPause", "(I)V", (void*)nContextPause },
1324{"rsnContextResume", "(I)V", (void*)nContextResume },
1325{"rsnAssignName", "(II[B)V", (void*)nAssignName },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001326{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
Jason Sams2e1872f2010-08-17 16:25:41 -07001327{"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001328
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001329{"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
Jason Sams2e1872f2010-08-17 16:25:41 -07001330{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001331{"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
Jason Sams2e1872f2010-08-17 16:25:41 -07001332{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001333{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Jason Sams2e1872f2010-08-17 16:25:41 -07001334{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001335
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -08001336{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001337{"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1338{"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001339
Jason Sams2e1872f2010-08-17 16:25:41 -07001340{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
Jason Sams70d4e502010-09-02 17:35:23 -07001341{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
Jason Sams2e1872f2010-08-17 16:25:41 -07001342{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001343{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001344
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001345{"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001346{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001347
Jason Sams857d0c72011-11-23 15:02:15 -08001348{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped },
Jason Sams5476b452010-12-08 16:14:36 -08001349{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
1350{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001351
Jason Sams4ef66502010-12-10 16:03:15 -08001352{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1353{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1354
Jason Sams5476b452010-12-08 16:14:36 -08001355{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
Jason Sams615e7ce2012-01-13 14:01:20 -08001356{"rsnAllocationGetSurfaceTextureID", "(II)I", (void*)nAllocationGetSurfaceTextureID },
Jason Sams163766c2012-02-15 12:04:24 -08001357{"rsnAllocationSetSurfaceTexture", "(IILandroid/graphics/SurfaceTexture;)V", (void*)nAllocationSetSurfaceTexture },
1358{"rsnAllocationIoSend", "(II)V", (void*)nAllocationIoSend },
1359{"rsnAllocationIoReceive", "(II)V", (void*)nAllocationIoReceive },
Jason Sams49a05d72010-12-29 14:31:29 -08001360{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i },
1361{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s },
1362{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b },
1363{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f },
1364{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
1365{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001366{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s },
1367{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b },
Jason Sams49a05d72010-12-29 14:31:29 -08001368{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f },
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001369{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc },
Jason Sams2e1872f2010-08-17 16:25:41 -07001370{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001371{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s },
1372{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b },
Jason Sams2e1872f2010-08-17 16:25:41 -07001373{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
Jason Sams2e1872f2010-08-17 16:25:41 -07001374{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
Jason Sams5edc6082010-10-05 13:32:49 -07001375{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
1376{"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D },
Jason Samsf7086092011-01-12 13:28:37 -08001377{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001378
Jason Sams2e1872f2010-08-17 16:25:41 -07001379{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1380{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1381{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1382{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
Jason Sams6e494d32011-04-27 16:33:11 -07001383{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1384{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
Jason Sams2e1872f2010-08-17 16:25:41 -07001385{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
Stephen Hines031ec58c2010-10-11 10:54:21 -07001386{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
Jason Sams2e1872f2010-08-17 16:25:41 -07001387{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
Stephen Hinesca54ec32010-09-20 17:20:30 -07001388{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
Jason Sams2e1872f2010-08-17 16:25:41 -07001389{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001390{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001391
Jason Samse4a06c52011-03-16 16:29:28 -07001392{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
Jason Sams0011bcf2009-12-15 12:58:36 -08001393
Jason Sams331bf9b2011-04-06 11:23:54 -07001394{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001395
Jason Sams2e1872f2010-08-17 16:25:41 -07001396{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1397{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1398{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001399
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001400{"rsnProgramFragmentCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate },
Jason Sams94aaed32011-09-23 14:18:53 -07001401{"rsnProgramRasterCreate", "(IZI)I", (void*)nProgramRasterCreate },
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001402{"rsnProgramVertexCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001403
Jason Sams2e1872f2010-08-17 16:25:41 -07001404{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001405{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
Jason Sams2e1872f2010-08-17 16:25:41 -07001406{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1407{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1408{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001409
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001410{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001411
Jason Samsf15ed012011-10-31 13:23:43 -07001412{"rsnPathCreate", "(IIZIIF)I", (void*)nPathCreate },
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001413{"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001414
1415{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1416{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001417{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
Jason Sams2e1872f2010-08-17 16:25:41 -07001418{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001419
Jason Samsd19f10d2009-05-22 14:03:28 -07001420};
1421
1422static int registerFuncs(JNIEnv *_env)
1423{
1424 return android::AndroidRuntime::registerNativeMethods(
1425 _env, classPathName, methods, NELEM(methods));
1426}
1427
1428// ---------------------------------------------------------------------------
1429
1430jint JNI_OnLoad(JavaVM* vm, void* reserved)
1431{
1432 JNIEnv* env = NULL;
1433 jint result = -1;
1434
Jason Samsd19f10d2009-05-22 14:03:28 -07001435 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001436 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001437 goto bail;
1438 }
1439 assert(env != NULL);
1440
1441 if (registerFuncs(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001442 ALOGE("ERROR: MediaPlayer native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001443 goto bail;
1444 }
1445
1446 /* success -- return valid version number */
1447 result = JNI_VERSION_1_4;
1448
1449bail:
1450 return result;
1451}