blob: 80001a6fc136f5a374b348de17e0a2adfcdba088 [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
Stephen Hines4cbe25a2012-01-18 18:46:27 -08002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Samsd19f10d2009-05-22 14:03:28 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jason Samsf29ca502009-06-23 12:22:47 -070017#define LOG_TAG "libRS_jni"
18
Jason Samsd19f10d2009-05-22 14:03:28 -070019#include <stdlib.h>
20#include <stdio.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <math.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070024#include <utils/misc.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070025
Jason Samsffe9f482009-06-01 17:45:53 -070026#include <core/SkBitmap.h>
Romain Guy650a3eb2009-08-31 14:06:43 -070027#include <core/SkPixelRef.h>
28#include <core/SkStream.h>
29#include <core/SkTemplates.h>
30#include <images/SkImageDecoder.h>
Jason Samsffe9f482009-06-01 17:45:53 -070031
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080032#include <androidfw/Asset.h>
33#include <androidfw/AssetManager.h>
34#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070035
Jason Samsd19f10d2009-05-22 14:03:28 -070036#include "jni.h"
37#include "JNIHelp.h"
38#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070039#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080040#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070041
Jason Sams1d6983a2012-02-16 16:07:49 -080042#include <rs.h>
43#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070044#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080045#include <gui/GLConsumer.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070046#include <gui/SurfaceTextureClient.h>
47#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070048
Steve Block3762c312012-01-06 19:20:56 +000049//#define LOG_API ALOGE
Jason Samsd19f10d2009-05-22 14:03:28 -070050#define LOG_API(...)
51
52using namespace android;
53
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080054class AutoJavaStringToUTF8 {
55public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080056 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080057 fCStr = env->GetStringUTFChars(str, NULL);
58 fLength = env->GetStringUTFLength(str);
59 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080060 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080061 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
62 }
63 const char* c_str() const { return fCStr; }
64 jsize length() const { return fLength; }
65
66private:
67 JNIEnv* fEnv;
68 jstring fJStr;
69 const char* fCStr;
70 jsize fLength;
71};
72
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080073class AutoJavaStringArrayToUTF8 {
74public:
75 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
76 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
77 mCStrings = NULL;
78 mSizeArray = NULL;
79 if (stringsLength > 0) {
80 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
81 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
82 for (jsize ct = 0; ct < stringsLength; ct ++) {
83 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
84 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL);
85 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
86 }
87 }
88 }
89 ~AutoJavaStringArrayToUTF8() {
90 for (jsize ct=0; ct < mStringsLength; ct++) {
91 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
92 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
93 }
94 free(mCStrings);
95 free(mSizeArray);
96 }
97 const char **c_str() const { return mCStrings; }
98 size_t *c_str_len() const { return mSizeArray; }
99 jsize length() const { return mStringsLength; }
100
101private:
102 JNIEnv *mEnv;
103 jobjectArray mStrings;
104 const char **mCStrings;
105 size_t *mSizeArray;
106 jsize mStringsLength;
107};
108
Jason Samsd19f10d2009-05-22 14:03:28 -0700109// ---------------------------------------------------------------------------
110
Jason Samsffe9f482009-06-01 17:45:53 -0700111static jfieldID gContextId = 0;
112static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -0700113static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700114
115static void _nInit(JNIEnv *_env, jclass _this)
116{
Jason Samsd19f10d2009-05-22 14:03:28 -0700117 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -0700118
119 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
120 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
Jason Samsd19f10d2009-05-22 14:03:28 -0700121}
122
Jason Samsd19f10d2009-05-22 14:03:28 -0700123// ---------------------------------------------------------------------------
124
Jason Sams3eaa338e2009-06-10 15:04:38 -0700125static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700126nContextFinish(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700127{
Jason Sams96ed4cf2010-06-15 12:15:57 -0700128 LOG_API("nContextFinish, con(%p)", con);
129 rsContextFinish(con);
130}
131
132static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700133nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700134{
Jason Sams07ae4062009-08-27 20:23:34 -0700135 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700136 jint len = _env->GetArrayLength(str);
137 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsbc948de2009-08-17 18:35:48 -0700138 rsAssignName(con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700139 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
140}
141
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700142static jstring
Jason Sams2e1872f2010-08-17 16:25:41 -0700143nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700144{
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700145 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700146 const char *name = NULL;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700147 rsaGetName(con, (void *)obj, &name);
148 if(name == NULL || strlen(name) == 0) {
149 return NULL;
150 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700151 return _env->NewStringUTF(name);
152}
153
Jason Sams7ce033d2009-08-18 14:14:24 -0700154static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700155nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700156{
Jason Sams7ce033d2009-08-18 14:14:24 -0700157 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
Jason Sams9c25aee2010-10-14 17:57:30 -0700158 rsObjDestroy(con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700159}
160
Jason Sams3eaa338e2009-06-10 15:04:38 -0700161// ---------------------------------------------------------------------------
162
Jason Samsd19f10d2009-05-22 14:03:28 -0700163static jint
164nDeviceCreate(JNIEnv *_env, jobject _this)
165{
166 LOG_API("nDeviceCreate");
167 return (jint)rsDeviceCreate();
168}
169
170static void
171nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
172{
173 LOG_API("nDeviceDestroy");
174 return rsDeviceDestroy((RsDevice)dev);
175}
176
Jason Samsebfb4362009-09-23 13:57:02 -0700177static void
178nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
179{
180 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
181 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
182}
183
Jason Samsd19f10d2009-05-22 14:03:28 -0700184static jint
Stephen Hines4382467a2011-08-01 15:02:34 -0700185nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700186{
187 LOG_API("nContextCreate");
Stephen Hines4382467a2011-08-01 15:02:34 -0700188 return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer);
Jason Sams704ff642010-02-09 16:05:07 -0800189}
190
191static jint
Stephen Hines4382467a2011-08-01 15:02:34 -0700192nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700193 int colorMin, int colorPref,
194 int alphaMin, int alphaPref,
195 int depthMin, int depthPref,
196 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700197 int samplesMin, int samplesPref, float samplesQ,
198 int dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800199{
Jason Sams11c8af92010-10-13 15:31:10 -0700200 RsSurfaceConfig sc;
201 sc.alphaMin = alphaMin;
202 sc.alphaPref = alphaPref;
203 sc.colorMin = colorMin;
204 sc.colorPref = colorPref;
205 sc.depthMin = depthMin;
206 sc.depthPref = depthPref;
207 sc.samplesMin = samplesMin;
208 sc.samplesPref = samplesPref;
209 sc.samplesQ = samplesQ;
210
Jason Sams704ff642010-02-09 16:05:07 -0800211 LOG_API("nContextCreateGL");
Stephen Hines4382467a2011-08-01 15:02:34 -0700212 return (jint)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700213}
214
215static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700216nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800217{
Jason Sams7d787b42009-11-15 12:14:26 -0800218 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
219 rsContextSetPriority(con, p);
220}
221
222
223
224static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700225nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800226{
Jason Sams3bc47d42009-11-12 15:10:25 -0800227 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800228
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700229 ANativeWindow * window = NULL;
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800230 if (wnd == NULL) {
231
232 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700233 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800234 }
235
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700236 rsContextSetSurface(con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800237}
238
239static void
Jason Samsfaa32b32011-06-20 16:58:04 -0700240nContextSetSurfaceTexture(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject sur)
241{
242 LOG_API("nContextSetSurfaceTexture, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)sur);
243
244 sp<ANativeWindow> window;
Andy McFaddend47f7d82012-12-18 09:48:38 -0800245 sp<GLConsumer> st;
Jason Samsfaa32b32011-06-20 16:58:04 -0700246 if (sur == 0) {
247
248 } else {
249 st = SurfaceTexture_getSurfaceTexture(_env, sur);
Jamie Gennis82bb8132012-12-11 17:00:29 -0800250 window = new SurfaceTextureClient(st->getBufferQueue());
Jason Samsfaa32b32011-06-20 16:58:04 -0700251 }
252
253 rsContextSetSurface(con, width, height, window.get());
254}
255
256static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700257nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700258{
Jason Sams2e1872f2010-08-17 16:25:41 -0700259 LOG_API("nContextDestroy, con(%p)", con);
260 rsContextDestroy(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700261}
262
Jason Sams715333b2009-11-17 17:26:46 -0800263static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700264nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800265{
Jason Sams715333b2009-11-17 17:26:46 -0800266 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
267 rsContextDump((RsContext)con, bits);
268}
Jason Samsd19f10d2009-05-22 14:03:28 -0700269
270static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700271nContextPause(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700272{
Jason Sams65e7aa52009-09-24 17:38:20 -0700273 LOG_API("nContextPause, con(%p)", con);
274 rsContextPause(con);
275}
276
277static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700278nContextResume(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700279{
Jason Sams65e7aa52009-09-24 17:38:20 -0700280 LOG_API("nContextResume, con(%p)", con);
281 rsContextResume(con);
282}
283
Jason Sams1c415172010-11-08 17:06:46 -0800284
285static jstring
286nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
287{
288 LOG_API("nContextGetErrorMessage, con(%p)", con);
289 char buf[1024];
290
291 size_t receiveLen;
292 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700293 int id = rsContextGetMessage(con,
294 buf, sizeof(buf),
295 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700296 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800297 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100298 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800299 }
300 return _env->NewStringUTF(buf);
301}
302
Jason Samsedbfabd2011-05-17 15:01:29 -0700303static jint
Jason Sams1c415172010-11-08 17:06:46 -0800304nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700305{
Jason Sams516c3192009-10-06 13:58:47 -0700306 jint len = _env->GetArrayLength(data);
307 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
308 jint *ptr = _env->GetIntArrayElements(data, NULL);
309 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800310 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700311 int id = rsContextGetMessage(con,
312 ptr, len * 4,
313 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700314 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700315 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100316 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700317 }
318 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Samsedbfabd2011-05-17 15:01:29 -0700319 return id;
Jason Sams1c415172010-11-08 17:06:46 -0800320}
321
322static jint
Jason Samsedbfabd2011-05-17 15:01:29 -0700323nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800324{
325 LOG_API("nContextPeekMessage, con(%p)", con);
326 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
327 size_t receiveLen;
328 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700329 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700330 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800331 auxDataPtr[0] = (jint)subID;
332 auxDataPtr[1] = (jint)receiveLen;
333 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Jason Sams516c3192009-10-06 13:58:47 -0700334 return id;
335}
336
Jason Sams2e1872f2010-08-17 16:25:41 -0700337static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700338{
Jason Sams516c3192009-10-06 13:58:47 -0700339 LOG_API("nContextInitToClient, con(%p)", con);
340 rsContextInitToClient(con);
341}
342
Jason Sams2e1872f2010-08-17 16:25:41 -0700343static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700344{
Jason Sams516c3192009-10-06 13:58:47 -0700345 LOG_API("nContextDeinitToClient, con(%p)", con);
346 rsContextDeinitToClient(con);
347}
348
Jason Sams455d6442013-02-05 19:20:18 -0800349static void
350nContextSendMessage(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray data)
351{
352 jint *ptr = NULL;
353 jint len = 0;
354 if (data) {
355 len = _env->GetArrayLength(data);
356 jint *ptr = _env->GetIntArrayElements(data, NULL);
357 }
358 LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", con, id, len);
359 rsContextSendMessage(con, id, (const uint8_t *)ptr, len * sizeof(int));
360 if (data) {
361 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
362 }
363}
364
365
Jason Sams516c3192009-10-06 13:58:47 -0700366
Jason Sams718cd1f2009-12-23 14:35:29 -0800367static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700368nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700369{
Jason Sams718cd1f2009-12-23 14:35:29 -0800370 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
371 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700372}
373
374static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800375nElementCreate2(JNIEnv *_env, jobject _this, RsContext con,
376 jintArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700377{
Jason Sams718cd1f2009-12-23 14:35:29 -0800378 int fieldCount = _env->GetArrayLength(_ids);
Jason Sams704ff642010-02-09 16:05:07 -0800379 LOG_API("nElementCreate2, con(%p)", con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800380
381 jint *ids = _env->GetIntArrayElements(_ids, NULL);
Jason Sams70d4e502010-09-02 17:35:23 -0700382 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
Jason Sams718cd1f2009-12-23 14:35:29 -0800383
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800384 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
385
386 const char **nameArray = names.c_str();
387 size_t *sizeArray = names.c_str_len();
388
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700389 jint id = (jint)rsElementCreate2(con,
390 (RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700391 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700392 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800393
Jason Sams718cd1f2009-12-23 14:35:29 -0800394 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
Jason Sams70d4e502010-09-02 17:35:23 -0700395 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
Jason Sams718cd1f2009-12-23 14:35:29 -0800396 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700397}
398
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700399static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700400nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700401{
402 int dataSize = _env->GetArrayLength(_elementData);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700403 LOG_API("nElementGetNativeData, con(%p)", con);
404
405 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
406 assert(dataSize == 5);
407
408 uint32_t elementData[5];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700409 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700410
411 for(jint i = 0; i < dataSize; i ++) {
412 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
413 }
414}
415
416
417static void
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700418nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
419 jintArray _IDs,
420 jobjectArray _names,
421 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700422{
423 int dataSize = _env->GetArrayLength(_IDs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700424 LOG_API("nElementGetSubElements, con(%p)", con);
425
426 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
427 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700428 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700429
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700430 rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700431
Jason Sams11c8af92010-10-13 15:31:10 -0700432 for(jint i = 0; i < dataSize; i++) {
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700433 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
434 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700435 _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700436 }
437
438 free(ids);
439 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700440 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700441}
442
Jason Samsd19f10d2009-05-22 14:03:28 -0700443// -----------------------------------
444
Jason Sams3b9c52a2010-10-14 17:48:46 -0700445static int
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800446nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800447 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700448{
Jason Samsb109cc72013-01-07 18:20:12 -0800449 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
450 con, eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700451
Jason Samsb109cc72013-01-07 18:20:12 -0800452 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700453 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700454}
455
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700456static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700457nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700458{
459 // We are packing 6 items: mDimX; mDimY; mDimZ;
460 // mDimLOD; mDimFaces; mElement; into typeData
461 int elementCount = _env->GetArrayLength(_typeData);
462
463 assert(elementCount == 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700464 LOG_API("nTypeCreate, con(%p)", con);
465
466 uint32_t typeData[6];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700467 rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700468
469 for(jint i = 0; i < elementCount; i ++) {
470 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
471 }
472}
473
Jason Samsd19f10d2009-05-22 14:03:28 -0700474// -----------------------------------
475
476static jint
Jason Sams857d0c72011-11-23 15:02:15 -0800477nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700478{
Jason Sams857d0c72011-11-23 15:02:15 -0800479 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer);
480 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700481}
482
Jason Samsd19f10d2009-05-22 14:03:28 -0700483static void
Jason Sams5476b452010-12-08 16:14:36 -0800484nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
485{
486 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
487 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
488}
489
Jason Sams615e7ce2012-01-13 14:01:20 -0800490static jint
491nAllocationGetSurfaceTextureID(JNIEnv *_env, jobject _this, RsContext con, jint a)
492{
493 LOG_API("nAllocationGetSurfaceTextureID, con(%p), a(%p)", con, (RsAllocation)a);
494 return rsAllocationGetSurfaceTextureID(con, (RsAllocation)a);
495}
496
Jason Samsf7086092011-01-12 13:28:37 -0800497static void
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700498nAllocationGetSurfaceTextureID2(JNIEnv *_env, jobject _this, RsContext con, jint a, jobject jst)
499{
500 LOG_API("nAllocationGetSurfaceTextureID2, con(%p), a(%p)", con, (RsAllocation)a);
Andy McFaddend47f7d82012-12-18 09:48:38 -0800501 sp<GLConsumer> st = SurfaceTexture_getSurfaceTexture(_env, jst);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700502
Andy McFaddend47f7d82012-12-18 09:48:38 -0800503 rsAllocationGetSurfaceTextureID2(con, (RsAllocation)a, st.get(), sizeof(GLConsumer *));
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700504}
505
506static void
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700507nAllocationSetSurface(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800508{
Stephen Hines06883b72012-05-16 18:01:34 -0700509 LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)",
Jason Sams163766c2012-02-15 12:04:24 -0800510 con, alloc, (Surface *)sur);
511
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700512 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800513 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700514 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800515 }
516
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700517 rsAllocationSetSurface(con, alloc, static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800518}
519
520static void
521nAllocationIoSend(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
522{
523 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", con, alloc);
524 rsAllocationIoSend(con, alloc);
525}
526
527static void
528nAllocationIoReceive(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
529{
530 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", con, alloc);
531 rsAllocationIoReceive(con, alloc);
532}
533
534
535static void
Jason Samsf7086092011-01-12 13:28:37 -0800536nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
537{
538 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
539 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
540}
541
Jason Samsffe9f482009-06-01 17:45:53 -0700542static int
Jason Sams5476b452010-12-08 16:14:36 -0800543nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700544{
Jason Samsffe9f482009-06-01 17:45:53 -0700545 SkBitmap const * nativeBitmap =
546 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
547 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700548
Jason Sams5476b452010-12-08 16:14:36 -0800549 bitmap.lockPixels();
550 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700551 jint id = (jint)rsAllocationCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700552 (RsType)type, (RsAllocationMipmapControl)mip,
553 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800554 bitmap.unlockPixels();
555 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700556}
Jason Samsfe08d992009-05-27 14:45:32 -0700557
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800558static int
Tim Murraya3145512012-12-04 17:59:29 -0800559nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
560{
561 SkBitmap const * nativeBitmap =
562 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
563 const SkBitmap& bitmap(*nativeBitmap);
564
565 bitmap.lockPixels();
566 const void* ptr = bitmap.getPixels();
567 jint id = (jint)rsAllocationCreateTyped(con,
568 (RsType)type, (RsAllocationMipmapControl)mip,
569 (uint32_t)usage, (size_t)ptr);
570 bitmap.unlockPixels();
571 return id;
572}
573
574static int
Jason Sams5476b452010-12-08 16:14:36 -0800575nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800576{
577 SkBitmap const * nativeBitmap =
578 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
579 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800580
Jason Sams5476b452010-12-08 16:14:36 -0800581 bitmap.lockPixels();
582 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700583 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700584 (RsType)type, (RsAllocationMipmapControl)mip,
585 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800586 bitmap.unlockPixels();
587 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800588}
589
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700590static void
Jason Sams4ef66502010-12-10 16:03:15 -0800591nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700592{
593 SkBitmap const * nativeBitmap =
594 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
595 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800596 int w = bitmap.width();
597 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700598
Jason Sams4ef66502010-12-10 16:03:15 -0800599 bitmap.lockPixels();
600 const void* ptr = bitmap.getPixels();
Jason Samsf7086092011-01-12 13:28:37 -0800601 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700602 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800603 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800604 bitmap.unlockPixels();
605}
606
607static void
608nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
609{
610 SkBitmap const * nativeBitmap =
611 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
612 const SkBitmap& bitmap(*nativeBitmap);
613
614 bitmap.lockPixels();
615 void* ptr = bitmap.getPixels();
616 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
617 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700618 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700619}
620
Jason Sams8a647432010-03-01 15:31:04 -0800621static void ReleaseBitmapCallback(void *bmp)
622{
623 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
624 nativeBitmap->unlockPixels();
625}
626
Romain Guy650a3eb2009-08-31 14:06:43 -0700627
Jason Samsd19f10d2009-05-22 14:03:28 -0700628static void
Jason Sams49a05d72010-12-29 14:31:29 -0800629nAllocationData1D_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 -0700630{
Jason Samsd19f10d2009-05-22 14:03:28 -0700631 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800632 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 -0700633 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800634 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700635 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
636}
637
638static void
Jason Sams49a05d72010-12-29 14:31:29 -0800639nAllocationData1D_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 -0700640{
Jason Sams768bc022009-09-21 19:41:04 -0700641 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800642 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 -0700643 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800644 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700645 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
646}
647
648static void
Jason Sams49a05d72010-12-29 14:31:29 -0800649nAllocationData1D_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 -0700650{
Jason Sams768bc022009-09-21 19:41:04 -0700651 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800652 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 -0700653 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800654 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700655 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
656}
657
658static void
Jason Sams49a05d72010-12-29 14:31:29 -0800659nAllocationData1D_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 -0700660{
Jason Samsd19f10d2009-05-22 14:03:28 -0700661 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800662 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 -0700663 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800664 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700665 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
666}
667
668static void
Jason Sams49a05d72010-12-29 14:31:29 -0800669// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
670nAllocationElementData1D(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 -0700671{
672 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800673 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 -0700674 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Stephen Hines4cbe25a2012-01-18 18:46:27 -0800675 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700676 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
677}
678
679static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800680nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
681 jint w, jint h, jshortArray data, int sizeBytes)
682{
683 jint len = _env->GetArrayLength(data);
684 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);
685 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Tim Murray38faea302012-11-27 14:55:08 -0800686 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800687 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
688}
689
690static void
691nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
692 jint w, jint h, jbyteArray data, int sizeBytes)
693{
694 jint len = _env->GetArrayLength(data);
695 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);
696 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Tim Murray38faea302012-11-27 14:55:08 -0800697 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800698 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
699}
700
701static void
Jason Sams49a05d72010-12-29 14:31:29 -0800702nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
703 jint w, jint h, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700704{
Jason Samsd19f10d2009-05-22 14:03:28 -0700705 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800706 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 -0700707 jint *ptr = _env->GetIntArrayElements(data, NULL);
Tim Murray38faea302012-11-27 14:55:08 -0800708 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700709 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
710}
711
712static void
Jason Sams49a05d72010-12-29 14:31:29 -0800713nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
714 jint w, jint h, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700715{
Jason Samsd19f10d2009-05-22 14:03:28 -0700716 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800717 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 -0700718 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Tim Murray38faea302012-11-27 14:55:08 -0800719 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700720 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
721}
722
Jason Sams40a29e82009-08-10 14:55:26 -0700723static void
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700724nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
725 jint dstAlloc, jint dstXoff, jint dstYoff,
726 jint dstMip, jint dstFace,
727 jint width, jint height,
728 jint srcAlloc, jint srcXoff, jint srcYoff,
729 jint srcMip, jint srcFace)
730{
Jason Sams4c2e4c82012-02-07 15:32:08 -0800731 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700732 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
733 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
734 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
735 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
736
737 rsAllocationCopy2DRange(con,
738 (RsAllocation)dstAlloc,
739 dstXoff, dstYoff,
740 dstMip, dstFace,
741 width, height,
742 (RsAllocation)srcAlloc,
743 srcXoff, srcYoff,
744 srcMip, srcFace);
745}
746
747static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700748nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700749{
Jason Sams40a29e82009-08-10 14:55:26 -0700750 jint len = _env->GetArrayLength(data);
751 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
752 jint *ptr = _env->GetIntArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700753 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700754 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(int));
Joe Onoratoae209ac2009-08-31 17:23:53 -0700755 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700756}
757
758static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800759nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
760{
761 jint len = _env->GetArrayLength(data);
762 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
763 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700764 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700765 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(short));
Jason Samsfb9f82c2011-01-12 14:53:25 -0800766 _env->ReleaseShortArrayElements(data, ptr, 0);
767}
768
769static void
770nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
771{
772 jint len = _env->GetArrayLength(data);
773 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
774 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700775 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700776 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(char));
Jason Samsfb9f82c2011-01-12 14:53:25 -0800777 _env->ReleaseByteArrayElements(data, ptr, 0);
778}
779
780static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700781nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700782{
Jason Sams40a29e82009-08-10 14:55:26 -0700783 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700784 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700785 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700786 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700787 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(float));
Joe Onoratoae209ac2009-08-31 17:23:53 -0700788 _env->ReleaseFloatArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700789}
Jason Samsd19f10d2009-05-22 14:03:28 -0700790
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700791static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700792nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700793{
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700794 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700795 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700796}
797
Jason Sams5edc6082010-10-05 13:32:49 -0700798static void
799nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
800{
801 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
802 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
803}
804
805static void
806nAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY)
807{
808 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY);
809 rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY);
810}
811
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700812// -----------------------------------
813
814static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700815nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700816{
Steve Block71f2cf12011-10-20 11:56:00 +0100817 ALOGV("______nFileA3D %u", (uint32_t) native_asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700818
819 Asset* asset = reinterpret_cast<Asset*>(native_asset);
820
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800821 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
822 return id;
823}
824
825static int
826nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
827{
828 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
829 if (mgr == NULL) {
830 return 0;
831 }
832
833 AutoJavaStringToUTF8 str(_env, _path);
834 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
835 if (asset == NULL) {
836 return 0;
837 }
838
839 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
840 return id;
841}
842
843static int
844nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
845{
846 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
847 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
848
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700849 return id;
850}
851
852static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700853nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700854{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700855 int32_t numEntries = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700856 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700857 return numEntries;
858}
859
860static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700861nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700862{
Steve Block71f2cf12011-10-20 11:56:00 +0100863 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700864 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
865
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700866 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700867
868 for(jint i = 0; i < numEntries; i ++) {
869 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
870 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
871 }
872
873 free(fileEntries);
874}
875
876static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700877nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700878{
Steve Block71f2cf12011-10-20 11:56:00 +0100879 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700880 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700881 return id;
882}
Jason Samsd19f10d2009-05-22 14:03:28 -0700883
884// -----------------------------------
885
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700886static int
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800887nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
888 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700889{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800890 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700891 jint id = (jint)rsFontCreateFromFile(con,
892 fileNameUTF.c_str(), fileNameUTF.length(),
893 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700894
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800895 return id;
896}
897
898static int
899nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
900 jstring name, jfloat fontSize, jint dpi, jint native_asset)
901{
902 Asset* asset = reinterpret_cast<Asset*>(native_asset);
903 AutoJavaStringToUTF8 nameUTF(_env, name);
904
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700905 jint id = (jint)rsFontCreateFromMemory(con,
906 nameUTF.c_str(), nameUTF.length(),
907 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800908 asset->getBuffer(false), asset->getLength());
909 return id;
910}
911
912static int
913nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
914 jfloat fontSize, jint dpi)
915{
916 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
917 if (mgr == NULL) {
918 return 0;
919 }
920
921 AutoJavaStringToUTF8 str(_env, _path);
922 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
923 if (asset == NULL) {
924 return 0;
925 }
926
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700927 jint id = (jint)rsFontCreateFromMemory(con,
928 str.c_str(), str.length(),
929 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800930 asset->getBuffer(false), asset->getLength());
931 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700932 return id;
933}
934
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700935// -----------------------------------
936
937static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700938nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700939{
Jason Samsd19f10d2009-05-22 14:03:28 -0700940 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700941 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700942}
943
944static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700945nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700946{
Jason Samscfc04362010-09-14 14:59:03 -0700947 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700948 rsScriptSetVarI(con, (RsScript)script, slot, val);
949}
950
951static void
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800952nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
953{
954 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
955 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
956}
957
958static void
Stephen Hines031ec58c2010-10-11 10:54:21 -0700959nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
960{
961 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
962 rsScriptSetVarJ(con, (RsScript)script, slot, val);
963}
964
965static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700966nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700967{
Stephen Hinesca54ec32010-09-20 17:20:30 -0700968 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700969 rsScriptSetVarF(con, (RsScript)script, slot, val);
970}
971
972static void
Stephen Hinesca54ec32010-09-20 17:20:30 -0700973nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
974{
975 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
976 rsScriptSetVarD(con, (RsScript)script, slot, val);
977}
978
979static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700980nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700981{
Jason Sams4d339932010-05-11 14:03:58 -0700982 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
983 jint len = _env->GetArrayLength(data);
984 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
985 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
986 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
987}
988
Stephen Hinesadeb8092012-04-20 14:26:06 -0700989static void
990nScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims)
991{
992 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
993 jint len = _env->GetArrayLength(data);
994 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
995 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
996 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
997 rsScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem,
998 (const size_t*) dimsPtr, dimsLen);
999 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1000 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1001}
1002
Jason Samsd19f10d2009-05-22 14:03:28 -07001003
1004static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001005nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001006{
Jason Sams07ae4062009-08-27 20:23:34 -07001007 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -07001008
1009 jint length = _env->GetArrayLength(timeZone);
1010 jbyte* timeZone_ptr;
1011 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1012
Jason Samsbc948de2009-08-17 18:35:48 -07001013 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001014
1015 if (timeZone_ptr) {
1016 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1017 }
1018}
1019
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001020static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001021nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001022{
Jason Samsbe2e8412009-09-16 15:04:38 -07001023 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
1024 rsScriptInvoke(con, (RsScript)obj, slot);
1025}
1026
1027static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001028nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001029{
Jason Sams4d339932010-05-11 14:03:58 -07001030 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1031 jint len = _env->GetArrayLength(data);
1032 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1033 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
1034 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1035}
1036
Jason Sams6e494d32011-04-27 16:33:11 -07001037static void
1038nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
1039 jint script, jint slot, jint ain, jint aout)
1040{
1041 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1042 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0);
1043}
1044static void
1045nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
1046 jint script, jint slot, jint ain, jint aout, jbyteArray params)
1047{
1048 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1049 jint len = _env->GetArrayLength(params);
1050 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
1051 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len);
1052 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1053}
1054
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001055
Jason Sams22534172009-08-04 16:58:20 -07001056// -----------------------------------
1057
Jason Samse4a06c52011-03-16 16:29:28 -07001058static jint
1059nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
1060 jstring resName, jstring cacheDir,
1061 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001062{
Jason Samse4a06c52011-03-16 16:29:28 -07001063 LOG_API("nScriptCCreate, con(%p)", con);
Jason Sams22534172009-08-04 16:58:20 -07001064
Jason Samse4a06c52011-03-16 16:29:28 -07001065 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1066 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
1067 jint ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -07001068 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -07001069 jint _exception = 0;
1070 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001071 if (!scriptRef) {
1072 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001073 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001074 goto exit;
1075 }
Jack Palevich43702d82009-05-28 13:38:16 -07001076 if (length < 0) {
1077 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001078 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001079 goto exit;
1080 }
Jason Samse4a06c52011-03-16 16:29:28 -07001081 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001082 if (remaining < length) {
1083 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001084 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1085 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001086 goto exit;
1087 }
Jason Samse4a06c52011-03-16 16:29:28 -07001088 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001089 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001090
Jason Samse4a06c52011-03-16 16:29:28 -07001091 //rsScriptCSetText(con, (const char *)script_ptr, length);
1092
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001093 ret = (jint)rsScriptCCreate(con,
1094 resNameUTF.c_str(), resNameUTF.length(),
1095 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001096 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001097
Jack Palevich43702d82009-05-28 13:38:16 -07001098exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001099 if (script_ptr) {
1100 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001101 _exception ? JNI_ABORT: 0);
1102 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001103
Jason Samse4a06c52011-03-16 16:29:28 -07001104 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001105}
1106
Jason Sams6ab97682012-08-10 12:09:43 -07001107static jint
1108nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, RsContext con, jint id, jint eid)
1109{
1110 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", con, id, (void *)eid);
1111 return (jint)rsScriptIntrinsicCreate(con, id, (RsElement)eid);
1112}
1113
Jason Sams08a81582012-09-18 12:32:10 -07001114static jint
1115nScriptKernelIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot, jint sig)
1116{
1117 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", con, (void *)sid, slot, sig);
1118 return (jint)rsScriptKernelIDCreate(con, (RsScript)sid, slot, sig);
1119}
1120
1121static jint
1122nScriptFieldIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot)
1123{
1124 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", con, (void *)sid, slot);
1125 return (jint)rsScriptFieldIDCreate(con, (RsScript)sid, slot);
1126}
1127
1128static jint
1129nScriptGroupCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _kernels, jintArray _src,
1130 jintArray _dstk, jintArray _dstf, jintArray _types)
1131{
1132 LOG_API("nScriptGroupCreate, con(%p)", con);
1133
1134 jint kernelsLen = _env->GetArrayLength(_kernels) * sizeof(int);
1135 jint *kernelsPtr = _env->GetIntArrayElements(_kernels, NULL);
1136 jint srcLen = _env->GetArrayLength(_src) * sizeof(int);
1137 jint *srcPtr = _env->GetIntArrayElements(_src, NULL);
1138 jint dstkLen = _env->GetArrayLength(_dstk) * sizeof(int);
1139 jint *dstkPtr = _env->GetIntArrayElements(_dstk, NULL);
1140 jint dstfLen = _env->GetArrayLength(_dstf) * sizeof(int);
1141 jint *dstfPtr = _env->GetIntArrayElements(_dstf, NULL);
1142 jint typesLen = _env->GetArrayLength(_types) * sizeof(int);
1143 jint *typesPtr = _env->GetIntArrayElements(_types, NULL);
1144
1145 int id = (int)rsScriptGroupCreate(con,
1146 (RsScriptKernelID *)kernelsPtr, kernelsLen,
1147 (RsScriptKernelID *)srcPtr, srcLen,
1148 (RsScriptKernelID *)dstkPtr, dstkLen,
1149 (RsScriptFieldID *)dstfPtr, dstfLen,
1150 (RsType *)typesPtr, typesLen);
1151
1152 _env->ReleaseIntArrayElements(_kernels, kernelsPtr, 0);
1153 _env->ReleaseIntArrayElements(_src, srcPtr, 0);
1154 _env->ReleaseIntArrayElements(_dstk, dstkPtr, 0);
1155 _env->ReleaseIntArrayElements(_dstf, dstfPtr, 0);
1156 _env->ReleaseIntArrayElements(_types, typesPtr, 0);
1157 return id;
1158}
1159
1160static void
1161nScriptGroupSetInput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
1162{
1163 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
1164 (void *)gid, (void *)kid, (void *)alloc);
1165 rsScriptGroupSetInput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
1166}
1167
1168static void
1169nScriptGroupSetOutput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
1170{
1171 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
1172 (void *)gid, (void *)kid, (void *)alloc);
1173 rsScriptGroupSetOutput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
1174}
1175
1176static void
1177nScriptGroupExecute(JNIEnv *_env, jobject _this, RsContext con, jint gid)
1178{
1179 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", con, (void *)gid);
1180 rsScriptGroupExecute(con, (RsScriptGroup)gid);
1181}
1182
Jason Samsd19f10d2009-05-22 14:03:28 -07001183// ---------------------------------------------------------------------------
1184
Jason Samsd19f10d2009-05-22 14:03:28 -07001185static jint
Jason Sams331bf9b2011-04-06 11:23:54 -07001186nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
1187 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1188 jboolean depthMask, jboolean ditherEnable,
1189 jint srcFunc, jint destFunc,
1190 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001191{
Jason Sams54db59c2010-05-13 18:30:11 -07001192 LOG_API("nProgramStoreCreate, con(%p)", con);
Jason Sams331bf9b2011-04-06 11:23:54 -07001193 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
1194 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1195 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001196}
1197
Jason Sams0011bcf2009-12-15 12:58:36 -08001198// ---------------------------------------------------------------------------
1199
1200static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001201nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001202{
Jason Sams0011bcf2009-12-15 12:58:36 -08001203 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
1204 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
1205}
Jason Sams54c0ec12009-11-30 14:49:55 -08001206
Jason Sams68afd012009-12-17 16:55:08 -08001207static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001208nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001209{
Jason Sams68afd012009-12-17 16:55:08 -08001210 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1211 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1212}
1213
1214static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001215nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001216{
Jason Sams68afd012009-12-17 16:55:08 -08001217 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1218 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1219}
1220
Jason Samsd19f10d2009-05-22 14:03:28 -07001221// ---------------------------------------------------------------------------
1222
Jason Samsd19f10d2009-05-22 14:03:28 -07001223static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001224nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1225 jobjectArray texNames, jintArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001226{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001227 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001228 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1229 jint paramLen = _env->GetArrayLength(params);
1230
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001231 int texCount = _env->GetArrayLength(texNames);
1232 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1233 const char ** nameArray = names.c_str();
1234 size_t* sizeArray = names.c_str_len();
1235
Jason Sams991040c2011-01-17 15:59:39 -08001236 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001237
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001238 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1239 nameArray, texCount, sizeArray,
1240 (uint32_t *)paramPtr, paramLen);
1241
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001242 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1243 return ret;
1244}
1245
1246
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001247// ---------------------------------------------------------------------------
1248
Jason Sams0011bcf2009-12-15 12:58:36 -08001249static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001250nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1251 jobjectArray texNames, jintArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001252{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001253 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams0011bcf2009-12-15 12:58:36 -08001254 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1255 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001256
Jason Sams991040c2011-01-17 15:59:39 -08001257 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001258
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001259 int texCount = _env->GetArrayLength(texNames);
1260 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1261 const char ** nameArray = names.c_str();
1262 size_t* sizeArray = names.c_str_len();
1263
1264 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1265 nameArray, texCount, sizeArray,
1266 (uint32_t *)paramPtr, paramLen);
1267
Jason Sams0011bcf2009-12-15 12:58:36 -08001268 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1269 return ret;
1270}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001271
Jason Samsebfb4362009-09-23 13:57:02 -07001272// ---------------------------------------------------------------------------
1273
1274static jint
Jason Sams94aaed32011-09-23 14:18:53 -07001275nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001276{
Jason Sams94aaed32011-09-23 14:18:53 -07001277 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", con, pointSprite, cull);
1278 return (jint)rsProgramRasterCreate(con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001279}
1280
Jason Samsd19f10d2009-05-22 14:03:28 -07001281
1282// ---------------------------------------------------------------------------
1283
1284static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001285nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001286{
Jason Samsd19f10d2009-05-22 14:03:28 -07001287 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001288 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001289}
1290
1291static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001292nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001293{
Jason Sams54db59c2010-05-13 18:30:11 -07001294 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1295 rsContextBindProgramStore(con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001296}
1297
1298static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001299nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001300{
Jason Samsd19f10d2009-05-22 14:03:28 -07001301 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001302 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001303}
1304
Jason Sams0826a6f2009-06-15 19:04:56 -07001305static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001306nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001307{
Jason Sams0826a6f2009-06-15 19:04:56 -07001308 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001309 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001310}
1311
Joe Onoratod7b37742009-08-09 22:57:44 -07001312static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001313nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001314{
Jason Samsebfb4362009-09-23 13:57:02 -07001315 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1316 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1317}
1318
Joe Onoratod7b37742009-08-09 22:57:44 -07001319
Jason Sams02fb2cb2009-05-28 15:37:57 -07001320// ---------------------------------------------------------------------------
1321
Jason Sams02fb2cb2009-05-28 15:37:57 -07001322static jint
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001323nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1324 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001325{
Jason Samsbba134c2009-06-22 15:49:21 -07001326 LOG_API("nSamplerCreate, con(%p)", con);
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001327 return (jint)rsSamplerCreate(con,
1328 (RsSamplerValue)magFilter,
1329 (RsSamplerValue)minFilter,
1330 (RsSamplerValue)wrapS,
1331 (RsSamplerValue)wrapT,
1332 (RsSamplerValue)wrapR,
1333 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001334}
1335
Jason Samsbba134c2009-06-22 15:49:21 -07001336// ---------------------------------------------------------------------------
1337
Jason Samsf15ed012011-10-31 13:23:43 -07001338//native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
1339static jint
1340nPathCreate(JNIEnv *_env, jobject _this, RsContext con, jint prim, jboolean isStatic, jint _vtx, jint _loop, jfloat q) {
1341 LOG_API("nPathCreate, con(%p)", con);
1342
1343 int id = (int)rsPathCreate(con, (RsPathPrimitive)prim, isStatic,
1344 (RsAllocation)_vtx,
1345 (RsAllocation)_loop, q);
1346 return id;
1347}
1348
Jason Samsbba134c2009-06-22 15:49:21 -07001349static jint
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001350nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001351{
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001352 LOG_API("nMeshCreate, con(%p)", con);
1353
1354 jint vtxLen = _env->GetArrayLength(_vtx);
1355 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
1356 jint idxLen = _env->GetArrayLength(_idx);
1357 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
1358 jint primLen = _env->GetArrayLength(_prim);
1359 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1360
1361 int id = (int)rsMeshCreate(con,
1362 (RsAllocation *)vtxPtr, vtxLen,
1363 (RsAllocation *)idxPtr, idxLen,
1364 (uint32_t *)primPtr, primLen);
1365
1366 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
1367 _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
1368 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001369 return id;
1370}
1371
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001372static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001373nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001374{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001375 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1376 jint vtxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001377 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001378 return vtxCount;
1379}
1380
1381static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001382nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001383{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001384 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1385 jint idxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001386 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001387 return idxCount;
1388}
1389
1390static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001391nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001392{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001393 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1394
1395 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001396 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001397
1398 for(jint i = 0; i < numVtxIDs; i ++) {
1399 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1400 }
1401
1402 free(allocs);
1403}
1404
1405static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001406nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001407{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001408 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1409
1410 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1411 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1412
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001413 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001414
1415 for(jint i = 0; i < numIndices; i ++) {
1416 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1417 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1418 }
1419
1420 free(allocs);
1421 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001422}
1423
1424// ---------------------------------------------------------------------------
1425
Jason Samsd19f10d2009-05-22 14:03:28 -07001426
Jason Sams94d8e90a2009-06-10 16:09:05 -07001427static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001428
1429static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001430{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001431
Jason Sams1c415172010-11-08 17:06:46 -08001432{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1433{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1434{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
Jason Samsedbfabd2011-05-17 15:01:29 -07001435{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001436{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
Jason Samsedbfabd2011-05-17 15:01:29 -07001437{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001438
1439{"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1440{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001441
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001442
Jason Sams2e1872f2010-08-17 16:25:41 -07001443// All methods below are thread protected in java.
Stephen Hines4382467a2011-08-01 15:02:34 -07001444{"rsnContextCreate", "(III)I", (void*)nContextCreate },
1445{"rsnContextCreateGL", "(IIIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
Jason Sams2e1872f2010-08-17 16:25:41 -07001446{"rsnContextFinish", "(I)V", (void*)nContextFinish },
1447{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1448{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
Jason Samsfaa32b32011-06-20 16:58:04 -07001449{"rsnContextSetSurfaceTexture", "(IIILandroid/graphics/SurfaceTexture;)V", (void*)nContextSetSurfaceTexture },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001450{"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams2e1872f2010-08-17 16:25:41 -07001451{"rsnContextDump", "(II)V", (void*)nContextDump },
1452{"rsnContextPause", "(I)V", (void*)nContextPause },
1453{"rsnContextResume", "(I)V", (void*)nContextResume },
Jason Sams455d6442013-02-05 19:20:18 -08001454{"rsnContextSendMessage", "(II[I)V", (void*)nContextSendMessage },
Jason Sams2e1872f2010-08-17 16:25:41 -07001455{"rsnAssignName", "(II[B)V", (void*)nAssignName },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001456{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
Jason Sams2e1872f2010-08-17 16:25:41 -07001457{"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001458
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001459{"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
Jason Sams2e1872f2010-08-17 16:25:41 -07001460{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001461{"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
Jason Sams2e1872f2010-08-17 16:25:41 -07001462{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001463{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Jason Sams2e1872f2010-08-17 16:25:41 -07001464{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001465
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -08001466{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001467{"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1468{"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001469
Jason Sams2e1872f2010-08-17 16:25:41 -07001470{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
Jason Sams70d4e502010-09-02 17:35:23 -07001471{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
Jason Sams2e1872f2010-08-17 16:25:41 -07001472{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001473{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001474
Jason Samsb109cc72013-01-07 18:20:12 -08001475{"rsnTypeCreate", "(IIIIIZZI)I", (void*)nTypeCreate },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001476{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001477
Jason Sams857d0c72011-11-23 15:02:15 -08001478{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped },
Jason Sams5476b452010-12-08 16:14:36 -08001479{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
Tim Murraya3145512012-12-04 17:59:29 -08001480{"rsnAllocationCreateBitmapBackedAllocation", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateBitmapBackedAllocation },
Jason Sams5476b452010-12-08 16:14:36 -08001481{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001482
Jason Sams4ef66502010-12-10 16:03:15 -08001483{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1484{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1485
Jason Sams5476b452010-12-08 16:14:36 -08001486{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
Jason Sams615e7ce2012-01-13 14:01:20 -08001487{"rsnAllocationGetSurfaceTextureID", "(II)I", (void*)nAllocationGetSurfaceTextureID },
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001488{"rsnAllocationGetSurfaceTextureID2","(IILandroid/graphics/SurfaceTexture;)V",(void*)nAllocationGetSurfaceTextureID2 },
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001489{"rsnAllocationSetSurface", "(IILandroid/view/Surface;)V", (void*)nAllocationSetSurface },
Jason Sams163766c2012-02-15 12:04:24 -08001490{"rsnAllocationIoSend", "(II)V", (void*)nAllocationIoSend },
1491{"rsnAllocationIoReceive", "(II)V", (void*)nAllocationIoReceive },
Jason Sams49a05d72010-12-29 14:31:29 -08001492{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i },
1493{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s },
1494{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b },
1495{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f },
1496{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
1497{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001498{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s },
1499{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b },
Jason Sams49a05d72010-12-29 14:31:29 -08001500{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f },
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001501{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc },
Jason Sams2e1872f2010-08-17 16:25:41 -07001502{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001503{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s },
1504{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b },
Jason Sams2e1872f2010-08-17 16:25:41 -07001505{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
Jason Sams2e1872f2010-08-17 16:25:41 -07001506{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
Jason Sams5edc6082010-10-05 13:32:49 -07001507{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
1508{"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D },
Jason Samsf7086092011-01-12 13:28:37 -08001509{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001510
Jason Sams2e1872f2010-08-17 16:25:41 -07001511{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1512{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1513{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1514{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
Jason Sams6e494d32011-04-27 16:33:11 -07001515{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1516{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
Jason Sams2e1872f2010-08-17 16:25:41 -07001517{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
Stephen Hines031ec58c2010-10-11 10:54:21 -07001518{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
Jason Sams2e1872f2010-08-17 16:25:41 -07001519{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
Stephen Hinesca54ec32010-09-20 17:20:30 -07001520{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
Jason Sams2e1872f2010-08-17 16:25:41 -07001521{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
Stephen Hinesadeb8092012-04-20 14:26:06 -07001522{"rsnScriptSetVarVE", "(III[BI[I)V", (void*)nScriptSetVarVE },
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001523{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001524
Jason Samse4a06c52011-03-16 16:29:28 -07001525{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
Jason Sams6ab97682012-08-10 12:09:43 -07001526{"rsnScriptIntrinsicCreate", "(III)I", (void*)nScriptIntrinsicCreate },
Jason Sams08a81582012-09-18 12:32:10 -07001527{"rsnScriptKernelIDCreate", "(IIII)I", (void*)nScriptKernelIDCreate },
1528{"rsnScriptFieldIDCreate", "(III)I", (void*)nScriptFieldIDCreate },
1529{"rsnScriptGroupCreate", "(I[I[I[I[I[I)I", (void*)nScriptGroupCreate },
1530{"rsnScriptGroupSetInput", "(IIII)V", (void*)nScriptGroupSetInput },
1531{"rsnScriptGroupSetOutput", "(IIII)V", (void*)nScriptGroupSetOutput },
1532{"rsnScriptGroupExecute", "(II)V", (void*)nScriptGroupExecute },
Jason Sams0011bcf2009-12-15 12:58:36 -08001533
Jason Sams331bf9b2011-04-06 11:23:54 -07001534{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001535
Jason Sams2e1872f2010-08-17 16:25:41 -07001536{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1537{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1538{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001539
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001540{"rsnProgramFragmentCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate },
Jason Sams94aaed32011-09-23 14:18:53 -07001541{"rsnProgramRasterCreate", "(IZI)I", (void*)nProgramRasterCreate },
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001542{"rsnProgramVertexCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001543
Jason Sams2e1872f2010-08-17 16:25:41 -07001544{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001545{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
Jason Sams2e1872f2010-08-17 16:25:41 -07001546{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1547{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1548{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001549
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001550{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001551
Jason Samsf15ed012011-10-31 13:23:43 -07001552{"rsnPathCreate", "(IIZIIF)I", (void*)nPathCreate },
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001553{"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001554
1555{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1556{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001557{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
Jason Sams2e1872f2010-08-17 16:25:41 -07001558{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001559
Jason Samsd19f10d2009-05-22 14:03:28 -07001560};
1561
1562static int registerFuncs(JNIEnv *_env)
1563{
1564 return android::AndroidRuntime::registerNativeMethods(
1565 _env, classPathName, methods, NELEM(methods));
1566}
1567
1568// ---------------------------------------------------------------------------
1569
1570jint JNI_OnLoad(JavaVM* vm, void* reserved)
1571{
1572 JNIEnv* env = NULL;
1573 jint result = -1;
1574
Jason Samsd19f10d2009-05-22 14:03:28 -07001575 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001576 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001577 goto bail;
1578 }
1579 assert(env != NULL);
1580
1581 if (registerFuncs(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001582 ALOGE("ERROR: MediaPlayer native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001583 goto bail;
1584 }
1585
1586 /* success -- return valid version number */
1587 result = JNI_VERSION_1_4;
1588
1589bail:
1590 return result;
1591}