blob: 4a85faf7dd2e9bced11ff0997a891e65a72300cb [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
Jason Samsfaa32b32011-06-20 16:58:04 -07002 * Copyright (C) 2011 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
Romain Guy650a3eb2009-08-31 14:06:43 -070034#include <utils/Asset.h>
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080035#include <utils/AssetManager.h>
Romain Guy650a3eb2009-08-31 14:06:43 -070036#include <utils/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 Samse29d4712009-07-23 15:19:03 -070044#include <RenderScript.h>
45#include <RenderScriptEnv.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
50//#define LOG_API LOGE
51#define LOG_API(...)
52
53using namespace android;
54
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080055class AutoJavaStringToUTF8 {
56public:
57 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str)
58 {
59 fCStr = env->GetStringUTFChars(str, NULL);
60 fLength = env->GetStringUTFLength(str);
61 }
62 ~AutoJavaStringToUTF8()
63 {
64 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
65 }
66 const char* c_str() const { return fCStr; }
67 jsize length() const { return fLength; }
68
69private:
70 JNIEnv* fEnv;
71 jstring fJStr;
72 const char* fCStr;
73 jsize fLength;
74};
75
Jason Samsd19f10d2009-05-22 14:03:28 -070076// ---------------------------------------------------------------------------
77
Jason Samsffe9f482009-06-01 17:45:53 -070078static jfieldID gContextId = 0;
79static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -070080static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -070081
82static void _nInit(JNIEnv *_env, jclass _this)
83{
Jason Samsd19f10d2009-05-22 14:03:28 -070084 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -070085
86 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
87 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
Jason Samsd19f10d2009-05-22 14:03:28 -070088}
89
Jason Samsd19f10d2009-05-22 14:03:28 -070090// ---------------------------------------------------------------------------
91
Jason Sams3eaa338e2009-06-10 15:04:38 -070092static void
Jason Sams2e1872f2010-08-17 16:25:41 -070093nContextFinish(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams96ed4cf2010-06-15 12:15:57 -070094{
Jason Sams96ed4cf2010-06-15 12:15:57 -070095 LOG_API("nContextFinish, con(%p)", con);
96 rsContextFinish(con);
97}
98
99static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700100nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700101{
Jason Sams07ae4062009-08-27 20:23:34 -0700102 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700103 jint len = _env->GetArrayLength(str);
104 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsbc948de2009-08-17 18:35:48 -0700105 rsAssignName(con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700106 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
107}
108
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700109static jstring
Jason Sams2e1872f2010-08-17 16:25:41 -0700110nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700111{
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700112 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700113 const char *name = NULL;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700114 rsaGetName(con, (void *)obj, &name);
115 if(name == NULL || strlen(name) == 0) {
116 return NULL;
117 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700118 return _env->NewStringUTF(name);
119}
120
Jason Sams7ce033d2009-08-18 14:14:24 -0700121static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700122nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700123{
Jason Sams7ce033d2009-08-18 14:14:24 -0700124 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
Jason Sams9c25aee2010-10-14 17:57:30 -0700125 rsObjDestroy(con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700126}
127
Jason Sams3eaa338e2009-06-10 15:04:38 -0700128// ---------------------------------------------------------------------------
129
Jason Samsd19f10d2009-05-22 14:03:28 -0700130static jint
131nDeviceCreate(JNIEnv *_env, jobject _this)
132{
133 LOG_API("nDeviceCreate");
134 return (jint)rsDeviceCreate();
135}
136
137static void
138nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
139{
140 LOG_API("nDeviceDestroy");
141 return rsDeviceDestroy((RsDevice)dev);
142}
143
Jason Samsebfb4362009-09-23 13:57:02 -0700144static void
145nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
146{
147 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
148 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
149}
150
Jason Samsd19f10d2009-05-22 14:03:28 -0700151static jint
Jason Sams704ff642010-02-09 16:05:07 -0800152nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver)
Jason Samsd19f10d2009-05-22 14:03:28 -0700153{
154 LOG_API("nContextCreate");
Jason Sams704ff642010-02-09 16:05:07 -0800155 return (jint)rsContextCreate((RsDevice)dev, ver);
156}
157
158static jint
Jason Sams11c8af92010-10-13 15:31:10 -0700159nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver,
160 int colorMin, int colorPref,
161 int alphaMin, int alphaPref,
162 int depthMin, int depthPref,
163 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700164 int samplesMin, int samplesPref, float samplesQ,
165 int dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800166{
Jason Sams11c8af92010-10-13 15:31:10 -0700167 RsSurfaceConfig sc;
168 sc.alphaMin = alphaMin;
169 sc.alphaPref = alphaPref;
170 sc.colorMin = colorMin;
171 sc.colorPref = colorPref;
172 sc.depthMin = depthMin;
173 sc.depthPref = depthPref;
174 sc.samplesMin = samplesMin;
175 sc.samplesPref = samplesPref;
176 sc.samplesQ = samplesQ;
177
Jason Sams704ff642010-02-09 16:05:07 -0800178 LOG_API("nContextCreateGL");
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700179 return (jint)rsContextCreateGL((RsDevice)dev, ver, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700180}
181
182static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700183nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800184{
Jason Sams7d787b42009-11-15 12:14:26 -0800185 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
186 rsContextSetPriority(con, p);
187}
188
189
190
191static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700192nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800193{
Jason Sams3bc47d42009-11-12 15:10:25 -0800194 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800195
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700196 ANativeWindow * window = NULL;
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800197 if (wnd == NULL) {
198
199 } else {
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700200 window = android_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800201 }
202
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700203 rsContextSetSurface(con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800204}
205
206static void
Jason Samsfaa32b32011-06-20 16:58:04 -0700207nContextSetSurfaceTexture(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject sur)
208{
209 LOG_API("nContextSetSurfaceTexture, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)sur);
210
211 sp<ANativeWindow> window;
212 sp<SurfaceTexture> st;
213 if (sur == 0) {
214
215 } else {
216 st = SurfaceTexture_getSurfaceTexture(_env, sur);
217 window = new SurfaceTextureClient(st);
218 }
219
220 rsContextSetSurface(con, width, height, window.get());
221}
222
223static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700224nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700225{
Jason Sams2e1872f2010-08-17 16:25:41 -0700226 LOG_API("nContextDestroy, con(%p)", con);
227 rsContextDestroy(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700228}
229
Jason Sams715333b2009-11-17 17:26:46 -0800230static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700231nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800232{
Jason Sams715333b2009-11-17 17:26:46 -0800233 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
234 rsContextDump((RsContext)con, bits);
235}
Jason Samsd19f10d2009-05-22 14:03:28 -0700236
237static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700238nContextPause(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700239{
Jason Sams65e7aa52009-09-24 17:38:20 -0700240 LOG_API("nContextPause, con(%p)", con);
241 rsContextPause(con);
242}
243
244static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700245nContextResume(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700246{
Jason Sams65e7aa52009-09-24 17:38:20 -0700247 LOG_API("nContextResume, con(%p)", con);
248 rsContextResume(con);
249}
250
Jason Sams1c415172010-11-08 17:06:46 -0800251
252static jstring
253nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
254{
255 LOG_API("nContextGetErrorMessage, con(%p)", con);
256 char buf[1024];
257
258 size_t receiveLen;
259 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700260 int id = rsContextGetMessage(con,
261 buf, sizeof(buf),
262 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700263 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800264 if (!id && receiveLen) {
265 LOGV("message receive buffer too small. %i", receiveLen);
266 }
267 return _env->NewStringUTF(buf);
268}
269
Jason Samsedbfabd2011-05-17 15:01:29 -0700270static jint
Jason Sams1c415172010-11-08 17:06:46 -0800271nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700272{
Jason Sams516c3192009-10-06 13:58:47 -0700273 jint len = _env->GetArrayLength(data);
274 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
275 jint *ptr = _env->GetIntArrayElements(data, NULL);
276 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800277 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700278 int id = rsContextGetMessage(con,
279 ptr, len * 4,
280 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700281 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700282 if (!id && receiveLen) {
Jason Sams1d45c472010-08-25 14:31:48 -0700283 LOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700284 }
285 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Samsedbfabd2011-05-17 15:01:29 -0700286 return id;
Jason Sams1c415172010-11-08 17:06:46 -0800287}
288
289static jint
Jason Samsedbfabd2011-05-17 15:01:29 -0700290nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800291{
292 LOG_API("nContextPeekMessage, con(%p)", con);
293 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
294 size_t receiveLen;
295 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700296 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700297 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800298 auxDataPtr[0] = (jint)subID;
299 auxDataPtr[1] = (jint)receiveLen;
300 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Jason Sams516c3192009-10-06 13:58:47 -0700301 return id;
302}
303
Jason Sams2e1872f2010-08-17 16:25:41 -0700304static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700305{
Jason Sams516c3192009-10-06 13:58:47 -0700306 LOG_API("nContextInitToClient, con(%p)", con);
307 rsContextInitToClient(con);
308}
309
Jason Sams2e1872f2010-08-17 16:25:41 -0700310static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700311{
Jason Sams516c3192009-10-06 13:58:47 -0700312 LOG_API("nContextDeinitToClient, con(%p)", con);
313 rsContextDeinitToClient(con);
314}
315
316
Jason Sams718cd1f2009-12-23 14:35:29 -0800317static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700318nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700319{
Jason Sams718cd1f2009-12-23 14:35:29 -0800320 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
321 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700322}
323
324static jint
Jason Sams70d4e502010-09-02 17:35:23 -0700325nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700326{
Jason Sams718cd1f2009-12-23 14:35:29 -0800327 int fieldCount = _env->GetArrayLength(_ids);
Jason Sams704ff642010-02-09 16:05:07 -0800328 LOG_API("nElementCreate2, con(%p)", con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800329
330 jint *ids = _env->GetIntArrayElements(_ids, NULL);
Jason Sams70d4e502010-09-02 17:35:23 -0700331 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
Jason Sams718cd1f2009-12-23 14:35:29 -0800332 const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *));
333 size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t));
334
335 for (int ct=0; ct < fieldCount; ct++) {
336 jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
337 nameArray[ct] = _env->GetStringUTFChars(s, NULL);
338 sizeArray[ct] = _env->GetStringUTFLength(s);
339 }
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700340 jint id = (jint)rsElementCreate2(con,
341 (RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700342 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700343 (const uint32_t *)arraySizes, fieldCount);
Jason Sams718cd1f2009-12-23 14:35:29 -0800344 for (int ct=0; ct < fieldCount; ct++) {
345 jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
346 _env->ReleaseStringUTFChars(s, nameArray[ct]);
347 }
348 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
Jason Sams70d4e502010-09-02 17:35:23 -0700349 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
Jason Sams718cd1f2009-12-23 14:35:29 -0800350 free(nameArray);
351 free(sizeArray);
352 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700353}
354
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700355static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700356nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700357{
358 int dataSize = _env->GetArrayLength(_elementData);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700359 LOG_API("nElementGetNativeData, con(%p)", con);
360
361 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
362 assert(dataSize == 5);
363
364 uint32_t elementData[5];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700365 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700366
367 for(jint i = 0; i < dataSize; i ++) {
368 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
369 }
370}
371
372
373static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700374nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _IDs, jobjectArray _names)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700375{
376 int dataSize = _env->GetArrayLength(_IDs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700377 LOG_API("nElementGetSubElements, con(%p)", con);
378
379 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
380 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
381
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700382 rsaElementGetSubElements(con, (RsElement)id, ids, names, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700383
Jason Sams11c8af92010-10-13 15:31:10 -0700384 for(jint i = 0; i < dataSize; i++) {
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700385 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
386 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
387 }
388
389 free(ids);
390 free(names);
391}
392
Jason Samsd19f10d2009-05-22 14:03:28 -0700393// -----------------------------------
394
Jason Sams3b9c52a2010-10-14 17:48:46 -0700395static int
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800396nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
397 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces)
Jason Samsd19f10d2009-05-22 14:03:28 -0700398{
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800399 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
400 con, eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700401
Jason Samsc5765372011-04-28 18:26:48 -0700402 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700403 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700404}
405
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700406static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700407nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700408{
409 // We are packing 6 items: mDimX; mDimY; mDimZ;
410 // mDimLOD; mDimFaces; mElement; into typeData
411 int elementCount = _env->GetArrayLength(_typeData);
412
413 assert(elementCount == 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700414 LOG_API("nTypeCreate, con(%p)", con);
415
416 uint32_t typeData[6];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700417 rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700418
419 for(jint i = 0; i < elementCount; i ++) {
420 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
421 }
422}
423
Jason Samsd19f10d2009-05-22 14:03:28 -0700424// -----------------------------------
425
426static jint
Jason Sams5476b452010-12-08 16:14:36 -0800427nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage)
Jason Samsd19f10d2009-05-22 14:03:28 -0700428{
Jason Samsd4b23b52010-12-13 15:32:35 -0800429 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i)", con, (RsElement)type, mips, usage);
Jason Samsc5765372011-04-28 18:26:48 -0700430 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage);
Jason Samsd19f10d2009-05-22 14:03:28 -0700431}
432
Jason Samsd19f10d2009-05-22 14:03:28 -0700433static void
Jason Sams5476b452010-12-08 16:14:36 -0800434nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
435{
436 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
437 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
438}
439
Jason Samsf7086092011-01-12 13:28:37 -0800440static void
441nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
442{
443 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
444 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
445}
446
Jason Samsffe9f482009-06-01 17:45:53 -0700447static int
Jason Sams5476b452010-12-08 16:14:36 -0800448nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700449{
Jason Samsffe9f482009-06-01 17:45:53 -0700450 SkBitmap const * nativeBitmap =
451 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
452 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700453
Jason Sams5476b452010-12-08 16:14:36 -0800454 bitmap.lockPixels();
455 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700456 jint id = (jint)rsAllocationCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700457 (RsType)type, (RsAllocationMipmapControl)mip,
458 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800459 bitmap.unlockPixels();
460 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700461}
Jason Samsfe08d992009-05-27 14:45:32 -0700462
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800463static int
Jason Sams5476b452010-12-08 16:14:36 -0800464nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800465{
466 SkBitmap const * nativeBitmap =
467 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
468 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800469
Jason Sams5476b452010-12-08 16:14:36 -0800470 bitmap.lockPixels();
471 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700472 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700473 (RsType)type, (RsAllocationMipmapControl)mip,
474 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800475 bitmap.unlockPixels();
476 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800477}
478
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700479static void
Jason Sams4ef66502010-12-10 16:03:15 -0800480nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700481{
482 SkBitmap const * nativeBitmap =
483 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
484 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800485 int w = bitmap.width();
486 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700487
Jason Sams4ef66502010-12-10 16:03:15 -0800488 bitmap.lockPixels();
489 const void* ptr = bitmap.getPixels();
Jason Samsf7086092011-01-12 13:28:37 -0800490 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700491 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Jason Samsf7086092011-01-12 13:28:37 -0800492 w, h, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800493 bitmap.unlockPixels();
494}
495
496static void
497nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
498{
499 SkBitmap const * nativeBitmap =
500 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
501 const SkBitmap& bitmap(*nativeBitmap);
502
503 bitmap.lockPixels();
504 void* ptr = bitmap.getPixels();
505 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
506 bitmap.unlockPixels();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700507}
508
Jason Sams8a647432010-03-01 15:31:04 -0800509static void ReleaseBitmapCallback(void *bmp)
510{
511 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
512 nativeBitmap->unlockPixels();
513}
514
Romain Guy650a3eb2009-08-31 14:06:43 -0700515
Jason Samsd19f10d2009-05-22 14:03:28 -0700516static void
Jason Sams49a05d72010-12-29 14:31:29 -0800517nAllocationData1D_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 -0700518{
Jason Samsd19f10d2009-05-22 14:03:28 -0700519 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800520 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 -0700521 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800522 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700523 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
524}
525
526static void
Jason Sams49a05d72010-12-29 14:31:29 -0800527nAllocationData1D_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 -0700528{
Jason Sams768bc022009-09-21 19:41:04 -0700529 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800530 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 -0700531 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800532 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700533 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
534}
535
536static void
Jason Sams49a05d72010-12-29 14:31:29 -0800537nAllocationData1D_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 -0700538{
Jason Sams768bc022009-09-21 19:41:04 -0700539 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800540 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 -0700541 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800542 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700543 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
544}
545
546static void
Jason Sams49a05d72010-12-29 14:31:29 -0800547nAllocationData1D_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 -0700548{
Jason Samsd19f10d2009-05-22 14:03:28 -0700549 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800550 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 -0700551 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800552 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700553 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
554}
555
556static void
Jason Sams49a05d72010-12-29 14:31:29 -0800557// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
558nAllocationElementData1D(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 -0700559{
560 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800561 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 -0700562 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800563 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, compIdx, sizeBytes);
Jason Sams49bdaf02010-08-31 13:50:42 -0700564 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
565}
566
567static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800568nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
569 jint w, jint h, jshortArray data, int sizeBytes)
570{
571 jint len = _env->GetArrayLength(data);
572 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);
573 jshort *ptr = _env->GetShortArrayElements(data, NULL);
574 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
575 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
576}
577
578static void
579nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
580 jint w, jint h, jbyteArray data, int sizeBytes)
581{
582 jint len = _env->GetArrayLength(data);
583 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);
584 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
585 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
586 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
587}
588
589static void
Jason Sams49a05d72010-12-29 14:31:29 -0800590nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
591 jint w, jint h, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700592{
Jason Samsd19f10d2009-05-22 14:03:28 -0700593 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800594 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 -0700595 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800596 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700597 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
598}
599
600static void
Jason Sams49a05d72010-12-29 14:31:29 -0800601nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
602 jint w, jint h, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700603{
Jason Samsd19f10d2009-05-22 14:03:28 -0700604 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800605 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 -0700606 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800607 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700608 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
609}
610
Jason Sams40a29e82009-08-10 14:55:26 -0700611static void
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700612nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
613 jint dstAlloc, jint dstXoff, jint dstYoff,
614 jint dstMip, jint dstFace,
615 jint width, jint height,
616 jint srcAlloc, jint srcXoff, jint srcYoff,
617 jint srcMip, jint srcFace)
618{
619 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff, dstYoff,"
620 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
621 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
622 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
623 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
624
625 rsAllocationCopy2DRange(con,
626 (RsAllocation)dstAlloc,
627 dstXoff, dstYoff,
628 dstMip, dstFace,
629 width, height,
630 (RsAllocation)srcAlloc,
631 srcXoff, srcYoff,
632 srcMip, srcFace);
633}
634
635static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700636nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700637{
Jason Sams40a29e82009-08-10 14:55:26 -0700638 jint len = _env->GetArrayLength(data);
639 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
640 jint *ptr = _env->GetIntArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700641 jsize length = _env->GetArrayLength(data);
642 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Joe Onoratoae209ac2009-08-31 17:23:53 -0700643 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700644}
645
646static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800647nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
648{
649 jint len = _env->GetArrayLength(data);
650 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
651 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700652 jsize length = _env->GetArrayLength(data);
653 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800654 _env->ReleaseShortArrayElements(data, ptr, 0);
655}
656
657static void
658nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
659{
660 jint len = _env->GetArrayLength(data);
661 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
662 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700663 jsize length = _env->GetArrayLength(data);
664 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800665 _env->ReleaseByteArrayElements(data, ptr, 0);
666}
667
668static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700669nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700670{
Jason Sams40a29e82009-08-10 14:55:26 -0700671 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700672 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700673 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700674 jsize length = _env->GetArrayLength(data);
675 rsAllocationRead(con, (RsAllocation)alloc, ptr, length);
Joe Onoratoae209ac2009-08-31 17:23:53 -0700676 _env->ReleaseFloatArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700677}
Jason Samsd19f10d2009-05-22 14:03:28 -0700678
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700679static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700680nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700681{
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700682 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700683 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700684}
685
Jason Sams5edc6082010-10-05 13:32:49 -0700686static void
687nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
688{
689 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
690 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
691}
692
693static void
694nAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY)
695{
696 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY);
697 rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY);
698}
699
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700700// -----------------------------------
701
702static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700703nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700704{
705 LOGV("______nFileA3D %u", (uint32_t) native_asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700706
707 Asset* asset = reinterpret_cast<Asset*>(native_asset);
708
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800709 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
710 return id;
711}
712
713static int
714nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
715{
716 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
717 if (mgr == NULL) {
718 return 0;
719 }
720
721 AutoJavaStringToUTF8 str(_env, _path);
722 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
723 if (asset == NULL) {
724 return 0;
725 }
726
727 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
728 return id;
729}
730
731static int
732nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
733{
734 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
735 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
736
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700737 return id;
738}
739
740static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700741nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700742{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700743 int32_t numEntries = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700744 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700745 return numEntries;
746}
747
748static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700749nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700750{
751 LOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700752 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
753
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700754 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700755
756 for(jint i = 0; i < numEntries; i ++) {
757 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
758 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
759 }
760
761 free(fileEntries);
762}
763
764static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700765nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700766{
767 LOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700768 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700769 return id;
770}
Jason Samsd19f10d2009-05-22 14:03:28 -0700771
772// -----------------------------------
773
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700774static int
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800775nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
776 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700777{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800778 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700779 jint id = (jint)rsFontCreateFromFile(con,
780 fileNameUTF.c_str(), fileNameUTF.length(),
781 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700782
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800783 return id;
784}
785
786static int
787nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
788 jstring name, jfloat fontSize, jint dpi, jint native_asset)
789{
790 Asset* asset = reinterpret_cast<Asset*>(native_asset);
791 AutoJavaStringToUTF8 nameUTF(_env, name);
792
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700793 jint id = (jint)rsFontCreateFromMemory(con,
794 nameUTF.c_str(), nameUTF.length(),
795 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800796 asset->getBuffer(false), asset->getLength());
797 return id;
798}
799
800static int
801nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
802 jfloat fontSize, jint dpi)
803{
804 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
805 if (mgr == NULL) {
806 return 0;
807 }
808
809 AutoJavaStringToUTF8 str(_env, _path);
810 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
811 if (asset == NULL) {
812 return 0;
813 }
814
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700815 jint id = (jint)rsFontCreateFromMemory(con,
816 str.c_str(), str.length(),
817 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800818 asset->getBuffer(false), asset->getLength());
819 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700820 return id;
821}
822
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700823// -----------------------------------
824
825static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700826nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700827{
Jason Samsd19f10d2009-05-22 14:03:28 -0700828 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700829 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700830}
831
832static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700833nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700834{
Jason Samscfc04362010-09-14 14:59:03 -0700835 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700836 rsScriptSetVarI(con, (RsScript)script, slot, val);
837}
838
839static void
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800840nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
841{
842 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
843 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
844}
845
846static void
Stephen Hines031ec58c2010-10-11 10:54:21 -0700847nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
848{
849 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
850 rsScriptSetVarJ(con, (RsScript)script, slot, val);
851}
852
853static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700854nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700855{
Stephen Hinesca54ec32010-09-20 17:20:30 -0700856 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700857 rsScriptSetVarF(con, (RsScript)script, slot, val);
858}
859
860static void
Stephen Hinesca54ec32010-09-20 17:20:30 -0700861nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
862{
863 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
864 rsScriptSetVarD(con, (RsScript)script, slot, val);
865}
866
867static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700868nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700869{
Jason Sams4d339932010-05-11 14:03:58 -0700870 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
871 jint len = _env->GetArrayLength(data);
872 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
873 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
874 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
875}
876
Jason Samsd19f10d2009-05-22 14:03:28 -0700877
878static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700879nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -0700880{
Jason Sams07ae4062009-08-27 20:23:34 -0700881 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -0700882
883 jint length = _env->GetArrayLength(timeZone);
884 jbyte* timeZone_ptr;
885 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
886
Jason Samsbc948de2009-08-17 18:35:48 -0700887 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -0700888
889 if (timeZone_ptr) {
890 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
891 }
892}
893
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700894static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700895nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -0700896{
Jason Samsbe2e8412009-09-16 15:04:38 -0700897 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
898 rsScriptInvoke(con, (RsScript)obj, slot);
899}
900
901static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700902nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700903{
Jason Sams4d339932010-05-11 14:03:58 -0700904 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
905 jint len = _env->GetArrayLength(data);
906 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
907 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
908 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
909}
910
Jason Sams6e494d32011-04-27 16:33:11 -0700911static void
912nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
913 jint script, jint slot, jint ain, jint aout)
914{
915 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
916 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0);
917}
918static void
919nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
920 jint script, jint slot, jint ain, jint aout, jbyteArray params)
921{
922 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
923 jint len = _env->GetArrayLength(params);
924 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
925 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len);
926 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
927}
928
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700929
Jason Sams22534172009-08-04 16:58:20 -0700930// -----------------------------------
931
Jason Samse4a06c52011-03-16 16:29:28 -0700932static jint
933nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
934 jstring resName, jstring cacheDir,
935 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -0700936{
Jason Samse4a06c52011-03-16 16:29:28 -0700937 LOG_API("nScriptCCreate, con(%p)", con);
Jason Sams22534172009-08-04 16:58:20 -0700938
Jason Samse4a06c52011-03-16 16:29:28 -0700939 AutoJavaStringToUTF8 resNameUTF(_env, resName);
940 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
941 jint ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -0700942 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -0700943 jint _exception = 0;
944 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -0700945 if (!scriptRef) {
946 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -0700947 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -0700948 goto exit;
949 }
Jack Palevich43702d82009-05-28 13:38:16 -0700950 if (length < 0) {
951 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -0700952 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -0700953 goto exit;
954 }
Jason Samse4a06c52011-03-16 16:29:28 -0700955 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -0700956 if (remaining < length) {
957 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -0700958 //jniThrowException(_env, "java/lang/IllegalArgumentException",
959 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -0700960 goto exit;
961 }
Jason Samse4a06c52011-03-16 16:29:28 -0700962 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -0700963 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -0700964
Jason Samse4a06c52011-03-16 16:29:28 -0700965 //rsScriptCSetText(con, (const char *)script_ptr, length);
966
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700967 ret = (jint)rsScriptCCreate(con,
968 resNameUTF.c_str(), resNameUTF.length(),
969 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -0700970 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -0700971
Jack Palevich43702d82009-05-28 13:38:16 -0700972exit:
Jason Samse4a06c52011-03-16 16:29:28 -0700973 if (script_ptr) {
974 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -0700975 _exception ? JNI_ABORT: 0);
976 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700977
Jason Samse4a06c52011-03-16 16:29:28 -0700978 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -0700979}
980
981// ---------------------------------------------------------------------------
982
Jason Samsd19f10d2009-05-22 14:03:28 -0700983static jint
Jason Sams331bf9b2011-04-06 11:23:54 -0700984nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
985 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
986 jboolean depthMask, jboolean ditherEnable,
987 jint srcFunc, jint destFunc,
988 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -0700989{
Jason Sams54db59c2010-05-13 18:30:11 -0700990 LOG_API("nProgramStoreCreate, con(%p)", con);
Jason Sams331bf9b2011-04-06 11:23:54 -0700991 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
992 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
993 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -0700994}
995
Jason Sams0011bcf2009-12-15 12:58:36 -0800996// ---------------------------------------------------------------------------
997
998static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700999nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001000{
Jason Sams0011bcf2009-12-15 12:58:36 -08001001 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
1002 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
1003}
Jason Sams54c0ec12009-11-30 14:49:55 -08001004
Jason Sams68afd012009-12-17 16:55:08 -08001005static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001006nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001007{
Jason Sams68afd012009-12-17 16:55:08 -08001008 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1009 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1010}
1011
1012static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001013nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001014{
Jason Sams68afd012009-12-17 16:55:08 -08001015 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1016 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1017}
1018
Jason Samsd19f10d2009-05-22 14:03:28 -07001019// ---------------------------------------------------------------------------
1020
Jason Samsd19f10d2009-05-22 14:03:28 -07001021static jint
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001022nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001023{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001024 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001025 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1026 jint paramLen = _env->GetArrayLength(params);
1027
Jason Sams991040c2011-01-17 15:59:39 -08001028 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001029
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001030 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001031 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1032 return ret;
1033}
1034
1035
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001036// ---------------------------------------------------------------------------
1037
Jason Sams0011bcf2009-12-15 12:58:36 -08001038static jint
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001039nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001040{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001041 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams0011bcf2009-12-15 12:58:36 -08001042 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1043 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001044
Jason Sams991040c2011-01-17 15:59:39 -08001045 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001046
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001047 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001048 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1049 return ret;
1050}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001051
Jason Samsebfb4362009-09-23 13:57:02 -07001052// ---------------------------------------------------------------------------
1053
1054static jint
Jason Sams331bf9b2011-04-06 11:23:54 -07001055nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSmooth,
1056 jboolean lineSmooth, jboolean pointSprite, jfloat lineWidth, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001057{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001058 LOG_API("nProgramRasterCreate, con(%p), pointSmooth(%i), lineSmooth(%i), pointSprite(%i)",
1059 con, pointSmooth, lineSmooth, pointSprite);
Jason Sams331bf9b2011-04-06 11:23:54 -07001060 return (jint)rsProgramRasterCreate(con, pointSmooth, lineSmooth, pointSprite, lineWidth, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001061}
1062
Jason Samsd19f10d2009-05-22 14:03:28 -07001063
1064// ---------------------------------------------------------------------------
1065
1066static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001067nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001068{
Jason Samsd19f10d2009-05-22 14:03:28 -07001069 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001070 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001071}
1072
1073static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001074nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001075{
Jason Sams54db59c2010-05-13 18:30:11 -07001076 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1077 rsContextBindProgramStore(con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001078}
1079
1080static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001081nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001082{
Jason Samsd19f10d2009-05-22 14:03:28 -07001083 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001084 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001085}
1086
Jason Sams0826a6f2009-06-15 19:04:56 -07001087static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001088nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001089{
Jason Sams0826a6f2009-06-15 19:04:56 -07001090 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001091 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001092}
1093
Joe Onoratod7b37742009-08-09 22:57:44 -07001094static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001095nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001096{
Jason Samsebfb4362009-09-23 13:57:02 -07001097 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1098 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1099}
1100
Joe Onoratod7b37742009-08-09 22:57:44 -07001101
Jason Sams02fb2cb2009-05-28 15:37:57 -07001102// ---------------------------------------------------------------------------
1103
Jason Sams02fb2cb2009-05-28 15:37:57 -07001104static jint
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001105nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1106 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001107{
Jason Samsbba134c2009-06-22 15:49:21 -07001108 LOG_API("nSamplerCreate, con(%p)", con);
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001109 return (jint)rsSamplerCreate(con,
1110 (RsSamplerValue)magFilter,
1111 (RsSamplerValue)minFilter,
1112 (RsSamplerValue)wrapS,
1113 (RsSamplerValue)wrapT,
1114 (RsSamplerValue)wrapR,
1115 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001116}
1117
Jason Samsbba134c2009-06-22 15:49:21 -07001118// ---------------------------------------------------------------------------
1119
Jason Samsbba134c2009-06-22 15:49:21 -07001120static jint
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001121nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001122{
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001123 LOG_API("nMeshCreate, con(%p)", con);
1124
1125 jint vtxLen = _env->GetArrayLength(_vtx);
1126 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
1127 jint idxLen = _env->GetArrayLength(_idx);
1128 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
1129 jint primLen = _env->GetArrayLength(_prim);
1130 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1131
1132 int id = (int)rsMeshCreate(con,
1133 (RsAllocation *)vtxPtr, vtxLen,
1134 (RsAllocation *)idxPtr, idxLen,
1135 (uint32_t *)primPtr, primLen);
1136
1137 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
1138 _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
1139 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001140 return id;
1141}
1142
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001143static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001144nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001145{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001146 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1147 jint vtxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001148 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001149 return vtxCount;
1150}
1151
1152static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001153nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001154{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001155 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1156 jint idxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001157 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001158 return idxCount;
1159}
1160
1161static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001162nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001163{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001164 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1165
1166 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001167 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001168
1169 for(jint i = 0; i < numVtxIDs; i ++) {
1170 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1171 }
1172
1173 free(allocs);
1174}
1175
1176static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001177nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001178{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001179 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1180
1181 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1182 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1183
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001184 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001185
1186 for(jint i = 0; i < numIndices; i ++) {
1187 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1188 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1189 }
1190
1191 free(allocs);
1192 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001193}
1194
1195// ---------------------------------------------------------------------------
1196
Jason Samsd19f10d2009-05-22 14:03:28 -07001197
Jason Sams94d8e90a2009-06-10 16:09:05 -07001198static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001199
1200static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001201{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001202
Jason Sams1c415172010-11-08 17:06:46 -08001203{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1204{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1205{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
Jason Samsedbfabd2011-05-17 15:01:29 -07001206{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001207{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
Jason Samsedbfabd2011-05-17 15:01:29 -07001208{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001209
1210{"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1211{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001212
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001213
Jason Sams2e1872f2010-08-17 16:25:41 -07001214// All methods below are thread protected in java.
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001215{"rsnContextCreate", "(II)I", (void*)nContextCreate },
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -07001216{"rsnContextCreateGL", "(IIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
Jason Sams2e1872f2010-08-17 16:25:41 -07001217{"rsnContextFinish", "(I)V", (void*)nContextFinish },
1218{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1219{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
Jason Samsfaa32b32011-06-20 16:58:04 -07001220{"rsnContextSetSurfaceTexture", "(IIILandroid/graphics/SurfaceTexture;)V", (void*)nContextSetSurfaceTexture },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001221{"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams2e1872f2010-08-17 16:25:41 -07001222{"rsnContextDump", "(II)V", (void*)nContextDump },
1223{"rsnContextPause", "(I)V", (void*)nContextPause },
1224{"rsnContextResume", "(I)V", (void*)nContextResume },
1225{"rsnAssignName", "(II[B)V", (void*)nAssignName },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001226{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
Jason Sams2e1872f2010-08-17 16:25:41 -07001227{"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001228
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001229{"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
Jason Sams2e1872f2010-08-17 16:25:41 -07001230{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001231{"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
Jason Sams2e1872f2010-08-17 16:25:41 -07001232{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001233{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Jason Sams2e1872f2010-08-17 16:25:41 -07001234{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001235
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -08001236{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001237{"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1238{"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001239
Jason Sams2e1872f2010-08-17 16:25:41 -07001240{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
Jason Sams70d4e502010-09-02 17:35:23 -07001241{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
Jason Sams2e1872f2010-08-17 16:25:41 -07001242{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001243{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001244
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001245{"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001246{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001247
Jason Samsd4b23b52010-12-13 15:32:35 -08001248{"rsnAllocationCreateTyped", "(IIII)I", (void*)nAllocationCreateTyped },
Jason Sams5476b452010-12-08 16:14:36 -08001249{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
1250{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001251
Jason Sams4ef66502010-12-10 16:03:15 -08001252{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1253{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1254
Jason Sams5476b452010-12-08 16:14:36 -08001255{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
Jason Sams49a05d72010-12-29 14:31:29 -08001256{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i },
1257{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s },
1258{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b },
1259{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f },
1260{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
1261{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001262{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s },
1263{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b },
Jason Sams49a05d72010-12-29 14:31:29 -08001264{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f },
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001265{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc },
Jason Sams2e1872f2010-08-17 16:25:41 -07001266{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001267{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s },
1268{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b },
Jason Sams2e1872f2010-08-17 16:25:41 -07001269{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
Jason Sams2e1872f2010-08-17 16:25:41 -07001270{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
Jason Sams5edc6082010-10-05 13:32:49 -07001271{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
1272{"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D },
Jason Samsf7086092011-01-12 13:28:37 -08001273{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001274
Jason Sams2e1872f2010-08-17 16:25:41 -07001275{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1276{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1277{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1278{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
Jason Sams6e494d32011-04-27 16:33:11 -07001279{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1280{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
Jason Sams2e1872f2010-08-17 16:25:41 -07001281{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
Stephen Hines031ec58c2010-10-11 10:54:21 -07001282{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
Jason Sams2e1872f2010-08-17 16:25:41 -07001283{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
Stephen Hinesca54ec32010-09-20 17:20:30 -07001284{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
Jason Sams2e1872f2010-08-17 16:25:41 -07001285{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001286{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001287
Jason Samse4a06c52011-03-16 16:29:28 -07001288{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
Jason Sams0011bcf2009-12-15 12:58:36 -08001289
Jason Sams331bf9b2011-04-06 11:23:54 -07001290{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001291
Jason Sams2e1872f2010-08-17 16:25:41 -07001292{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1293{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1294{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001295
Jason Sams49a05d72010-12-29 14:31:29 -08001296{"rsnProgramFragmentCreate", "(ILjava/lang/String;[I)I", (void*)nProgramFragmentCreate },
Jason Sams331bf9b2011-04-06 11:23:54 -07001297{"rsnProgramRasterCreate", "(IZZZFI)I", (void*)nProgramRasterCreate },
Jason Sams49a05d72010-12-29 14:31:29 -08001298{"rsnProgramVertexCreate", "(ILjava/lang/String;[I)I", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001299
Jason Sams2e1872f2010-08-17 16:25:41 -07001300{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001301{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
Jason Sams2e1872f2010-08-17 16:25:41 -07001302{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1303{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1304{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001305
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001306{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001307
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001308{"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001309
1310{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1311{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001312{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
Jason Sams2e1872f2010-08-17 16:25:41 -07001313{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001314
Jason Samsd19f10d2009-05-22 14:03:28 -07001315};
1316
1317static int registerFuncs(JNIEnv *_env)
1318{
1319 return android::AndroidRuntime::registerNativeMethods(
1320 _env, classPathName, methods, NELEM(methods));
1321}
1322
1323// ---------------------------------------------------------------------------
1324
1325jint JNI_OnLoad(JavaVM* vm, void* reserved)
1326{
1327 JNIEnv* env = NULL;
1328 jint result = -1;
1329
Jason Samsd19f10d2009-05-22 14:03:28 -07001330 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
1331 LOGE("ERROR: GetEnv failed\n");
1332 goto bail;
1333 }
1334 assert(env != NULL);
1335
1336 if (registerFuncs(env) < 0) {
1337 LOGE("ERROR: MediaPlayer native registration failed\n");
1338 goto bail;
1339 }
1340
1341 /* success -- return valid version number */
1342 result = JNI_VERSION_1_4;
1343
1344bail:
1345 return result;
1346}