blob: b320e4bbab14d85b1aa25fadbc20f5f6cc0989de [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
Stephen Hines4cbe25a2012-01-18 18:46:27 -08002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Samsd19f10d2009-05-22 14:03:28 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jason Samsf29ca502009-06-23 12:22:47 -070017#define LOG_TAG "libRS_jni"
18
Jason Samsd19f10d2009-05-22 14:03:28 -070019#include <stdlib.h>
20#include <stdio.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <math.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070024#include <utils/misc.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070025
Jason Samsffe9f482009-06-01 17:45:53 -070026#include <core/SkBitmap.h>
Romain Guy650a3eb2009-08-31 14:06:43 -070027#include <core/SkPixelRef.h>
28#include <core/SkStream.h>
29#include <core/SkTemplates.h>
30#include <images/SkImageDecoder.h>
Jason Samsffe9f482009-06-01 17:45:53 -070031
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080032#include <androidfw/Asset.h>
33#include <androidfw/AssetManager.h>
34#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070035
Jason Samsd19f10d2009-05-22 14:03:28 -070036#include "jni.h"
37#include "JNIHelp.h"
38#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070039#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080040#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070041
Jason Sams1d6983a2012-02-16 16:07:49 -080042#include <rs.h>
43#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070044#include <gui/Surface.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070045#include <gui/SurfaceTexture.h>
46#include <gui/SurfaceTextureClient.h>
47#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070048
Steve Block3762c312012-01-06 19:20:56 +000049//#define LOG_API ALOGE
Jason Samsd19f10d2009-05-22 14:03:28 -070050#define LOG_API(...)
51
52using namespace android;
53
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080054class AutoJavaStringToUTF8 {
55public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080056 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080057 fCStr = env->GetStringUTFChars(str, NULL);
58 fLength = env->GetStringUTFLength(str);
59 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080060 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080061 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
62 }
63 const char* c_str() const { return fCStr; }
64 jsize length() const { return fLength; }
65
66private:
67 JNIEnv* fEnv;
68 jstring fJStr;
69 const char* fCStr;
70 jsize fLength;
71};
72
Alex Sakhartchouk2123b462012-02-15 16:21:46 -080073class AutoJavaStringArrayToUTF8 {
74public:
75 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
76 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
77 mCStrings = NULL;
78 mSizeArray = NULL;
79 if (stringsLength > 0) {
80 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
81 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
82 for (jsize ct = 0; ct < stringsLength; ct ++) {
83 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
84 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL);
85 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
86 }
87 }
88 }
89 ~AutoJavaStringArrayToUTF8() {
90 for (jsize ct=0; ct < mStringsLength; ct++) {
91 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
92 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
93 }
94 free(mCStrings);
95 free(mSizeArray);
96 }
97 const char **c_str() const { return mCStrings; }
98 size_t *c_str_len() const { return mSizeArray; }
99 jsize length() const { return mStringsLength; }
100
101private:
102 JNIEnv *mEnv;
103 jobjectArray mStrings;
104 const char **mCStrings;
105 size_t *mSizeArray;
106 jsize mStringsLength;
107};
108
Jason Samsd19f10d2009-05-22 14:03:28 -0700109// ---------------------------------------------------------------------------
110
Jason Samsffe9f482009-06-01 17:45:53 -0700111static jfieldID gContextId = 0;
112static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -0700113static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700114
115static void _nInit(JNIEnv *_env, jclass _this)
116{
Jason Samsd19f10d2009-05-22 14:03:28 -0700117 gContextId = _env->GetFieldID(_this, "mContext", "I");
Jason Samsffe9f482009-06-01 17:45:53 -0700118
119 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
120 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
Jason Samsd19f10d2009-05-22 14:03:28 -0700121}
122
Jason Samsd19f10d2009-05-22 14:03:28 -0700123// ---------------------------------------------------------------------------
124
Jason Sams3eaa338e2009-06-10 15:04:38 -0700125static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700126nContextFinish(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700127{
Jason Sams96ed4cf2010-06-15 12:15:57 -0700128 LOG_API("nContextFinish, con(%p)", con);
129 rsContextFinish(con);
130}
131
132static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700133nAssignName(JNIEnv *_env, jobject _this, RsContext con, jint obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700134{
Jason Sams07ae4062009-08-27 20:23:34 -0700135 LOG_API("nAssignName, con(%p), obj(%p)", con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700136 jint len = _env->GetArrayLength(str);
137 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Jason Samsbc948de2009-08-17 18:35:48 -0700138 rsAssignName(con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700139 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
140}
141
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700142static jstring
Jason Sams2e1872f2010-08-17 16:25:41 -0700143nGetName(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700144{
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700145 LOG_API("nGetName, con(%p), obj(%p)", con, (void *)obj);
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700146 const char *name = NULL;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700147 rsaGetName(con, (void *)obj, &name);
148 if(name == NULL || strlen(name) == 0) {
149 return NULL;
150 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700151 return _env->NewStringUTF(name);
152}
153
Jason Sams7ce033d2009-08-18 14:14:24 -0700154static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700155nObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700156{
Jason Sams7ce033d2009-08-18 14:14:24 -0700157 LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
Jason Sams9c25aee2010-10-14 17:57:30 -0700158 rsObjDestroy(con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700159}
160
Jason Sams3eaa338e2009-06-10 15:04:38 -0700161// ---------------------------------------------------------------------------
162
Jason Samsd19f10d2009-05-22 14:03:28 -0700163static jint
164nDeviceCreate(JNIEnv *_env, jobject _this)
165{
166 LOG_API("nDeviceCreate");
167 return (jint)rsDeviceCreate();
168}
169
170static void
171nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
172{
173 LOG_API("nDeviceDestroy");
174 return rsDeviceDestroy((RsDevice)dev);
175}
176
Jason Samsebfb4362009-09-23 13:57:02 -0700177static void
178nDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
179{
180 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
181 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
182}
183
Jason Samsd19f10d2009-05-22 14:03:28 -0700184static jint
Stephen Hines4382467a2011-08-01 15:02:34 -0700185nContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700186{
187 LOG_API("nContextCreate");
Stephen Hines4382467a2011-08-01 15:02:34 -0700188 return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer);
Jason Sams704ff642010-02-09 16:05:07 -0800189}
190
191static jint
Stephen Hines4382467a2011-08-01 15:02:34 -0700192nContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer,
Jason Sams11c8af92010-10-13 15:31:10 -0700193 int colorMin, int colorPref,
194 int alphaMin, int alphaPref,
195 int depthMin, int depthPref,
196 int stencilMin, int stencilPref,
Alex Sakhartchouk2c74ad92011-03-16 19:28:25 -0700197 int samplesMin, int samplesPref, float samplesQ,
198 int dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800199{
Jason Sams11c8af92010-10-13 15:31:10 -0700200 RsSurfaceConfig sc;
201 sc.alphaMin = alphaMin;
202 sc.alphaPref = alphaPref;
203 sc.colorMin = colorMin;
204 sc.colorPref = colorPref;
205 sc.depthMin = depthMin;
206 sc.depthPref = depthPref;
207 sc.samplesMin = samplesMin;
208 sc.samplesPref = samplesPref;
209 sc.samplesQ = samplesQ;
210
Jason Sams704ff642010-02-09 16:05:07 -0800211 LOG_API("nContextCreateGL");
Stephen Hines4382467a2011-08-01 15:02:34 -0700212 return (jint)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700213}
214
215static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700216nContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800217{
Jason Sams7d787b42009-11-15 12:14:26 -0800218 LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
219 rsContextSetPriority(con, p);
220}
221
222
223
224static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700225nContextSetSurface(JNIEnv *_env, jobject _this, RsContext con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800226{
Jason Sams3bc47d42009-11-12 15:10:25 -0800227 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800228
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700229 ANativeWindow * window = NULL;
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800230 if (wnd == NULL) {
231
232 } else {
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;
245 sp<SurfaceTexture> st;
246 if (sur == 0) {
247
248 } else {
249 st = SurfaceTexture_getSurfaceTexture(_env, sur);
250 window = new SurfaceTextureClient(st);
251 }
252
253 rsContextSetSurface(con, width, height, window.get());
254}
255
256static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700257nContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700258{
Jason Sams2e1872f2010-08-17 16:25:41 -0700259 LOG_API("nContextDestroy, con(%p)", con);
260 rsContextDestroy(con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700261}
262
Jason Sams715333b2009-11-17 17:26:46 -0800263static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700264nContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800265{
Jason Sams715333b2009-11-17 17:26:46 -0800266 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
267 rsContextDump((RsContext)con, bits);
268}
Jason Samsd19f10d2009-05-22 14:03:28 -0700269
270static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700271nContextPause(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700272{
Jason Sams65e7aa52009-09-24 17:38:20 -0700273 LOG_API("nContextPause, con(%p)", con);
274 rsContextPause(con);
275}
276
277static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700278nContextResume(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700279{
Jason Sams65e7aa52009-09-24 17:38:20 -0700280 LOG_API("nContextResume, con(%p)", con);
281 rsContextResume(con);
282}
283
Jason Sams1c415172010-11-08 17:06:46 -0800284
285static jstring
286nContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
287{
288 LOG_API("nContextGetErrorMessage, con(%p)", con);
289 char buf[1024];
290
291 size_t receiveLen;
292 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700293 int id = rsContextGetMessage(con,
294 buf, sizeof(buf),
295 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700296 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800297 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100298 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800299 }
300 return _env->NewStringUTF(buf);
301}
302
Jason Samsedbfabd2011-05-17 15:01:29 -0700303static jint
Jason Sams1c415172010-11-08 17:06:46 -0800304nContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700305{
Jason Sams516c3192009-10-06 13:58:47 -0700306 jint len = _env->GetArrayLength(data);
307 LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
308 jint *ptr = _env->GetIntArrayElements(data, NULL);
309 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800310 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700311 int id = rsContextGetMessage(con,
312 ptr, len * 4,
313 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700314 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700315 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100316 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700317 }
318 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Samsedbfabd2011-05-17 15:01:29 -0700319 return id;
Jason Sams1c415172010-11-08 17:06:46 -0800320}
321
322static jint
Jason Samsedbfabd2011-05-17 15:01:29 -0700323nContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800324{
325 LOG_API("nContextPeekMessage, con(%p)", con);
326 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
327 size_t receiveLen;
328 uint32_t subID;
Jason Sams65bdaf12011-04-26 14:50:00 -0700329 int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700330 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800331 auxDataPtr[0] = (jint)subID;
332 auxDataPtr[1] = (jint)receiveLen;
333 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Jason Sams516c3192009-10-06 13:58:47 -0700334 return id;
335}
336
Jason Sams2e1872f2010-08-17 16:25:41 -0700337static void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700338{
Jason Sams516c3192009-10-06 13:58:47 -0700339 LOG_API("nContextInitToClient, con(%p)", con);
340 rsContextInitToClient(con);
341}
342
Jason Sams2e1872f2010-08-17 16:25:41 -0700343static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
Jason Sams516c3192009-10-06 13:58:47 -0700344{
Jason Sams516c3192009-10-06 13:58:47 -0700345 LOG_API("nContextDeinitToClient, con(%p)", con);
346 rsContextDeinitToClient(con);
347}
348
349
Jason Sams718cd1f2009-12-23 14:35:29 -0800350static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700351nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700352{
Jason Sams718cd1f2009-12-23 14:35:29 -0800353 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
354 return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700355}
356
357static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800358nElementCreate2(JNIEnv *_env, jobject _this, RsContext con,
359 jintArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700360{
Jason Sams718cd1f2009-12-23 14:35:29 -0800361 int fieldCount = _env->GetArrayLength(_ids);
Jason Sams704ff642010-02-09 16:05:07 -0800362 LOG_API("nElementCreate2, con(%p)", con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800363
364 jint *ids = _env->GetIntArrayElements(_ids, NULL);
Jason Sams70d4e502010-09-02 17:35:23 -0700365 jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
Jason Sams718cd1f2009-12-23 14:35:29 -0800366
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800367 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
368
369 const char **nameArray = names.c_str();
370 size_t *sizeArray = names.c_str_len();
371
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700372 jint id = (jint)rsElementCreate2(con,
373 (RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700374 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700375 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800376
Jason Sams718cd1f2009-12-23 14:35:29 -0800377 _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
Jason Sams70d4e502010-09-02 17:35:23 -0700378 _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
Jason Sams718cd1f2009-12-23 14:35:29 -0800379 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700380}
381
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700382static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700383nElementGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700384{
385 int dataSize = _env->GetArrayLength(_elementData);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700386 LOG_API("nElementGetNativeData, con(%p)", con);
387
388 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
389 assert(dataSize == 5);
390
391 uint32_t elementData[5];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700392 rsaElementGetNativeData(con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700393
394 for(jint i = 0; i < dataSize; i ++) {
395 _env->SetIntArrayRegion(_elementData, i, 1, (const jint*)&elementData[i]);
396 }
397}
398
399
400static void
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700401nElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
402 jintArray _IDs,
403 jobjectArray _names,
404 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700405{
406 int dataSize = _env->GetArrayLength(_IDs);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700407 LOG_API("nElementGetSubElements, con(%p)", con);
408
409 uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
410 const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700411 uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700412
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700413 rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700414
Jason Sams11c8af92010-10-13 15:31:10 -0700415 for(jint i = 0; i < dataSize; i++) {
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700416 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
417 _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700418 _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700419 }
420
421 free(ids);
422 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700423 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700424}
425
Jason Samsd19f10d2009-05-22 14:03:28 -0700426// -----------------------------------
427
Jason Sams3b9c52a2010-10-14 17:48:46 -0700428static int
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800429nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
430 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces)
Jason Samsd19f10d2009-05-22 14:03:28 -0700431{
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800432 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
433 con, eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700434
Jason Samsc5765372011-04-28 18:26:48 -0700435 jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700436 return (jint)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700437}
438
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700439static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700440nTypeGetNativeData(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700441{
442 // We are packing 6 items: mDimX; mDimY; mDimZ;
443 // mDimLOD; mDimFaces; mElement; into typeData
444 int elementCount = _env->GetArrayLength(_typeData);
445
446 assert(elementCount == 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700447 LOG_API("nTypeCreate, con(%p)", con);
448
449 uint32_t typeData[6];
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700450 rsaTypeGetNativeData(con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700451
452 for(jint i = 0; i < elementCount; i ++) {
453 _env->SetIntArrayRegion(_typeData, i, 1, (const jint*)&typeData[i]);
454 }
455}
456
Jason Samsd19f10d2009-05-22 14:03:28 -0700457// -----------------------------------
458
459static jint
Jason Sams857d0c72011-11-23 15:02:15 -0800460nAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700461{
Jason Sams857d0c72011-11-23 15:02:15 -0800462 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer);
463 return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700464}
465
Jason Samsd19f10d2009-05-22 14:03:28 -0700466static void
Jason Sams5476b452010-12-08 16:14:36 -0800467nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
468{
469 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
470 rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
471}
472
Jason Sams615e7ce2012-01-13 14:01:20 -0800473static jint
474nAllocationGetSurfaceTextureID(JNIEnv *_env, jobject _this, RsContext con, jint a)
475{
476 LOG_API("nAllocationGetSurfaceTextureID, con(%p), a(%p)", con, (RsAllocation)a);
477 return rsAllocationGetSurfaceTextureID(con, (RsAllocation)a);
478}
479
Jason Samsf7086092011-01-12 13:28:37 -0800480static void
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700481nAllocationGetSurfaceTextureID2(JNIEnv *_env, jobject _this, RsContext con, jint a, jobject jst)
482{
483 LOG_API("nAllocationGetSurfaceTextureID2, con(%p), a(%p)", con, (RsAllocation)a);
484 sp<SurfaceTexture> st = SurfaceTexture_getSurfaceTexture(_env, jst);
485
486 rsAllocationGetSurfaceTextureID2(con, (RsAllocation)a, st.get(), sizeof(SurfaceTexture *));
487}
488
489static void
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700490nAllocationSetSurface(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800491{
Stephen Hines06883b72012-05-16 18:01:34 -0700492 LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)",
Jason Sams163766c2012-02-15 12:04:24 -0800493 con, alloc, (Surface *)sur);
494
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700495 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800496 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700497 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800498 }
499
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700500 rsAllocationSetSurface(con, alloc, static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800501}
502
503static void
504nAllocationIoSend(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
505{
506 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", con, alloc);
507 rsAllocationIoSend(con, alloc);
508}
509
510static void
511nAllocationIoReceive(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc)
512{
513 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", con, alloc);
514 rsAllocationIoReceive(con, alloc);
515}
516
517
518static void
Jason Samsf7086092011-01-12 13:28:37 -0800519nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
520{
521 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
522 rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
523}
524
Jason Samsffe9f482009-06-01 17:45:53 -0700525static int
Jason Sams5476b452010-12-08 16:14:36 -0800526nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700527{
Jason Samsffe9f482009-06-01 17:45:53 -0700528 SkBitmap const * nativeBitmap =
529 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
530 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700531
Jason Sams5476b452010-12-08 16:14:36 -0800532 bitmap.lockPixels();
533 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700534 jint id = (jint)rsAllocationCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700535 (RsType)type, (RsAllocationMipmapControl)mip,
536 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800537 bitmap.unlockPixels();
538 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700539}
Jason Samsfe08d992009-05-27 14:45:32 -0700540
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800541static int
Tim Murraya3145512012-12-04 17:59:29 -0800542nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
543{
544 SkBitmap const * nativeBitmap =
545 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
546 const SkBitmap& bitmap(*nativeBitmap);
547
548 bitmap.lockPixels();
549 const void* ptr = bitmap.getPixels();
550 jint id = (jint)rsAllocationCreateTyped(con,
551 (RsType)type, (RsAllocationMipmapControl)mip,
552 (uint32_t)usage, (size_t)ptr);
553 bitmap.unlockPixels();
554 return id;
555}
556
557static int
Jason Sams5476b452010-12-08 16:14:36 -0800558nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800559{
560 SkBitmap const * nativeBitmap =
561 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
562 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800563
Jason Sams5476b452010-12-08 16:14:36 -0800564 bitmap.lockPixels();
565 const void* ptr = bitmap.getPixels();
Jason Samsc5765372011-04-28 18:26:48 -0700566 jint id = (jint)rsAllocationCubeCreateFromBitmap(con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700567 (RsType)type, (RsAllocationMipmapControl)mip,
568 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800569 bitmap.unlockPixels();
570 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800571}
572
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700573static void
Jason Sams4ef66502010-12-10 16:03:15 -0800574nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700575{
576 SkBitmap const * nativeBitmap =
577 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
578 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800579 int w = bitmap.width();
580 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700581
Jason Sams4ef66502010-12-10 16:03:15 -0800582 bitmap.lockPixels();
583 const void* ptr = bitmap.getPixels();
Jason Samsf7086092011-01-12 13:28:37 -0800584 rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700585 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800586 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800587 bitmap.unlockPixels();
588}
589
590static void
591nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
592{
593 SkBitmap const * nativeBitmap =
594 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
595 const SkBitmap& bitmap(*nativeBitmap);
596
597 bitmap.lockPixels();
598 void* ptr = bitmap.getPixels();
599 rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
600 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700601 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700602}
603
Jason Sams8a647432010-03-01 15:31:04 -0800604static void ReleaseBitmapCallback(void *bmp)
605{
606 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
607 nativeBitmap->unlockPixels();
608}
609
Romain Guy650a3eb2009-08-31 14:06:43 -0700610
Jason Samsd19f10d2009-05-22 14:03:28 -0700611static void
Jason Sams49a05d72010-12-29 14:31:29 -0800612nAllocationData1D_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 -0700613{
Jason Samsd19f10d2009-05-22 14:03:28 -0700614 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800615 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 -0700616 jint *ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800617 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700618 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
619}
620
621static void
Jason Sams49a05d72010-12-29 14:31:29 -0800622nAllocationData1D_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 -0700623{
Jason Sams768bc022009-09-21 19:41:04 -0700624 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800625 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 -0700626 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800627 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700628 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
629}
630
631static void
Jason Sams49a05d72010-12-29 14:31:29 -0800632nAllocationData1D_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 -0700633{
Jason Sams768bc022009-09-21 19:41:04 -0700634 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800635 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 -0700636 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800637 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Sams768bc022009-09-21 19:41:04 -0700638 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
639}
640
641static void
Jason Sams49a05d72010-12-29 14:31:29 -0800642nAllocationData1D_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 -0700643{
Jason Samsd19f10d2009-05-22 14:03:28 -0700644 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800645 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 -0700646 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Jason Sams49a05d72010-12-29 14:31:29 -0800647 rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700648 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
649}
650
651static void
Jason Sams49a05d72010-12-29 14:31:29 -0800652// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
653nAllocationElementData1D(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 -0700654{
655 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800656 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 -0700657 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Stephen Hines4cbe25a2012-01-18 18:46:27 -0800658 rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700659 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
660}
661
662static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800663nAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
664 jint w, jint h, jshortArray data, int sizeBytes)
665{
666 jint len = _env->GetArrayLength(data);
667 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);
668 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Tim Murray38faea302012-11-27 14:55:08 -0800669 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800670 _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
671}
672
673static void
674nAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
675 jint w, jint h, jbyteArray data, int sizeBytes)
676{
677 jint len = _env->GetArrayLength(data);
678 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);
679 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Tim Murray38faea302012-11-27 14:55:08 -0800680 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800681 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
682}
683
684static void
Jason Sams49a05d72010-12-29 14:31:29 -0800685nAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
686 jint w, jint h, jintArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700687{
Jason Samsd19f10d2009-05-22 14:03:28 -0700688 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800689 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 -0700690 jint *ptr = _env->GetIntArrayElements(data, NULL);
Tim Murray38faea302012-11-27 14:55:08 -0800691 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700692 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
693}
694
695static void
Jason Sams49a05d72010-12-29 14:31:29 -0800696nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
697 jint w, jint h, jfloatArray data, int sizeBytes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700698{
Jason Samsd19f10d2009-05-22 14:03:28 -0700699 jint len = _env->GetArrayLength(data);
Jason Sams49a05d72010-12-29 14:31:29 -0800700 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 -0700701 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Tim Murray38faea302012-11-27 14:55:08 -0800702 rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700703 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
704}
705
Jason Sams40a29e82009-08-10 14:55:26 -0700706static void
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700707nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
708 jint dstAlloc, jint dstXoff, jint dstYoff,
709 jint dstMip, jint dstFace,
710 jint width, jint height,
711 jint srcAlloc, jint srcXoff, jint srcYoff,
712 jint srcMip, jint srcFace)
713{
Jason Sams4c2e4c82012-02-07 15:32:08 -0800714 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700715 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
716 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
717 con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
718 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
719
720 rsAllocationCopy2DRange(con,
721 (RsAllocation)dstAlloc,
722 dstXoff, dstYoff,
723 dstMip, dstFace,
724 width, height,
725 (RsAllocation)srcAlloc,
726 srcXoff, srcYoff,
727 srcMip, srcFace);
728}
729
730static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700731nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700732{
Jason Sams40a29e82009-08-10 14:55:26 -0700733 jint len = _env->GetArrayLength(data);
734 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
735 jint *ptr = _env->GetIntArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700736 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700737 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(int));
Joe Onoratoae209ac2009-08-31 17:23:53 -0700738 _env->ReleaseIntArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700739}
740
741static void
Jason Samsfb9f82c2011-01-12 14:53:25 -0800742nAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
743{
744 jint len = _env->GetArrayLength(data);
745 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
746 jshort *ptr = _env->GetShortArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700747 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700748 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(short));
Jason Samsfb9f82c2011-01-12 14:53:25 -0800749 _env->ReleaseShortArrayElements(data, ptr, 0);
750}
751
752static void
753nAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
754{
755 jint len = _env->GetArrayLength(data);
756 LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
757 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700758 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700759 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(char));
Jason Samsfb9f82c2011-01-12 14:53:25 -0800760 _env->ReleaseByteArrayElements(data, ptr, 0);
761}
762
763static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700764nAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
Jason Sams40a29e82009-08-10 14:55:26 -0700765{
Jason Sams40a29e82009-08-10 14:55:26 -0700766 jint len = _env->GetArrayLength(data);
Joe Onoratoa8f2ace2009-08-12 11:47:23 -0700767 LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
Jason Sams40a29e82009-08-10 14:55:26 -0700768 jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700769 jsize length = _env->GetArrayLength(data);
Jason Sams3655e442012-07-26 16:56:01 -0700770 rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(float));
Joe Onoratoae209ac2009-08-31 17:23:53 -0700771 _env->ReleaseFloatArrayElements(data, ptr, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700772}
Jason Samsd19f10d2009-05-22 14:03:28 -0700773
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700774static jint
Jason Sams2e1872f2010-08-17 16:25:41 -0700775nAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700776{
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700777 LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700778 return (jint) rsaAllocationGetType(con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700779}
780
Jason Sams5edc6082010-10-05 13:32:49 -0700781static void
782nAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
783{
784 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
785 rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
786}
787
788static void
789nAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY)
790{
791 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY);
792 rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY);
793}
794
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700795// -----------------------------------
796
797static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700798nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con, jint native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700799{
Steve Block71f2cf12011-10-20 11:56:00 +0100800 ALOGV("______nFileA3D %u", (uint32_t) native_asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700801
802 Asset* asset = reinterpret_cast<Asset*>(native_asset);
803
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800804 jint id = (jint)rsaFileA3DCreateFromMemory(con, asset->getBuffer(false), asset->getLength());
805 return id;
806}
807
808static int
809nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path)
810{
811 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
812 if (mgr == NULL) {
813 return 0;
814 }
815
816 AutoJavaStringToUTF8 str(_env, _path);
817 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
818 if (asset == NULL) {
819 return 0;
820 }
821
822 jint id = (jint)rsaFileA3DCreateFromAsset(con, asset);
823 return id;
824}
825
826static int
827nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, RsContext con, jstring fileName)
828{
829 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
830 jint id = (jint)rsaFileA3DCreateFromFile(con, fileNameUTF.c_str());
831
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700832 return id;
833}
834
835static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700836nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700837{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700838 int32_t numEntries = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700839 rsaFileA3DGetNumIndexEntries(con, &numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700840 return numEntries;
841}
842
843static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700844nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700845{
Steve Block71f2cf12011-10-20 11:56:00 +0100846 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700847 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
848
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700849 rsaFileA3DGetIndexEntries(con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700850
851 for(jint i = 0; i < numEntries; i ++) {
852 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
853 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
854 }
855
856 free(fileEntries);
857}
858
859static int
Jason Sams2e1872f2010-08-17 16:25:41 -0700860nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, RsContext con, jint fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700861{
Steve Block71f2cf12011-10-20 11:56:00 +0100862 ALOGV("______nFileA3D %u", (uint32_t) fileA3D);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700863 jint id = (jint)rsaFileA3DGetEntryByIndex(con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700864 return id;
865}
Jason Samsd19f10d2009-05-22 14:03:28 -0700866
867// -----------------------------------
868
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700869static int
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800870nFontCreateFromFile(JNIEnv *_env, jobject _this, RsContext con,
871 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700872{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800873 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700874 jint id = (jint)rsFontCreateFromFile(con,
875 fileNameUTF.c_str(), fileNameUTF.length(),
876 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700877
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800878 return id;
879}
880
881static int
882nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, RsContext con,
883 jstring name, jfloat fontSize, jint dpi, jint native_asset)
884{
885 Asset* asset = reinterpret_cast<Asset*>(native_asset);
886 AutoJavaStringToUTF8 nameUTF(_env, name);
887
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700888 jint id = (jint)rsFontCreateFromMemory(con,
889 nameUTF.c_str(), nameUTF.length(),
890 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800891 asset->getBuffer(false), asset->getLength());
892 return id;
893}
894
895static int
896nFontCreateFromAsset(JNIEnv *_env, jobject _this, RsContext con, jobject _assetMgr, jstring _path,
897 jfloat fontSize, jint dpi)
898{
899 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
900 if (mgr == NULL) {
901 return 0;
902 }
903
904 AutoJavaStringToUTF8 str(_env, _path);
905 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
906 if (asset == NULL) {
907 return 0;
908 }
909
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700910 jint id = (jint)rsFontCreateFromMemory(con,
911 str.c_str(), str.length(),
912 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800913 asset->getBuffer(false), asset->getLength());
914 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700915 return id;
916}
917
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700918// -----------------------------------
919
920static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700921nScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700922{
Jason Samsd19f10d2009-05-22 14:03:28 -0700923 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsbc948de2009-08-17 18:35:48 -0700924 rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700925}
926
927static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700928nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700929{
Jason Samscfc04362010-09-14 14:59:03 -0700930 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700931 rsScriptSetVarI(con, (RsScript)script, slot, val);
932}
933
934static void
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800935nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
936{
937 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
938 rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
939}
940
941static void
Stephen Hines031ec58c2010-10-11 10:54:21 -0700942nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
943{
944 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
945 rsScriptSetVarJ(con, (RsScript)script, slot, val);
946}
947
948static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700949nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700950{
Stephen Hinesca54ec32010-09-20 17:20:30 -0700951 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700952 rsScriptSetVarF(con, (RsScript)script, slot, val);
953}
954
955static void
Stephen Hinesca54ec32010-09-20 17:20:30 -0700956nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
957{
958 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
959 rsScriptSetVarD(con, (RsScript)script, slot, val);
960}
961
962static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700963nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -0700964{
Jason Sams4d339932010-05-11 14:03:58 -0700965 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
966 jint len = _env->GetArrayLength(data);
967 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
968 rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
969 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
970}
971
Stephen Hinesadeb8092012-04-20 14:26:06 -0700972static void
973nScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims)
974{
975 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
976 jint len = _env->GetArrayLength(data);
977 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
978 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
979 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
980 rsScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem,
981 (const size_t*) dimsPtr, dimsLen);
982 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
983 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
984}
985
Jason Samsd19f10d2009-05-22 14:03:28 -0700986
987static void
Jason Sams2e1872f2010-08-17 16:25:41 -0700988nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -0700989{
Jason Sams07ae4062009-08-27 20:23:34 -0700990 LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
Romain Guy584a3752009-07-30 18:45:01 -0700991
992 jint length = _env->GetArrayLength(timeZone);
993 jbyte* timeZone_ptr;
994 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
995
Jason Samsbc948de2009-08-17 18:35:48 -0700996 rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -0700997
998 if (timeZone_ptr) {
999 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1000 }
1001}
1002
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001003static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001004nScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001005{
Jason Samsbe2e8412009-09-16 15:04:38 -07001006 LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
1007 rsScriptInvoke(con, (RsScript)obj, slot);
1008}
1009
1010static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001011nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001012{
Jason Sams4d339932010-05-11 14:03:58 -07001013 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1014 jint len = _env->GetArrayLength(data);
1015 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1016 rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
1017 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1018}
1019
Jason Sams6e494d32011-04-27 16:33:11 -07001020static void
1021nScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
1022 jint script, jint slot, jint ain, jint aout)
1023{
1024 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1025 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0);
1026}
1027static void
1028nScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
1029 jint script, jint slot, jint ain, jint aout, jbyteArray params)
1030{
1031 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
1032 jint len = _env->GetArrayLength(params);
1033 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
1034 rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len);
1035 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1036}
1037
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001038
Jason Sams22534172009-08-04 16:58:20 -07001039// -----------------------------------
1040
Jason Samse4a06c52011-03-16 16:29:28 -07001041static jint
1042nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
1043 jstring resName, jstring cacheDir,
1044 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001045{
Jason Samse4a06c52011-03-16 16:29:28 -07001046 LOG_API("nScriptCCreate, con(%p)", con);
Jason Sams22534172009-08-04 16:58:20 -07001047
Jason Samse4a06c52011-03-16 16:29:28 -07001048 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1049 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
1050 jint ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -07001051 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -07001052 jint _exception = 0;
1053 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001054 if (!scriptRef) {
1055 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001056 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001057 goto exit;
1058 }
Jack Palevich43702d82009-05-28 13:38:16 -07001059 if (length < 0) {
1060 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001061 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001062 goto exit;
1063 }
Jason Samse4a06c52011-03-16 16:29:28 -07001064 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001065 if (remaining < length) {
1066 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001067 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1068 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001069 goto exit;
1070 }
Jason Samse4a06c52011-03-16 16:29:28 -07001071 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001072 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001073
Jason Samse4a06c52011-03-16 16:29:28 -07001074 //rsScriptCSetText(con, (const char *)script_ptr, length);
1075
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001076 ret = (jint)rsScriptCCreate(con,
1077 resNameUTF.c_str(), resNameUTF.length(),
1078 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001079 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001080
Jack Palevich43702d82009-05-28 13:38:16 -07001081exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001082 if (script_ptr) {
1083 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001084 _exception ? JNI_ABORT: 0);
1085 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001086
Jason Samse4a06c52011-03-16 16:29:28 -07001087 return ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001088}
1089
Jason Sams6ab97682012-08-10 12:09:43 -07001090static jint
1091nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, RsContext con, jint id, jint eid)
1092{
1093 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", con, id, (void *)eid);
1094 return (jint)rsScriptIntrinsicCreate(con, id, (RsElement)eid);
1095}
1096
Jason Sams08a81582012-09-18 12:32:10 -07001097static jint
1098nScriptKernelIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot, jint sig)
1099{
1100 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", con, (void *)sid, slot, sig);
1101 return (jint)rsScriptKernelIDCreate(con, (RsScript)sid, slot, sig);
1102}
1103
1104static jint
1105nScriptFieldIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot)
1106{
1107 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", con, (void *)sid, slot);
1108 return (jint)rsScriptFieldIDCreate(con, (RsScript)sid, slot);
1109}
1110
1111static jint
1112nScriptGroupCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _kernels, jintArray _src,
1113 jintArray _dstk, jintArray _dstf, jintArray _types)
1114{
1115 LOG_API("nScriptGroupCreate, con(%p)", con);
1116
1117 jint kernelsLen = _env->GetArrayLength(_kernels) * sizeof(int);
1118 jint *kernelsPtr = _env->GetIntArrayElements(_kernels, NULL);
1119 jint srcLen = _env->GetArrayLength(_src) * sizeof(int);
1120 jint *srcPtr = _env->GetIntArrayElements(_src, NULL);
1121 jint dstkLen = _env->GetArrayLength(_dstk) * sizeof(int);
1122 jint *dstkPtr = _env->GetIntArrayElements(_dstk, NULL);
1123 jint dstfLen = _env->GetArrayLength(_dstf) * sizeof(int);
1124 jint *dstfPtr = _env->GetIntArrayElements(_dstf, NULL);
1125 jint typesLen = _env->GetArrayLength(_types) * sizeof(int);
1126 jint *typesPtr = _env->GetIntArrayElements(_types, NULL);
1127
1128 int id = (int)rsScriptGroupCreate(con,
1129 (RsScriptKernelID *)kernelsPtr, kernelsLen,
1130 (RsScriptKernelID *)srcPtr, srcLen,
1131 (RsScriptKernelID *)dstkPtr, dstkLen,
1132 (RsScriptFieldID *)dstfPtr, dstfLen,
1133 (RsType *)typesPtr, typesLen);
1134
1135 _env->ReleaseIntArrayElements(_kernels, kernelsPtr, 0);
1136 _env->ReleaseIntArrayElements(_src, srcPtr, 0);
1137 _env->ReleaseIntArrayElements(_dstk, dstkPtr, 0);
1138 _env->ReleaseIntArrayElements(_dstf, dstfPtr, 0);
1139 _env->ReleaseIntArrayElements(_types, typesPtr, 0);
1140 return id;
1141}
1142
1143static void
1144nScriptGroupSetInput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
1145{
1146 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
1147 (void *)gid, (void *)kid, (void *)alloc);
1148 rsScriptGroupSetInput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
1149}
1150
1151static void
1152nScriptGroupSetOutput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
1153{
1154 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
1155 (void *)gid, (void *)kid, (void *)alloc);
1156 rsScriptGroupSetOutput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
1157}
1158
1159static void
1160nScriptGroupExecute(JNIEnv *_env, jobject _this, RsContext con, jint gid)
1161{
1162 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", con, (void *)gid);
1163 rsScriptGroupExecute(con, (RsScriptGroup)gid);
1164}
1165
Jason Samsd19f10d2009-05-22 14:03:28 -07001166// ---------------------------------------------------------------------------
1167
Jason Samsd19f10d2009-05-22 14:03:28 -07001168static jint
Jason Sams331bf9b2011-04-06 11:23:54 -07001169nProgramStoreCreate(JNIEnv *_env, jobject _this, RsContext con,
1170 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1171 jboolean depthMask, jboolean ditherEnable,
1172 jint srcFunc, jint destFunc,
1173 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001174{
Jason Sams54db59c2010-05-13 18:30:11 -07001175 LOG_API("nProgramStoreCreate, con(%p)", con);
Jason Sams331bf9b2011-04-06 11:23:54 -07001176 return (jint)rsProgramStoreCreate(con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
1177 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1178 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001179}
1180
Jason Sams0011bcf2009-12-15 12:58:36 -08001181// ---------------------------------------------------------------------------
1182
1183static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001184nProgramBindConstants(JNIEnv *_env, jobject _this, RsContext con, jint vpv, jint slot, jint a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001185{
Jason Sams0011bcf2009-12-15 12:58:36 -08001186 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
1187 rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
1188}
Jason Sams54c0ec12009-11-30 14:49:55 -08001189
Jason Sams68afd012009-12-17 16:55:08 -08001190static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001191nProgramBindTexture(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001192{
Jason Sams68afd012009-12-17 16:55:08 -08001193 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1194 rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
1195}
1196
1197static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001198nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint slot, jint a)
Jason Sams68afd012009-12-17 16:55:08 -08001199{
Jason Sams68afd012009-12-17 16:55:08 -08001200 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1201 rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
1202}
1203
Jason Samsd19f10d2009-05-22 14:03:28 -07001204// ---------------------------------------------------------------------------
1205
Jason Samsd19f10d2009-05-22 14:03:28 -07001206static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001207nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1208 jobjectArray texNames, jintArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001209{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001210 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001211 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1212 jint paramLen = _env->GetArrayLength(params);
1213
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001214 int texCount = _env->GetArrayLength(texNames);
1215 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1216 const char ** nameArray = names.c_str();
1217 size_t* sizeArray = names.c_str_len();
1218
Jason Sams991040c2011-01-17 15:59:39 -08001219 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001220
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001221 jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1222 nameArray, texCount, sizeArray,
1223 (uint32_t *)paramPtr, paramLen);
1224
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001225 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1226 return ret;
1227}
1228
1229
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001230// ---------------------------------------------------------------------------
1231
Jason Sams0011bcf2009-12-15 12:58:36 -08001232static jint
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001233nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader,
1234 jobjectArray texNames, jintArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001235{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001236 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Jason Sams0011bcf2009-12-15 12:58:36 -08001237 jint *paramPtr = _env->GetIntArrayElements(params, NULL);
1238 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001239
Jason Sams991040c2011-01-17 15:59:39 -08001240 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001241
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001242 int texCount = _env->GetArrayLength(texNames);
1243 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1244 const char ** nameArray = names.c_str();
1245 size_t* sizeArray = names.c_str_len();
1246
1247 jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(),
1248 nameArray, texCount, sizeArray,
1249 (uint32_t *)paramPtr, paramLen);
1250
Jason Sams0011bcf2009-12-15 12:58:36 -08001251 _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
1252 return ret;
1253}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001254
Jason Samsebfb4362009-09-23 13:57:02 -07001255// ---------------------------------------------------------------------------
1256
1257static jint
Jason Sams94aaed32011-09-23 14:18:53 -07001258nProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001259{
Jason Sams94aaed32011-09-23 14:18:53 -07001260 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", con, pointSprite, cull);
1261 return (jint)rsProgramRasterCreate(con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001262}
1263
Jason Samsd19f10d2009-05-22 14:03:28 -07001264
1265// ---------------------------------------------------------------------------
1266
1267static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001268nContextBindRootScript(JNIEnv *_env, jobject _this, RsContext con, jint script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001269{
Jason Samsd19f10d2009-05-22 14:03:28 -07001270 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script);
Jason Samsbc948de2009-08-17 18:35:48 -07001271 rsContextBindRootScript(con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001272}
1273
1274static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001275nContextBindProgramStore(JNIEnv *_env, jobject _this, RsContext con, jint pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001276{
Jason Sams54db59c2010-05-13 18:30:11 -07001277 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", con, (RsProgramStore)pfs);
1278 rsContextBindProgramStore(con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001279}
1280
1281static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001282nContextBindProgramFragment(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001283{
Jason Samsd19f10d2009-05-22 14:03:28 -07001284 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001285 rsContextBindProgramFragment(con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001286}
1287
Jason Sams0826a6f2009-06-15 19:04:56 -07001288static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001289nContextBindProgramVertex(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001290{
Jason Sams0826a6f2009-06-15 19:04:56 -07001291 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
Jason Samsbc948de2009-08-17 18:35:48 -07001292 rsContextBindProgramVertex(con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001293}
1294
Joe Onoratod7b37742009-08-09 22:57:44 -07001295static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001296nContextBindProgramRaster(JNIEnv *_env, jobject _this, RsContext con, jint pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001297{
Jason Samsebfb4362009-09-23 13:57:02 -07001298 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", con, (RsProgramRaster)pf);
1299 rsContextBindProgramRaster(con, (RsProgramRaster)pf);
1300}
1301
Joe Onoratod7b37742009-08-09 22:57:44 -07001302
Jason Sams02fb2cb2009-05-28 15:37:57 -07001303// ---------------------------------------------------------------------------
1304
Jason Sams02fb2cb2009-05-28 15:37:57 -07001305static jint
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001306nSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
1307 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001308{
Jason Samsbba134c2009-06-22 15:49:21 -07001309 LOG_API("nSamplerCreate, con(%p)", con);
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001310 return (jint)rsSamplerCreate(con,
1311 (RsSamplerValue)magFilter,
1312 (RsSamplerValue)minFilter,
1313 (RsSamplerValue)wrapS,
1314 (RsSamplerValue)wrapT,
1315 (RsSamplerValue)wrapR,
1316 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001317}
1318
Jason Samsbba134c2009-06-22 15:49:21 -07001319// ---------------------------------------------------------------------------
1320
Jason Samsf15ed012011-10-31 13:23:43 -07001321//native int rsnPathCreate(int con, int prim, boolean isStatic, int vtx, int loop, float q);
1322static jint
1323nPathCreate(JNIEnv *_env, jobject _this, RsContext con, jint prim, jboolean isStatic, jint _vtx, jint _loop, jfloat q) {
1324 LOG_API("nPathCreate, con(%p)", con);
1325
1326 int id = (int)rsPathCreate(con, (RsPathPrimitive)prim, isStatic,
1327 (RsAllocation)_vtx,
1328 (RsAllocation)_loop, q);
1329 return id;
1330}
1331
Jason Samsbba134c2009-06-22 15:49:21 -07001332static jint
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001333nMeshCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _vtx, jintArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001334{
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001335 LOG_API("nMeshCreate, con(%p)", con);
1336
1337 jint vtxLen = _env->GetArrayLength(_vtx);
1338 jint *vtxPtr = _env->GetIntArrayElements(_vtx, NULL);
1339 jint idxLen = _env->GetArrayLength(_idx);
1340 jint *idxPtr = _env->GetIntArrayElements(_idx, NULL);
1341 jint primLen = _env->GetArrayLength(_prim);
1342 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1343
1344 int id = (int)rsMeshCreate(con,
1345 (RsAllocation *)vtxPtr, vtxLen,
1346 (RsAllocation *)idxPtr, idxLen,
1347 (uint32_t *)primPtr, primLen);
1348
1349 _env->ReleaseIntArrayElements(_vtx, vtxPtr, 0);
1350 _env->ReleaseIntArrayElements(_idx, idxPtr, 0);
1351 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001352 return id;
1353}
1354
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001355static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001356nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001357{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001358 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1359 jint vtxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001360 rsaMeshGetVertexBufferCount(con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001361 return vtxCount;
1362}
1363
1364static jint
Jason Sams2e1872f2010-08-17 16:25:41 -07001365nMeshGetIndexCount(JNIEnv *_env, jobject _this, RsContext con, jint mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001366{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001367 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1368 jint idxCount = 0;
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001369 rsaMeshGetIndexCount(con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001370 return idxCount;
1371}
1372
1373static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001374nMeshGetVertices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _ids, int numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001375{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001376 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1377
1378 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001379 rsaMeshGetVertices(con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001380
1381 for(jint i = 0; i < numVtxIDs; i ++) {
1382 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&allocs[i]);
1383 }
1384
1385 free(allocs);
1386}
1387
1388static void
Jason Sams2e1872f2010-08-17 16:25:41 -07001389nMeshGetIndices(JNIEnv *_env, jobject _this, RsContext con, jint mesh, jintArray _idxIds, jintArray _primitives, int numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001390{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001391 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", con, (RsMesh)mesh);
1392
1393 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1394 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1395
Alex Sakhartchouk581cc642010-10-27 14:10:07 -07001396 rsaMeshGetIndices(con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001397
1398 for(jint i = 0; i < numIndices; i ++) {
1399 _env->SetIntArrayRegion(_idxIds, i, 1, (const jint*)&allocs[i]);
1400 _env->SetIntArrayRegion(_primitives, i, 1, (const jint*)&prims[i]);
1401 }
1402
1403 free(allocs);
1404 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001405}
1406
1407// ---------------------------------------------------------------------------
1408
Jason Samsd19f10d2009-05-22 14:03:28 -07001409
Jason Sams94d8e90a2009-06-10 16:09:05 -07001410static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001411
1412static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001413{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001414
Jason Sams1c415172010-11-08 17:06:46 -08001415{"nDeviceCreate", "()I", (void*)nDeviceCreate },
1416{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
1417{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig },
Jason Samsedbfabd2011-05-17 15:01:29 -07001418{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001419{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage },
Jason Samsedbfabd2011-05-17 15:01:29 -07001420{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001421
1422{"nContextInitToClient", "(I)V", (void*)nContextInitToClient },
1423{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001424
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001425
Jason Sams2e1872f2010-08-17 16:25:41 -07001426// All methods below are thread protected in java.
Stephen Hines4382467a2011-08-01 15:02:34 -07001427{"rsnContextCreate", "(III)I", (void*)nContextCreate },
1428{"rsnContextCreateGL", "(IIIIIIIIIIIIIFI)I", (void*)nContextCreateGL },
Jason Sams2e1872f2010-08-17 16:25:41 -07001429{"rsnContextFinish", "(I)V", (void*)nContextFinish },
1430{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority },
1431{"rsnContextSetSurface", "(IIILandroid/view/Surface;)V", (void*)nContextSetSurface },
Jason Samsfaa32b32011-06-20 16:58:04 -07001432{"rsnContextSetSurfaceTexture", "(IIILandroid/graphics/SurfaceTexture;)V", (void*)nContextSetSurfaceTexture },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001433{"rsnContextDestroy", "(I)V", (void*)nContextDestroy },
Jason Sams2e1872f2010-08-17 16:25:41 -07001434{"rsnContextDump", "(II)V", (void*)nContextDump },
1435{"rsnContextPause", "(I)V", (void*)nContextPause },
1436{"rsnContextResume", "(I)V", (void*)nContextResume },
1437{"rsnAssignName", "(II[B)V", (void*)nAssignName },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001438{"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName },
Jason Sams2e1872f2010-08-17 16:25:41 -07001439{"rsnObjDestroy", "(II)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001440
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001441{"rsnFileA3DCreateFromFile", "(ILjava/lang/String;)I", (void*)nFileA3DCreateFromFile },
Jason Sams2e1872f2010-08-17 16:25:41 -07001442{"rsnFileA3DCreateFromAssetStream", "(II)I", (void*)nFileA3DCreateFromAssetStream },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001443{"rsnFileA3DCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;)I", (void*)nFileA3DCreateFromAsset },
Jason Sams2e1872f2010-08-17 16:25:41 -07001444{"rsnFileA3DGetNumIndexEntries", "(II)I", (void*)nFileA3DGetNumIndexEntries },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001445{"rsnFileA3DGetIndexEntries", "(III[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Jason Sams2e1872f2010-08-17 16:25:41 -07001446{"rsnFileA3DGetEntryByIndex", "(III)I", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001447
Alex Sakhartchouke27cdee2010-12-17 11:41:08 -08001448{"rsnFontCreateFromFile", "(ILjava/lang/String;FI)I", (void*)nFontCreateFromFile },
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001449{"rsnFontCreateFromAssetStream", "(ILjava/lang/String;FII)I", (void*)nFontCreateFromAssetStream },
1450{"rsnFontCreateFromAsset", "(ILandroid/content/res/AssetManager;Ljava/lang/String;FI)I", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001451
Jason Sams2e1872f2010-08-17 16:25:41 -07001452{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate },
Jason Sams70d4e502010-09-02 17:35:23 -07001453{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 },
Jason Sams2e1872f2010-08-17 16:25:41 -07001454{"rsnElementGetNativeData", "(II[I)V", (void*)nElementGetNativeData },
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -07001455{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001456
Jason Samsbf6ef8d72010-12-06 15:59:59 -08001457{"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001458{"rsnTypeGetNativeData", "(II[I)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001459
Jason Sams857d0c72011-11-23 15:02:15 -08001460{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped },
Jason Sams5476b452010-12-08 16:14:36 -08001461{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap },
Tim Murraya3145512012-12-04 17:59:29 -08001462{"rsnAllocationCreateBitmapBackedAllocation", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateBitmapBackedAllocation },
Jason Sams5476b452010-12-08 16:14:36 -08001463{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001464
Jason Sams4ef66502010-12-10 16:03:15 -08001465{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1466{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
1467
Jason Sams5476b452010-12-08 16:14:36 -08001468{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll },
Jason Sams615e7ce2012-01-13 14:01:20 -08001469{"rsnAllocationGetSurfaceTextureID", "(II)I", (void*)nAllocationGetSurfaceTextureID },
Jason Samsfe1d5ff2012-03-23 11:47:26 -07001470{"rsnAllocationGetSurfaceTextureID2","(IILandroid/graphics/SurfaceTexture;)V",(void*)nAllocationGetSurfaceTextureID2 },
Jason Samsfb9aa9f2012-03-28 15:30:07 -07001471{"rsnAllocationSetSurface", "(IILandroid/view/Surface;)V", (void*)nAllocationSetSurface },
Jason Sams163766c2012-02-15 12:04:24 -08001472{"rsnAllocationIoSend", "(II)V", (void*)nAllocationIoSend },
1473{"rsnAllocationIoReceive", "(II)V", (void*)nAllocationIoReceive },
Jason Sams49a05d72010-12-29 14:31:29 -08001474{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i },
1475{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s },
1476{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b },
1477{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f },
1478{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D },
1479{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001480{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s },
1481{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b },
Jason Sams49a05d72010-12-29 14:31:29 -08001482{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f },
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -07001483{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc },
Jason Sams2e1872f2010-08-17 16:25:41 -07001484{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i },
Jason Samsfb9f82c2011-01-12 14:53:25 -08001485{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s },
1486{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b },
Jason Sams2e1872f2010-08-17 16:25:41 -07001487{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f },
Jason Sams2e1872f2010-08-17 16:25:41 -07001488{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType},
Jason Sams5edc6082010-10-05 13:32:49 -07001489{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D },
1490{"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D },
Jason Samsf7086092011-01-12 13:28:37 -08001491{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001492
Jason Sams2e1872f2010-08-17 16:25:41 -07001493{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation },
1494{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone },
1495{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke },
1496{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV },
Jason Sams6e494d32011-04-27 16:33:11 -07001497{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach },
1498{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV },
Jason Sams2e1872f2010-08-17 16:25:41 -07001499{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI },
Stephen Hines031ec58c2010-10-11 10:54:21 -07001500{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ },
Jason Sams2e1872f2010-08-17 16:25:41 -07001501{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
Stephen Hinesca54ec32010-09-20 17:20:30 -07001502{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
Jason Sams2e1872f2010-08-17 16:25:41 -07001503{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
Stephen Hinesadeb8092012-04-20 14:26:06 -07001504{"rsnScriptSetVarVE", "(III[BI[I)V", (void*)nScriptSetVarVE },
Jason Sams6f4cf0b2010-11-16 17:37:02 -08001505{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001506
Jason Samse4a06c52011-03-16 16:29:28 -07001507{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },
Jason Sams6ab97682012-08-10 12:09:43 -07001508{"rsnScriptIntrinsicCreate", "(III)I", (void*)nScriptIntrinsicCreate },
Jason Sams08a81582012-09-18 12:32:10 -07001509{"rsnScriptKernelIDCreate", "(IIII)I", (void*)nScriptKernelIDCreate },
1510{"rsnScriptFieldIDCreate", "(III)I", (void*)nScriptFieldIDCreate },
1511{"rsnScriptGroupCreate", "(I[I[I[I[I[I)I", (void*)nScriptGroupCreate },
1512{"rsnScriptGroupSetInput", "(IIII)V", (void*)nScriptGroupSetInput },
1513{"rsnScriptGroupSetOutput", "(IIII)V", (void*)nScriptGroupSetOutput },
1514{"rsnScriptGroupExecute", "(II)V", (void*)nScriptGroupExecute },
Jason Sams0011bcf2009-12-15 12:58:36 -08001515
Jason Sams331bf9b2011-04-06 11:23:54 -07001516{"rsnProgramStoreCreate", "(IZZZZZZIII)I", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001517
Jason Sams2e1872f2010-08-17 16:25:41 -07001518{"rsnProgramBindConstants", "(IIII)V", (void*)nProgramBindConstants },
1519{"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture },
1520{"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001521
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001522{"rsnProgramFragmentCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate },
Jason Sams94aaed32011-09-23 14:18:53 -07001523{"rsnProgramRasterCreate", "(IZI)I", (void*)nProgramRasterCreate },
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001524{"rsnProgramVertexCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001525
Jason Sams2e1872f2010-08-17 16:25:41 -07001526{"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001527{"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore },
Jason Sams2e1872f2010-08-17 16:25:41 -07001528{"rsnContextBindProgramFragment", "(II)V", (void*)nContextBindProgramFragment },
1529{"rsnContextBindProgramVertex", "(II)V", (void*)nContextBindProgramVertex },
1530{"rsnContextBindProgramRaster", "(II)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001531
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001532{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001533
Jason Samsf15ed012011-10-31 13:23:43 -07001534{"rsnPathCreate", "(IIZIIF)I", (void*)nPathCreate },
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001535{"rsnMeshCreate", "(I[I[I[I)I", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001536
1537{"rsnMeshGetVertexBufferCount", "(II)I", (void*)nMeshGetVertexBufferCount },
1538{"rsnMeshGetIndexCount", "(II)I", (void*)nMeshGetIndexCount },
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -07001539{"rsnMeshGetVertices", "(II[II)V", (void*)nMeshGetVertices },
Jason Sams2e1872f2010-08-17 16:25:41 -07001540{"rsnMeshGetIndices", "(II[I[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001541
Jason Samsd19f10d2009-05-22 14:03:28 -07001542};
1543
1544static int registerFuncs(JNIEnv *_env)
1545{
1546 return android::AndroidRuntime::registerNativeMethods(
1547 _env, classPathName, methods, NELEM(methods));
1548}
1549
1550// ---------------------------------------------------------------------------
1551
1552jint JNI_OnLoad(JavaVM* vm, void* reserved)
1553{
1554 JNIEnv* env = NULL;
1555 jint result = -1;
1556
Jason Samsd19f10d2009-05-22 14:03:28 -07001557 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001558 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001559 goto bail;
1560 }
1561 assert(env != NULL);
1562
1563 if (registerFuncs(env) < 0) {
Steve Block3762c312012-01-06 19:20:56 +00001564 ALOGE("ERROR: MediaPlayer native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001565 goto bail;
1566 }
1567
1568 /* success -- return valid version number */
1569 result = JNI_VERSION_1_4;
1570
1571bail:
1572 return result;
1573}